From 508c4723c4bf35d8f5c08075980a44feb83b71f7 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Tue, 26 Mar 2024 14:51:54 +0530 Subject: [PATCH 01/33] speed up test_vae_slicing in animatediff --- tests/pipelines/animatediff/test_animatediff.py | 3 +++ tests/pipelines/test_pipelines_common.py | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/pipelines/animatediff/test_animatediff.py b/tests/pipelines/animatediff/test_animatediff.py index 288f856dc677..2188ffa77c4f 100644 --- a/tests/pipelines/animatediff/test_animatediff.py +++ b/tests/pipelines/animatediff/test_animatediff.py @@ -299,6 +299,9 @@ def test_xformers_attention_forwardGenerator_pass(self): max_diff = np.abs(to_np(output_with_offload) - to_np(output_without_offload)).max() self.assertLess(max_diff, 1e-4, "XFormers attention should not affect the inference results") + def test_vae_slicing(self): + return super().test_vae_slicing(image_count=2) + @slow @require_torch_gpu diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index 13007a2aa1f7..e8bf7283d52c 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -71,7 +71,7 @@ class SDFunctionTesterMixin: It provides a set of common tests for PyTorch pipeline that inherit from StableDiffusionMixin, e.g. vae_slicing, vae_tiling, freeu, etc. """ - def test_vae_slicing(self): + def test_vae_slicing(self, image_count=4): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() # components["scheduler"] = LMSDiscreteScheduler.from_config(components["scheduler"].config) @@ -79,8 +79,6 @@ def test_vae_slicing(self): pipe = pipe.to(device) pipe.set_progress_bar_config(disable=None) - image_count = 4 - inputs = self.get_dummy_inputs(device) inputs["prompt"] = [inputs["prompt"]] * image_count if "image" in inputs: # fix batch size mismatch in I2V_Gen pipeline From d45699e5f60707fb593e8f4a6fb7605b2cc9f696 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Tue, 26 Mar 2024 15:40:48 +0530 Subject: [PATCH 02/33] speed up test_karras_schedulers_shape for attend and excite. --- .../test_stable_diffusion_attend_and_excite.py | 3 +++ tests/pipelines/test_pipelines_common.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_attend_and_excite.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_attend_and_excite.py index e342ca7c9ee7..0957fd587e1f 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_attend_and_excite.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_attend_and_excite.py @@ -185,6 +185,9 @@ def test_save_load_local(self): def test_save_load_optional_components(self): super().test_save_load_optional_components(expected_max_difference=4e-4) + def test_karras_schedulers_shape(self): + super().test_karras_schedulers_shape(num_inference_steps_for_strength_for_iterations=3) + @require_torch_gpu @nightly diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index e8bf7283d52c..f1d9c0adf7d0 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -511,7 +511,7 @@ class PipelineKarrasSchedulerTesterMixin: equivalence of dict and tuple outputs, etc. """ - def test_karras_schedulers_shape(self): + def test_karras_schedulers_shape(self, num_inference_steps_for_strength=4, num_inference_steps_for_strength_for_iterations=5): components = self.get_dummy_components() pipe = self.pipeline_class(**components) @@ -524,13 +524,13 @@ def test_karras_schedulers_shape(self): inputs["num_inference_steps"] = 2 if "strength" in inputs: - inputs["num_inference_steps"] = 4 + inputs["num_inference_steps"] = num_inference_steps_for_strength inputs["strength"] = 0.5 outputs = [] for scheduler_enum in KarrasDiffusionSchedulers: if "KDPM2" in scheduler_enum.name: - inputs["num_inference_steps"] = 5 + inputs["num_inference_steps"] = num_inference_steps_for_strength_for_iterations scheduler_cls = getattr(diffusers, scheduler_enum.name) pipe.scheduler = scheduler_cls.from_config(pipe.scheduler.config) From 43f5496e9618cefcd3d5b62d634ab516b13ee427 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Tue, 26 Mar 2024 15:45:12 +0530 Subject: [PATCH 03/33] style. --- tests/pipelines/test_pipelines_common.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index f1d9c0adf7d0..3f575450886b 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -511,7 +511,9 @@ class PipelineKarrasSchedulerTesterMixin: equivalence of dict and tuple outputs, etc. """ - def test_karras_schedulers_shape(self, num_inference_steps_for_strength=4, num_inference_steps_for_strength_for_iterations=5): + def test_karras_schedulers_shape( + self, num_inference_steps_for_strength=4, num_inference_steps_for_strength_for_iterations=5 + ): components = self.get_dummy_components() pipe = self.pipeline_class(**components) From ec4240b0c3158afe4e438da785267a52b8363c79 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:01:15 +0530 Subject: [PATCH 04/33] get the static slices out. --- tests/pipelines/test_pipelines_common.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index 3f575450886b..c2714c98d609 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -37,11 +37,7 @@ from diffusers.schedulers import KarrasDiffusionSchedulers from diffusers.utils import logging from diffusers.utils.import_utils import is_accelerate_available, is_accelerate_version, is_xformers_available -from diffusers.utils.testing_utils import ( - CaptureLogger, - require_torch, - torch_device, -) +from diffusers.utils.testing_utils import CaptureLogger, print_tensor_test, require_torch, torch_device from ..models.autoencoders.test_models_vae import ( get_asym_autoencoder_kl_config, @@ -247,6 +243,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4): # forward pass without ip adapter inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) output_without_adapter = pipe(**inputs)[0] + print_tensor_test(output_without_adapter) adapter_state_dict = create_ip_adapter_state_dict(pipe.unet) pipe.unet._load_ip_adapter_weights(adapter_state_dict) From 70c459f0f243db8840ae95dbae97447b3b168208 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:17:43 +0530 Subject: [PATCH 05/33] specify torch print options. --- src/diffusers/utils/testing_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index f073ce231921..1a9eab4ba24e 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -56,6 +56,7 @@ if is_torch_available(): import torch + torch.set_printoptions(threshold=10_000) # Set a backend environment variable for any extra module import required for a custom accelerator if "DIFFUSERS_TEST_BACKEND" in os.environ: From a6781d75276aed66cfdf11313a489309c51c4c1d Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:22:36 +0530 Subject: [PATCH 06/33] modify --- src/diffusers/utils/testing_utils.py | 14 ++++++++++++-- tests/pipelines/test_pipelines_common.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 1a9eab4ba24e..71c908565018 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -56,7 +56,6 @@ if is_torch_available(): import torch - torch.set_printoptions(threshold=10_000) # Set a backend environment variable for any extra module import required for a custom accelerator if "DIFFUSERS_TEST_BACKEND" in os.environ: @@ -106,10 +105,21 @@ def numpy_cosine_similarity_distance(a, b): return distance -def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_name="expected_slice"): +def print_tensor_test( + tensor, + limit_to_slices=None, + max_torch_print=None, + filename="test_corrections.txt", + expected_tensor_name="expected_slice", +): + if max_torch_print: + torch.set_printoptions(threshold=10_000) + test_name = os.environ.get("PYTEST_CURRENT_TEST") if not torch.is_tensor(tensor): tensor = torch.from_numpy(tensor) + if limit_to_slices: + tensor = tensor[0, -3:, -3:, -1] tensor_str = str(tensor.detach().cpu().flatten().to(torch.float32)).replace("\n", "") # format is usually: diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index c2714c98d609..0b39fb550ab1 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -243,7 +243,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4): # forward pass without ip adapter inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) output_without_adapter = pipe(**inputs)[0] - print_tensor_test(output_without_adapter) + print_tensor_test(output_without_adapter, limit_to_slices=True, max_torch_print=True) adapter_state_dict = create_ip_adapter_state_dict(pipe.unet) pipe.unet._load_ip_adapter_weights(adapter_state_dict) From eee75636a7bd775f3c8f416e4cf3a50d30b5b090 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:34:15 +0530 Subject: [PATCH 07/33] test run with controlnet --- tests/pipelines/controlnet/test_controlnet.py | 4 ++++ tests/pipelines/test_pipelines_common.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/controlnet/test_controlnet.py b/tests/pipelines/controlnet/test_controlnet.py index abf83973adc2..c7c58df69cda 100644 --- a/tests/pipelines/controlnet/test_controlnet.py +++ b/tests/pipelines/controlnet/test_controlnet.py @@ -221,6 +221,10 @@ def get_dummy_inputs(self, device, seed=0): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.5234, 0.3333, 0.1745, 0.7605, 0.6224, 0.4637, 0.6989, 0.7526, 0.4665]) + return super().test_ip_adapter_single(expected_pipe_slice) + @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), reason="XFormers attention is only available with CUDA and `xformers` installed", diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index 0b39fb550ab1..ff7599f15319 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -234,7 +234,7 @@ def _modify_inputs_for_ip_adapter_test(self, inputs: Dict[str, Any]): inputs["return_dict"] = False return inputs - def test_ip_adapter_single(self, expected_max_diff: float = 1e-4): + def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_slice=None): components = self.get_dummy_components() pipe = self.pipeline_class(**components).to(torch_device) pipe.set_progress_bar_config(disable=None) @@ -242,8 +242,11 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4): # forward pass without ip adapter inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) - output_without_adapter = pipe(**inputs)[0] - print_tensor_test(output_without_adapter, limit_to_slices=True, max_torch_print=True) + if not expected_pipe_slice: + output_without_adapter = pipe(**inputs)[0] + print_tensor_test(output_without_adapter, limit_to_slices=True, max_torch_print=True) + else: + output_without_adapter = expected_pipe_slice adapter_state_dict = create_ip_adapter_state_dict(pipe.unet) pipe.unet._load_ip_adapter_weights(adapter_state_dict) @@ -252,13 +255,13 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4): inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)] pipe.set_ip_adapter_scale(0.0) - output_without_adapter_scale = pipe(**inputs)[0] + output_without_adapter_scale = pipe(**inputs)[0][0, -3:, -3:, -1] # forward pass with single ip adapter, but with scale of adapter weights inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)] pipe.set_ip_adapter_scale(42.0) - output_with_adapter_scale = pipe(**inputs)[0] + output_with_adapter_scale = pipe(**inputs)[0][0, -3:, -3:, -1] max_diff_without_adapter_scale = np.abs(output_without_adapter_scale - output_without_adapter).max() max_diff_with_adapter_scale = np.abs(output_with_adapter_scale - output_without_adapter).max() From 031e37477c80d7e266d072b83f69ededca8ffb7f Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:34:38 +0530 Subject: [PATCH 08/33] specify kwarg --- tests/pipelines/controlnet/test_controlnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pipelines/controlnet/test_controlnet.py b/tests/pipelines/controlnet/test_controlnet.py index c7c58df69cda..f9787b6bd450 100644 --- a/tests/pipelines/controlnet/test_controlnet.py +++ b/tests/pipelines/controlnet/test_controlnet.py @@ -223,7 +223,7 @@ def test_attention_slicing_forward_pass(self): def test_ip_adapter_single(self): expected_pipe_slice = np.array([0.5234, 0.3333, 0.1745, 0.7605, 0.6224, 0.4637, 0.6989, 0.7526, 0.4665]) - return super().test_ip_adapter_single(expected_pipe_slice) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), From 0f7184388c36fc643cc188afbd0958a6b96dbbe5 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:37:17 +0530 Subject: [PATCH 09/33] fix: things --- src/diffusers/utils/testing_utils.py | 2 +- tests/pipelines/test_pipelines_common.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 71c908565018..4ea541dac356 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -128,7 +128,7 @@ def print_tensor_test( test_file, test_class, test_fn = test_name.split("::") test_fn = test_fn.split()[0] with open(filename, "a") as f: - print(";".join([test_file, test_class, test_fn, output_str]), file=f) + print("::".join([test_file, test_class, test_fn, output_str]), file=f) def get_tests_dir(append_path=None): diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index ff7599f15319..a37b46e1fac1 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -242,7 +242,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ # forward pass without ip adapter inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) - if not expected_pipe_slice: + if expected_pipe_slice is None: output_without_adapter = pipe(**inputs)[0] print_tensor_test(output_without_adapter, limit_to_slices=True, max_torch_print=True) else: @@ -255,13 +255,17 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)] pipe.set_ip_adapter_scale(0.0) - output_without_adapter_scale = pipe(**inputs)[0][0, -3:, -3:, -1] + output_without_adapter_scale = pipe(**inputs)[0] + if expected_pipe_slice: + output_without_adapter_scale = output_without_adapter_scale[0, -3:, -3:, -1] # forward pass with single ip adapter, but with scale of adapter weights inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)] pipe.set_ip_adapter_scale(42.0) - output_with_adapter_scale = pipe(**inputs)[0][0, -3:, -3:, -1] + output_with_adapter_scale = pipe(**inputs)[0] + if expected_pipe_slice: + output_with_adapter_scale = output_with_adapter_scale[0, -3:, -3:, -1] max_diff_without_adapter_scale = np.abs(output_without_adapter_scale - output_without_adapter).max() max_diff_with_adapter_scale = np.abs(output_with_adapter_scale - output_without_adapter).max() From 62f0669d83574471f56a6133aa9e69daa9c36570 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:38:03 +0530 Subject: [PATCH 10/33] not None --- tests/pipelines/test_pipelines_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index a37b46e1fac1..dce010e672c3 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -256,7 +256,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)] pipe.set_ip_adapter_scale(0.0) output_without_adapter_scale = pipe(**inputs)[0] - if expected_pipe_slice: + if expected_pipe_slice is not None: output_without_adapter_scale = output_without_adapter_scale[0, -3:, -3:, -1] # forward pass with single ip adapter, but with scale of adapter weights @@ -264,7 +264,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)] pipe.set_ip_adapter_scale(42.0) output_with_adapter_scale = pipe(**inputs)[0] - if expected_pipe_slice: + if expected_pipe_slice is not None: output_with_adapter_scale = output_with_adapter_scale[0, -3:, -3:, -1] max_diff_without_adapter_scale = np.abs(output_without_adapter_scale - output_without_adapter).max() From aedccad4b0e992b68fa92d0df21c26c36d52de56 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:39:05 +0530 Subject: [PATCH 11/33] flatten --- tests/pipelines/test_pipelines_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index dce010e672c3..edf911527292 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -257,7 +257,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ pipe.set_ip_adapter_scale(0.0) output_without_adapter_scale = pipe(**inputs)[0] if expected_pipe_slice is not None: - output_without_adapter_scale = output_without_adapter_scale[0, -3:, -3:, -1] + output_without_adapter_scale = output_without_adapter_scale[0, -3:, -3:, -1].flatten() # forward pass with single ip adapter, but with scale of adapter weights inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) @@ -265,7 +265,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ pipe.set_ip_adapter_scale(42.0) output_with_adapter_scale = pipe(**inputs)[0] if expected_pipe_slice is not None: - output_with_adapter_scale = output_with_adapter_scale[0, -3:, -3:, -1] + output_with_adapter_scale = output_with_adapter_scale[0, -3:, -3:, -1].flatten() max_diff_without_adapter_scale = np.abs(output_without_adapter_scale - output_without_adapter).max() max_diff_with_adapter_scale = np.abs(output_with_adapter_scale - output_without_adapter).max() From 50de2cbd368f86dc7863d01c0137f780a302fbca Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:40:51 +0530 Subject: [PATCH 12/33] controlnet img2img --- tests/pipelines/controlnet/test_controlnet_img2img.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pipelines/controlnet/test_controlnet_img2img.py b/tests/pipelines/controlnet/test_controlnet_img2img.py index 7496021a2c1b..09022d549c8d 100644 --- a/tests/pipelines/controlnet/test_controlnet_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_img2img.py @@ -174,6 +174,10 @@ def get_dummy_inputs(self, device, seed=0): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.7096, 0.5149, 0.3571, 0.5897, 0.4715, 0.4052, 0.6098, 0.6886, 0.4213]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), reason="XFormers attention is only available with CUDA and `xformers` installed", From da64f0c008961644230abebe7a562bf6e65a0fed Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:47:24 +0530 Subject: [PATCH 13/33] complete controlet sd --- tests/pipelines/controlnet/test_controlnet.py | 10 ++++++++++ tests/pipelines/controlnet/test_controlnet_img2img.py | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/tests/pipelines/controlnet/test_controlnet.py b/tests/pipelines/controlnet/test_controlnet.py index f9787b6bd450..06663eba71e1 100644 --- a/tests/pipelines/controlnet/test_controlnet.py +++ b/tests/pipelines/controlnet/test_controlnet.py @@ -449,6 +449,8 @@ def test_control_guidance_switch(self): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) + + @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), reason="XFormers attention is only available with CUDA and `xformers` installed", @@ -459,6 +461,10 @@ def test_xformers_attention_forwardGenerator_pass(self): def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(expected_max_diff=2e-3) + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.2422, 0.3425, 0.4048, 0.5351, 0.3503, 0.2419, 0.4645, 0.4570, 0.3804]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_save_pretrained_raise_not_implemented_exception(self): components = self.get_dummy_components() pipe = self.pipeline_class(**components) @@ -663,6 +669,10 @@ def test_xformers_attention_forwardGenerator_pass(self): def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(expected_max_diff=2e-3) + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.5264, 0.3203, 0.1602, 0.8235, 0.6332, 0.4593, 0.7226, 0.7777, 0.4780]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_save_pretrained_raise_not_implemented_exception(self): components = self.get_dummy_components() pipe = self.pipeline_class(**components) diff --git a/tests/pipelines/controlnet/test_controlnet_img2img.py b/tests/pipelines/controlnet/test_controlnet_img2img.py index 09022d549c8d..46e016555c75 100644 --- a/tests/pipelines/controlnet/test_controlnet_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_img2img.py @@ -370,6 +370,10 @@ def test_xformers_attention_forwardGenerator_pass(self): def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(expected_max_diff=2e-3) + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.5293, 0.7339, 0.6642, 0.3950, 0.5212, 0.5175, 0.7002, 0.5907, 0.5182]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_save_pretrained_raise_not_implemented_exception(self): components = self.get_dummy_components() pipe = self.pipeline_class(**components) From f8f79e3b12147ef999304883be30646bede05246 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:51:02 +0530 Subject: [PATCH 14/33] finish more --- tests/pipelines/controlnet/test_controlnet_sdxl.py | 8 ++++++++ .../stable_diffusion/test_stable_diffusion_inpaint.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index 3e09a587cb3c..c5e23bd1ecfc 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -190,6 +190,10 @@ def get_dummy_inputs(self, device, seed=0): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) + + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), @@ -1042,6 +1046,10 @@ def test_controlnet_sdxl_guess(self): # make sure that it's equal assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-4 + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_controlnet_sdxl_lcm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index dec62e7e46ae..eab9b5cd4f4d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -388,6 +388,10 @@ def callback_on_step_end(pipe, i, t, callback_kwargs): # they should be the same assert torch.allclose(intermediate_latent, output_interrupted, atol=1e-4) + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.4390, 0.5452, 0.3772, 0.5448, 0.6031, 0.4480, 0.5194, 0.4687, 0.4640]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + class StableDiffusionSimpleInpaintPipelineFastTests(StableDiffusionInpaintPipelineFastTests): pipeline_class = StableDiffusionInpaintPipeline @@ -474,6 +478,10 @@ def get_dummy_inputs_2images(self, device, seed=0, img_res=64): "output_type": "np", } return inputs + + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.6345, 0.5395, 0.5611, 0.5403, 0.5830, 0.5855, 0.5193, 0.5443, 0.5211]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_inpaint(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator From 77f93cde0579bd6bdfbe54c5277fed41b0cdcf35 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:55:44 +0530 Subject: [PATCH 15/33] finish more --- .../pipelines/animatediff/test_animatediff.py | 34 +++++++++++++++++++ tests/pipelines/controlnet/test_controlnet.py | 2 -- .../controlnet/test_controlnet_sdxl.py | 2 +- .../test_controlnet_sdxl_img2img.py | 4 +++ .../test_stable_diffusion_inpaint.py | 2 +- .../test_stable_diffusion_xl_adapter.py | 8 +++++ 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/tests/pipelines/animatediff/test_animatediff.py b/tests/pipelines/animatediff/test_animatediff.py index 2188ffa77c4f..72ba8a640f5d 100644 --- a/tests/pipelines/animatediff/test_animatediff.py +++ b/tests/pipelines/animatediff/test_animatediff.py @@ -131,6 +131,40 @@ def test_motion_unet_loading(self): def test_attention_slicing_forward_pass(self): pass + def test_ip_adapter_single(self): + expected_pipe_slice = np.array( + [ + 0.5541, + 0.5802, + 0.5074, + 0.4583, + 0.4729, + 0.5374, + 0.4051, + 0.4495, + 0.4480, + 0.5292, + 0.6322, + 0.6265, + 0.5455, + 0.4771, + 0.5795, + 0.5845, + 0.4172, + 0.6066, + 0.6535, + 0.4113, + 0.6833, + 0.5736, + 0.3589, + 0.5730, + 0.4205, + 0.3786, + 0.5323, + ] + ) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_inference_batch_single_identical( self, batch_size=2, diff --git a/tests/pipelines/controlnet/test_controlnet.py b/tests/pipelines/controlnet/test_controlnet.py index 06663eba71e1..85c00ff31f70 100644 --- a/tests/pipelines/controlnet/test_controlnet.py +++ b/tests/pipelines/controlnet/test_controlnet.py @@ -449,8 +449,6 @@ def test_control_guidance_switch(self): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) - - @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), reason="XFormers attention is only available with CUDA and `xformers` installed", diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index c5e23bd1ecfc..901e43821675 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -190,7 +190,7 @@ def get_dummy_inputs(self, device, seed=0): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) - + def test_ip_adapter_single(self): expected_pipe_slice = np.array([0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py index 0e648a339a2a..1ddbceddac23 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py @@ -169,6 +169,10 @@ def get_dummy_inputs(self, device, seed=0): } return inputs + + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.6265, 0.5441, 0.5384, 0.5446, 0.5810, 0.5908, 0.5414, 0.5428, 0.5353]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_xl_controlnet_img2img(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index eab9b5cd4f4d..a9b260fe6c11 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -478,7 +478,7 @@ def get_dummy_inputs_2images(self, device, seed=0, img_res=64): "output_type": "np", } return inputs - + def test_ip_adapter_single(self): expected_pipe_slice = np.array([0.6345, 0.5395, 0.5611, 0.5403, 0.5830, 0.5855, 0.5193, 0.5443, 0.5211]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py index af5a8f5ccccb..654e302bd74a 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py @@ -294,6 +294,10 @@ def get_dummy_inputs(self, device, seed=0, height=64, width=64, num_images=1): } return inputs + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.5753, 0.6022, 0.4728, 0.4986, 0.5708, 0.4645, 0.5194, 0.5134, 0.4730]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_stable_diffusion_adapter_default_case(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() @@ -446,6 +450,10 @@ def test_stable_diffusion_adapter_default_case(self): ) assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-3 + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.5813, 0.6100, 0.4756, 0.5057, 0.5720, 0.4632, 0.5177, 0.5125, 0.4718]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_inference_batch_consistent( self, batch_sizes=[2, 4, 13], additional_params_copy_to_batched_inputs=["num_inference_steps"] ): From ae432854c6f8559f3a4b08389643687125862842 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 09:58:02 +0530 Subject: [PATCH 16/33] finish more --- .../test_latent_consistency_models.py | 4 ++++ .../test_latent_consistency_models_img2img.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py index eaf8fa2cdd59..b9aa8b74d6b3 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py @@ -107,6 +107,10 @@ def get_dummy_inputs(self, device, seed=0): "output_type": "np", } return inputs + + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.1403, 0.5072, 0.5316, 0.1202, 0.3865, 0.4211, 0.5363, 0.3557, 0.3645]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_lcm_onestep(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py index cfd596dcd0ed..137389367237 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py @@ -118,6 +118,11 @@ def get_dummy_inputs(self, device, seed=0): "output_type": "np", } return inputs + + + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.4003, 0.3718, 0.2863, 0.5500, 0.5587, 0.3772, 0.4617, 0.4961, 0.4417]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_lcm_onestep(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator From 7d583e5e3e099b8025fac3b070c875e702f7f837 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:00:11 +0530 Subject: [PATCH 17/33] finish more --- .../test_animatediff_video2video.py | 25 ++++++++++++++ .../test_controlnet_sdxl_img2img.py | 2 +- .../test_latent_consistency_models.py | 2 +- .../test_latent_consistency_models_img2img.py | 1 - tests/pipelines/pia/test_pia.py | 34 +++++++++++++++++++ .../test_stable_diffusion_panorama.py | 4 +++ 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/tests/pipelines/animatediff/test_animatediff_video2video.py b/tests/pipelines/animatediff/test_animatediff_video2video.py index 6cc54d97d8c6..a5b084176253 100644 --- a/tests/pipelines/animatediff/test_animatediff_video2video.py +++ b/tests/pipelines/animatediff/test_animatediff_video2video.py @@ -135,6 +135,31 @@ def test_motion_unet_loading(self): def test_attention_slicing_forward_pass(self): pass + def test_ip_adapter_single(self): + expected_pipe_slice = np.array( + [ + 0.4947, + 0.4780, + 0.4340, + 0.4666, + 0.4028, + 0.4645, + 0.4915, + 0.4101, + 0.4308, + 0.4581, + 0.3582, + 0.4953, + 0.4466, + 0.5348, + 0.5863, + 0.5299, + 0.5213, + 0.5017, + ] + ) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_inference_batch_single_identical( self, batch_size=2, diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py index 1ddbceddac23..6749ad47a74b 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py @@ -169,7 +169,7 @@ def get_dummy_inputs(self, device, seed=0): } return inputs - + def test_ip_adapter_single(self): expected_pipe_slice = np.array([0.6265, 0.5441, 0.5384, 0.5446, 0.5810, 0.5908, 0.5414, 0.5428, 0.5353]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py index b9aa8b74d6b3..74d050561abe 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py @@ -107,7 +107,7 @@ def get_dummy_inputs(self, device, seed=0): "output_type": "np", } return inputs - + def test_ip_adapter_single(self): expected_pipe_slice = np.array([0.1403, 0.5072, 0.5316, 0.1202, 0.3865, 0.4211, 0.5363, 0.3557, 0.3645]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py index 137389367237..094ce99320f0 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py @@ -118,7 +118,6 @@ def get_dummy_inputs(self, device, seed=0): "output_type": "np", } return inputs - def test_ip_adapter_single(self): expected_pipe_slice = np.array([0.4003, 0.3718, 0.2863, 0.5500, 0.5587, 0.3772, 0.4617, 0.4961, 0.4417]) diff --git a/tests/pipelines/pia/test_pia.py b/tests/pipelines/pia/test_pia.py index 2813dc70a71d..2ea9492e5f4a 100644 --- a/tests/pipelines/pia/test_pia.py +++ b/tests/pipelines/pia/test_pia.py @@ -138,6 +138,40 @@ def test_motion_unet_loading(self): assert isinstance(pipe.unet, UNetMotionModel) + def test_ip_adapter_single(self): + expected_pipe_slice = np.array( + [ + 0.5609, + 0.5756, + 0.4830, + 0.4420, + 0.4547, + 0.5129, + 0.3779, + 0.4042, + 0.3772, + 0.4450, + 0.5710, + 0.5536, + 0.4835, + 0.4308, + 0.5578, + 0.5578, + 0.4395, + 0.5440, + 0.6051, + 0.4651, + 0.6258, + 0.5662, + 0.3988, + 0.5108, + 0.4153, + 0.3993, + 0.4803, + ] + ) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + @unittest.skip("Attention slicing is not enabled in this pipeline") def test_attention_slicing_forward_pass(self): pass diff --git a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py index ede4552e3499..72ee030549f1 100644 --- a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py +++ b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py @@ -111,6 +111,10 @@ def get_dummy_inputs(self, device, seed=0): } return inputs + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_stable_diffusion_panorama_default_case(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() From b5e1da0f32bb095db4f5f51132900a7e16e1778d Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:05:58 +0530 Subject: [PATCH 18/33] finish the final batch --- tests/pipelines/stable_diffusion/test_stable_diffusion.py | 4 ++++ .../stable_diffusion/test_stable_diffusion_img2img.py | 4 ++++ .../pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py | 4 ++++ .../stable_diffusion_xl/test_stable_diffusion_xl_img2img.py | 4 ++++ .../stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 86bdc9af1b90..b0609d65603c 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -370,6 +370,10 @@ def test_stable_diffusion_prompt_embeds_with_plain_negative_prompt_list(self): assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1e-4 + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.3203, 0.4555, 0.4711, 0.3505, 0.3973, 0.4650, 0.5137, 0.3392, 0.4045]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_stable_diffusion_ddim_factor_8(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 922bf4dba381..1cbc16149aee 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -253,6 +253,10 @@ def test_stable_diffusion_img2img_negative_prompt(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.4932, 0.5092, 0.5135, 0.5517, 0.5626, 0.6621, 0.6490, 0.5021, 0.5441]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_stable_diffusion_img2img_multiple_init_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py index a9acebb5c7d5..dba582ac52ba 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py @@ -292,6 +292,10 @@ def test_stable_diffusion_xl_negative_prompt_embeds(self): # make sure that it's equal assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1e-4 + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.5552, 0.5569, 0.4725, 0.4348, 0.4994, 0.4632, 0.5142, 0.5012, 0.4700]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_attention_slicing_forward_pass(self): super().test_attention_slicing_forward_pass(expected_max_diff=3e-3) diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py index bf2d3035d5a2..50d0d773efd1 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py @@ -311,6 +311,10 @@ def test_stable_diffusion_xl_img2img_negative_prompt_embeds(self): # make sure that it's equal assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1e-4 + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.5174, 0.4512, 0.5006, 0.6273, 0.5160, 0.6825, 0.6655, 0.5840, 0.5675]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_stable_diffusion_xl_img2img_tiny_autoencoder(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py index 11c711e82e8b..9d9fd047a6b7 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py @@ -223,6 +223,10 @@ def get_dummy_inputs_2images(self, device, seed=0, img_res=64): } return inputs + def test_ip_adapter_single(self): + expected_pipe_slice = np.array([0.7971, 0.5371, 0.5973, 0.5642, 0.6689, 0.6894, 0.5770, 0.6063, 0.5261]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_components_function(self): init_components = self.get_dummy_components() init_components.pop("requires_aesthetics_score") From 9fa2ffdc4ca236418943977dffb87b90dcc1448e Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:11:37 +0530 Subject: [PATCH 19/33] add cpu check for expected_pipe_slice. --- .../pipelines/animatediff/test_animatediff.py | 64 ++++++++++--------- .../test_animatediff_video2video.py | 47 +++++++------- tests/pipelines/controlnet/test_controlnet.py | 12 +++- .../controlnet/test_controlnet_img2img.py | 8 ++- .../controlnet/test_controlnet_sdxl.py | 8 ++- .../test_controlnet_sdxl_img2img.py | 4 +- .../test_latent_consistency_models.py | 4 +- .../test_latent_consistency_models_img2img.py | 4 +- 8 files changed, 88 insertions(+), 63 deletions(-) diff --git a/tests/pipelines/animatediff/test_animatediff.py b/tests/pipelines/animatediff/test_animatediff.py index 72ba8a640f5d..ca6045ac397f 100644 --- a/tests/pipelines/animatediff/test_animatediff.py +++ b/tests/pipelines/animatediff/test_animatediff.py @@ -132,37 +132,39 @@ def test_attention_slicing_forward_pass(self): pass def test_ip_adapter_single(self): - expected_pipe_slice = np.array( - [ - 0.5541, - 0.5802, - 0.5074, - 0.4583, - 0.4729, - 0.5374, - 0.4051, - 0.4495, - 0.4480, - 0.5292, - 0.6322, - 0.6265, - 0.5455, - 0.4771, - 0.5795, - 0.5845, - 0.4172, - 0.6066, - 0.6535, - 0.4113, - 0.6833, - 0.5736, - 0.3589, - 0.5730, - 0.4205, - 0.3786, - 0.5323, - ] - ) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array( + [ + 0.5541, + 0.5802, + 0.5074, + 0.4583, + 0.4729, + 0.5374, + 0.4051, + 0.4495, + 0.4480, + 0.5292, + 0.6322, + 0.6265, + 0.5455, + 0.4771, + 0.5795, + 0.5845, + 0.4172, + 0.6066, + 0.6535, + 0.4113, + 0.6833, + 0.5736, + 0.3589, + 0.5730, + 0.4205, + 0.3786, + 0.5323, + ] + ) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_inference_batch_single_identical( diff --git a/tests/pipelines/animatediff/test_animatediff_video2video.py b/tests/pipelines/animatediff/test_animatediff_video2video.py index a5b084176253..81317b44a3c9 100644 --- a/tests/pipelines/animatediff/test_animatediff_video2video.py +++ b/tests/pipelines/animatediff/test_animatediff_video2video.py @@ -136,28 +136,31 @@ def test_attention_slicing_forward_pass(self): pass def test_ip_adapter_single(self): - expected_pipe_slice = np.array( - [ - 0.4947, - 0.4780, - 0.4340, - 0.4666, - 0.4028, - 0.4645, - 0.4915, - 0.4101, - 0.4308, - 0.4581, - 0.3582, - 0.4953, - 0.4466, - 0.5348, - 0.5863, - 0.5299, - 0.5213, - 0.5017, - ] - ) + expected_pipe_slice = None + + if torch_device == "cpu": + expected_pipe_slice = np.array( + [ + 0.4947, + 0.4780, + 0.4340, + 0.4666, + 0.4028, + 0.4645, + 0.4915, + 0.4101, + 0.4308, + 0.4581, + 0.3582, + 0.4953, + 0.4466, + 0.5348, + 0.5863, + 0.5299, + 0.5213, + 0.5017, + ] + ) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_inference_batch_single_identical( diff --git a/tests/pipelines/controlnet/test_controlnet.py b/tests/pipelines/controlnet/test_controlnet.py index 85c00ff31f70..5772c667170b 100644 --- a/tests/pipelines/controlnet/test_controlnet.py +++ b/tests/pipelines/controlnet/test_controlnet.py @@ -222,7 +222,9 @@ def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.5234, 0.3333, 0.1745, 0.7605, 0.6224, 0.4637, 0.6989, 0.7526, 0.4665]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.5234, 0.3333, 0.1745, 0.7605, 0.6224, 0.4637, 0.6989, 0.7526, 0.4665]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( @@ -460,7 +462,9 @@ def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(expected_max_diff=2e-3) def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.2422, 0.3425, 0.4048, 0.5351, 0.3503, 0.2419, 0.4645, 0.4570, 0.3804]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.2422, 0.3425, 0.4048, 0.5351, 0.3503, 0.2419, 0.4645, 0.4570, 0.3804]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_save_pretrained_raise_not_implemented_exception(self): @@ -668,7 +672,9 @@ def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(expected_max_diff=2e-3) def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.5264, 0.3203, 0.1602, 0.8235, 0.6332, 0.4593, 0.7226, 0.7777, 0.4780]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.5264, 0.3203, 0.1602, 0.8235, 0.6332, 0.4593, 0.7226, 0.7777, 0.4780]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_save_pretrained_raise_not_implemented_exception(self): diff --git a/tests/pipelines/controlnet/test_controlnet_img2img.py b/tests/pipelines/controlnet/test_controlnet_img2img.py index 46e016555c75..85312656e825 100644 --- a/tests/pipelines/controlnet/test_controlnet_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_img2img.py @@ -175,7 +175,9 @@ def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.7096, 0.5149, 0.3571, 0.5897, 0.4715, 0.4052, 0.6098, 0.6886, 0.4213]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.7096, 0.5149, 0.3571, 0.5897, 0.4715, 0.4052, 0.6098, 0.6886, 0.4213]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( @@ -371,7 +373,9 @@ def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(expected_max_diff=2e-3) def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.5293, 0.7339, 0.6642, 0.3950, 0.5212, 0.5175, 0.7002, 0.5907, 0.5182]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.5293, 0.7339, 0.6642, 0.3950, 0.5212, 0.5175, 0.7002, 0.5907, 0.5182]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_save_pretrained_raise_not_implemented_exception(self): diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index 901e43821675..4d0b35c8449e 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -192,7 +192,9 @@ def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( @@ -1047,7 +1049,9 @@ def test_controlnet_sdxl_guess(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-4 def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_controlnet_sdxl_lcm(self): diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py index 6749ad47a74b..61ff675856ae 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py @@ -171,7 +171,9 @@ def get_dummy_inputs(self, device, seed=0): return inputs def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.6265, 0.5441, 0.5384, 0.5446, 0.5810, 0.5908, 0.5414, 0.5428, 0.5353]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.6265, 0.5441, 0.5384, 0.5446, 0.5810, 0.5908, 0.5414, 0.5428, 0.5353]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_xl_controlnet_img2img(self): diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py index 74d050561abe..7ae5a8dd818f 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py @@ -109,7 +109,9 @@ def get_dummy_inputs(self, device, seed=0): return inputs def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.1403, 0.5072, 0.5316, 0.1202, 0.3865, 0.4211, 0.5363, 0.3557, 0.3645]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.1403, 0.5072, 0.5316, 0.1202, 0.3865, 0.4211, 0.5363, 0.3557, 0.3645]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_lcm_onestep(self): diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py index 094ce99320f0..1f0f384eeac1 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py @@ -120,7 +120,9 @@ def get_dummy_inputs(self, device, seed=0): return inputs def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.4003, 0.3718, 0.2863, 0.5500, 0.5587, 0.3772, 0.4617, 0.4961, 0.4417]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.4003, 0.3718, 0.2863, 0.5500, 0.5587, 0.3772, 0.4617, 0.4961, 0.4417]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_lcm_onestep(self): From b7ec1c28f74d5f5f7e2f6729e38331cd8e4b0716 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:15:03 +0530 Subject: [PATCH 20/33] finish the rest --- tests/pipelines/pia/test_pia.py | 65 ++++++++++--------- .../stable_diffusion/test_stable_diffusion.py | 4 +- .../test_stable_diffusion_img2img.py | 4 +- .../test_stable_diffusion_inpaint.py | 8 ++- .../test_stable_diffusion_panorama.py | 4 +- .../test_stable_diffusion_xl.py | 4 +- .../test_stable_diffusion_xl_adapter.py | 8 ++- .../test_stable_diffusion_xl_img2img.py | 4 +- .../test_stable_diffusion_xl_inpaint.py | 4 +- 9 files changed, 64 insertions(+), 41 deletions(-) diff --git a/tests/pipelines/pia/test_pia.py b/tests/pipelines/pia/test_pia.py index 2ea9492e5f4a..16ca4bc0957d 100644 --- a/tests/pipelines/pia/test_pia.py +++ b/tests/pipelines/pia/test_pia.py @@ -139,37 +139,40 @@ def test_motion_unet_loading(self): assert isinstance(pipe.unet, UNetMotionModel) def test_ip_adapter_single(self): - expected_pipe_slice = np.array( - [ - 0.5609, - 0.5756, - 0.4830, - 0.4420, - 0.4547, - 0.5129, - 0.3779, - 0.4042, - 0.3772, - 0.4450, - 0.5710, - 0.5536, - 0.4835, - 0.4308, - 0.5578, - 0.5578, - 0.4395, - 0.5440, - 0.6051, - 0.4651, - 0.6258, - 0.5662, - 0.3988, - 0.5108, - 0.4153, - 0.3993, - 0.4803, - ] - ) + expected_pipe_slice = None + + if torch_device == "cpu": + expected_pipe_slice = np.array( + [ + 0.5609, + 0.5756, + 0.4830, + 0.4420, + 0.4547, + 0.5129, + 0.3779, + 0.4042, + 0.3772, + 0.4450, + 0.5710, + 0.5536, + 0.4835, + 0.4308, + 0.5578, + 0.5578, + 0.4395, + 0.5440, + 0.6051, + 0.4651, + 0.6258, + 0.5662, + 0.3988, + 0.5108, + 0.4153, + 0.3993, + 0.4803, + ] + ) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skip("Attention slicing is not enabled in this pipeline") diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index b0609d65603c..b2821f71c058 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -371,7 +371,9 @@ def test_stable_diffusion_prompt_embeds_with_plain_negative_prompt_list(self): assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1e-4 def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.3203, 0.4555, 0.4711, 0.3505, 0.3973, 0.4650, 0.5137, 0.3392, 0.4045]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.3203, 0.4555, 0.4711, 0.3505, 0.3973, 0.4650, 0.5137, 0.3392, 0.4045]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_ddim_factor_8(self): diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 1cbc16149aee..48e520e9030b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -254,7 +254,9 @@ def test_stable_diffusion_img2img_negative_prompt(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.4932, 0.5092, 0.5135, 0.5517, 0.5626, 0.6621, 0.6490, 0.5021, 0.5441]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.4932, 0.5092, 0.5135, 0.5517, 0.5626, 0.6621, 0.6490, 0.5021, 0.5441]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_img2img_multiple_init_images(self): diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index a9b260fe6c11..daa91197b371 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -389,7 +389,9 @@ def callback_on_step_end(pipe, i, t, callback_kwargs): assert torch.allclose(intermediate_latent, output_interrupted, atol=1e-4) def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.4390, 0.5452, 0.3772, 0.5448, 0.6031, 0.4480, 0.5194, 0.4687, 0.4640]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.4390, 0.5452, 0.3772, 0.5448, 0.6031, 0.4480, 0.5194, 0.4687, 0.4640]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @@ -480,7 +482,9 @@ def get_dummy_inputs_2images(self, device, seed=0, img_res=64): return inputs def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.6345, 0.5395, 0.5611, 0.5403, 0.5830, 0.5855, 0.5193, 0.5443, 0.5211]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.6345, 0.5395, 0.5611, 0.5403, 0.5830, 0.5855, 0.5193, 0.5443, 0.5211]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_inpaint(self): diff --git a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py index 72ee030549f1..04181e584aa9 100644 --- a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py +++ b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py @@ -112,7 +112,9 @@ def get_dummy_inputs(self, device, seed=0): return inputs def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_panorama_default_case(self): diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py index dba582ac52ba..9670f069a21f 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py @@ -293,7 +293,9 @@ def test_stable_diffusion_xl_negative_prompt_embeds(self): assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1e-4 def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.5552, 0.5569, 0.4725, 0.4348, 0.4994, 0.4632, 0.5142, 0.5012, 0.4700]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.5552, 0.5569, 0.4725, 0.4348, 0.4994, 0.4632, 0.5142, 0.5012, 0.4700]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_attention_slicing_forward_pass(self): diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py index 654e302bd74a..3503d41e82ba 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py @@ -295,7 +295,9 @@ def get_dummy_inputs(self, device, seed=0, height=64, width=64, num_images=1): return inputs def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.5753, 0.6022, 0.4728, 0.4986, 0.5708, 0.4645, 0.5194, 0.5134, 0.4730]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.5753, 0.6022, 0.4728, 0.4986, 0.5708, 0.4645, 0.5194, 0.5134, 0.4730]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_adapter_default_case(self): @@ -451,7 +453,9 @@ def test_stable_diffusion_adapter_default_case(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-3 def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.5813, 0.6100, 0.4756, 0.5057, 0.5720, 0.4632, 0.5177, 0.5125, 0.4718]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.5813, 0.6100, 0.4756, 0.5057, 0.5720, 0.4632, 0.5177, 0.5125, 0.4718]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_inference_batch_consistent( diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py index 50d0d773efd1..19cab2b32a35 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py @@ -312,7 +312,9 @@ def test_stable_diffusion_xl_img2img_negative_prompt_embeds(self): assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1e-4 def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.5174, 0.4512, 0.5006, 0.6273, 0.5160, 0.6825, 0.6655, 0.5840, 0.5675]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.5174, 0.4512, 0.5006, 0.6273, 0.5160, 0.6825, 0.6655, 0.5840, 0.5675]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_xl_img2img_tiny_autoencoder(self): diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py index 9d9fd047a6b7..d096096e0bd2 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py @@ -224,7 +224,9 @@ def get_dummy_inputs_2images(self, device, seed=0, img_res=64): return inputs def test_ip_adapter_single(self): - expected_pipe_slice = np.array([0.7971, 0.5371, 0.5973, 0.5642, 0.6689, 0.6894, 0.5770, 0.6063, 0.5261]) + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.7971, 0.5371, 0.5973, 0.5642, 0.6689, 0.6894, 0.5770, 0.6063, 0.5261]) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_components_function(self): From 8de2bdd928c9a9b562eb842285097e8e26348e49 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:15:52 +0530 Subject: [PATCH 21/33] remove print --- tests/pipelines/test_pipelines_common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index edf911527292..ffa60f788429 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -244,7 +244,6 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) if expected_pipe_slice is None: output_without_adapter = pipe(**inputs)[0] - print_tensor_test(output_without_adapter, limit_to_slices=True, max_torch_print=True) else: output_without_adapter = expected_pipe_slice From 90736b0446f983fdc9b15f6808690b50d5c6f943 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:16:03 +0530 Subject: [PATCH 22/33] style --- tests/pipelines/test_pipelines_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index ffa60f788429..7cd958ca55b1 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -37,7 +37,7 @@ from diffusers.schedulers import KarrasDiffusionSchedulers from diffusers.utils import logging from diffusers.utils.import_utils import is_accelerate_available, is_accelerate_version, is_xformers_available -from diffusers.utils.testing_utils import CaptureLogger, print_tensor_test, require_torch, torch_device +from diffusers.utils.testing_utils import CaptureLogger, require_torch, torch_device from ..models.autoencoders.test_models_vae import ( get_asym_autoencoder_kl_config, From 9752100ab9a188cc671c37610f1e63730529843d Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:20:07 +0530 Subject: [PATCH 23/33] fix ssd1b controlnet test --- tests/pipelines/controlnet/test_controlnet_sdxl.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index 4d0b35c8449e..c5d606f5a84e 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -191,10 +191,13 @@ def get_dummy_inputs(self, device, seed=0): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) - def test_ip_adapter_single(self): + def test_ip_adapter_single(self, expected_pipe_slice=None): expected_pipe_slice = None if torch_device == "cpu": - expected_pipe_slice = np.array([0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090]) + if expected_pipe_slice is None: + expected_pipe_slice = np.array( + [0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090] + ) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( From 7260a1ac180c5d72052511d2e9a1aec7a5e99a70 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:23:00 +0530 Subject: [PATCH 24/33] checking ssd1b --- .../pipelines/controlnet/test_controlnet_sdxl.py | 16 ++++++++-------- tests/pipelines/test_pipelines_common.py | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index c5d606f5a84e..743f0d1301ad 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -191,14 +191,14 @@ def get_dummy_inputs(self, device, seed=0): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) - def test_ip_adapter_single(self, expected_pipe_slice=None): - expected_pipe_slice = None - if torch_device == "cpu": - if expected_pipe_slice is None: - expected_pipe_slice = np.array( - [0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090] - ) - return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + # def test_ip_adapter_single(self, expected_pipe_slice=None): + # expected_pipe_slice = None + # if torch_device == "cpu": + # if expected_pipe_slice is None: + # expected_pipe_slice = np.array( + # [0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090] + # ) + # return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index 7cd958ca55b1..ba796d375cca 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -37,7 +37,7 @@ from diffusers.schedulers import KarrasDiffusionSchedulers from diffusers.utils import logging from diffusers.utils.import_utils import is_accelerate_available, is_accelerate_version, is_xformers_available -from diffusers.utils.testing_utils import CaptureLogger, require_torch, torch_device +from diffusers.utils.testing_utils import CaptureLogger, require_torch, torch_device, print_tensor_test from ..models.autoencoders.test_models_vae import ( get_asym_autoencoder_kl_config, @@ -244,6 +244,7 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) if expected_pipe_slice is None: output_without_adapter = pipe(**inputs)[0] + print_tensor_test(output_without_adapter, limit_to_slices=True, max_torch_print=True) else: output_without_adapter = expected_pipe_slice From 2cdc18e3c2837ae043a87fa6f589845eabff3358 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:27:41 +0530 Subject: [PATCH 25/33] disable the test. --- tests/pipelines/controlnet/test_controlnet_sdxl.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index 743f0d1301ad..5cbbc41e4172 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -1051,11 +1051,11 @@ def test_controlnet_sdxl_guess(self): # make sure that it's equal assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-4 - def test_ip_adapter_single(self): - expected_pipe_slice = None - if torch_device == "cpu": - expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036]) - return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + # def test_ip_adapter_single(self): + # expected_pipe_slice = None + # if torch_device == "cpu": + # expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036]) + # return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_controlnet_sdxl_lcm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator From f562e757c35cbce54ee0308c8f217c98b618f5d4 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:35:40 +0530 Subject: [PATCH 26/33] make the test_ip_adapter_single controlnet test more robust --- .../controlnet/test_controlnet_sdxl.py | 26 +++++++++---------- tests/pipelines/test_pipelines_common.py | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index 5cbbc41e4172..3bbb54b0a433 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -191,14 +191,14 @@ def get_dummy_inputs(self, device, seed=0): def test_attention_slicing_forward_pass(self): return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) - # def test_ip_adapter_single(self, expected_pipe_slice=None): - # expected_pipe_slice = None - # if torch_device == "cpu": - # if expected_pipe_slice is None: - # expected_pipe_slice = np.array( - # [0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090] - # ) - # return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_ip_adapter_single(self, from_ssd1b=False, expected_pipe_slice=None): + if not from_ssd1b: + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array( + [0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090] + ) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), @@ -1051,11 +1051,11 @@ def test_controlnet_sdxl_guess(self): # make sure that it's equal assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-4 - # def test_ip_adapter_single(self): - # expected_pipe_slice = None - # if torch_device == "cpu": - # expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036]) - # return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_ip_adapter_single(self): + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036]) + return super().test_ip_adapter_single(from_ssd1b=True, expected_pipe_slice=expected_pipe_slice) def test_controlnet_sdxl_lcm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index ba796d375cca..edf911527292 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -37,7 +37,7 @@ from diffusers.schedulers import KarrasDiffusionSchedulers from diffusers.utils import logging from diffusers.utils.import_utils import is_accelerate_available, is_accelerate_version, is_xformers_available -from diffusers.utils.testing_utils import CaptureLogger, require_torch, torch_device, print_tensor_test +from diffusers.utils.testing_utils import CaptureLogger, print_tensor_test, require_torch, torch_device from ..models.autoencoders.test_models_vae import ( get_asym_autoencoder_kl_config, From 0b0c290c24835e01951c2117bf3c11bd3e3714bd Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:52:01 +0530 Subject: [PATCH 27/33] fix: simple inpaint --- .../test_stable_diffusion_inpaint.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index daa91197b371..8c6d0caed5c9 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -388,10 +388,13 @@ def callback_on_step_end(pipe, i, t, callback_kwargs): # they should be the same assert torch.allclose(intermediate_latent, output_interrupted, atol=1e-4) - def test_ip_adapter_single(self): - expected_pipe_slice = None - if torch_device == "cpu": - expected_pipe_slice = np.array([0.4390, 0.5452, 0.3772, 0.5448, 0.6031, 0.4480, 0.5194, 0.4687, 0.4640]) + def test_ip_adapter_single(self, from_simple=False, expected_pipe_slice=None): + if not from_simple: + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array( + [0.4390, 0.5452, 0.3772, 0.5448, 0.6031, 0.4480, 0.5194, 0.4687, 0.4640] + ) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) @@ -485,7 +488,7 @@ def test_ip_adapter_single(self): expected_pipe_slice = None if torch_device == "cpu": expected_pipe_slice = np.array([0.6345, 0.5395, 0.5611, 0.5403, 0.5830, 0.5855, 0.5193, 0.5443, 0.5211]) - return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + return super().test_ip_adapter_single(from_simple=True, expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_inpaint(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator From fe4c04334585ce4402f7f852ad754013714289da Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:53:39 +0530 Subject: [PATCH 28/33] multi --- .../test_stable_diffusion_xl_adapter.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py index 3503d41e82ba..eb687f8035d4 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py @@ -294,10 +294,13 @@ def get_dummy_inputs(self, device, seed=0, height=64, width=64, num_images=1): } return inputs - def test_ip_adapter_single(self): - expected_pipe_slice = None - if torch_device == "cpu": - expected_pipe_slice = np.array([0.5753, 0.6022, 0.4728, 0.4986, 0.5708, 0.4645, 0.5194, 0.5134, 0.4730]) + def test_ip_adapter_single(self, from_multi=False, expected_pipe_slice=None): + if not from_multi: + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array( + [0.5753, 0.6022, 0.4728, 0.4986, 0.5708, 0.4645, 0.5194, 0.5134, 0.4730] + ) return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_adapter_default_case(self): @@ -456,7 +459,7 @@ def test_ip_adapter_single(self): expected_pipe_slice = None if torch_device == "cpu": expected_pipe_slice = np.array([0.5813, 0.6100, 0.4756, 0.5057, 0.5720, 0.4632, 0.5177, 0.5125, 0.4718]) - return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + return super().test_ip_adapter_single(from_multi=True, expected_pipe_slice=expected_pipe_slice) def test_inference_batch_consistent( self, batch_sizes=[2, 4, 13], additional_params_copy_to_batched_inputs=["num_inference_steps"] From 29a0b140f9ce203bd0ffb4e6eb9028ec05f1a4de Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:54:53 +0530 Subject: [PATCH 29/33] disable panorama --- .../test_stable_diffusion_panorama.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py index 04181e584aa9..28b6d338ad43 100644 --- a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py +++ b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py @@ -111,11 +111,11 @@ def get_dummy_inputs(self, device, seed=0): } return inputs - def test_ip_adapter_single(self): - expected_pipe_slice = None - if torch_device == "cpu": - expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) - return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + # def test_ip_adapter_single(self): + # expected_pipe_slice = None + # if torch_device == "cpu": + # expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) + # return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_panorama_default_case(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator From 5b44d4e0b7d96755502c55435843523c16be3af1 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:56:56 +0530 Subject: [PATCH 30/33] enable again --- .../test_stable_diffusion_panorama.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py index 28b6d338ad43..04181e584aa9 100644 --- a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py +++ b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py @@ -111,11 +111,11 @@ def get_dummy_inputs(self, device, seed=0): } return inputs - # def test_ip_adapter_single(self): - # expected_pipe_slice = None - # if torch_device == "cpu": - # expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) - # return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) + def test_ip_adapter_single(self): + expected_pipe_slice = None + if torch_device == "cpu": + expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) + return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) def test_stable_diffusion_panorama_default_case(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator From a70526d9046196ac6905938d17d2430596d32512 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:58:48 +0530 Subject: [PATCH 31/33] panorama is shaky so leave it for now --- .../test_stable_diffusion_panorama.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py index 04181e584aa9..ede4552e3499 100644 --- a/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py +++ b/tests/pipelines/stable_diffusion_panorama/test_stable_diffusion_panorama.py @@ -111,12 +111,6 @@ def get_dummy_inputs(self, device, seed=0): } return inputs - def test_ip_adapter_single(self): - expected_pipe_slice = None - if torch_device == "cpu": - expected_pipe_slice = np.array([0.6185, 0.5373, 0.4915, 0.4134, 0.4114, 0.4564, 0.5128, 0.4977, 0.4758]) - return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice) - def test_stable_diffusion_panorama_default_case(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() From 833b759c1843fc582af4ed74d8d603dbc4582d37 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 27 Mar 2024 10:59:17 +0530 Subject: [PATCH 32/33] remove print --- tests/pipelines/test_pipelines_common.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index edf911527292..7cd958ca55b1 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -37,7 +37,7 @@ from diffusers.schedulers import KarrasDiffusionSchedulers from diffusers.utils import logging from diffusers.utils.import_utils import is_accelerate_available, is_accelerate_version, is_xformers_available -from diffusers.utils.testing_utils import CaptureLogger, print_tensor_test, require_torch, torch_device +from diffusers.utils.testing_utils import CaptureLogger, require_torch, torch_device from ..models.autoencoders.test_models_vae import ( get_asym_autoencoder_kl_config, @@ -244,7 +244,6 @@ def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_ inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device)) if expected_pipe_slice is None: output_without_adapter = pipe(**inputs)[0] - print_tensor_test(output_without_adapter, limit_to_slices=True, max_torch_print=True) else: output_without_adapter = expected_pipe_slice From c0a6a111e3d4240b84a316653bcdfa4a45dfa8d5 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Fri, 29 Mar 2024 12:45:24 +0530 Subject: [PATCH 33/33] raise tolerance. --- tests/pipelines/test_pipelines_common.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index a98e89698af1..d7f0c6baa339 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -236,6 +236,10 @@ def _modify_inputs_for_ip_adapter_test(self, inputs: Dict[str, Any]): return inputs def test_ip_adapter_single(self, expected_max_diff: float = 1e-4, expected_pipe_slice=None): + # Raising the tolerance for this test when it's run on a CPU because we + # compare against static slices and that can be shaky (with a VVVV low probability). + expected_max_diff = 9e-4 if torch_device == "cpu" else expected_max_diff + components = self.get_dummy_components() pipe = self.pipeline_class(**components).to(torch_device) pipe.set_progress_bar_config(disable=None)