From b9b6d344f297973de7da7bc6a72e485545f4c30a Mon Sep 17 00:00:00 2001 From: Yao Matrix Date: Mon, 28 Apr 2025 23:06:09 +0000 Subject: [PATCH 1/3] enable unidiffuser cases on XPU Signed-off-by: Yao Matrix --- tests/pipelines/test_pipelines_common.py | 10 +++++----- tests/pipelines/unidiffuser/test_unidiffuser.py | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index 62ceea21bbac..7478898644b4 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -1485,8 +1485,8 @@ def test_to_device(self): model_devices = [component.device.type for component in components.values() if hasattr(component, "device")] self.assertTrue(all(device == torch_device for device in model_devices)) - output_cuda = pipe(**self.get_dummy_inputs(torch_device))[0] - self.assertTrue(np.isnan(to_np(output_cuda)).sum() == 0) + output_device = pipe(**self.get_dummy_inputs(torch_device))[0] + self.assertTrue(np.isnan(to_np(output_device)).sum() == 0) def test_to_dtype(self): components = self.get_dummy_components() @@ -1677,11 +1677,11 @@ def test_cpu_offload_forward_pass_twice(self, expected_max_diff=2e-4): pipe.set_progress_bar_config(disable=None) - pipe.enable_model_cpu_offload(device=torch_device) + pipe.enable_model_cpu_offload() inputs = self.get_dummy_inputs(generator_device) output_with_offload = pipe(**inputs)[0] - pipe.enable_model_cpu_offload(device=torch_device) + pipe.enable_model_cpu_offload() inputs = self.get_dummy_inputs(generator_device) output_with_offload_twice = pipe(**inputs)[0] @@ -2226,7 +2226,7 @@ def create_pipe(): def enable_group_offload_on_component(pipe, group_offloading_kwargs): # We intentionally don't test VAE's here. This is because some tests enable tiling on the VAE. If - # tiling is enabled and a forward pass is run, when cuda streams are used, the execution order of + # tiling is enabled and a forward pass is run, when accelerator streams are used, the execution order of # the layers is not traced correctly. This causes errors. For apply group offloading to VAE, a # warmup forward pass (even with dummy small inputs) is recommended. for component_name in [ diff --git a/tests/pipelines/unidiffuser/test_unidiffuser.py b/tests/pipelines/unidiffuser/test_unidiffuser.py index 292978eb6eee..ce8f4b24747c 100644 --- a/tests/pipelines/unidiffuser/test_unidiffuser.py +++ b/tests/pipelines/unidiffuser/test_unidiffuser.py @@ -22,6 +22,7 @@ UniDiffuserTextDecoder, ) from diffusers.utils.testing_utils import ( + backend_empty_cache, enable_full_determinism, floats_tensor, load_image, @@ -584,17 +585,17 @@ def test_encode_prompt_works_in_isolation(): @nightly -@require_torch_gpu +@require_torch_accelerator class UniDiffuserPipelineSlowTests(unittest.TestCase): def setUp(self): super().setUp() gc.collect() - torch.cuda.empty_cache() + backend_empty_cache(torch_device) def tearDown(self): super().tearDown() gc.collect() - torch.cuda.empty_cache() + backend_empty_cache(torch_device) def get_inputs(self, device, seed=0, generate_latents=False): generator = torch.manual_seed(seed) @@ -705,17 +706,17 @@ def test_unidiffuser_compile(self, seed=0): @nightly -@require_torch_gpu +@require_torch_accelerator class UniDiffuserPipelineNightlyTests(unittest.TestCase): def setUp(self): super().setUp() gc.collect() - torch.cuda.empty_cache() + backend_empty_cache(torch_device) def tearDown(self): super().tearDown() gc.collect() - torch.cuda.empty_cache() + backend_empty_cache(torch_device) def get_inputs(self, device, seed=0, generate_latents=False): generator = torch.manual_seed(seed) From c5c97d10d88d59581b63d64af3e1bfda3fb91f00 Mon Sep 17 00:00:00 2001 From: Yao Matrix Date: Tue, 29 Apr 2025 04:55:22 +0000 Subject: [PATCH 2/3] fix a typo Signed-off-by: Yao Matrix --- tests/pipelines/unidiffuser/test_unidiffuser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pipelines/unidiffuser/test_unidiffuser.py b/tests/pipelines/unidiffuser/test_unidiffuser.py index ce8f4b24747c..9c697743eb03 100644 --- a/tests/pipelines/unidiffuser/test_unidiffuser.py +++ b/tests/pipelines/unidiffuser/test_unidiffuser.py @@ -578,7 +578,7 @@ def test_unidiffuser_default_img2text_v1_fp16(self): assert text[0][: len(expected_text_prefix)] == expected_text_prefix @unittest.skip( - "Test not supported becauseit has a bunch of direct configs at init and also, this pipeline isn't used that much now." + "Test not supported because it has a bunch of direct configs at init and also, this pipeline isn't used that much now." ) def test_encode_prompt_works_in_isolation(): pass From e7c2e3829a846dc9c3351c6cfa8c6110abda304e Mon Sep 17 00:00:00 2001 From: Yao Matrix Date: Tue, 29 Apr 2025 04:55:46 +0000 Subject: [PATCH 3/3] fix style Signed-off-by: Yao Matrix --- tests/pipelines/unidiffuser/test_unidiffuser.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/pipelines/unidiffuser/test_unidiffuser.py b/tests/pipelines/unidiffuser/test_unidiffuser.py index 9c697743eb03..b1216a091c8b 100644 --- a/tests/pipelines/unidiffuser/test_unidiffuser.py +++ b/tests/pipelines/unidiffuser/test_unidiffuser.py @@ -29,7 +29,6 @@ nightly, require_torch_2, require_torch_accelerator, - require_torch_gpu, run_test_in_subprocess, torch_device, )