Skip to content

Commit c372615

Browse files
enable several pipeline integration tests on XPU (#11526)
* enable kandinsky2_2 integration test cases on XPU Signed-off-by: Yao Matrix <[email protected]> * fix style Signed-off-by: Yao Matrix <[email protected]> * enable latent_diffusion, dance_diffusion, musicldm, shap_e integration uts on xpu Signed-off-by: Yao Matrix <[email protected]> * fix style Signed-off-by: Yao Matrix <[email protected]> --------- Signed-off-by: Yao Matrix <[email protected]> Co-authored-by: Aryan <[email protected]>
1 parent e48f6ae commit c372615

File tree

7 files changed

+57
-32
lines changed

7 files changed

+57
-32
lines changed

tests/pipelines/dance_diffusion/test_dance_diffusion.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
import torch
2121

2222
from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNet1DModel
23-
from diffusers.utils.testing_utils import enable_full_determinism, nightly, require_torch_gpu, skip_mps, torch_device
23+
from diffusers.utils.testing_utils import (
24+
backend_empty_cache,
25+
enable_full_determinism,
26+
nightly,
27+
require_torch_accelerator,
28+
skip_mps,
29+
torch_device,
30+
)
2431

2532
from ..pipeline_params import UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS, UNCONDITIONAL_AUDIO_GENERATION_PARAMS
2633
from ..test_pipelines_common import PipelineTesterMixin
@@ -116,19 +123,19 @@ def test_inference_batch_single_identical(self):
116123

117124

118125
@nightly
119-
@require_torch_gpu
126+
@require_torch_accelerator
120127
class PipelineIntegrationTests(unittest.TestCase):
121128
def setUp(self):
122129
# clean up the VRAM before each test
123130
super().setUp()
124131
gc.collect()
125-
torch.cuda.empty_cache()
132+
backend_empty_cache(torch_device)
126133

127134
def tearDown(self):
128135
# clean up the VRAM after each test
129136
super().tearDown()
130137
gc.collect()
131-
torch.cuda.empty_cache()
138+
backend_empty_cache(torch_device)
132139

133140
def test_dance_diffusion(self):
134141
device = torch_device

tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
VQModel,
2929
)
3030
from diffusers.utils.testing_utils import (
31+
backend_empty_cache,
3132
enable_full_determinism,
3233
floats_tensor,
3334
load_image,
3435
load_numpy,
3536
nightly,
3637
numpy_cosine_similarity_distance,
37-
require_torch_gpu,
38+
require_torch_accelerator,
39+
torch_device,
3840
)
3941

4042
from ..test_pipelines_common import PipelineTesterMixin
@@ -226,19 +228,19 @@ def test_inference_batch_single_identical(self):
226228

227229

228230
@nightly
229-
@require_torch_gpu
231+
@require_torch_accelerator
230232
class KandinskyV22ControlnetPipelineIntegrationTests(unittest.TestCase):
231233
def setUp(self):
232234
# clean up the VRAM before each test
233235
super().setUp()
234236
gc.collect()
235-
torch.cuda.empty_cache()
237+
backend_empty_cache(torch_device)
236238

237239
def tearDown(self):
238240
# clean up the VRAM after each test
239241
super().tearDown()
240242
gc.collect()
241-
torch.cuda.empty_cache()
243+
backend_empty_cache(torch_device)
242244

243245
def test_kandinsky_controlnet(self):
244246
expected_image = load_numpy(

tests/pipelines/kandinsky2_2/test_kandinsky_controlnet_img2img.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
VQModel,
3030
)
3131
from diffusers.utils.testing_utils import (
32+
backend_empty_cache,
3233
enable_full_determinism,
3334
floats_tensor,
3435
load_image,
3536
load_numpy,
3637
nightly,
3738
numpy_cosine_similarity_distance,
38-
require_torch_gpu,
39+
require_torch_accelerator,
40+
torch_device,
3941
)
4042

4143
from ..test_pipelines_common import PipelineTesterMixin
@@ -233,19 +235,19 @@ def test_float16_inference(self):
233235

234236

235237
@nightly
236-
@require_torch_gpu
238+
@require_torch_accelerator
237239
class KandinskyV22ControlnetImg2ImgPipelineIntegrationTests(unittest.TestCase):
238240
def setUp(self):
239241
# clean up the VRAM before each test
240242
super().setUp()
241243
gc.collect()
242-
torch.cuda.empty_cache()
244+
backend_empty_cache(torch_device)
243245

244246
def tearDown(self):
245247
# clean up the VRAM after each test
246248
super().tearDown()
247249
gc.collect()
248-
torch.cuda.empty_cache()
250+
backend_empty_cache(torch_device)
249251

