Skip to content

Commit 1f0570d

Browse files
committed
update
1 parent a176cfd commit 1f0570d

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
from diffusers import (
2626
ClassifierFreeGuidance,
27-
ComponentsManager,
2827
ModularPipeline,
2928
StableDiffusionXLAutoBlocks,
3029
StableDiffusionXLModularPipeline,
@@ -33,7 +32,6 @@
3332
from diffusers.utils.testing_utils import (
3433
enable_full_determinism,
3534
floats_tensor,
36-
require_torch_accelerator,
3735
torch_device,
3836
)
3937

@@ -99,9 +97,9 @@ def _test_stable_diffusion_xl_euler(self, expected_image_shape, expected_slice,
9997

10098
assert image.shape == expected_image_shape
10199

102-
assert (
103-
np.abs(image_slice.flatten() - expected_slice).max() < expected_max_diff
104-
), "Image Slice does not match expected slice"
100+
assert np.abs(image_slice.flatten() - expected_slice).max() < expected_max_diff, (
101+
"Image Slice does not match expected slice"
102+
)
105103

106104

107105
class SDXLModularIPAdapterTests:
@@ -114,20 +112,20 @@ def test_pipeline_inputs_and_blocks(self):
114112
parameters = blocks.input_names
115113

116114
assert issubclass(self.pipeline_class, ModularIPAdapterMixin)
117-
assert (
118-
"ip_adapter_image" in parameters
119-
), "`ip_adapter_image` argument must be supported by the `__call__` method"
115+
assert "ip_adapter_image" in parameters, (
116+
"`ip_adapter_image` argument must be supported by the `__call__` method"
117+
)
120118
assert "ip_adapter" in blocks.sub_blocks, "pipeline must contain an IPAdapter block"
121119

122120
_ = blocks.sub_blocks.pop("ip_adapter")
123121
parameters = blocks.input_names
124122
intermediate_parameters = blocks.intermediate_input_names
125-
assert (
126-
"ip_adapter_image" not in parameters
127-
), "`ip_adapter_image` argument must be removed from the `__call__` method"
128-
assert (
129-
"ip_adapter_image_embeds" not in intermediate_parameters
130-
), "`ip_adapter_image_embeds` argument must be supported by the `__call__` method"
123+
assert "ip_adapter_image" not in parameters, (
124+
"`ip_adapter_image` argument must be removed from the `__call__` method"
125+
)
126+
assert "ip_adapter_image_embeds" not in intermediate_parameters, (
127+
"`ip_adapter_image_embeds` argument must be supported by the `__call__` method"
128+
)
131129

132130
def _get_dummy_image_embeds(self, cross_attention_dim: int = 32):
133131
return torch.randn((1, 1, cross_attention_dim), device=torch_device)
@@ -203,9 +201,9 @@ def test_ip_adapter(self, expected_max_diff: float = 1e-4, expected_pipe_slice=N
203201
max_diff_without_adapter_scale = np.abs(output_without_adapter_scale - output_without_adapter).max()
204202
max_diff_with_adapter_scale = np.abs(output_with_adapter_scale - output_without_adapter).max()
205203

206-
assert (
207-
max_diff_without_adapter_scale < expected_max_diff
208-
), "Output without ip-adapter must be same as normal inference"
204+
assert max_diff_without_adapter_scale < expected_max_diff, (
205+
"Output without ip-adapter must be same as normal inference"
206+
)
209207
assert max_diff_with_adapter_scale > 1e-2, "Output with ip-adapter must be different from normal inference"
210208

211209
# 2. Multi IP-Adapter test cases
@@ -235,12 +233,12 @@ def test_ip_adapter(self, expected_max_diff: float = 1e-4, expected_pipe_slice=N
235233
output_without_multi_adapter_scale - output_without_adapter
236234
).max()
237235
max_diff_with_multi_adapter_scale = np.abs(output_with_multi_adapter_scale - output_without_adapter).max()
238-
assert (
239-
max_diff_without_multi_adapter_scale < expected_max_diff
240-
), "Output without multi-ip-adapter must be same as normal inference"
241-
assert (
242-
max_diff_with_multi_adapter_scale > 1e-2
243-
), "Output with multi-ip-adapter scale must be different from normal inference"
236+
assert max_diff_without_multi_adapter_scale < expected_max_diff, (
237+
"Output without multi-ip-adapter must be same as normal inference"
238+
)
239+
assert max_diff_with_multi_adapter_scale > 1e-2, (
240+
"Output with multi-ip-adapter scale must be different from normal inference"
241+
)
244242

245243

246244
class SDXLModularControlNetTests:
@@ -253,9 +251,9 @@ def test_pipeline_inputs(self):
253251
parameters = blocks.input_names
254252

255253
assert "control_image" in parameters, "`control_image` argument must be supported by the `__call__` method"
256-
assert (
257-
"controlnet_conditioning_scale" in parameters
258-
), "`controlnet_conditioning_scale` argument must be supported by the `__call__` method"
254+
assert "controlnet_conditioning_scale" in parameters, (
255+
"`controlnet_conditioning_scale` argument must be supported by the `__call__` method"
256+
)
259257

260258
def _modify_inputs_for_controlnet_test(self, inputs: Dict[str, Any]):
261259
controlnet_embedder_scale_factor = 2
@@ -301,9 +299,9 @@ def test_controlnet(self, expected_max_diff: float = 1e-4, expected_pipe_slice=N
301299
max_diff_without_controlnet_scale = np.abs(output_without_controlnet_scale - output_without_controlnet).max()
302300
max_diff_with_controlnet_scale = np.abs(output_with_controlnet_scale - output_without_controlnet).max()
303301

304-
assert (
305-
max_diff_without_controlnet_scale < expected_max_diff
306-
), "Output without controlnet must be same as normal inference"
302+
assert max_diff_without_controlnet_scale < expected_max_diff, (
303+
"Output without controlnet must be same as normal inference"
304+
)
307305
assert max_diff_with_controlnet_scale > 1e-2, "Output with controlnet must be different from normal inference"
308306

309307
def test_controlnet_cfg(self):

tests/modular_pipelines/test_modular_pipelines_common.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import gc
2+
import tempfile
23
import unittest
34
from typing import Callable, Union
45

56
import numpy as np
67
import torch
78

89
import diffusers
10+
from diffusers import ComponentsManager, ModularPipeline, ModularPipelineBlocks
911
from diffusers.utils import logging
10-
from diffusers.utils.dummy_pt_objects import ModularPipeline, ModularPipelineBlocks
1112
from diffusers.utils.testing_utils import (
1213
backend_empty_cache,
1314
numpy_cosine_similarity_distance,
@@ -143,9 +144,9 @@ def test_pipeline_call_signature(self):
143144

144145
def _check_for_parameters(parameters, expected_parameters, param_type):
145146
remaining_parameters = {param for param in parameters if param not in expected_parameters}
146-
assert (
147-
len(remaining_parameters) == 0
148-
), f"Required {param_type} parameters not present: {remaining_parameters}"
147+
assert len(remaining_parameters) == 0, (
148+
f"Required {param_type} parameters not present: {remaining_parameters}"
149+
)
149150

150151
_check_for_parameters(self.params, input_parameters, "input")
151152
_check_for_parameters(self.intermediate_params, intermediate_parameters, "intermediate")
@@ -274,9 +275,9 @@ def test_to_device(self):
274275
model_devices = [
275276
component.device.type for component in pipe.components.values() if hasattr(component, "device")
276277
]
277-
assert all(
278-
device == torch_device for device in model_devices
279-
), "All pipeline components are not on accelerator device"
278+
assert all(device == torch_device for device in model_devices), (
279+
"All pipeline components are not on accelerator device"
280+
)
280281

281282
def test_inference_is_not_nan_cpu(self):
282283
pipe = self.get_pipeline()
@@ -344,7 +345,7 @@ def test_save_from_pretrained(self):
344345
with tempfile.TemporaryDirectory() as tmpdirname:
345346
base_pipe.save_pretrained(tmpdirname)
346347
pipe = ModularPipeline.from_pretrained(tmpdirname).to(torch_device)
347-
pipe.load_default_components(torch_dtype=torch.float32)
348+
pipe.load_default_components(torch_dtype=torch.float16)
348349
pipe.to(torch_device)
349350

350351
pipes.append(pipe)

0 commit comments

Comments
 (0)