-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename test_unet.py to test_sd15_unet.py + use test_device fixture
- Loading branch information
1 parent
4eceda8
commit 2c0174f
Showing
2 changed files
with
31 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
import torch | ||
|
||
from refiners.fluxion import manual_seed | ||
from refiners.fluxion.utils import no_grad | ||
from refiners.foundationals.latent_diffusion import SD1UNet | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def refiners_sd15_unet(test_device: torch.device) -> SD1UNet: | ||
unet = SD1UNet(in_channels=4, device=test_device) | ||
return unet | ||
|
||
|
||
def test_unet_context_flush(refiners_sd15_unet: SD1UNet): | ||
manual_seed(0) | ||
text_embedding = torch.randn(1, 77, 768, device=refiners_sd15_unet.device, dtype=refiners_sd15_unet.dtype) | ||
timestep = torch.randint(0, 999, size=(1, 1), device=refiners_sd15_unet.device) | ||
x = torch.randn(1, 4, 32, 32, device=refiners_sd15_unet.device, dtype=refiners_sd15_unet.dtype) | ||
|
||
refiners_sd15_unet.set_clip_text_embedding(clip_text_embedding=text_embedding) # not flushed between forward-s | ||
|
||
with no_grad(): | ||
refiners_sd15_unet.set_timestep(timestep=timestep) | ||
y_1 = refiners_sd15_unet(x.clone()) | ||
|
||
with no_grad(): | ||
refiners_sd15_unet.set_timestep(timestep=timestep) | ||
y_2 = refiners_sd15_unet(x.clone()) | ||
|
||
assert torch.equal(y_1, y_2) |
This file was deleted.
Oops, something went wrong.