Skip to content

Commit 59a00e4

Browse files
committed
enable esingle g
1 parent 186cdb6 commit 59a00e4

7 files changed

+45
-32
lines changed

tests/single_file/test_stable_diffusion_inpaint_single_file.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
)
99
from diffusers.utils import load_image
1010
from diffusers.utils.testing_utils import (
11+
backend_empty_cache,
1112
enable_full_determinism,
12-
require_torch_gpu,
13+
require_torch_accelerator,
1314
slow,
15+
torch_device,
1416
)
1517

1618
from .single_file_testing_utils import SDSingleFileTesterMixin
@@ -20,7 +22,7 @@
2022

2123

2224
@slow
23-
@require_torch_gpu
25+
@require_torch_accelerator
2426
class StableDiffusionInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
2527
pipeline_class = StableDiffusionInpaintPipeline
2628
ckpt_path = "https://huggingface.co/botp/stable-diffusion-v1-5-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
@@ -30,12 +32,12 @@ class StableDiffusionInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSin
3032
def setUp(self):
3133
super().setUp()
3234
gc.collect()
33-
torch.cuda.empty_cache()
35+
backend_empty_cache(torch_device)
3436

3537
def tearDown(self):
3638
super().tearDown()
3739
gc.collect()
38-
torch.cuda.empty_cache()
40+
backend_empty_cache(torch_device)
3941

4042
def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
4143
generator = torch.Generator(device=generator_device).manual_seed(seed)
@@ -78,7 +80,7 @@ def test_single_file_components_with_original_config_local_files_only(self):
7880

7981

