2525from diffusers import AutoencoderKL , DDIMScheduler , LMSDiscreteScheduler , PNDMScheduler , UNet2DConditionModel
2626from diffusers .pipelines .semantic_stable_diffusion import SemanticStableDiffusionPipeline as StableDiffusionPipeline
2727from diffusers .utils .testing_utils import (
28+ backend_empty_cache ,
2829 enable_full_determinism ,
2930 floats_tensor ,
3031 nightly ,
31- require_accelerator ,
32- require_torch_gpu ,
32+ require_torch_accelerator ,
3333 torch_device ,
3434)
3535
@@ -42,13 +42,13 @@ def setUp(self):
4242 # clean up the VRAM before each test
4343 super ().setUp ()
4444 gc .collect ()
45- torch . cuda . empty_cache ( )
45+ backend_empty_cache ( torch_device )
4646
4747 def tearDown (self ):
4848 # clean up the VRAM after each test
4949 super ().tearDown ()
5050 gc .collect ()
51- torch . cuda . empty_cache ( )
51+ backend_empty_cache ( torch_device )
5252
5353 @property
5454 def dummy_image (self ):
@@ -238,7 +238,7 @@ def test_semantic_diffusion_no_safety_checker(self):
238238 image = pipe ("example prompt" , num_inference_steps = 2 ).images [0 ]
239239 assert image is not None
240240
241- @require_accelerator
241+ @require_torch_accelerator
242242 def test_semantic_diffusion_fp16 (self ):
243243 """Test that stable diffusion works with fp16"""
244244 unet = self .dummy_cond_unet
@@ -272,22 +272,21 @@ def test_semantic_diffusion_fp16(self):
272272
273273
274274@nightly
275- @require_torch_gpu
275+ @require_torch_accelerator
276276class SemanticDiffusionPipelineIntegrationTests (unittest .TestCase ):
277277 def setUp (self ):
278278 # clean up the VRAM before each test
279279 super ().setUp ()
280280 gc .collect ()
281- torch . cuda . empty_cache ( )
281+ backend_empty_cache ( torch_device )
282282
283283 def tearDown (self ):
284284 # clean up the VRAM after each test
285285 super ().tearDown ()
286286 gc .collect ()
287- torch . cuda . empty_cache ( )
287+ backend_empty_cache ( torch_device )
288288
289289 def test_positive_guidance (self ):
290- torch_device = "cuda"
291290 pipe = StableDiffusionPipeline .from_pretrained ("stable-diffusion-v1-5/stable-diffusion-v1-5" )
292291 pipe = pipe .to (torch_device )
293292 pipe .set_progress_bar_config (disable = None )
@@ -370,7 +369,6 @@ def test_positive_guidance(self):
370369 assert np .abs (image_slice .flatten () - expected_slice ).max () < 1e-2
371370
372371 def test_negative_guidance (self ):
373- torch_device = "cuda"
374372 pipe = StableDiffusionPipeline .from_pretrained ("stable-diffusion-v1-5/stable-diffusion-v1-5" )
375373 pipe = pipe .to (torch_device )
376374 pipe .set_progress_bar_config (disable = None )
@@ -453,7 +451,6 @@ def test_negative_guidance(self):
453451 assert np .abs (image_slice .flatten () - expected_slice ).max () < 1e-2
454452
455453 def test_multi_cond_guidance (self ):
456- torch_device = "cuda"
457454 pipe = StableDiffusionPipeline .from_pretrained ("stable-diffusion-v1-5/stable-diffusion-v1-5" )
458455 pipe = pipe .to (torch_device )
459456 pipe .set_progress_bar_config (disable = None )
@@ -536,7 +533,6 @@ def test_multi_cond_guidance(self):
536533 assert np .abs (image_slice .flatten () - expected_slice ).max () < 1e-2
537534
538535 def test_guidance_fp16 (self ):
539- torch_device = "cuda"
540536 pipe = StableDiffusionPipeline .from_pretrained (
541537 "stable-diffusion-v1-5/stable-diffusion-v1-5" , torch_dtype = torch .float16
542538 )
0 commit comments