diffusers 0.24.0__py3-none-any.whl → 0.25.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 +11 -1
- diffusers/commands/fp16_safetensors.py +10 -11
- diffusers/configuration_utils.py +12 -8
- diffusers/dependency_versions_table.py +3 -2
- diffusers/experimental/rl/value_guided_sampling.py +1 -1
- diffusers/image_processor.py +286 -46
- diffusers/loaders/ip_adapter.py +11 -9
- diffusers/loaders/lora.py +198 -60
- diffusers/loaders/single_file.py +24 -18
- diffusers/loaders/textual_inversion.py +10 -14
- diffusers/loaders/unet.py +130 -37
- diffusers/models/__init__.py +18 -12
- diffusers/models/activations.py +9 -6
- diffusers/models/attention.py +137 -16
- diffusers/models/attention_processor.py +133 -46
- diffusers/models/autoencoders/__init__.py +5 -0
- diffusers/models/{autoencoder_asym_kl.py → autoencoders/autoencoder_asym_kl.py} +4 -4
- diffusers/models/{autoencoder_kl.py → autoencoders/autoencoder_kl.py} +45 -6
- diffusers/models/{autoencoder_kl_temporal_decoder.py → autoencoders/autoencoder_kl_temporal_decoder.py} +8 -8
- diffusers/models/{autoencoder_tiny.py → autoencoders/autoencoder_tiny.py} +4 -4
- diffusers/models/{consistency_decoder_vae.py → autoencoders/consistency_decoder_vae.py} +14 -14
- diffusers/models/{vae.py → autoencoders/vae.py} +9 -5
- diffusers/models/downsampling.py +338 -0
- diffusers/models/embeddings.py +112 -29
- diffusers/models/modeling_flax_utils.py +12 -7
- diffusers/models/modeling_utils.py +10 -10
- diffusers/models/normalization.py +108 -2
- diffusers/models/resnet.py +15 -699
- diffusers/models/transformer_2d.py +2 -2
- diffusers/models/unet_2d_condition.py +37 -0
- diffusers/models/{unet_kandi3.py → unet_kandinsky3.py} +105 -159
- diffusers/models/upsampling.py +454 -0
- diffusers/models/uvit_2d.py +471 -0
- diffusers/models/vq_model.py +9 -2
- diffusers/pipelines/__init__.py +81 -73
- diffusers/pipelines/amused/__init__.py +62 -0
- diffusers/pipelines/amused/pipeline_amused.py +328 -0
- diffusers/pipelines/amused/pipeline_amused_img2img.py +347 -0
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +378 -0
- diffusers/pipelines/animatediff/pipeline_animatediff.py +38 -10
- diffusers/pipelines/auto_pipeline.py +17 -13
- diffusers/pipelines/controlnet/pipeline_controlnet.py +27 -10
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +47 -5
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +25 -8
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +4 -6
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +26 -10
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +4 -3
- diffusers/pipelines/deprecated/__init__.py +153 -0
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/__init__.py +3 -3
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion.py +91 -18
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py +91 -18
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_output.py +1 -1
- diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/__init__.py +1 -1
- diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/mel.py +2 -2
- diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py +4 -4
- diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/__init__.py +1 -1
- diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/pipeline_latent_diffusion_uncond.py +4 -4
- diffusers/pipelines/{pndm → deprecated/pndm}/__init__.py +1 -1
- diffusers/pipelines/{pndm → deprecated/pndm}/pipeline_pndm.py +4 -4
- diffusers/pipelines/{repaint → deprecated/repaint}/__init__.py +1 -1
- diffusers/pipelines/{repaint → deprecated/repaint}/pipeline_repaint.py +5 -5
- diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/__init__.py +1 -1
- diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/pipeline_score_sde_ve.py +4 -4
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/__init__.py +6 -6
- diffusers/pipelines/{spectrogram_diffusion/continous_encoder.py → deprecated/spectrogram_diffusion/continuous_encoder.py} +2 -2
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/midi_utils.py +1 -1
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py +2 -2
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/pipeline_spectrogram_diffusion.py +7 -7
- diffusers/pipelines/deprecated/stable_diffusion_variants/__init__.py +55 -0
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_cycle_diffusion.py +16 -11
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_onnx_stable_diffusion_inpaint_legacy.py +6 -6
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_inpaint_legacy.py +11 -11
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_model_editing.py +16 -11
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_paradigms.py +10 -10
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_pix2pix_zero.py +13 -13
- diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/__init__.py +1 -1
- diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/pipeline_stochastic_karras_ve.py +4 -4
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/__init__.py +3 -3
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/modeling_text_unet.py +54 -11
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion.py +4 -4
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_dual_guided.py +6 -6
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_image_variation.py +6 -6
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_text_to_image.py +6 -6
- diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/__init__.py +3 -3
- diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/pipeline_vq_diffusion.py +5 -5
- diffusers/pipelines/kandinsky3/__init__.py +4 -4
- diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +98 -0
- diffusers/pipelines/kandinsky3/{kandinsky3_pipeline.py → pipeline_kandinsky3.py} +172 -35
- diffusers/pipelines/kandinsky3/{kandinsky3img2img_pipeline.py → pipeline_kandinsky3_img2img.py} +228 -34
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +46 -5
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +47 -6
- diffusers/pipelines/onnx_utils.py +8 -5
- diffusers/pipelines/pipeline_flax_utils.py +7 -6
- diffusers/pipelines/pipeline_utils.py +32 -31
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +51 -2
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +3 -3
- diffusers/pipelines/stable_diffusion/__init__.py +1 -72
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +67 -75
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +92 -8
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -8
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +138 -10
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +57 -7
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +3 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +6 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -0
- diffusers/pipelines/stable_diffusion_attend_and_excite/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_attend_and_excite}/pipeline_stable_diffusion_attend_and_excite.py +5 -2
- diffusers/pipelines/stable_diffusion_diffedit/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_diffedit}/pipeline_stable_diffusion_diffedit.py +2 -3
- diffusers/pipelines/stable_diffusion_gligen/__init__.py +50 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py +2 -2
- diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen_text_image.py +3 -3
- diffusers/pipelines/stable_diffusion_k_diffusion/__init__.py +60 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_k_diffusion}/pipeline_stable_diffusion_k_diffusion.py +6 -1
- diffusers/pipelines/stable_diffusion_ldm3d/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py +50 -7
- diffusers/pipelines/stable_diffusion_panorama/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_panorama}/pipeline_stable_diffusion_panorama.py +56 -8
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +58 -6
- diffusers/pipelines/stable_diffusion_sag/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_sag}/pipeline_stable_diffusion_sag.py +67 -10
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +97 -15
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +98 -14
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +97 -14
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +7 -5
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +12 -9
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +6 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +5 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +5 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +331 -9
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +468 -9
- diffusers/pipelines/unclip/pipeline_unclip.py +2 -1
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -0
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +4 -0
- diffusers/schedulers/__init__.py +2 -0
- diffusers/schedulers/scheduling_amused.py +162 -0
- diffusers/schedulers/scheduling_consistency_models.py +2 -0
- diffusers/schedulers/scheduling_ddim_inverse.py +1 -4
- diffusers/schedulers/scheduling_ddpm.py +46 -0
- diffusers/schedulers/scheduling_ddpm_parallel.py +46 -0
- diffusers/schedulers/scheduling_deis_multistep.py +13 -1
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +13 -1
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +13 -1
- diffusers/schedulers/scheduling_dpmsolver_sde.py +2 -0
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +13 -1
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +58 -0
- diffusers/schedulers/scheduling_euler_discrete.py +62 -3
- diffusers/schedulers/scheduling_heun_discrete.py +2 -0
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +2 -0
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +2 -0
- diffusers/schedulers/scheduling_lms_discrete.py +2 -0
- diffusers/schedulers/scheduling_unipc_multistep.py +13 -1
- diffusers/schedulers/scheduling_utils.py +3 -1
- diffusers/schedulers/scheduling_utils_flax.py +3 -1
- diffusers/training_utils.py +1 -1
- diffusers/utils/__init__.py +0 -2
- diffusers/utils/constants.py +2 -5
- diffusers/utils/dummy_pt_objects.py +30 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +45 -0
- diffusers/utils/dynamic_modules_utils.py +14 -18
- diffusers/utils/hub_utils.py +24 -36
- diffusers/utils/logging.py +1 -1
- diffusers/utils/state_dict_utils.py +8 -0
- diffusers/utils/testing_utils.py +199 -1
- diffusers/utils/torch_utils.py +3 -3
- {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/METADATA +55 -53
- {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/RECORD +174 -155
- {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/WHEEL +1 -1
- {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/entry_points.txt +0 -1
- /diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/modeling_roberta_series.py +0 -0
- {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/LICENSE +0 -0
- {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/top_level.txt +0 -0
@@ -19,13 +19,14 @@ import torch
|
|
19
19
|
from packaging import version
|
20
20
|
from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection, XLMRobertaTokenizer
|
21
21
|
|
22
|
-
from
|
23
|
-
from
|
24
|
-
from
|
25
|
-
from
|
26
|
-
from
|
27
|
-
from
|
28
|
-
from
|
22
|
+
from ....configuration_utils import FrozenDict
|
23
|
+
from ....image_processor import PipelineImageInput, VaeImageProcessor
|
24
|
+
from ....loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
25
|
+
from ....models import AutoencoderKL, ImageProjection, UNet2DConditionModel
|
26
|
+
from ....models.attention_processor import FusedAttnProcessor2_0
|
27
|
+
from ....models.lora import adjust_lora_scale_text_encoder
|
28
|
+
from ....schedulers import KarrasDiffusionSchedulers
|
29
|
+
from ....utils import (
|
29
30
|
USE_PEFT_BACKEND,
|
30
31
|
deprecate,
|
31
32
|
logging,
|
@@ -33,9 +34,9 @@ from ...utils import (
|
|
33
34
|
scale_lora_layers,
|
34
35
|
unscale_lora_layers,
|
35
36
|
)
|
36
|
-
from
|
37
|
-
from
|
38
|
-
from
|
37
|
+
from ....utils.torch_utils import randn_tensor
|
38
|
+
from ...pipeline_utils import DiffusionPipeline
|
39
|
+
from ...stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
39
40
|
from .modeling_roberta_series import RobertaSeriesModelWithTransformation
|
40
41
|
from .pipeline_output import AltDiffusionPipelineOutput
|
41
42
|
|
@@ -118,7 +119,6 @@ def retrieve_timesteps(
|
|
118
119
|
return timesteps, num_inference_steps
|
119
120
|
|
120
121
|
|
121
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline with Stable->Alt, CLIPTextModel->RobertaSeriesModelWithTransformation, CLIPTokenizer->XLMRobertaTokenizer, AltDiffusionSafetyChecker->StableDiffusionSafetyChecker
|
122
122
|
class AltDiffusionPipeline(
|
123
123
|
DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, IPAdapterMixin, FromSingleFileMixin
|
124
124
|
):
|
@@ -155,7 +155,7 @@ class AltDiffusionPipeline(
|
|
155
155
|
A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
|
156
156
|
"""
|
157
157
|
|
158
|
-
model_cpu_offload_seq = "text_encoder->unet->vae"
|
158
|
+
model_cpu_offload_seq = "text_encoder->image_encoder->unet->vae"
|
159
159
|
_optional_components = ["safety_checker", "feature_extractor", "image_encoder"]
|
160
160
|
_exclude_from_cpu_offload = ["safety_checker"]
|
161
161
|
_callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
|
@@ -494,18 +494,29 @@ class AltDiffusionPipeline(
|
|
494
494
|
|
495
495
|
return prompt_embeds, negative_prompt_embeds
|
496
496
|
|
497
|
-
def encode_image(self, image, device, num_images_per_prompt):
|
497
|
+
def encode_image(self, image, device, num_images_per_prompt, output_hidden_states=None):
|
498
498
|
dtype = next(self.image_encoder.parameters()).dtype
|
499
499
|
|
500
500
|
if not isinstance(image, torch.Tensor):
|
501
501
|
image = self.feature_extractor(image, return_tensors="pt").pixel_values
|
502
502
|
|
503
503
|
image = image.to(device=device, dtype=dtype)
|
504
|
-
|
505
|
-
|
504
|
+
if output_hidden_states:
|
505
|
+
image_enc_hidden_states = self.image_encoder(image, output_hidden_states=True).hidden_states[-2]
|
506
|
+
image_enc_hidden_states = image_enc_hidden_states.repeat_interleave(num_images_per_prompt, dim=0)
|
507
|
+
uncond_image_enc_hidden_states = self.image_encoder(
|
508
|
+
torch.zeros_like(image), output_hidden_states=True
|
509
|
+
).hidden_states[-2]
|
510
|
+
uncond_image_enc_hidden_states = uncond_image_enc_hidden_states.repeat_interleave(
|
511
|
+
num_images_per_prompt, dim=0
|
512
|
+
)
|
513
|
+
return image_enc_hidden_states, uncond_image_enc_hidden_states
|
514
|
+
else:
|
515
|
+
image_embeds = self.image_encoder(image).image_embeds
|
516
|
+
image_embeds = image_embeds.repeat_interleave(num_images_per_prompt, dim=0)
|
517
|
+
uncond_image_embeds = torch.zeros_like(image_embeds)
|
506
518
|
|
507
|
-
|
508
|
-
return image_embeds, uncond_image_embeds
|
519
|
+
return image_embeds, uncond_image_embeds
|
509
520
|
|
510
521
|
def run_safety_checker(self, image, device, dtype):
|
511
522
|
if self.safety_checker is None:
|
@@ -644,6 +655,65 @@ class AltDiffusionPipeline(
|
|
644
655
|
"""Disables the FreeU mechanism if enabled."""
|
645
656
|
self.unet.disable_freeu()
|
646
657
|
|
658
|
+
def fuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
659
|
+
"""
|
660
|
+
Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query,
|
661
|
+
key, value) are fused. For cross-attention modules, key and value projection matrices are fused.
|
662
|
+
|
663
|
+
<Tip warning={true}>
|
664
|
+
|
665
|
+
This API is 🧪 experimental.
|
666
|
+
|
667
|
+
</Tip>
|
668
|
+
|
669
|
+
Args:
|
670
|
+
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
671
|
+
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
672
|
+
"""
|
673
|
+
self.fusing_unet = False
|
674
|
+
self.fusing_vae = False
|
675
|
+
|
676
|
+
if unet:
|
677
|
+
self.fusing_unet = True
|
678
|
+
self.unet.fuse_qkv_projections()
|
679
|
+
self.unet.set_attn_processor(FusedAttnProcessor2_0())
|
680
|
+
|
681
|
+
if vae:
|
682
|
+
if not isinstance(self.vae, AutoencoderKL):
|
683
|
+
raise ValueError("`fuse_qkv_projections()` is only supported for the VAE of type `AutoencoderKL`.")
|
684
|
+
|
685
|
+
self.fusing_vae = True
|
686
|
+
self.vae.fuse_qkv_projections()
|
687
|
+
self.vae.set_attn_processor(FusedAttnProcessor2_0())
|
688
|
+
|
689
|
+
def unfuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
690
|
+
"""Disable QKV projection fusion if enabled.
|
691
|
+
|
692
|
+
<Tip warning={true}>
|
693
|
+
|
694
|
+
This API is 🧪 experimental.
|
695
|
+
|
696
|
+
</Tip>
|
697
|
+
|
698
|
+
Args:
|
699
|
+
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
700
|
+
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
701
|
+
|
702
|
+
"""
|
703
|
+
if unet:
|
704
|
+
if not self.fusing_unet:
|
705
|
+
logger.warning("The UNet was not initially fused for QKV projections. Doing nothing.")
|
706
|
+
else:
|
707
|
+
self.unet.unfuse_qkv_projections()
|
708
|
+
self.fusing_unet = False
|
709
|
+
|
710
|
+
if vae:
|
711
|
+
if not self.fusing_vae:
|
712
|
+
logger.warning("The VAE was not initially fused for QKV projections. Doing nothing.")
|
713
|
+
else:
|
714
|
+
self.vae.unfuse_qkv_projections()
|
715
|
+
self.fusing_vae = False
|
716
|
+
|
647
717
|
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
648
718
|
"""
|
649
719
|
See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
|
@@ -875,7 +945,10 @@ class AltDiffusionPipeline(
|
|
875
945
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
876
946
|
|
877
947
|
if ip_adapter_image is not None:
|
878
|
-
|
948
|
+
output_hidden_state = False if isinstance(self.unet.encoder_hid_proj, ImageProjection) else True
|
949
|
+
image_embeds, negative_image_embeds = self.encode_image(
|
950
|
+
ip_adapter_image, device, num_images_per_prompt, output_hidden_state
|
951
|
+
)
|
879
952
|
if self.do_classifier_free_guidance:
|
880
953
|
image_embeds = torch.cat([negative_image_embeds, image_embeds])
|
881
954
|
|
diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py
RENAMED
@@ -21,13 +21,14 @@ import torch
|
|
21
21
|
from packaging import version
|
22
22
|
from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection, XLMRobertaTokenizer
|
23
23
|
|
24
|
-
from
|
25
|
-
from
|
26
|
-
from
|
27
|
-
from
|
28
|
-
from
|
29
|
-
from
|
30
|
-
from
|
24
|
+
from ....configuration_utils import FrozenDict
|
25
|
+
from ....image_processor import PipelineImageInput, VaeImageProcessor
|
26
|
+
from ....loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
27
|
+
from ....models import AutoencoderKL, ImageProjection, UNet2DConditionModel
|
28
|
+
from ....models.attention_processor import FusedAttnProcessor2_0
|
29
|
+
from ....models.lora import adjust_lora_scale_text_encoder
|
30
|
+
from ....schedulers import KarrasDiffusionSchedulers
|
31
|
+
from ....utils import (
|
31
32
|
PIL_INTERPOLATION,
|
32
33
|
USE_PEFT_BACKEND,
|
33
34
|
deprecate,
|
@@ -36,9 +37,9 @@ from ...utils import (
|
|
36
37
|
scale_lora_layers,
|
37
38
|
unscale_lora_layers,
|
38
39
|
)
|
39
|
-
from
|
40
|
-
from
|
41
|
-
from
|
40
|
+
from ....utils.torch_utils import randn_tensor
|
41
|
+
from ...pipeline_utils import DiffusionPipeline
|
42
|
+
from ...stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
42
43
|
from .modeling_roberta_series import RobertaSeriesModelWithTransformation
|
43
44
|
from .pipeline_output import AltDiffusionPipelineOutput
|
44
45
|
|
@@ -158,7 +159,6 @@ def retrieve_timesteps(
|
|
158
159
|
return timesteps, num_inference_steps
|
159
160
|
|
160
161
|
|
161
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline with Stable->Alt, CLIPTextModel->RobertaSeriesModelWithTransformation, CLIPTokenizer->XLMRobertaTokenizer, AltDiffusionSafetyChecker->StableDiffusionSafetyChecker
|
162
162
|
class AltDiffusionImg2ImgPipeline(
|
163
163
|
DiffusionPipeline, TextualInversionLoaderMixin, IPAdapterMixin, LoraLoaderMixin, FromSingleFileMixin
|
164
164
|
):
|
@@ -195,7 +195,7 @@ class AltDiffusionImg2ImgPipeline(
|
|
195
195
|
A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
|
196
196
|
"""
|
197
197
|
|
198
|
-
model_cpu_offload_seq = "text_encoder->unet->vae"
|
198
|
+
model_cpu_offload_seq = "text_encoder->image_encoder->unet->vae"
|
199
199
|
_optional_components = ["safety_checker", "feature_extractor", "image_encoder"]
|
200
200
|
_exclude_from_cpu_offload = ["safety_checker"]
|
201
201
|
_callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
|
@@ -505,18 +505,29 @@ class AltDiffusionImg2ImgPipeline(
|
|
505
505
|
|
506
506
|
return prompt_embeds, negative_prompt_embeds
|
507
507
|
|
508
|
-
def encode_image(self, image, device, num_images_per_prompt):
|
508
|
+
def encode_image(self, image, device, num_images_per_prompt, output_hidden_states=None):
|
509
509
|
dtype = next(self.image_encoder.parameters()).dtype
|
510
510
|
|
511
511
|
if not isinstance(image, torch.Tensor):
|
512
512
|
image = self.feature_extractor(image, return_tensors="pt").pixel_values
|
513
513
|
|
514
514
|
image = image.to(device=device, dtype=dtype)
|
515
|
-
|
516
|
-
|
515
|
+
if output_hidden_states:
|
516
|
+
image_enc_hidden_states = self.image_encoder(image, output_hidden_states=True).hidden_states[-2]
|
517
|
+
image_enc_hidden_states = image_enc_hidden_states.repeat_interleave(num_images_per_prompt, dim=0)
|
518
|
+
uncond_image_enc_hidden_states = self.image_encoder(
|
519
|
+
torch.zeros_like(image), output_hidden_states=True
|
520
|
+
).hidden_states[-2]
|
521
|
+
uncond_image_enc_hidden_states = uncond_image_enc_hidden_states.repeat_interleave(
|
522
|
+
num_images_per_prompt, dim=0
|
523
|
+
)
|
524
|
+
return image_enc_hidden_states, uncond_image_enc_hidden_states
|
525
|
+
else:
|
526
|
+
image_embeds = self.image_encoder(image).image_embeds
|
527
|
+
image_embeds = image_embeds.repeat_interleave(num_images_per_prompt, dim=0)
|
528
|
+
uncond_image_embeds = torch.zeros_like(image_embeds)
|
517
529
|
|
518
|
-
|
519
|
-
return image_embeds, uncond_image_embeds
|
530
|
+
return image_embeds, uncond_image_embeds
|
520
531
|
|
521
532
|
def run_safety_checker(self, image, device, dtype):
|
522
533
|
if self.safety_checker is None:
|
@@ -704,6 +715,65 @@ class AltDiffusionImg2ImgPipeline(
|
|
704
715
|
"""Disables the FreeU mechanism if enabled."""
|
705
716
|
self.unet.disable_freeu()
|
706
717
|
|
718
|
+
def fuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
719
|
+
"""
|
720
|
+
Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query,
|
721
|
+
key, value) are fused. For cross-attention modules, key and value projection matrices are fused.
|
722
|
+
|
723
|
+
<Tip warning={true}>
|
724
|
+
|
725
|
+
This API is 🧪 experimental.
|
726
|
+
|
727
|
+
</Tip>
|
728
|
+
|
729
|
+
Args:
|
730
|
+
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
731
|
+
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
732
|
+
"""
|
733
|
+
self.fusing_unet = False
|
734
|
+
self.fusing_vae = False
|
735
|
+
|
736
|
+
if unet:
|
737
|
+
self.fusing_unet = True
|
738
|
+
self.unet.fuse_qkv_projections()
|
739
|
+
self.unet.set_attn_processor(FusedAttnProcessor2_0())
|
740
|
+
|
741
|
+
if vae:
|
742
|
+
if not isinstance(self.vae, AutoencoderKL):
|
743
|
+
raise ValueError("`fuse_qkv_projections()` is only supported for the VAE of type `AutoencoderKL`.")
|
744
|
+
|
745
|
+
self.fusing_vae = True
|
746
|
+
self.vae.fuse_qkv_projections()
|
747
|
+
self.vae.set_attn_processor(FusedAttnProcessor2_0())
|
748
|
+
|
749
|
+
def unfuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
750
|
+
"""Disable QKV projection fusion if enabled.
|
751
|
+
|
752
|
+
<Tip warning={true}>
|
753
|
+
|
754
|
+
This API is 🧪 experimental.
|
755
|
+
|
756
|
+
</Tip>
|
757
|
+
|
758
|
+
Args:
|
759
|
+
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
760
|
+
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
761
|
+
|
762
|
+
"""
|
763
|
+
if unet:
|
764
|
+
if not self.fusing_unet:
|
765
|
+
logger.warning("The UNet was not initially fused for QKV projections. Doing nothing.")
|
766
|
+
else:
|
767
|
+
self.unet.unfuse_qkv_projections()
|
768
|
+
self.fusing_unet = False
|
769
|
+
|
770
|
+
if vae:
|
771
|
+
if not self.fusing_vae:
|
772
|
+
logger.warning("The VAE was not initially fused for QKV projections. Doing nothing.")
|
773
|
+
else:
|
774
|
+
self.vae.unfuse_qkv_projections()
|
775
|
+
self.fusing_vae = False
|
776
|
+
|
707
777
|
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
708
778
|
"""
|
709
779
|
See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
|
@@ -919,7 +989,10 @@ class AltDiffusionImg2ImgPipeline(
|
|
919
989
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
920
990
|
|
921
991
|
if ip_adapter_image is not None:
|
922
|
-
|
992
|
+
output_hidden_state = False if isinstance(self.unet.encoder_hid_proj, ImageProjection) else True
|
993
|
+
image_embeds, negative_image_embeds = self.encode_image(
|
994
|
+
ip_adapter_image, device, num_images_per_prompt, output_hidden_state
|
995
|
+
)
|
923
996
|
if self.do_classifier_free_guidance:
|
924
997
|
image_embeds = torch.cat([negative_image_embeds, image_embeds])
|
925
998
|
|
@@ -15,8 +15,8 @@
|
|
15
15
|
|
16
16
|
import numpy as np # noqa: E402
|
17
17
|
|
18
|
-
from
|
19
|
-
from
|
18
|
+
from ....configuration_utils import ConfigMixin, register_to_config
|
19
|
+
from ....schedulers.scheduling_utils import SchedulerMixin
|
20
20
|
|
21
21
|
|
22
22
|
try:
|
diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py
RENAMED
@@ -20,10 +20,10 @@ import numpy as np
|
|
20
20
|
import torch
|
21
21
|
from PIL import Image
|
22
22
|
|
23
|
-
from
|
24
|
-
from
|
25
|
-
from
|
26
|
-
from
|
23
|
+
from ....models import AutoencoderKL, UNet2DConditionModel
|
24
|
+
from ....schedulers import DDIMScheduler, DDPMScheduler
|
25
|
+
from ....utils.torch_utils import randn_tensor
|
26
|
+
from ...pipeline_utils import AudioPipelineOutput, BaseOutput, DiffusionPipeline, ImagePipelineOutput
|
27
27
|
from .mel import Mel
|
28
28
|
|
29
29
|
|
@@ -17,10 +17,10 @@ from typing import List, Optional, Tuple, Union
|
|
17
17
|
|
18
18
|
import torch
|
19
19
|
|
20
|
-
from
|
21
|
-
from
|
22
|
-
from
|
23
|
-
from
|
20
|
+
from ....models import UNet2DModel, VQModel
|
21
|
+
from ....schedulers import DDIMScheduler
|
22
|
+
from ....utils.torch_utils import randn_tensor
|
23
|
+
from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
24
24
|
|
25
25
|
|
26
26
|
class LDMPipeline(DiffusionPipeline):
|
@@ -17,10 +17,10 @@ from typing import List, Optional, Tuple, Union
|
|
17
17
|
|
18
18
|
import torch
|
19
19
|
|
20
|
-
from
|
21
|
-
from
|
22
|
-
from
|
23
|
-
from
|
20
|
+
from ....models import UNet2DModel
|
21
|
+
from ....schedulers import PNDMScheduler
|
22
|
+
from ....utils.torch_utils import randn_tensor
|
23
|
+
from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
24
24
|
|
25
25
|
|
26
26
|
class PNDMPipeline(DiffusionPipeline):
|
@@ -19,11 +19,11 @@ import numpy as np
|
|
19
19
|
import PIL.Image
|
20
20
|
import torch
|
21
21
|
|
22
|
-
from
|
23
|
-
from
|
24
|
-
from
|
25
|
-
from
|
26
|
-
from
|
22
|
+
from ....models import UNet2DModel
|
23
|
+
from ....schedulers import RePaintScheduler
|
24
|
+
from ....utils import PIL_INTERPOLATION, deprecate, logging
|
25
|
+
from ....utils.torch_utils import randn_tensor
|
26
|
+
from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
27
27
|
|
28
28
|
|
29
29
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -16,10 +16,10 @@ from typing import List, Optional, Tuple, Union
|
|
16
16
|
|
17
17
|
import torch
|
18
18
|
|
19
|
-
from
|
20
|
-
from
|
21
|
-
from
|
22
|
-
from
|
19
|
+
from ....models import UNet2DModel
|
20
|
+
from ....schedulers import ScoreSdeVeScheduler
|
21
|
+
from ....utils.torch_utils import randn_tensor
|
22
|
+
from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
23
23
|
|
24
24
|
|
25
25
|
class ScoreSdeVePipeline(DiffusionPipeline):
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# flake8: noqa
|
2
2
|
from typing import TYPE_CHECKING
|
3
|
-
from
|
4
|
-
|
3
|
+
from ....utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
5
|
_LazyModule,
|
6
6
|
is_note_seq_available,
|
7
7
|
OptionalDependencyNotAvailable,
|
@@ -17,7 +17,7 @@ try:
|
|
17
17
|
if not (is_transformers_available() and is_torch_available()):
|
18
18
|
raise OptionalDependencyNotAvailable()
|
19
19
|
except OptionalDependencyNotAvailable:
|
20
|
-
from
|
20
|
+
from ....utils import dummy_torch_and_transformers_objects # noqa F403
|
21
21
|
|
22
22
|
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
23
23
|
else:
|
@@ -32,7 +32,7 @@ try:
|
|
32
32
|
if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
|
33
33
|
raise OptionalDependencyNotAvailable()
|
34
34
|
except OptionalDependencyNotAvailable:
|
35
|
-
from
|
35
|
+
from ....utils import dummy_transformers_and_torch_and_note_seq_objects
|
36
36
|
|
37
37
|
_dummy_objects.update(get_objects_from_module(dummy_transformers_and_torch_and_note_seq_objects))
|
38
38
|
else:
|
@@ -45,7 +45,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
45
45
|
raise OptionalDependencyNotAvailable()
|
46
46
|
|
47
47
|
except OptionalDependencyNotAvailable:
|
48
|
-
from
|
48
|
+
from ....utils.dummy_torch_and_transformers_objects import *
|
49
49
|
else:
|
50
50
|
from .pipeline_spectrogram_diffusion import SpectrogramDiffusionPipeline
|
51
51
|
from .pipeline_spectrogram_diffusion import SpectrogramContEncoder
|
@@ -56,7 +56,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
56
56
|
if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
|
57
57
|
raise OptionalDependencyNotAvailable()
|
58
58
|
except OptionalDependencyNotAvailable:
|
59
|
-
from
|
59
|
+
from ....utils.dummy_transformers_and_torch_and_note_seq_objects import *
|
60
60
|
|
61
61
|
else:
|
62
62
|
from .midi_utils import MidiProcessor
|
@@ -22,8 +22,8 @@ from transformers.models.t5.modeling_t5 import (
|
|
22
22
|
T5LayerNorm,
|
23
23
|
)
|
24
24
|
|
25
|
-
from
|
26
|
-
from
|
25
|
+
from ....configuration_utils import ConfigMixin, register_to_config
|
26
|
+
from ....models import ModelMixin
|
27
27
|
|
28
28
|
|
29
29
|
class SpectrogramContEncoder(ModelMixin, ConfigMixin, ModuleUtilsMixin):
|
diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py
RENAMED
@@ -18,8 +18,8 @@ import torch.nn as nn
|
|
18
18
|
from transformers.modeling_utils import ModuleUtilsMixin
|
19
19
|
from transformers.models.t5.modeling_t5 import T5Block, T5Config, T5LayerNorm
|
20
20
|
|
21
|
-
from
|
22
|
-
from
|
21
|
+
from ....configuration_utils import ConfigMixin, register_to_config
|
22
|
+
from ....models import ModelMixin
|
23
23
|
|
24
24
|
|
25
25
|
class SpectrogramNotesEncoder(ModelMixin, ConfigMixin, ModuleUtilsMixin):
|
@@ -19,17 +19,17 @@ from typing import Any, Callable, List, Optional, Tuple, Union
|
|
19
19
|
import numpy as np
|
20
20
|
import torch
|
21
21
|
|
22
|
-
from
|
23
|
-
from
|
24
|
-
from
|
25
|
-
from
|
22
|
+
from ....models import T5FilmDecoder
|
23
|
+
from ....schedulers import DDPMScheduler
|
24
|
+
from ....utils import is_onnx_available, logging
|
25
|
+
from ....utils.torch_utils import randn_tensor
|
26
26
|
|
27
27
|
|
28
28
|
if is_onnx_available():
|
29
|
-
from
|
29
|
+
from ...onnx_utils import OnnxRuntimeModel
|
30
30
|
|
31
|
-
from
|
32
|
-
from .
|
31
|
+
from ...pipeline_utils import AudioPipelineOutput, DiffusionPipeline
|
32
|
+
from .continuous_encoder import SpectrogramContEncoder
|
33
33
|
from .notes_encoder import SpectrogramNotesEncoder
|
34
34
|
|
35
35
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from ....utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
|
+
OptionalDependencyNotAvailable,
|
6
|
+
_LazyModule,
|
7
|
+
get_objects_from_module,
|
8
|
+
is_torch_available,
|
9
|
+
is_transformers_available,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
_dummy_objects = {}
|
14
|
+
_import_structure = {}
|
15
|
+
|
16
|
+
try:
|
17
|
+
if not (is_transformers_available() and is_torch_available()):
|
18
|
+
raise OptionalDependencyNotAvailable()
|
19
|
+
except OptionalDependencyNotAvailable:
|
20
|
+
from ....utils import dummy_torch_and_transformers_objects
|
21
|
+
|
22
|
+
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
23
|
+
else:
|
24
|
+
_import_structure["pipeline_cycle_diffusion"] = ["CycleDiffusionPipeline"]
|
25
|
+
_import_structure["pipeline_stable_diffusion_inpaint_legacy"] = ["StableDiffusionInpaintPipelineLegacy"]
|
26
|
+
_import_structure["pipeline_stable_diffusion_model_editing"] = ["StableDiffusionModelEditingPipeline"]
|
27
|
+
|
28
|
+
_import_structure["pipeline_stable_diffusion_paradigms"] = ["StableDiffusionParadigmsPipeline"]
|
29
|
+
_import_structure["pipeline_stable_diffusion_pix2pix_zero"] = ["StableDiffusionPix2PixZeroPipeline"]
|
30
|
+
|
31
|
+
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
32
|
+
try:
|
33
|
+
if not (is_transformers_available() and is_torch_available()):
|
34
|
+
raise OptionalDependencyNotAvailable()
|
35
|
+
except OptionalDependencyNotAvailable:
|
36
|
+
from ....utils.dummy_torch_and_transformers_objects import *
|
37
|
+
|
38
|
+
else:
|
39
|
+
from .pipeline_cycle_diffusion import CycleDiffusionPipeline
|
40
|
+
from .pipeline_stable_diffusion_inpaint_legacy import StableDiffusionInpaintPipelineLegacy
|
41
|
+
from .pipeline_stable_diffusion_model_editing import StableDiffusionModelEditingPipeline
|
42
|
+
from .pipeline_stable_diffusion_paradigms import StableDiffusionParadigmsPipeline
|
43
|
+
from .pipeline_stable_diffusion_pix2pix_zero import StableDiffusionPix2PixZeroPipeline
|
44
|
+
|
45
|
+
else:
|
46
|
+
import sys
|
47
|
+
|
48
|
+
sys.modules[__name__] = _LazyModule(
|
49
|
+
__name__,
|
50
|
+
globals()["__file__"],
|
51
|
+
_import_structure,
|
52
|
+
module_spec=__spec__,
|
53
|
+
)
|
54
|
+
for name, value in _dummy_objects.items():
|
55
|
+
setattr(sys.modules[__name__], name, value)
|