From 80f27d7e8db9a6d9a79a320171446963660d8cdf Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 25 Jun 2025 08:59:36 +0530 Subject: [PATCH 1/3] [tests] skip instead of returning. (#11793) skip instead of returning. --- tests/models/test_modeling_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/models/test_modeling_common.py b/tests/models/test_modeling_common.py index eba8cc23b7e1..3a401c46fb5e 100644 --- a/tests/models/test_modeling_common.py +++ b/tests/models/test_modeling_common.py @@ -2107,7 +2107,7 @@ def test_hotswapping_compiled_model_linear(self, rank0, rank1): @parameterized.expand([(11, 11), (7, 13), (13, 7)]) # important to test small to large and vice versa def test_hotswapping_compiled_model_conv2d(self, rank0, rank1): if "unet" not in self.model_class.__name__.lower(): - return + pytest.skip("Test only applies to UNet.") # It's important to add this context to raise an error on recompilation target_modules = ["conv", "conv1", "conv2"] @@ -2117,7 +2117,7 @@ def test_hotswapping_compiled_model_conv2d(self, rank0, rank1): @parameterized.expand([(11, 11), (7, 13), (13, 7)]) # important to test small to large and vice versa def test_hotswapping_compiled_model_both_linear_and_conv2d(self, rank0, rank1): if "unet" not in self.model_class.__name__.lower(): - return + pytest.skip("Test only applies to UNet.") # It's important to add this context to raise an error on recompilation target_modules = ["to_q", "conv"] From dd285099ebe556da550dc0b7c2130cc829ce6395 Mon Sep 17 00:00:00 2001 From: kaixuanliu Date: Wed, 25 Jun 2025 16:32:17 +0800 Subject: [PATCH 2/3] adjust to get CI test cases passed on XPU (#11759) * adjust to get CI test cases passed on XPU Signed-off-by: Liu, Kaixuan * fix format issue Signed-off-by: Liu, Kaixuan * Apply style fixes --------- Signed-off-by: Liu, Kaixuan Co-authored-by: github-actions[bot] Co-authored-by: Aryan --- .../kandinsky2_2/test_kandinsky_controlnet.py | 3 +- .../test_ledits_pp_stable_diffusion.py | 33 +++++++++++- tests/pipelines/test_pipelines_common.py | 6 +-- tests/quantization/gguf/test_gguf.py | 50 +++++++++---------- 4 files changed, 60 insertions(+), 32 deletions(-) diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py b/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py index 84085f9d7d39..b2d6f0fc0590 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py @@ -289,6 +289,5 @@ def test_kandinsky_controlnet(self): image = output.images[0] assert image.shape == (512, 512, 3) - max_diff = numpy_cosine_similarity_distance(expected_image.flatten(), image.flatten()) - assert max_diff < 1e-4 + assert max_diff < 2e-4 diff --git a/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py b/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py index 342561d4f5e9..ab0221dc815e 100644 --- a/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py +++ b/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py @@ -29,6 +29,7 @@ UNet2DConditionModel, ) from diffusers.utils.testing_utils import ( + Expectations, backend_empty_cache, enable_full_determinism, floats_tensor, @@ -244,7 +245,35 @@ def test_ledits_pp_editing(self): output_slice = reconstruction[150:153, 140:143, -1] output_slice = output_slice.flatten() - expected_slice = np.array( - [0.9453125, 0.93310547, 0.84521484, 0.94628906, 0.9111328, 0.80859375, 0.93847656, 0.9042969, 0.8144531] + expected_slices = Expectations( + { + ("xpu", 3): np.array( + [ + 0.9511719, + 0.94140625, + 0.87597656, + 0.9472656, + 0.9296875, + 0.8378906, + 0.94433594, + 0.91503906, + 0.8491211, + ] + ), + ("cuda", 7): np.array( + [ + 0.9453125, + 0.93310547, + 0.84521484, + 0.94628906, + 0.9111328, + 0.80859375, + 0.93847656, + 0.9042969, + 0.8144531, + ] + ), + } ) + expected_slice = expected_slices.get_expectation() assert np.abs(output_slice - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index 207cff2a3cdc..4a3a9b1796a1 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -49,6 +49,7 @@ from diffusers.utils.testing_utils import ( CaptureLogger, backend_empty_cache, + numpy_cosine_similarity_distance, require_accelerate_version_greater, require_accelerator, require_hf_hub_version_greater, @@ -1394,9 +1395,8 @@ def test_float16_inference(self, expected_max_diff=5e-2): fp16_inputs["generator"] = self.get_generator(0) output_fp16 = pipe_fp16(**fp16_inputs)[0] - - max_diff = np.abs(to_np(output) - to_np(output_fp16)).max() - self.assertLess(max_diff, expected_max_diff, "The outputs of the fp16 and fp32 pipelines are too different.") + max_diff = numpy_cosine_similarity_distance(output.flatten(), output_fp16.flatten()) + assert max_diff < 2e-4 @unittest.skipIf(torch_device not in ["cuda", "xpu"], reason="float16 requires CUDA or XPU") @require_accelerator diff --git a/tests/quantization/gguf/test_gguf.py b/tests/quantization/gguf/test_gguf.py index ae3900459de2..5d1fa4c22e2a 100644 --- a/tests/quantization/gguf/test_gguf.py +++ b/tests/quantization/gguf/test_gguf.py @@ -286,33 +286,33 @@ def test_pipeline_inference(self): { ("xpu", 3): np.array( [ - 0.19335938, - 0.3125, - 0.3203125, - 0.1328125, - 0.3046875, - 0.296875, - 0.11914062, - 0.2890625, - 0.2890625, - 0.16796875, - 0.30273438, - 0.33203125, - 0.14648438, - 0.31640625, - 0.33007812, + 0.16210938, + 0.2734375, + 0.27734375, + 0.109375, + 0.27148438, + 0.2578125, + 0.1015625, + 0.2578125, + 0.2578125, + 0.14453125, + 0.26953125, + 0.29492188, 0.12890625, - 0.3046875, - 0.30859375, - 0.17773438, - 0.33789062, - 0.33203125, - 0.16796875, - 0.34570312, - 0.32421875, + 0.28710938, + 0.30078125, + 0.11132812, + 0.27734375, + 0.27929688, 0.15625, - 0.33203125, - 0.31445312, + 0.31054688, + 0.296875, + 0.15234375, + 0.3203125, + 0.29492188, + 0.140625, + 0.3046875, + 0.28515625, ] ), ("cuda", 7): np.array( From 88466358733da21a4ab45d85300ee6960f588e7d Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Thu, 26 Jun 2025 00:18:20 +0530 Subject: [PATCH 3/3] fix deprecation in lora after 0.34.0 release (#11802) --- src/diffusers/loaders/lora_base.py | 12 -------- tests/lora/test_deprecated_utilities.py | 39 ------------------------- 2 files changed, 51 deletions(-) delete mode 100644 tests/lora/test_deprecated_utilities.py diff --git a/src/diffusers/loaders/lora_base.py b/src/diffusers/loaders/lora_base.py index 16f0d4836505..e6941a521d06 100644 --- a/src/diffusers/loaders/lora_base.py +++ b/src/diffusers/loaders/lora_base.py @@ -1022,15 +1022,3 @@ def save_function(weights, filename): @classmethod def _optionally_disable_offloading(cls, _pipeline): return _func_optionally_disable_offloading(_pipeline=_pipeline) - - @classmethod - def _fetch_state_dict(cls, *args, **kwargs): - deprecation_message = f"Using the `_fetch_state_dict()` method from {cls} has been deprecated and will be removed in a future version. Please use `from diffusers.loaders.lora_base import _fetch_state_dict`." - deprecate("_fetch_state_dict", "0.35.0", deprecation_message) - return _fetch_state_dict(*args, **kwargs) - - @classmethod - def _best_guess_weight_name(cls, *args, **kwargs): - deprecation_message = f"Using the `_best_guess_weight_name()` method from {cls} has been deprecated and will be removed in a future version. Please use `from diffusers.loaders.lora_base import _best_guess_weight_name`." - deprecate("_best_guess_weight_name", "0.35.0", deprecation_message) - return _best_guess_weight_name(*args, **kwargs) diff --git a/tests/lora/test_deprecated_utilities.py b/tests/lora/test_deprecated_utilities.py deleted file mode 100644 index 4275ef8089a3..000000000000 --- a/tests/lora/test_deprecated_utilities.py +++ /dev/null @@ -1,39 +0,0 @@ -import os -import tempfile -import unittest - -import torch - -from diffusers.loaders.lora_base import LoraBaseMixin - - -class UtilityMethodDeprecationTests(unittest.TestCase): - def test_fetch_state_dict_cls_method_raises_warning(self): - state_dict = torch.nn.Linear(3, 3).state_dict() - with self.assertWarns(FutureWarning) as warning: - _ = LoraBaseMixin._fetch_state_dict( - state_dict, - weight_name=None, - use_safetensors=False, - local_files_only=True, - cache_dir=None, - force_download=False, - proxies=None, - token=None, - revision=None, - subfolder=None, - user_agent=None, - allow_pickle=None, - ) - warning_message = str(warning.warnings[0].message) - assert "Using the `_fetch_state_dict()` method from" in warning_message - - def test_best_guess_weight_name_cls_method_raises_warning(self): - with tempfile.TemporaryDirectory() as tmpdir: - state_dict = torch.nn.Linear(3, 3).state_dict() - torch.save(state_dict, os.path.join(tmpdir, "pytorch_lora_weights.bin")) - - with self.assertWarns(FutureWarning) as warning: - _ = LoraBaseMixin._best_guess_weight_name(pretrained_model_name_or_path_or_dict=tmpdir) - warning_message = str(warning.warnings[0].message) - assert "Using the `_best_guess_weight_name()` method from" in warning_message