Skip to content

Commit 35099b2

Browse files
[Versatile Diffusion] Fix remaining tests (#1418)
fix all tests
1 parent 2c6bc0f commit 35099b2

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class VersatileDiffusionDualGuidedPipeline(DiffusionPipeline):
6565
vae: AutoencoderKL
6666
scheduler: Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]
6767

68+
_optional_components = ["text_unet"]
69+
6870
def __init__(
6971
self,
7072
tokenizer: CLIPTokenizer,
@@ -143,6 +145,8 @@ def _revert_dual_attention(self):
143145
index = int(index)
144146
self.image_unet.get_submodule(parent_name)[index] = module.transformers[0]
145147

148+
self.image_unet.register_to_config(dual_cross_attention=False)
149+
146150
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_xformers_memory_efficient_attention with unet->image_unet
147151
def enable_xformers_memory_efficient_attention(self):
148152
r"""

src/diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class VersatileDiffusionTextToImagePipeline(DiffusionPipeline):
5757
vae: AutoencoderKL
5858
scheduler: Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]
5959

60+
_optional_components = ["text_unet"]
61+
6062
def __init__(
6163
self,
6264
tokenizer: CLIPTokenizer,

tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ def test_inference_image_variations(self):
5454
image_slice = image[0, 253:256, 253:256, -1]
5555

5656
assert image.shape == (1, 512, 512, 3)
57-
print(torch.from_numpy(image_slice.flatten()))
58-
expected_slice = np.array([0.0113, 0.2241, 0.4024, 0.0839, 0.0871, 0.2725, 0.2581, 0.0, 0.1096])
57+
expected_slice = np.array([0.1205, 0.1914, 0.2289, 0.0883, 0.1595, 0.1683, 0.0703, 0.1493, 0.1298])
5958
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_inference_dual_guided_then_text_to_image(self):
104104
image_slice = image[0, 253:256, 253:256, -1]
105105

106106
assert image.shape == (1, 512, 512, 3)
107-
expected_slice = np.array([0.014, 0.0112, 0.0136, 0.0145, 0.0107, 0.0113, 0.0272, 0.0215, 0.0216])
107+
expected_slice = np.array([0.0081, 0.0032, 0.0002, 0.0056, 0.0027, 0.0000, 0.0051, 0.0020, 0.0007])
108108
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
109109

110110
prompt = "A painting of a squirrel eating a burger "
@@ -119,11 +119,10 @@ def test_inference_dual_guided_then_text_to_image(self):
119119
expected_slice = np.array([0.0408, 0.0181, 0.0, 0.0388, 0.0046, 0.0461, 0.0411, 0.0, 0.0222])
120120
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
121121

122-
pipe = VersatileDiffusionPipeline.from_pretrained("shi-labs/versatile-diffusion", torch_dtype=torch.float16)
123-
image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images[0]
122+
image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images
124123

125124
image_slice = image[0, 253:256, 253:256, -1]
126125

127126
assert image.shape == (1, 512, 512, 3)
128-
expected_slice = np.array([0.0657, 0.0529, 0.0455, 0.0802, 0.0570, 0.0179, 0.0267, 0.0483, 0.0769])
127+
expected_slice = np.array([0.3479, 0.1943, 0.1060, 0.3894, 0.2537, 0.1394, 0.3989, 0.3191, 0.1987])
129128
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

0 commit comments

Comments
 (0)