Skip to content

Commit 8a86f6e

Browse files
authored
Merge branch 'main' into let-server-decide-default-repo-visibility
2 parents ffe64b8 + 6b288ec commit 8a86f6e

17 files changed

+99
-72
lines changed

docs/source/en/api/pipelines/flux.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ image.save("output.png")
148148
**Note:** `black-forest-labs/Flux.1-Depth-dev` is _not_ a ControlNet model. [`ControlNetModel`] models are a separate component from the UNet/Transformer whose residuals are added to the actual underlying model. Depth Control is an alternate architecture that achieves effectively the same results as a ControlNet model would, by using channel-wise concatenation with input control condition and ensuring the transformer learns structure control by following the condition as closely as possible.
149149

150150
```python
151-
# !pip install git+https://github.com/asomoza/image_gen_aux.git
151+
# !pip install git+https://github.com/huggingface/image_gen_aux
152152
import torch
153153
from diffusers import FluxControlPipeline, FluxTransformer2DModel
154154
from diffusers.utils import load_image

tests/single_file/single_file_testing_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ def test_single_file_components_with_original_config_local_files_only(
156156
def test_single_file_format_inference_is_same_as_pretrained(self, expected_max_diff=1e-4):
157157
sf_pipe = self.pipeline_class.from_single_file(self.ckpt_path, safety_checker=None)
158158
sf_pipe.unet.set_attn_processor(AttnProcessor())
159-
sf_pipe.enable_model_cpu_offload()
159+
sf_pipe.enable_model_cpu_offload(device=torch_device)
160160

161161
inputs = self.get_inputs(torch_device)
162162
image_single_file = sf_pipe(**inputs).images[0]
163163

164164
pipe = self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)
165165
pipe.unet.set_attn_processor(AttnProcessor())
166-
pipe.enable_model_cpu_offload()
166+
pipe.enable_model_cpu_offload(device=torch_device)
167167

168168
inputs = self.get_inputs(torch_device)
169169
image = pipe(**inputs).images[0]

tests/single_file/test_model_controlnet_single_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@
2222
ControlNetModel,
2323
)
2424
from diffusers.utils.testing_utils import (
25+
backend_empty_cache,
2526
enable_full_determinism,
26-
require_torch_gpu,
27+
require_torch_accelerator,
2728
slow,
29+
torch_device,
2830
)
2931

3032

3133
enable_full_determinism()
3234

3335

3436
@slow
35-
@require_torch_gpu
37+
@require_torch_accelerator
3638
class ControlNetModelSingleFileTests(unittest.TestCase):
3739
model_class = ControlNetModel
3840
ckpt_path = "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth"
@@ -41,12 +43,12 @@ class ControlNetModelSingleFileTests(unittest.TestCase):
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 test_single_file_components(self):
5254
model = self.model_class.from_pretrained(self.repo_id)

tests/single_file/test_model_sd_cascade_unet_single_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
from diffusers import StableCascadeUNet
2222
from diffusers.utils import logging
2323
from diffusers.utils.testing_utils import (
24+
backend_empty_cache,
2425
enable_full_determinism,
25-
require_torch_gpu,
26+
require_torch_accelerator,
2627
slow,
28+
torch_device,
2729
)
2830

2931

@@ -33,17 +35,17 @@
3335

3436

3537
@slow
36-
@require_torch_gpu
38+
@require_torch_accelerator
3739
class StableCascadeUNetSingleFileTest(unittest.TestCase):
3840
def setUp(self):
3941
super().setUp()
4042
gc.collect()
41-
torch.cuda.empty_cache()
43+
backend_empty_cache(torch_device)
4244

4345
def tearDown(self):
4446
super().tearDown()
4547
gc.collect()
46-
torch.cuda.empty_cache()
48+
backend_empty_cache(torch_device)
4749

4850
def test_single_file_components_stage_b(self):
4951
model_single_file = StableCascadeUNet.from_single_file(

tests/single_file/test_model_vae_single_file.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
AutoencoderKL,
2323
)
2424
from diffusers.utils.testing_utils import (
25+
backend_empty_cache,
2526
enable_full_determinism,
2627
load_hf_numpy,
2728
numpy_cosine_similarity_distance,
28-
require_torch_gpu,
29+
require_torch_accelerator,
2930
slow,
3031
torch_device,
3132
)
@@ -35,7 +36,7 @@
3536

3637

3738
@slow
38-
@require_torch_gpu
39+
@require_torch_accelerator
3940
class AutoencoderKLSingleFileTests(unittest.TestCase):
4041
model_class = AutoencoderKL
4142
ckpt_path = (
@@ -48,12 +49,12 @@ class AutoencoderKLSingleFileTests(unittest.TestCase):
4849
def setUp(self):
4950
super().setUp()
5051
gc.collect()
51-
torch.cuda.empty_cache()
52+
backend_empty_cache(torch_device)
5253

5354
def tearDown(self):
5455
super().tearDown()
5556
gc.collect()
56-
torch.cuda.empty_cache()
57+
backend_empty_cache(torch_device)
5758

5859
def get_file_format(self, seed, shape):
5960
return f"gaussian_noise_s={seed}_shape={'_'.join([str(s) for s in shape])}.npy"

tests/single_file/test_stable_diffusion_controlnet_img2img_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
)
@@ -27,7 +28,7 @@
2728

2829

2930
@slow
30-
@require_torch_gpu
31+
@require_torch_accelerator
3132
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
3233
pipeline_class = StableDiffusionControlNetPipeline
3334
ckpt_path = (
@@ -41,12 +42,12 @@ class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SD
4142
def setUp(self):
4243
super().setUp()
4344
gc.collect()
44-
torch.cuda.empty_cache()
45+
backend_empty_cache(torch_device)
4546

4647
def tearDown(self):
4748
super().tearDown()
4849
gc.collect()
49-
torch.cuda.empty_cache()
50+
backend_empty_cache(torch_device)
5051

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

tests/single_file/test_stable_diffusion_controlnet_inpaint_single_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
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,
16+
torch_device,
1517
)
1618

1719
from .single_file_testing_utils import (
@@ -26,7 +28,7 @@
2628

2729

2830
@slow
29-
@require_torch_gpu
31+
@require_torch_accelerator
3032
class StableDiffusionControlNetInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
3133
pipeline_class = StableDiffusionControlNetInpaintPipeline
3234
ckpt_path = "https://huggingface.co/botp/stable-diffusion-v1-5-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
@@ -36,12 +38,12 @@ class StableDiffusionControlNetInpaintPipelineSingleFileSlowTests(unittest.TestC
3638
def setUp(self):
3739
super().setUp()
3840
gc.collect()
39-
torch.cuda.empty_cache()
41+
backend_empty_cache(torch_device)
4042

4143
def tearDown(self):
4244
super().tearDown()
4345
gc.collect()
44-
torch.cuda.empty_cache()
46+
backend_empty_cache(torch_device)
4547

4648
def get_inputs(self):
4749
control_image = load_image(

tests/single_file/test_stable_diffusion_controlnet_single_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
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,
16+
torch_device,
1517
)
1618

1719
from .single_file_testing_utils import (
@@ -26,7 +28,7 @@
2628

2729

2830
@slow
29-
@require_torch_gpu
31+
@require_torch_accelerator
3032
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
3133
pipeline_class = StableDiffusionControlNetPipeline
3234
ckpt_path = (
@@ -40,12 +42,12 @@ class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SD
4042
def setUp(self):
4143
super().setUp()
4244
gc.collect()
43-
torch.cuda.empty_cache()
45+
backend_empty_cache(torch_device)
4446

4547
def tearDown(self):
4648
super().tearDown()
4749
gc.collect()
48-
torch.cuda.empty_cache()
50+
backend_empty_cache(torch_device)
4951

5052
def get_inputs(self):
5153
control_image = load_image(

tests/single_file/test_stable_diffusion_img2img_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 StableDiffusionImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
2527
pipeline_class = StableDiffusionImg2ImgPipeline
2628
ckpt_path = (
@@ -34,12 +36,12 @@ class StableDiffusionImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSin
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 StableDiffusion21Img2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
6870
pipeline_class = StableDiffusionImg2ImgPipeline
6971
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-2-1/blob/main/v2-1_768-ema-pruned.safetensors"
@@ -73,12 +75,12 @@ class StableDiffusion21Img2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDS
7375
def setUp(self):
7476
super().setUp()
7577
gc.collect()
76-
torch.cuda.empty_cache()
78+
backend_empty_cache(torch_device)
7779

7880
def tearDown(self):
7981
super().tearDown()
8082
gc.collect()
81-
torch.cuda.empty_cache()
83+
backend_empty_cache(torch_device)
8284

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

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)

0 commit comments

Comments
 (0)