8082
@slow
81-
@require_torch_gpu
83+
@require_torch_accelerator
8284
class StableDiffusion21InpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
8385
pipeline_class = StableDiffusionInpaintPipeline
8486
ckpt_path = (
@@ -90,12 +92,12 @@ class StableDiffusion21InpaintPipelineSingleFileSlowTests(unittest.TestCase, SDS
9092
def setUp(self):
9193
super().setUp()
9294
gc.collect()
93-
torch.cuda.empty_cache()
95+
backend_empty_cache(torch_device)
9496

9597
def tearDown(self):
9698
super().tearDown()
9799
gc.collect()
98-
torch.cuda.empty_cache()
100+
backend_empty_cache(torch_device)
99101

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

tests/single_file/test_stable_diffusion_upscale_single_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
)
99
from diffusers.utils import load_image
1010
from diffusers.utils.testing_utils import (
11+
backend_empty_cache,
1112
enable_full_determinism,
1213
numpy_cosine_similarity_distance,
13-
require_torch_gpu,
14+
require_torch_accelerator,
1415
slow,
16+
torch_device,
1517
)
1618

1719
from .single_file_testing_utils import SDSingleFileTesterMixin
@@ -21,7 +23,7 @@
2123

2224

2325
@slow
24-
@require_torch_gpu
26+
@require_torch_accelerator
2527
class StableDiffusionUpscalePipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
2628
pipeline_class = StableDiffusionUpscalePipeline
2729
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler/blob/main/x4-upscaler-ema.safetensors"
@@ -31,12 +33,12 @@ class StableDiffusionUpscalePipelineSingleFileSlowTests(unittest.TestCase, SDSin
3133
def setUp(self):
3234
super().setUp()
3335
gc.collect()
34-
torch.cuda.empty_cache()
36+
backend_empty_cache(torch_device)
3537

3638
def tearDown(self):
3739
super().tearDown()
3840
gc.collect()
39-
torch.cuda.empty_cache()
41+
backend_empty_cache(torch_device)
4042

4143
def test_single_file_format_inference_is_same_as_pretrained(self):
4244
image = load_image(

tests/single_file/test_stable_diffusion_xl_adapter_single_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
1212
from diffusers.utils import load_image
1313
from diffusers.utils.testing_utils import (
14+
backend_empty_cache,
1415
enable_full_determinism,
1516
numpy_cosine_similarity_distance,
16-
require_torch_gpu,
17+
require_torch_accelerator,
1718
slow,
19+
torch_device,
1820
)
1921

2022
from .single_file_testing_utils import (
@@ -29,7 +31,7 @@
2931

3032

3133
@slow
32-
@require_torch_gpu
34+
@require_torch_accelerator
3335
class StableDiffusionXLAdapterPipelineSingleFileSlowTests(unittest.TestCase, SDXLSingleFileTesterMixin):
3436
pipeline_class = StableDiffusionXLAdapterPipeline
3537
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
@@ -41,12 +43,12 @@ class StableDiffusionXLAdapterPipelineSingleFileSlowTests(unittest.TestCase, SDX
4143
def setUp(self):
4244
super().setUp()
4345
gc.collect()
44-
torch.cuda.empty_cache()
46+
backend_empty_cache(torch_device)
4547

4648
def tearDown(self):
4749
super().tearDown()
4850
gc.collect()
49-
torch.cuda.empty_cache()
51+
backend_empty_cache(torch_device)
5052

5153
def get_inputs(self):
5254
prompt = "toy"

tests/single_file/test_stable_diffusion_xl_controlnet_single_file.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
99
from diffusers.utils import load_image
1010
from diffusers.utils.testing_utils import (
11+
backend_empty_cache,
1112
enable_full_determinism,
1213
numpy_cosine_similarity_distance,
13-
require_torch_gpu,
14+
require_torch_accelerator,
1415
slow,
1516
torch_device,
1617
)
@@ -26,7 +27,7 @@
2627

2728

2829
@slow
29-
@require_torch_gpu
30+
@require_torch_accelerator
3031
class StableDiffusionXLControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDXLSingleFileTesterMixin):
3132
pipeline_class = StableDiffusionXLControlNetPipeline
3233
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
@@ -38,12 +39,12 @@ class StableDiffusionXLControlNetPipelineSingleFileSlowTests(unittest.TestCase,
3839
def setUp(self):
3940
super().setUp()
4041
gc.collect()
41-
torch.cuda.empty_cache()
42+
backend_empty_cache(torch_device)
4243

4344
def tearDown(self):
4445
super().tearDown()
4546
gc.collect()
46-
torch.cuda.empty_cache()
47+
backend_empty_cache(torch_device)
4748

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

tests/single_file/test_stable_diffusion_xl_img2img_single_file.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
)
1010
from diffusers.utils import load_image
1111
from diffusers.utils.testing_utils import (
12+
backend_empty_cache,
1213
enable_full_determinism,
1314
numpy_cosine_similarity_distance,
14-
require_torch_gpu,
15+
require_torch_accelerator,
1516
slow,
17+
torch_device,
1618
)
1719

1820
from .single_file_testing_utils import SDXLSingleFileTesterMixin
@@ -22,7 +24,7 @@
2224

2325

2426
@slow
25-
@require_torch_gpu
27+
@require_torch_accelerator
2628
class StableDiffusionXLImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDXLSingleFileTesterMixin):
2729
pipeline_class = StableDiffusionXLImg2ImgPipeline
2830
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
@@ -34,12 +36,12 @@ class StableDiffusionXLImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDX
3436
def setUp(self):
3537
super().setUp()
3638
gc.collect()
37-
torch.cuda.empty_cache()
39+
backend_empty_cache(torch_device)
3840

3941
def tearDown(self):
4042
super().tearDown()
4143
gc.collect()
42-
torch.cuda.empty_cache()
44+
backend_empty_cache(torch_device)
4345

4446
def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
4547
generator = torch.Generator(device=generator_device).manual_seed(seed)
@@ -63,7 +65,7 @@ def test_single_file_format_inference_is_same_as_pretrained(self):
6365

6466

6567
@slow
66-
@require_torch_gpu
68+
@require_torch_accelerator
6769
class StableDiffusionXLImg2ImgRefinerPipelineSingleFileSlowTests(unittest.TestCase):
6870
pipeline_class = StableDiffusionXLImg2ImgPipeline
6971
ckpt_path = (

tests/single_file/test_stable_diffusion_xl_instruct_pix2pix.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55

66
from diffusers import StableDiffusionXLInstructPix2PixPipeline
77
from diffusers.utils.testing_utils import (
8+
backend_empty_cache,
89
enable_full_determinism,
9-
require_torch_gpu,
10+
require_torch_accelerator,
1011
slow,
12+
torch_device,
1113
)
1214

1315

1416
enable_full_determinism()
1517

1618

1719
@slow
18-
@require_torch_gpu
20+
@require_torch_accelerator
1921
class StableDiffusionXLInstructPix2PixPipeline(unittest.TestCase):
2022
pipeline_class = StableDiffusionXLInstructPix2PixPipeline
2123
ckpt_path = "https://huggingface.co/stabilityai/cosxl/blob/main/cosxl_edit.safetensors"
@@ -25,12 +27,12 @@ class StableDiffusionXLInstructPix2PixPipeline(unittest.TestCase):
2527
def setUp(self):
2628
super().setUp()
2729
gc.collect()
28-
torch.cuda.empty_cache()
30+
backend_empty_cache(torch_device)
2931

3032
def tearDown(self):
3133
super().tearDown()
3234
gc.collect()
33-
torch.cuda.empty_cache()
35+
backend_empty_cache(torch_device)
3436

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

tests/single_file/test_stable_diffusion_xl_single_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
StableDiffusionXLPipeline,
88
)
99
from diffusers.utils.testing_utils import (
10+
backend_empty_cache,
1011
enable_full_determinism,
11-
require_torch_gpu,
12+
require_torch_accelerator,
1213
slow,
14+
torch_device,
1315
)
1416

1517
from .single_file_testing_utils import SDXLSingleFileTesterMixin
@@ -19,7 +21,7 @@
1921

2022

2123
@slow
22-
@require_torch_gpu
24+
@require_torch_accelerator
2325
class StableDiffusionXLPipelineSingleFileSlowTests(unittest.TestCase, SDXLSingleFileTesterMixin):
2426
pipeline_class = StableDiffusionXLPipeline
2527
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
@@ -31,12 +33,12 @@ class StableDiffusionXLPipelineSingleFileSlowTests(unittest.TestCase, SDXLSingle
3133
def setUp(self):
3234
super().setUp()
3335
gc.collect()
34-
torch.cuda.empty_cache()
36+
backend_empty_cache(torch_device)
3537

3638
def tearDown(self):
3739
super().tearDown()
3840
gc.collect()
39-
torch.cuda.empty_cache()
41+
backend_empty_cache(torch_device)
4042

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

0 commit comments

Comments
 (0)