250252
def test_kandinsky_controlnet_img2img(self):
251253
expected_image = load_numpy(
@@ -309,4 +311,4 @@ def test_kandinsky_controlnet_img2img(self):
309311
assert image.shape == (512, 512, 3)
310312

311313
max_diff = numpy_cosine_similarity_distance(expected_image.flatten(), image.flatten())
312-
assert max_diff < 1e-4
314+
assert max_diff < 5e-4

tests/pipelines/latent_diffusion/test_latent_diffusion.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
from diffusers import AutoencoderKL, DDIMScheduler, LDMTextToImagePipeline, UNet2DConditionModel
2424
from diffusers.utils.testing_utils import (
25+
backend_empty_cache,
2526
enable_full_determinism,
2627
load_numpy,
2728
nightly,
28-
require_torch_gpu,
29+
require_torch_accelerator,
2930
torch_device,
3031
)
3132

@@ -136,17 +137,17 @@ def test_inference_text2img(self):
136137

137138

138139
@nightly
139-
@require_torch_gpu
140+
@require_torch_accelerator
140141
class LDMTextToImagePipelineSlowTests(unittest.TestCase):
141142
def setUp(self):
142143
super().setUp()
143144
gc.collect()
144-
torch.cuda.empty_cache()
145+
backend_empty_cache(torch_device)
145146

146147
def tearDown(self):
147148
super().tearDown()
148149
gc.collect()
149-
torch.cuda.empty_cache()
150+
backend_empty_cache(torch_device)
150151

151152
def get_inputs(self, device, dtype=torch.float32, seed=0):
152153
generator = torch.manual_seed(seed)
@@ -177,17 +178,17 @@ def test_ldm_default_ddim(self):
177178

178179

179180
@nightly
180-
@require_torch_gpu
181+
@require_torch_accelerator
181182
class LDMTextToImagePipelineNightlyTests(unittest.TestCase):
182183
def setUp(self):
183184
super().setUp()
184185
gc.collect()
185-
torch.cuda.empty_cache()
186+
backend_empty_cache(torch_device)
186187

187188
def tearDown(self):
188189
super().tearDown()
189190
gc.collect()
190-
torch.cuda.empty_cache()
191+
backend_empty_cache(torch_device)
191192

192193
def get_inputs(self, device, dtype=torch.float32, seed=0):
193194
generator = torch.manual_seed(seed)

tests/pipelines/musicldm/test_musicldm.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@
3939
UNet2DConditionModel,
4040
)
4141
from diffusers.utils import is_xformers_available
42-
from diffusers.utils.testing_utils import enable_full_determinism, nightly, require_torch_gpu, torch_device
42+
from diffusers.utils.testing_utils import (
43+
backend_empty_cache,
44+
enable_full_determinism,
45+
nightly,
46+
require_torch_accelerator,
47+
torch_device,
48+
)
4349

4450
from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS, TEXT_TO_AUDIO_PARAMS
4551
from ..test_pipelines_common import PipelineTesterMixin
@@ -408,17 +414,17 @@ def test_to_dtype(self):
408414

409415

410416
@nightly
411-
@require_torch_gpu
417+
@require_torch_accelerator
412418
class MusicLDMPipelineNightlyTests(unittest.TestCase):
413419
def setUp(self):
414420
super().setUp()
415421
gc.collect()
416-
torch.cuda.empty_cache()
422+
backend_empty_cache(torch_device)
417423

418424
def tearDown(self):
419425
super().tearDown()
420426
gc.collect()
421-
torch.cuda.empty_cache()
427+
backend_empty_cache(torch_device)
422428

423429
def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
424430
generator = torch.Generator(device=generator_device).manual_seed(seed)

tests/pipelines/shap_e/test_shap_e.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121

2222
from diffusers import HeunDiscreteScheduler, PriorTransformer, ShapEPipeline
2323
from diffusers.pipelines.shap_e import ShapERenderer
24-
from diffusers.utils.testing_utils import load_numpy, nightly, require_torch_gpu, torch_device
24+
from diffusers.utils.testing_utils import (
25+
backend_empty_cache,
26+
load_numpy,
27+
nightly,
28+
require_torch_accelerator,
29+
torch_device,
30+
)
2531

2632
from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference
2733

@@ -222,19 +228,19 @@ def test_sequential_cpu_offload_forward_pass(self):
222228

223229

224230
@nightly
225-
@require_torch_gpu
231+
@require_torch_accelerator
226232
class ShapEPipelineIntegrationTests(unittest.TestCase):
227233
def setUp(self):
228234
# clean up the VRAM before each test
229235
super().setUp()
230236
gc.collect()
231-
torch.cuda.empty_cache()
237+
backend_empty_cache(torch_device)
232238

233239
def tearDown(self):
234240
# clean up the VRAM after each test
235241
super().tearDown()
236242
gc.collect()
237-
torch.cuda.empty_cache()
243+
backend_empty_cache(torch_device)
238244

239245
def test_shap_e(self):
240246
expected_image = load_numpy(

tests/pipelines/shap_e/test_shap_e_img2img.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
from diffusers import HeunDiscreteScheduler, PriorTransformer, ShapEImg2ImgPipeline
2424
from diffusers.pipelines.shap_e import ShapERenderer
2525
from diffusers.utils.testing_utils import (
26+
backend_empty_cache,
2627
floats_tensor,
2728
load_image,
2829
load_numpy,
2930
nightly,
30-
require_torch_gpu,
31+
require_torch_accelerator,
3132
torch_device,
3233
)
3334

@@ -250,19 +251,19 @@ def test_sequential_cpu_offload_forward_pass(self):
250251

251252

252253
@nightly
253-
@require_torch_gpu
254+
@require_torch_accelerator
254255
class ShapEImg2ImgPipelineIntegrationTests(unittest.TestCase):
255256
def setUp(self):
256257
# clean up the VRAM before each test
257258
super().setUp()
258259
gc.collect()
259-
torch.cuda.empty_cache()
260+
backend_empty_cache(torch_device)
260261

261262
def tearDown(self):
262263
# clean up the VRAM after each test
263264
super().tearDown()
264265
gc.collect()
265-
torch.cuda.empty_cache()
266+
backend_empty_cache(torch_device)
266267

267268
def test_shap_e_img2img(self):
268269
input_image = load_image(

0 commit comments

Comments
 (0)