Skip to content

Commit 12fbe3f

Browse files
hlkysayakpaul
andauthored
Use Pipelines without unet (#10440)
* Use Pipelines without unet * unet.config.in_channels * default_sample_size * is_unet_version_less_0_9_0 --------- Co-authored-by: Sayak Paul <[email protected]>
1 parent 83ba01a commit 12fbe3f

File tree

56 files changed

+377
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+377
-166
lines changed

Diff for: examples/community/adaptive_mask_inpainting.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,14 @@ def __init__(
416416
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
417417
)
418418

419-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
420-
version.parse(unet.config._diffusers_version).base_version
421-
) < version.parse("0.9.0.dev0")
422-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
419+
is_unet_version_less_0_9_0 = (
420+
unet is not None
421+
and hasattr(unet.config, "_diffusers_version")
422+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
423+
)
424+
is_unet_sample_size_less_64 = (
425+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
426+
)
423427
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
424428
deprecation_message = (
425429
"The configuration file of the unet has set the default `sample_size` to smaller than"
@@ -438,7 +442,7 @@ def __init__(
438442
unet._internal_dict = FrozenDict(new_config)
439443

440444
# Check shapes, assume num_channels_latents == 4, num_channels_mask == 1, num_channels_masked == 4
441-
if unet.config.in_channels != 9:
445+
if unet is not None and unet.config.in_channels != 9:
442446
logger.info(f"You have loaded a UNet with {unet.config.in_channels} input channels which.")
443447

444448
self.register_modules(

Diff for: examples/community/composable_stable_diffusion.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,14 @@ def __init__(
132132
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
133133
)
134134

135-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
136-
version.parse(unet.config._diffusers_version).base_version
137-
) < version.parse("0.9.0.dev0")
138-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
135+
is_unet_version_less_0_9_0 = (
136+
unet is not None
137+
and hasattr(unet.config, "_diffusers_version")
138+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
139+
)
140+
is_unet_sample_size_less_64 = (
141+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
142+
)
139143
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
140144
deprecation_message = (
141145
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/instaflow_one_step.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ def __init__(
152152
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
153153
)
154154

155-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
156-
version.parse(unet.config._diffusers_version).base_version
157-
) < version.parse("0.9.0.dev0")
158-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
155+
is_unet_version_less_0_9_0 = (
156+
unet is not None
157+
and hasattr(unet.config, "_diffusers_version")
158+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
159+
)
160+
is_unet_sample_size_less_64 = (
161+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
162+
)
159163
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
160164
deprecation_message = (
161165
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/ip_adapter_face_id.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ def __init__(
234234
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
235235
)
236236

237-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
238-
version.parse(unet.config._diffusers_version).base_version
239-
) < version.parse("0.9.0.dev0")
240-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
237+
is_unet_version_less_0_9_0 = (
238+
unet is not None
239+
and hasattr(unet.config, "_diffusers_version")
240+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
241+
)
242+
is_unet_sample_size_less_64 = (
243+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
244+
)
241245
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
242246
deprecation_message = (
243247
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/llm_grounded_diffusion.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,14 @@ def __init__(
379379
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
380380
)
381381

382-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
383-
version.parse(unet.config._diffusers_version).base_version
384-
) < version.parse("0.9.0.dev0")
385-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
382+
is_unet_version_less_0_9_0 = (
383+
unet is not None
384+
and hasattr(unet.config, "_diffusers_version")
385+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
386+
)
387+
is_unet_sample_size_less_64 = (
388+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
389+
)
386390
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
387391
deprecation_message = (
388392
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/lpw_stable_diffusion.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,14 @@ def __init__(
539539
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
540540
)
541541

542-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
543-
version.parse(unet.config._diffusers_version).base_version
544-
) < version.parse("0.9.0.dev0")
545-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
542+
is_unet_version_less_0_9_0 = (
543+
unet is not None
544+
and hasattr(unet.config, "_diffusers_version")
545+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
546+
)
547+
is_unet_sample_size_less_64 = (
548+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
549+
)
546550
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
547551
deprecation_message = (
548552
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/lpw_stable_diffusion_xl.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,11 @@ def __init__(
678678
self.mask_processor = VaeImageProcessor(
679679
vae_scale_factor=self.vae_scale_factor, do_normalize=False, do_binarize=True, do_convert_grayscale=True
680680
)
681-
self.default_sample_size = self.unet.config.sample_size
681+
self.default_sample_size = (
682+
self.unet.config.sample_size
683+
if hasattr(self, "unet") and self.unet is not None and hasattr(self.unet.config, "sample_size")
684+
else 128
685+
)
682686

683687
add_watermarker = add_watermarker if add_watermarker is not None else is_invisible_watermark_available()
684688

Diff for: examples/community/matryoshka.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -3793,10 +3793,14 @@ def __init__(
37933793
# new_config["clip_sample"] = False
37943794
# scheduler._internal_dict = FrozenDict(new_config)
37953795

3796-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
3797-
version.parse(unet.config._diffusers_version).base_version
3798-
) < version.parse("0.9.0.dev0")
3799-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
3796+
is_unet_version_less_0_9_0 = (
3797+
unet is not None
3798+
and hasattr(unet.config, "_diffusers_version")
3799+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
3800+
)
3801+
is_unet_sample_size_less_64 = (
3802+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
3803+
)
38003804
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
38013805
deprecation_message = (
38023806
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/pipeline_demofusion_sdxl.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ def __init__(
168168
self.register_to_config(force_zeros_for_empty_prompt=force_zeros_for_empty_prompt)
169169
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) if getattr(self, "vae", None) else 8
170170
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
171-
self.default_sample_size = self.unet.config.sample_size
171+
self.default_sample_size = (
172+
self.unet.config.sample_size
173+
if hasattr(self, "unet") and self.unet is not None and hasattr(self.unet.config, "sample_size")
174+
else 128
175+
)
172176

173177
add_watermarker = add_watermarker if add_watermarker is not None else is_invisible_watermark_available()
174178

Diff for: examples/community/pipeline_fabric.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@ def __init__(
150150
):
151151
super().__init__()
152152

153-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
154-
version.parse(unet.config._diffusers_version).base_version
155-
) < version.parse("0.9.0.dev0")
156-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
153+
is_unet_version_less_0_9_0 = (
154+
unet is not None
155+
and hasattr(unet.config, "_diffusers_version")
156+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
157+
)
158+
is_unet_sample_size_less_64 = (
159+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
160+
)
157161
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
158162
deprecation_message = (
159163
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/pipeline_kolors_differential_img2img.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ def __init__(
216216
vae_scale_factor=self.vae_scale_factor, do_normalize=False, do_convert_grayscale=True
217217
)
218218

219-
self.default_sample_size = self.unet.config.sample_size
219+
self.default_sample_size = (
220+
self.unet.config.sample_size
221+
if hasattr(self, "unet") and self.unet is not None and hasattr(self.unet.config, "sample_size")
222+
else 128
223+
)
220224

221225
# Copied from diffusers.pipelines.kolors.pipeline_kolors.KolorsPipeline.encode_prompt
222226
def encode_prompt(

Diff for: examples/community/pipeline_prompt2prompt.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,14 @@ def __init__(
174174
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
175175
)
176176

177-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
178-
version.parse(unet.config._diffusers_version).base_version
179-
) < version.parse("0.9.0.dev0")
180-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
177+
is_unet_version_less_0_9_0 = (
178+
unet is not None
179+
and hasattr(unet.config, "_diffusers_version")
180+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
181+
)
182+
is_unet_sample_size_less_64 = (
183+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
184+
)
181185
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
182186
deprecation_message = (
183187
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/pipeline_sdxl_style_aligned.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,11 @@ def __init__(
494494
vae_scale_factor=self.vae_scale_factor, do_normalize=False, do_binarize=True, do_convert_grayscale=True
495495
)
496496

497-
self.default_sample_size = self.unet.config.sample_size
497+
self.default_sample_size = (
498+
self.unet.config.sample_size
499+
if hasattr(self, "unet") and self.unet is not None and hasattr(self.unet.config, "sample_size")
500+
else 128
501+
)
498502

499503
add_watermarker = add_watermarker if add_watermarker is not None else is_invisible_watermark_available()
500504

Diff for: examples/community/pipeline_stable_diffusion_boxdiff.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,14 @@ def __init__(
460460
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
461461
)
462462

463-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
464-
version.parse(unet.config._diffusers_version).base_version
465-
) < version.parse("0.9.0.dev0")
466-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
463+
is_unet_version_less_0_9_0 = (
464+
unet is not None
465+
and hasattr(unet.config, "_diffusers_version")
466+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
467+
)
468+
is_unet_sample_size_less_64 = (
469+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
470+
)
467471
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
468472
deprecation_message = (
469473
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/pipeline_stable_diffusion_pag.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,14 @@ def __init__(
427427
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
428428
)
429429

430-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
431-
version.parse(unet.config._diffusers_version).base_version
432-
) < version.parse("0.9.0.dev0")
433-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
430+
is_unet_version_less_0_9_0 = (
431+
unet is not None
432+
and hasattr(unet.config, "_diffusers_version")
433+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
434+
)
435+
is_unet_sample_size_less_64 = (
436+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
437+
)
434438
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
435439
deprecation_message = (
436440
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/pipeline_stable_diffusion_xl_controlnet_adapter.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ def __init__(
231231
self.control_image_processor = VaeImageProcessor(
232232
vae_scale_factor=self.vae_scale_factor, do_convert_rgb=True, do_normalize=False
233233
)
234-
self.default_sample_size = self.unet.config.sample_size
234+
self.default_sample_size = (
235+
self.unet.config.sample_size
236+
if hasattr(self, "unet") and self.unet is not None and hasattr(self.unet.config, "sample_size")
237+
else 128
238+
)
235239

236240
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.encode_prompt
237241
def encode_prompt(

Diff for: examples/community/pipeline_stable_diffusion_xl_controlnet_adapter_inpaint.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ def __init__(
379379
self.control_image_processor = VaeImageProcessor(
380380
vae_scale_factor=self.vae_scale_factor, do_convert_rgb=True, do_normalize=False
381381
)
382-
self.default_sample_size = self.unet.config.sample_size
382+
self.default_sample_size = (
383+
self.unet.config.sample_size
384+
if hasattr(self, "unet") and self.unet is not None and hasattr(self.unet.config, "sample_size")
385+
else 128
386+
)
383387

384388
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.encode_prompt
385389
def encode_prompt(

Diff for: examples/community/pipeline_stable_diffusion_xl_ipex.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ def __init__(
256256
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) if getattr(self, "vae", None) else 8
257257
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
258258

259-
self.default_sample_size = self.unet.config.sample_size
259+
self.default_sample_size = (
260+
self.unet.config.sample_size
261+
if hasattr(self, "unet") and self.unet is not None and hasattr(self.unet.config, "sample_size")
262+
else 128
263+
)
260264

261265
add_watermarker = add_watermarker if add_watermarker is not None else is_invisible_watermark_available()
262266

Diff for: examples/community/pipeline_zero1to3.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,14 @@ def __init__(
151151
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
152152
)
153153

154-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
155-
version.parse(unet.config._diffusers_version).base_version
156-
) < version.parse("0.9.0.dev0")
157-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
154+
is_unet_version_less_0_9_0 = (
155+
unet is not None
156+
and hasattr(unet.config, "_diffusers_version")
157+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
158+
)
159+
is_unet_sample_size_less_64 = (
160+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
161+
)
158162
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
159163
deprecation_message = (
160164
"The configuration file of the unet has set the default `sample_size` to smaller than"

Diff for: examples/community/stable_diffusion_ipex.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ def __init__(
148148
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
149149
)
150150

151-
is_unet_version_less_0_9_0 = hasattr(unet.config, "_diffusers_version") and version.parse(
152-
version.parse(unet.config._diffusers_version).base_version
153-
) < version.parse("0.9.0.dev0")
154-
is_unet_sample_size_less_64 = hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
151+
is_unet_version_less_0_9_0 = (
152+
unet is not None
153+
and hasattr(unet.config, "_diffusers_version")
154+
and version.parse(version.parse(unet.config._diffusers_version).base_version) < version.parse("0.9.0.dev0")
155+
)
156+
is_unet_sample_size_less_64 = (
157+
unet is not None and hasattr(unet.config, "sample_size") and unet.config.sample_size < 64
158+
)
155159
if is_unet_version_less_0_9_0 and is_unet_sample_size_less_64:
156160
deprecation_message = (
157161
"The configuration file of the unet has set the default `sample_size` to smaller than"

0 commit comments

Comments
 (0)