diffusers 0.19.3__py3-none-any.whl → 0.20.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diffusers/__init__.py +3 -1
- diffusers/commands/fp16_safetensors.py +2 -7
- diffusers/configuration_utils.py +23 -1
- diffusers/dependency_versions_table.py +1 -1
- diffusers/loaders.py +62 -64
- diffusers/models/__init__.py +1 -0
- diffusers/models/activations.py +2 -0
- diffusers/models/attention.py +45 -1
- diffusers/models/autoencoder_tiny.py +193 -0
- diffusers/models/controlnet.py +1 -1
- diffusers/models/embeddings.py +56 -0
- diffusers/models/lora.py +0 -6
- diffusers/models/modeling_flax_utils.py +28 -2
- diffusers/models/modeling_utils.py +33 -16
- diffusers/models/transformer_2d.py +26 -9
- diffusers/models/unet_1d.py +2 -2
- diffusers/models/unet_2d_blocks.py +106 -56
- diffusers/models/unet_2d_condition.py +20 -5
- diffusers/models/vae.py +106 -1
- diffusers/pipelines/__init__.py +1 -0
- diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +10 -3
- diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +10 -3
- diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -1
- diffusers/pipelines/auto_pipeline.py +33 -43
- diffusers/pipelines/controlnet/multicontrolnet.py +4 -2
- diffusers/pipelines/controlnet/pipeline_controlnet.py +20 -4
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +15 -7
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +14 -4
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +157 -10
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +2 -10
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +43 -2
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +44 -2
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
- diffusers/pipelines/pipeline_flax_utils.py +41 -4
- diffusers/pipelines/pipeline_utils.py +60 -16
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +2 -2
- diffusers/pipelines/stable_diffusion/__init__.py +1 -0
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +81 -37
- diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_attend_and_excite.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py +12 -5
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen.py +832 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_k_diffusion.py +9 -2
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_ldm3d.py +17 -8
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_paradigms.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +10 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +10 -3
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +3 -5
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +75 -3
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +76 -6
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +1 -2
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +10 -3
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +10 -3
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +11 -4
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +1 -1
- diffusers/pipelines/versatile_diffusion/modeling_text_unet.py +131 -28
- diffusers/schedulers/scheduling_consistency_models.py +70 -57
- diffusers/schedulers/scheduling_ddim.py +76 -71
- diffusers/schedulers/scheduling_ddim_inverse.py +76 -44
- diffusers/schedulers/scheduling_ddim_parallel.py +11 -8
- diffusers/schedulers/scheduling_ddpm.py +68 -67
- diffusers/schedulers/scheduling_ddpm_parallel.py +18 -15
- diffusers/schedulers/scheduling_deis_multistep.py +93 -85
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +118 -120
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +116 -109
- diffusers/schedulers/scheduling_dpmsolver_sde.py +57 -43
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +122 -121
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +54 -44
- diffusers/schedulers/scheduling_euler_discrete.py +63 -56
- diffusers/schedulers/scheduling_heun_discrete.py +57 -45
- diffusers/schedulers/scheduling_ipndm.py +27 -22
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +54 -41
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +52 -41
- diffusers/schedulers/scheduling_karras_ve.py +55 -45
- diffusers/schedulers/scheduling_lms_discrete.py +58 -52
- diffusers/schedulers/scheduling_pndm.py +77 -62
- diffusers/schedulers/scheduling_repaint.py +56 -38
- diffusers/schedulers/scheduling_sde_ve.py +62 -50
- diffusers/schedulers/scheduling_sde_vp.py +32 -11
- diffusers/schedulers/scheduling_unclip.py +3 -3
- diffusers/schedulers/scheduling_unipc_multistep.py +131 -91
- diffusers/schedulers/scheduling_utils.py +41 -35
- diffusers/schedulers/scheduling_utils_flax.py +8 -2
- diffusers/schedulers/scheduling_vq_diffusion.py +39 -68
- diffusers/utils/__init__.py +2 -2
- diffusers/utils/dummy_pt_objects.py +15 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +15 -0
- diffusers/utils/hub_utils.py +105 -2
- diffusers/utils/import_utils.py +0 -4
- diffusers/utils/pil_utils.py +19 -0
- {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/METADATA +5 -7
- {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/RECORD +113 -112
- {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/WHEEL +1 -1
- {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/entry_points.txt +0 -1
- diffusers/models/cross_attention.py +0 -94
- {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/LICENSE +0 -0
- {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/top_level.txt +0 -0
@@ -340,7 +340,14 @@ class StableDiffusionImg2ImgPipeline(
|
|
340
340
|
)
|
341
341
|
prompt_embeds = prompt_embeds[0]
|
342
342
|
|
343
|
-
|
343
|
+
if self.text_encoder is not None:
|
344
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
345
|
+
elif self.unet is not None:
|
346
|
+
prompt_embeds_dtype = self.unet.dtype
|
347
|
+
else:
|
348
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
349
|
+
|
350
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
344
351
|
|
345
352
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
346
353
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -396,7 +403,7 @@ class StableDiffusionImg2ImgPipeline(
|
|
396
403
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
397
404
|
seq_len = negative_prompt_embeds.shape[1]
|
398
405
|
|
399
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
406
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
400
407
|
|
401
408
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
402
409
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -640,7 +647,7 @@ class StableDiffusionImg2ImgPipeline(
|
|
640
647
|
every step.
|
641
648
|
cross_attention_kwargs (`dict`, *optional*):
|
642
649
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
643
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
650
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
644
651
|
|
645
652
|
Examples:
|
646
653
|
|
@@ -398,7 +398,14 @@ class StableDiffusionInpaintPipeline(
|
|
398
398
|
)
|
399
399
|
prompt_embeds = prompt_embeds[0]
|
400
400
|
|
401
|
-
|
401
|
+
if self.text_encoder is not None:
|
402
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
403
|
+
elif self.unet is not None:
|
404
|
+
prompt_embeds_dtype = self.unet.dtype
|
405
|
+
else:
|
406
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
407
|
+
|
408
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
402
409
|
|
403
410
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
404
411
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -454,7 +461,7 @@ class StableDiffusionInpaintPipeline(
|
|
454
461
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
455
462
|
seq_len = negative_prompt_embeds.shape[1]
|
456
463
|
|
457
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
464
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
458
465
|
|
459
466
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
460
467
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -756,7 +763,7 @@ class StableDiffusionInpaintPipeline(
|
|
756
763
|
every step.
|
757
764
|
cross_attention_kwargs (`dict`, *optional*):
|
758
765
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
759
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
766
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
760
767
|
|
761
768
|
Examples:
|
762
769
|
|
@@ -336,7 +336,14 @@ class StableDiffusionInpaintPipelineLegacy(
|
|
336
336
|
)
|
337
337
|
prompt_embeds = prompt_embeds[0]
|
338
338
|
|
339
|
-
|
339
|
+
if self.text_encoder is not None:
|
340
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
341
|
+
elif self.unet is not None:
|
342
|
+
prompt_embeds_dtype = self.unet.dtype
|
343
|
+
else:
|
344
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
345
|
+
|
346
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
340
347
|
|
341
348
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
342
349
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -392,7 +399,7 @@ class StableDiffusionInpaintPipelineLegacy(
|
|
392
399
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
393
400
|
seq_len = negative_prompt_embeds.shape[1]
|
394
401
|
|
395
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
402
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
396
403
|
|
397
404
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
398
405
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -606,7 +613,7 @@ class StableDiffusionInpaintPipelineLegacy(
|
|
606
613
|
cross_attention_kwargs (`dict`, *optional*):
|
607
614
|
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
608
615
|
`self.processor` in
|
609
|
-
[diffusers.
|
616
|
+
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
610
617
|
|
611
618
|
Returns:
|
612
619
|
[`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`:
|
@@ -243,7 +243,14 @@ class StableDiffusionKDiffusionPipeline(DiffusionPipeline, TextualInversionLoade
|
|
243
243
|
)
|
244
244
|
prompt_embeds = prompt_embeds[0]
|
245
245
|
|
246
|
-
|
246
|
+
if self.text_encoder is not None:
|
247
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
248
|
+
elif self.unet is not None:
|
249
|
+
prompt_embeds_dtype = self.unet.dtype
|
250
|
+
else:
|
251
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
252
|
+
|
253
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
247
254
|
|
248
255
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
249
256
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -299,7 +306,7 @@ class StableDiffusionKDiffusionPipeline(DiffusionPipeline, TextualInversionLoade
|
|
299
306
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
300
307
|
seq_len = negative_prompt_embeds.shape[1]
|
301
308
|
|
302
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
309
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
303
310
|
|
304
311
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
305
312
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -41,11 +41,10 @@ logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
|
41
41
|
|
42
42
|
EXAMPLE_DOC_STRING = """
|
43
43
|
Examples:
|
44
|
-
```
|
45
|
-
>>> import
|
46
|
-
>>> from diffusers import StableDiffusionPipeline
|
44
|
+
```python
|
45
|
+
>>> from diffusers import StableDiffusionLDM3DPipeline
|
47
46
|
|
48
|
-
>>> pipe = StableDiffusionLDM3DPipeline.from_pretrained("Intel/ldm3d")
|
47
|
+
>>> pipe = StableDiffusionLDM3DPipeline.from_pretrained("Intel/ldm3d-4c")
|
49
48
|
>>> pipe = pipe.to("cuda")
|
50
49
|
|
51
50
|
>>> prompt = "a photo of an astronaut riding a horse on mars"
|
@@ -63,7 +62,10 @@ class LDM3DPipelineOutput(BaseOutput):
|
|
63
62
|
Output class for Stable Diffusion pipelines.
|
64
63
|
|
65
64
|
Args:
|
66
|
-
|
65
|
+
rgb (`List[PIL.Image.Image]` or `np.ndarray`)
|
66
|
+
List of denoised PIL images of length `batch_size` or NumPy array of shape `(batch_size, height, width,
|
67
|
+
num_channels)`.
|
68
|
+
depth (`List[PIL.Image.Image]` or `np.ndarray`)
|
67
69
|
List of denoised PIL images of length `batch_size` or NumPy array of shape `(batch_size, height, width,
|
68
70
|
num_channels)`.
|
69
71
|
nsfw_content_detected (`List[bool]`)
|
@@ -303,7 +305,14 @@ class StableDiffusionLDM3DPipeline(
|
|
303
305
|
)
|
304
306
|
prompt_embeds = prompt_embeds[0]
|
305
307
|
|
306
|
-
|
308
|
+
if self.text_encoder is not None:
|
309
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
310
|
+
elif self.unet is not None:
|
311
|
+
prompt_embeds_dtype = self.unet.dtype
|
312
|
+
else:
|
313
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
314
|
+
|
315
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
307
316
|
|
308
317
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
309
318
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -359,7 +368,7 @@ class StableDiffusionLDM3DPipeline(
|
|
359
368
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
360
369
|
seq_len = negative_prompt_embeds.shape[1]
|
361
370
|
|
362
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
371
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
363
372
|
|
364
373
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
365
374
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -541,7 +550,7 @@ class StableDiffusionLDM3DPipeline(
|
|
541
550
|
every step.
|
542
551
|
cross_attention_kwargs (`dict`, *optional*):
|
543
552
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
544
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
553
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
545
554
|
|
546
555
|
Examples:
|
547
556
|
|
@@ -247,7 +247,14 @@ class StableDiffusionModelEditingPipeline(DiffusionPipeline, TextualInversionLoa
|
|
247
247
|
)
|
248
248
|
prompt_embeds = prompt_embeds[0]
|
249
249
|
|
250
|
-
|
250
|
+
if self.text_encoder is not None:
|
251
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
252
|
+
elif self.unet is not None:
|
253
|
+
prompt_embeds_dtype = self.unet.dtype
|
254
|
+
else:
|
255
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
256
|
+
|
257
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
251
258
|
|
252
259
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
253
260
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -303,7 +310,7 @@ class StableDiffusionModelEditingPipeline(DiffusionPipeline, TextualInversionLoa
|
|
303
310
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
304
311
|
seq_len = negative_prompt_embeds.shape[1]
|
305
312
|
|
306
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
313
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
307
314
|
|
308
315
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
309
316
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -617,7 +624,7 @@ class StableDiffusionModelEditingPipeline(DiffusionPipeline, TextualInversionLoa
|
|
617
624
|
every step.
|
618
625
|
cross_attention_kwargs (`dict`, *optional*):
|
619
626
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
620
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
627
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
621
628
|
|
622
629
|
Examples:
|
623
630
|
|
@@ -224,7 +224,14 @@ class StableDiffusionPanoramaPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
224
224
|
)
|
225
225
|
prompt_embeds = prompt_embeds[0]
|
226
226
|
|
227
|
-
|
227
|
+
if self.text_encoder is not None:
|
228
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
229
|
+
elif self.unet is not None:
|
230
|
+
prompt_embeds_dtype = self.unet.dtype
|
231
|
+
else:
|
232
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
233
|
+
|
234
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
228
235
|
|
229
236
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
230
237
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -280,7 +287,7 @@ class StableDiffusionPanoramaPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
280
287
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
281
288
|
seq_len = negative_prompt_embeds.shape[1]
|
282
289
|
|
283
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
290
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
284
291
|
|
285
292
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
286
293
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -517,7 +524,7 @@ class StableDiffusionPanoramaPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
517
524
|
cross_attention_kwargs (`dict`, *optional*):
|
518
525
|
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
519
526
|
`self.processor` in
|
520
|
-
[diffusers.
|
527
|
+
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
521
528
|
circular_padding (`bool`, *optional*, defaults to `False`):
|
522
529
|
If set to `True`, circular padding is applied to ensure there are no stitching artifacts. Circular
|
523
530
|
padding allows the model to seamlessly generate a transition from the rightmost part of the image to
|
@@ -289,7 +289,14 @@ class StableDiffusionParadigmsPipeline(
|
|
289
289
|
)
|
290
290
|
prompt_embeds = prompt_embeds[0]
|
291
291
|
|
292
|
-
|
292
|
+
if self.text_encoder is not None:
|
293
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
294
|
+
elif self.unet is not None:
|
295
|
+
prompt_embeds_dtype = self.unet.dtype
|
296
|
+
else:
|
297
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
298
|
+
|
299
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
293
300
|
|
294
301
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
295
302
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -345,7 +352,7 @@ class StableDiffusionParadigmsPipeline(
|
|
345
352
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
346
353
|
seq_len = negative_prompt_embeds.shape[1]
|
347
354
|
|
348
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
355
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
349
356
|
|
350
357
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
351
358
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -546,7 +553,7 @@ class StableDiffusionParadigmsPipeline(
|
|
546
553
|
every step.
|
547
554
|
cross_attention_kwargs (`dict`, *optional*):
|
548
555
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
549
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
556
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
550
557
|
debug (`bool`, *optional*, defaults to `False`):
|
551
558
|
Whether or not to run in debug mode. In debug mode, `torch.cumsum` is evaluated using the CPU.
|
552
559
|
|
@@ -479,7 +479,14 @@ class StableDiffusionPix2PixZeroPipeline(DiffusionPipeline):
|
|
479
479
|
)
|
480
480
|
prompt_embeds = prompt_embeds[0]
|
481
481
|
|
482
|
-
|
482
|
+
if self.text_encoder is not None:
|
483
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
484
|
+
elif self.unet is not None:
|
485
|
+
prompt_embeds_dtype = self.unet.dtype
|
486
|
+
else:
|
487
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
488
|
+
|
489
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
483
490
|
|
484
491
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
485
492
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -535,7 +542,7 @@ class StableDiffusionPix2PixZeroPipeline(DiffusionPipeline):
|
|
535
542
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
536
543
|
seq_len = negative_prompt_embeds.shape[1]
|
537
544
|
|
538
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
545
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
539
546
|
|
540
547
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
541
548
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -1088,7 +1095,7 @@ class StableDiffusionPix2PixZeroPipeline(DiffusionPipeline):
|
|
1088
1095
|
The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
|
1089
1096
|
instead.
|
1090
1097
|
image (`torch.FloatTensor` `np.ndarray`, `PIL.Image.Image`, `List[torch.FloatTensor]`, `List[PIL.Image.Image]`, or `List[np.ndarray]`):
|
1091
|
-
`Image`, or tensor representing an image batch which will be used for conditioning. Can also
|
1098
|
+
`Image`, or tensor representing an image batch which will be used for conditioning. Can also accept
|
1092
1099
|
image latents as `image`, if passing latents directly, it will not be encoded again.
|
1093
1100
|
num_inference_steps (`int`, *optional*, defaults to 50):
|
1094
1101
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
@@ -247,7 +247,14 @@ class StableDiffusionSAGPipeline(DiffusionPipeline, TextualInversionLoaderMixin)
|
|
247
247
|
)
|
248
248
|
prompt_embeds = prompt_embeds[0]
|
249
249
|
|
250
|
-
|
250
|
+
if self.text_encoder is not None:
|
251
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
252
|
+
elif self.unet is not None:
|
253
|
+
prompt_embeds_dtype = self.unet.dtype
|
254
|
+
else:
|
255
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
256
|
+
|
257
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
251
258
|
|
252
259
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
253
260
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -303,7 +310,7 @@ class StableDiffusionSAGPipeline(DiffusionPipeline, TextualInversionLoaderMixin)
|
|
303
310
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
304
311
|
seq_len = negative_prompt_embeds.shape[1]
|
305
312
|
|
306
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
313
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
307
314
|
|
308
315
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
309
316
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -503,7 +510,7 @@ class StableDiffusionSAGPipeline(DiffusionPipeline, TextualInversionLoaderMixin)
|
|
503
510
|
every step.
|
504
511
|
cross_attention_kwargs (`dict`, *optional*):
|
505
512
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
506
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
513
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
507
514
|
|
508
515
|
Examples:
|
509
516
|
|
@@ -268,7 +268,14 @@ class StableDiffusionUpscalePipeline(DiffusionPipeline, TextualInversionLoaderMi
|
|
268
268
|
)
|
269
269
|
prompt_embeds = prompt_embeds[0]
|
270
270
|
|
271
|
-
|
271
|
+
if self.text_encoder is not None:
|
272
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
273
|
+
elif self.unet is not None:
|
274
|
+
prompt_embeds_dtype = self.unet.dtype
|
275
|
+
else:
|
276
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
277
|
+
|
278
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
272
279
|
|
273
280
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
274
281
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -324,7 +331,7 @@ class StableDiffusionUpscalePipeline(DiffusionPipeline, TextualInversionLoaderMi
|
|
324
331
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
325
332
|
seq_len = negative_prompt_embeds.shape[1]
|
326
333
|
|
327
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
334
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
328
335
|
|
329
336
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
330
337
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -561,7 +568,7 @@ class StableDiffusionUpscalePipeline(DiffusionPipeline, TextualInversionLoaderMi
|
|
561
568
|
every step.
|
562
569
|
cross_attention_kwargs (`dict`, *optional*):
|
563
570
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
564
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
571
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
565
572
|
|
566
573
|
Examples:
|
567
574
|
```py
|
@@ -371,7 +371,14 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
371
371
|
)
|
372
372
|
prompt_embeds = prompt_embeds[0]
|
373
373
|
|
374
|
-
|
374
|
+
if self.text_encoder is not None:
|
375
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
376
|
+
elif self.unet is not None:
|
377
|
+
prompt_embeds_dtype = self.unet.dtype
|
378
|
+
else:
|
379
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
380
|
+
|
381
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
375
382
|
|
376
383
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
377
384
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -427,7 +434,7 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
427
434
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
428
435
|
seq_len = negative_prompt_embeds.shape[1]
|
429
436
|
|
430
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
437
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
431
438
|
|
432
439
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
433
440
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -684,7 +691,7 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
684
691
|
every step.
|
685
692
|
cross_attention_kwargs (`dict`, *optional*):
|
686
693
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
687
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
694
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
688
695
|
noise_level (`int`, *optional*, defaults to `0`):
|
689
696
|
The amount of noise to add to the image embeddings. A higher `noise_level` increases the variance in
|
690
697
|
the final un-noised images. See [`StableUnCLIPPipeline.noise_image_embeddings`] for more details.
|
@@ -272,7 +272,14 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
|
|
272
272
|
)
|
273
273
|
prompt_embeds = prompt_embeds[0]
|
274
274
|
|
275
|
-
|
275
|
+
if self.text_encoder is not None:
|
276
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
277
|
+
elif self.unet is not None:
|
278
|
+
prompt_embeds_dtype = self.unet.dtype
|
279
|
+
else:
|
280
|
+
prompt_embeds_dtype = prompt_embeds.dtype
|
281
|
+
|
282
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
276
283
|
|
277
284
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
278
285
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -328,7 +335,7 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
|
|
328
335
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
329
336
|
seq_len = negative_prompt_embeds.shape[1]
|
330
337
|
|
331
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
338
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
332
339
|
|
333
340
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
334
341
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -654,7 +661,7 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
|
|
654
661
|
every step.
|
655
662
|
cross_attention_kwargs (`dict`, *optional*):
|
656
663
|
A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
|
657
|
-
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/
|
664
|
+
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
658
665
|
noise_level (`int`, *optional*, defaults to `0`):
|
659
666
|
The amount of noise to add to the image embeddings. A higher `noise_level` increases the variance in
|
660
667
|
the final un-noised images. See [`StableUnCLIPPipeline.noise_image_embeddings`] for more details.
|
@@ -87,7 +87,6 @@ class StableDiffusionXLPipeline(DiffusionPipeline, FromSingleFileMixin, LoraLoad
|
|
87
87
|
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
|
88
88
|
|
89
89
|
In addition the pipeline inherits the following loading methods:
|
90
|
-
- *Textual-Inversion*: [`loaders.TextualInversionLoaderMixin.load_textual_inversion`]
|
91
90
|
- *LoRA*: [`StableDiffusionXLPipeline.load_lora_weights`]
|
92
91
|
- *Ckpt*: [`loaders.FromSingleFileMixin.from_single_file`]
|
93
92
|
|
@@ -310,7 +309,6 @@ class StableDiffusionXLPipeline(DiffusionPipeline, FromSingleFileMixin, LoraLoad
|
|
310
309
|
|
311
310
|
text_input_ids = text_inputs.input_ids
|
312
311
|
untruncated_ids = tokenizer(prompt, padding="longest", return_tensors="pt").input_ids
|
313
|
-
untruncated_ids = tokenizer(prompt, padding="longest", return_tensors="pt").input_ids
|
314
312
|
|
315
313
|
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(
|
316
314
|
text_input_ids, untruncated_ids
|
@@ -609,7 +607,7 @@ class StableDiffusionXLPipeline(DiffusionPipeline, FromSingleFileMixin, LoraLoad
|
|
609
607
|
scheduler. The denoising_end parameter should ideally be utilized when this pipeline forms a part of a
|
610
608
|
"Mixture of Denoisers" multi-pipeline setup, as elaborated in [**Refining the Image
|
611
609
|
Output**](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl#refining-the-image-output)
|
612
|
-
guidance_scale (`float`, *optional*, defaults to
|
610
|
+
guidance_scale (`float`, *optional*, defaults to 5.0):
|
613
611
|
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
|
614
612
|
`guidance_scale` is defined as `w` of equation 2. of [Imagen
|
615
613
|
Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
|
@@ -663,7 +661,7 @@ class StableDiffusionXLPipeline(DiffusionPipeline, FromSingleFileMixin, LoraLoad
|
|
663
661
|
cross_attention_kwargs (`dict`, *optional*):
|
664
662
|
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
665
663
|
`self.processor` in
|
666
|
-
[diffusers.
|
664
|
+
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
667
665
|
guidance_rescale (`float`, *optional*, defaults to 0.7):
|
668
666
|
Guidance rescale factor proposed by [Common Diffusion Noise Schedules and Sample Steps are
|
669
667
|
Flawed](https://arxiv.org/pdf/2305.08891.pdf) `guidance_scale` is defined as `φ` in equation 16. of
|
@@ -906,7 +904,7 @@ class StableDiffusionXLPipeline(DiffusionPipeline, FromSingleFileMixin, LoraLoad
|
|
906
904
|
is_main_process: bool = True,
|
907
905
|
weight_name: str = None,
|
908
906
|
save_function: Callable = None,
|
909
|
-
safe_serialization: bool =
|
907
|
+
safe_serialization: bool = True,
|
910
908
|
):
|
911
909
|
state_dict = {}
|
912
910
|
|
@@ -13,6 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
import inspect
|
16
|
+
import os
|
16
17
|
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
17
18
|
|
18
19
|
import numpy as np
|
@@ -91,7 +92,6 @@ class StableDiffusionXLImg2ImgPipeline(DiffusionPipeline, FromSingleFileMixin, L
|
|
91
92
|
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
|
92
93
|
|
93
94
|
In addition the pipeline inherits the following loading methods:
|
94
|
-
- *Textual-Inversion*: [`loaders.TextualInversionLoaderMixin.load_textual_inversion`]
|
95
95
|
- *LoRA*: [`loaders.LoraLoaderMixin.load_lora_weights`]
|
96
96
|
- *Ckpt*: [`loaders.FromSingleFileMixin.from_single_file`]
|
97
97
|
|
@@ -317,7 +317,6 @@ class StableDiffusionXLImg2ImgPipeline(DiffusionPipeline, FromSingleFileMixin, L
|
|
317
317
|
|
318
318
|
text_input_ids = text_inputs.input_ids
|
319
319
|
untruncated_ids = tokenizer(prompt, padding="longest", return_tensors="pt").input_ids
|
320
|
-
untruncated_ids = tokenizer(prompt, padding="longest", return_tensors="pt").input_ids
|
321
320
|
|
322
321
|
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(
|
323
322
|
text_input_ids, untruncated_ids
|
@@ -783,7 +782,7 @@ class StableDiffusionXLImg2ImgPipeline(DiffusionPipeline, FromSingleFileMixin, L
|
|
783
782
|
cross_attention_kwargs (`dict`, *optional*):
|
784
783
|
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
785
784
|
`self.processor` in
|
786
|
-
[diffusers.
|
785
|
+
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
787
786
|
guidance_rescale (`float`, *optional*, defaults to 0.7):
|
788
787
|
Guidance rescale factor proposed by [Common Diffusion Noise Schedules and Sample Steps are
|
789
788
|
Flawed](https://arxiv.org/pdf/2305.08891.pdf) `guidance_scale` is defined as `φ` in equation 16. of
|
@@ -1014,3 +1013,76 @@ class StableDiffusionXLImg2ImgPipeline(DiffusionPipeline, FromSingleFileMixin, L
|
|
1014
1013
|
return (image,)
|
1015
1014
|
|
1016
1015
|
return StableDiffusionXLPipelineOutput(images=image)
|
1016
|
+
|
1017
|
+
# Overrride to properly handle the loading and unloading of the additional text encoder.
|
1018
|
+
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.load_lora_weights
|
1019
|
+
def load_lora_weights(self, pretrained_model_name_or_path_or_dict: Union[str, Dict[str, torch.Tensor]], **kwargs):
|
1020
|
+
# We could have accessed the unet config from `lora_state_dict()` too. We pass
|
1021
|
+
# it here explicitly to be able to tell that it's coming from an SDXL
|
1022
|
+
# pipeline.
|
1023
|
+
state_dict, network_alphas = self.lora_state_dict(
|
1024
|
+
pretrained_model_name_or_path_or_dict,
|
1025
|
+
unet_config=self.unet.config,
|
1026
|
+
**kwargs,
|
1027
|
+
)
|
1028
|
+
self.load_lora_into_unet(state_dict, network_alphas=network_alphas, unet=self.unet)
|
1029
|
+
|
1030
|
+
text_encoder_state_dict = {k: v for k, v in state_dict.items() if "text_encoder." in k}
|
1031
|
+
if len(text_encoder_state_dict) > 0:
|
1032
|
+
self.load_lora_into_text_encoder(
|
1033
|
+
text_encoder_state_dict,
|
1034
|
+
network_alphas=network_alphas,
|
1035
|
+
text_encoder=self.text_encoder,
|
1036
|
+
prefix="text_encoder",
|
1037
|
+
lora_scale=self.lora_scale,
|
1038
|
+
)
|
1039
|
+
|
1040
|
+
text_encoder_2_state_dict = {k: v for k, v in state_dict.items() if "text_encoder_2." in k}
|
1041
|
+
if len(text_encoder_2_state_dict) > 0:
|
1042
|
+
self.load_lora_into_text_encoder(
|
1043
|
+
text_encoder_2_state_dict,
|
1044
|
+
network_alphas=network_alphas,
|
1045
|
+
text_encoder=self.text_encoder_2,
|
1046
|
+
prefix="text_encoder_2",
|
1047
|
+
lora_scale=self.lora_scale,
|
1048
|
+
)
|
1049
|
+
|
1050
|
+
@classmethod
|
1051
|
+
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.save_lora_weights
|
1052
|
+
def save_lora_weights(
|
1053
|
+
self,
|
1054
|
+
save_directory: Union[str, os.PathLike],
|
1055
|
+
unet_lora_layers: Dict[str, Union[torch.nn.Module, torch.Tensor]] = None,
|
1056
|
+
text_encoder_lora_layers: Dict[str, Union[torch.nn.Module, torch.Tensor]] = None,
|
1057
|
+
text_encoder_2_lora_layers: Dict[str, Union[torch.nn.Module, torch.Tensor]] = None,
|
1058
|
+
is_main_process: bool = True,
|
1059
|
+
weight_name: str = None,
|
1060
|
+
save_function: Callable = None,
|
1061
|
+
safe_serialization: bool = True,
|
1062
|
+
):
|
1063
|
+
state_dict = {}
|
1064
|
+
|
1065
|
+
def pack_weights(layers, prefix):
|
1066
|
+
layers_weights = layers.state_dict() if isinstance(layers, torch.nn.Module) else layers
|
1067
|
+
layers_state_dict = {f"{prefix}.{module_name}": param for module_name, param in layers_weights.items()}
|
1068
|
+
return layers_state_dict
|
1069
|
+
|
1070
|
+
state_dict.update(pack_weights(unet_lora_layers, "unet"))
|
1071
|
+
|
1072
|
+
if text_encoder_lora_layers and text_encoder_2_lora_layers:
|
1073
|
+
state_dict.update(pack_weights(text_encoder_lora_layers, "text_encoder"))
|
1074
|
+
state_dict.update(pack_weights(text_encoder_2_lora_layers, "text_encoder_2"))
|
1075
|
+
|
1076
|
+
self.write_lora_layers(
|
1077
|
+
state_dict=state_dict,
|
1078
|
+
save_directory=save_directory,
|
1079
|
+
is_main_process=is_main_process,
|
1080
|
+
weight_name=weight_name,
|
1081
|
+
save_function=save_function,
|
1082
|
+
safe_serialization=safe_serialization,
|
1083
|
+
)
|
1084
|
+
|
1085
|
+
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline._remove_text_encoder_monkey_patch
|
1086
|
+
def _remove_text_encoder_monkey_patch(self):
|
1087
|
+
self._remove_text_encoder_monkey_patch_classmethod(self.text_encoder)
|
1088
|
+
self._remove_text_encoder_monkey_patch_classmethod(self.text_encoder_2)
|