Skip to content

Commit 5c02d93

Browse files
DN6sayakpaul
authored andcommitted
[CI] Update Single file Nightly Tests (#9357)
* update * update
1 parent b4ab5b0 commit 5c02d93

9 files changed

+77
-58
lines changed

tests/single_file/single_file_testing_utils.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66
from huggingface_hub import hf_hub_download, snapshot_download
77

8+
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
89
from diffusers.models.attention_processor import AttnProcessor
910
from diffusers.utils.testing_utils import (
1011
numpy_cosine_similarity_distance,
@@ -98,8 +99,8 @@ def test_single_file_components_local_files_only(self, pipe=None, single_file_pi
9899
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)
99100

100101
with tempfile.TemporaryDirectory() as tmpdir:
101-
ckpt_filename = self.ckpt_path.split("/")[-1]
102-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
102+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
103+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
103104

104105
single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
105106
local_ckpt_path, safety_checker=None, local_files_only=True
@@ -138,8 +139,8 @@ def test_single_file_components_with_original_config_local_files_only(
138139
upcast_attention = pipe.unet.config.upcast_attention
139140

140141
with tempfile.TemporaryDirectory() as tmpdir:
141-
ckpt_filename = self.ckpt_path.split("/")[-1]
142-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
142+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
143+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
143144
local_original_config = download_original_config(self.original_config, tmpdir)
144145

145146
single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
@@ -191,8 +192,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(
191192
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)
192193

193194
with tempfile.TemporaryDirectory() as tmpdir:
194-
ckpt_filename = self.ckpt_path.split("/")[-1]
195-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
195+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
196+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
196197
local_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)
197198

198199
single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
@@ -286,8 +287,8 @@ def test_single_file_components_local_files_only(
286287
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)
287288

288289
with tempfile.TemporaryDirectory() as tmpdir:
289-
ckpt_filename = self.ckpt_path.split("/")[-1]
290-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
290+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
291+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
291292

292293
single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
293294
local_ckpt_path, safety_checker=None, local_files_only=True
@@ -327,8 +328,8 @@ def test_single_file_components_with_original_config_local_files_only(
327328
upcast_attention = pipe.unet.config.upcast_attention
328329

329330
with tempfile.TemporaryDirectory() as tmpdir:
330-
ckpt_filename = self.ckpt_path.split("/")[-1]
331-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
331+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
332+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
332333
local_original_config = download_original_config(self.original_config, tmpdir)
333334

334335
single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
@@ -364,8 +365,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(
364365
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)
365366

366367
with tempfile.TemporaryDirectory() as tmpdir:
367-
ckpt_filename = self.ckpt_path.split("/")[-1]
368-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
368+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
369+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
369370
local_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)
370371

371372
single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(

tests/single_file/test_stable_diffusion_controlnet_img2img_single_file.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66

77
from diffusers import ControlNetModel, StableDiffusionControlNetPipeline
8+
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
89
from diffusers.utils import load_image
910
from diffusers.utils.testing_utils import (
1011
enable_full_determinism,
@@ -29,11 +30,11 @@
2930
@require_torch_gpu
3031
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
3132
pipeline_class = StableDiffusionControlNetPipeline
32-
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
33+
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
3334
original_config = (
3435
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
3536
)
36-
repo_id = "runwayml/stable-diffusion-v1-5"
37+
repo_id = "Lykon/dreamshaper-8"
3738

3839
def setUp(self):
3940
super().setUp()
@@ -108,8 +109,8 @@ def test_single_file_components_local_files_only(self):
108109
pipe = self.pipeline_class.from_pretrained(self.repo_id, controlnet=controlnet)
109110

110111
with tempfile.TemporaryDirectory() as tmpdir:
111-
ckpt_filename = self.ckpt_path.split("/")[-1]
112-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
112+
repo_id, weights_name = _extract_repo_id_and_weights_name(self.ckpt_path)
113+
local_ckpt_path = download_single_file_checkpoint(repo_id, weights_name, tmpdir)
113114

114115
pipe_single_file = self.pipeline_class.from_single_file(
115116
local_ckpt_path, controlnet=controlnet, safety_checker=None, local_files_only=True
@@ -136,8 +137,9 @@ def test_single_file_components_with_original_config_local_files_only(self):
136137
)
137138

138139
with tempfile.TemporaryDirectory() as tmpdir:
139-
ckpt_filename = self.ckpt_path.split("/")[-1]
140-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
140+
repo_id, weights_name = _extract_repo_id_and_weights_name(self.ckpt_path)
141+
local_ckpt_path = download_single_file_checkpoint(repo_id, weights_name, tmpdir)
142+
141143
local_original_config = download_original_config(self.original_config, tmpdir)
142144

143145
pipe_single_file = self.pipeline_class.from_single_file(
@@ -168,8 +170,9 @@ def test_single_file_components_with_diffusers_config_local_files_only(self):
168170
)
169171

170172
with tempfile.TemporaryDirectory() as tmpdir:
171-
ckpt_filename = self.ckpt_path.split("/")[-1]
172-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
173+
repo_id, weights_name = _extract_repo_id_and_weights_name(self.ckpt_path)
174+
local_ckpt_path = download_single_file_checkpoint(repo_id, weights_name, tmpdir)
175+
173176
local_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)
174177

175178
pipe_single_file = self.pipeline_class.from_single_file(

tests/single_file/test_stable_diffusion_controlnet_inpaint_single_file.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66

77
from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
8+
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
89
from diffusers.utils import load_image
910
from diffusers.utils.testing_utils import (
1011
enable_full_determinism,
@@ -28,9 +29,9 @@
2829
@require_torch_gpu
2930
class StableDiffusionControlNetInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
3031
pipeline_class = StableDiffusionControlNetInpaintPipeline
31-
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
32+
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_INPAINTING.inpainting.safetensors"
3233
original_config = "https://raw.githubusercontent.com/runwayml/stable-diffusion/main/configs/stable-diffusion/v1-inpainting-inference.yaml"
33-
repo_id = "runwayml/stable-diffusion-inpainting"
34+
repo_id = "Lykon/dreamshaper-8-inpainting"
3435

3536
def setUp(self):
3637
super().setUp()
@@ -83,7 +84,7 @@ def test_single_file_format_inference_is_same_as_pretrained(self):
8384
output_sf = pipe_sf(**inputs).images[0]
8485

8586
max_diff = numpy_cosine_similarity_distance(output_sf.flatten(), output.flatten())
86-
assert max_diff < 1e-3
87+
assert max_diff < 2e-3
8788

8889
def test_single_file_components(self):
8990
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny")
@@ -103,15 +104,16 @@ def test_single_file_components_local_files_only(self):
103104
pipe = self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None, controlnet=controlnet)
104105

105106
with tempfile.TemporaryDirectory() as tmpdir:
106-
ckpt_filename = self.ckpt_path.split("/")[-1]
107-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
107+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
108+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
108109

109110
pipe_single_file = self.pipeline_class.from_single_file(
110111
local_ckpt_path, controlnet=controlnet, safety_checker=None, local_files_only=True
111112
)
112113

113114
super()._compare_component_configs(pipe, pipe_single_file)
114115

116+
@unittest.skip("runwayml original config repo does not exist")
115117
def test_single_file_components_with_original_config(self):
116118
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny", variant="fp16")
117119
pipe = self.pipeline_class.from_pretrained(self.repo_id, controlnet=controlnet)
@@ -121,6 +123,7 @@ def test_single_file_components_with_original_config(self):
121123

122124
super()._compare_component_configs(pipe, pipe_single_file)
123125

126+
@unittest.skip("runwayml original config repo does not exist")
124127
def test_single_file_components_with_original_config_local_files_only(self):
125128
controlnet = ControlNetModel.from_pretrained(
126129
"lllyasviel/control_v11p_sd15_canny", torch_dtype=torch.float16, variant="fp16"
@@ -132,8 +135,8 @@ def test_single_file_components_with_original_config_local_files_only(self):
132135
)
133136

134137
with tempfile.TemporaryDirectory() as tmpdir:
135-
ckpt_filename = self.ckpt_path.split("/")[-1]
136-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
138+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
139+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
137140
local_original_config = download_original_config(self.original_config, tmpdir)
138141

139142
pipe_single_file = self.pipeline_class.from_single_file(
@@ -169,8 +172,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(self):
169172
)
170173

171174
with tempfile.TemporaryDirectory() as tmpdir:
172-
ckpt_filename = self.ckpt_path.split("/")[-1]
173-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
175+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
176+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
174177
local_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)
175178

176179
pipe_single_file = self.pipeline_class.from_single_file(

tests/single_file/test_stable_diffusion_controlnet_single_file.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66

77
from diffusers import ControlNetModel, StableDiffusionControlNetPipeline
8+
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
89
from diffusers.utils import load_image
910
from diffusers.utils.testing_utils import (
1011
enable_full_determinism,
@@ -28,11 +29,11 @@
2829
@require_torch_gpu
2930
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
3031
pipeline_class = StableDiffusionControlNetPipeline
31-
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
32+
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
3233
original_config = (
3334
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
3435
)
35-
repo_id = "runwayml/stable-diffusion-v1-5"
36+
repo_id = "Lykon/dreamshaper-8"
3637

3738
def setUp(self):
3839
super().setUp()
@@ -98,8 +99,8 @@ def test_single_file_components_local_files_only(self):
9899
pipe = self.pipeline_class.from_pretrained(self.repo_id, controlnet=controlnet)
99100

100101
with tempfile.TemporaryDirectory() as tmpdir:
101-
ckpt_filename = self.ckpt_path.split("/")[-1]
102-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
102+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
103+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
103104

104105
pipe_single_file = self.pipeline_class.from_single_file(
105106
local_ckpt_path, controlnet=controlnet, local_files_only=True
@@ -126,8 +127,8 @@ def test_single_file_components_with_original_config_local_files_only(self):
126127
)
127128

128129
with tempfile.TemporaryDirectory() as tmpdir:
129-
ckpt_filename = self.ckpt_path.split("/")[-1]
130-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
130+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
131+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
131132
local_original_config = download_original_config(self.original_config, tmpdir)
132133

133134
pipe_single_file = self.pipeline_class.from_single_file(
@@ -157,8 +158,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(self):
157158
)
158159

159160
with tempfile.TemporaryDirectory() as tmpdir:
160-
ckpt_filename = self.ckpt_path.split("/")[-1]
161-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
161+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
162+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
162163
local_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)
163164

164165
pipe_single_file = self.pipeline_class.from_single_file(

tests/single_file/test_stable_diffusion_img2img_single_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
@require_torch_gpu
2424
class StableDiffusionImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
2525
pipeline_class = StableDiffusionImg2ImgPipeline
26-
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
26+
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
2727
original_config = (
2828
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
2929
)
30-
repo_id = "runwayml/stable-diffusion-v1-5"
30+
repo_id = "Lykon/dreamshaper-8"
3131

3232
def setUp(self):
3333
super().setUp()

tests/single_file/test_stable_diffusion_inpaint_single_file.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
@require_torch_gpu
2424
class StableDiffusionInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
2525
pipeline_class = StableDiffusionInpaintPipeline
26-
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
26+
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_INPAINTING.inpainting.safetensors"
2727
original_config = "https://raw.githubusercontent.com/runwayml/stable-diffusion/main/configs/stable-diffusion/v1-inpainting-inference.yaml"
28-
repo_id = "runwayml/stable-diffusion-inpainting"
28+
repo_id = "Lykon/dreamshaper-8-inpainting"
2929

3030
def setUp(self):
3131
super().setUp()
@@ -63,11 +63,19 @@ def test_single_file_format_inference_is_same_as_pretrained(self):
6363

6464
def test_single_file_loading_4_channel_unet(self):
6565
# Test loading single file inpaint with a 4 channel UNet
66-
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
66+
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
6767
pipe = self.pipeline_class.from_single_file(ckpt_path)
6868

6969
assert pipe.unet.config.in_channels == 4
7070

71+
@unittest.skip("runwayml original config has been removed")
72+
def test_single_file_components_with_original_config(self):
73+
return
74+
75+
@unittest.skip("runwayml original config has been removed")
76+
def test_single_file_components_with_original_config_local_files_only(self):
77+
return
78+
7179

7280
@slow
7381
@require_torch_gpu

tests/single_file/test_stable_diffusion_single_file.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66

77
from diffusers import EulerDiscreteScheduler, StableDiffusionPipeline
8+
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
89
from diffusers.utils.testing_utils import (
910
enable_full_determinism,
1011
require_torch_gpu,
@@ -25,11 +26,11 @@
2526
@require_torch_gpu
2627
class StableDiffusionPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
2728
pipeline_class = StableDiffusionPipeline
28-
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
29+
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
2930
original_config = (
3031
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
3132
)
32-
repo_id = "runwayml/stable-diffusion-v1-5"
33+
repo_id = "Lykon/dreamshaper-8"
3334

3435
def setUp(self):
3536
super().setUp()
@@ -58,8 +59,8 @@ def test_single_file_format_inference_is_same_as_pretrained(self):
5859

5960
def test_single_file_legacy_scheduler_loading(self):
6061
with tempfile.TemporaryDirectory() as tmpdir:
61-
ckpt_filename = self.ckpt_path.split("/")[-1]
62-
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
62+
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
63+
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
6364
local_original_config = download_original_config(self.original_config, tmpdir)
6465

6566
pipe = self.pipeline_class.from_single_file(

0 commit comments

Comments
 (0)