diffusers 0.26.3__py3-none-any.whl → 0.27.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diffusers/__init__.py +20 -1
- diffusers/commands/__init__.py +1 -1
- diffusers/commands/diffusers_cli.py +1 -1
- diffusers/commands/env.py +1 -1
- diffusers/commands/fp16_safetensors.py +1 -1
- diffusers/configuration_utils.py +7 -3
- diffusers/dependency_versions_check.py +1 -1
- diffusers/dependency_versions_table.py +2 -2
- diffusers/experimental/rl/value_guided_sampling.py +1 -1
- diffusers/image_processor.py +110 -4
- diffusers/loaders/autoencoder.py +7 -8
- diffusers/loaders/controlnet.py +17 -8
- diffusers/loaders/ip_adapter.py +86 -23
- diffusers/loaders/lora.py +105 -310
- diffusers/loaders/lora_conversion_utils.py +1 -1
- diffusers/loaders/peft.py +1 -1
- diffusers/loaders/single_file.py +51 -12
- diffusers/loaders/single_file_utils.py +274 -49
- diffusers/loaders/textual_inversion.py +23 -4
- diffusers/loaders/unet.py +195 -41
- diffusers/loaders/utils.py +1 -1
- diffusers/models/__init__.py +3 -1
- diffusers/models/activations.py +9 -9
- diffusers/models/attention.py +26 -36
- diffusers/models/attention_flax.py +1 -1
- diffusers/models/attention_processor.py +171 -114
- diffusers/models/autoencoders/autoencoder_asym_kl.py +1 -1
- diffusers/models/autoencoders/autoencoder_kl.py +3 -1
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +1 -1
- diffusers/models/autoencoders/autoencoder_tiny.py +4 -2
- diffusers/models/autoencoders/consistency_decoder_vae.py +1 -1
- diffusers/models/autoencoders/vae.py +1 -1
- diffusers/models/controlnet.py +1 -1
- diffusers/models/controlnet_flax.py +1 -1
- diffusers/models/downsampling.py +8 -12
- diffusers/models/dual_transformer_2d.py +1 -1
- diffusers/models/embeddings.py +3 -4
- diffusers/models/embeddings_flax.py +1 -1
- diffusers/models/lora.py +33 -10
- diffusers/models/modeling_flax_pytorch_utils.py +1 -1
- diffusers/models/modeling_flax_utils.py +1 -1
- diffusers/models/modeling_pytorch_flax_utils.py +1 -1
- diffusers/models/modeling_utils.py +4 -6
- diffusers/models/normalization.py +1 -1
- diffusers/models/resnet.py +31 -58
- diffusers/models/resnet_flax.py +1 -1
- diffusers/models/t5_film_transformer.py +1 -1
- diffusers/models/transformer_2d.py +1 -1
- diffusers/models/transformer_temporal.py +1 -1
- diffusers/models/transformers/dual_transformer_2d.py +1 -1
- diffusers/models/transformers/t5_film_transformer.py +1 -1
- diffusers/models/transformers/transformer_2d.py +29 -31
- diffusers/models/transformers/transformer_temporal.py +1 -1
- diffusers/models/unet_1d.py +1 -1
- diffusers/models/unet_1d_blocks.py +1 -1
- diffusers/models/unet_2d.py +1 -1
- diffusers/models/unet_2d_blocks.py +1 -1
- diffusers/models/unet_2d_condition.py +1 -1
- diffusers/models/unets/__init__.py +1 -0
- diffusers/models/unets/unet_1d.py +1 -1
- diffusers/models/unets/unet_1d_blocks.py +1 -1
- diffusers/models/unets/unet_2d.py +4 -4
- diffusers/models/unets/unet_2d_blocks.py +238 -98
- diffusers/models/unets/unet_2d_blocks_flax.py +1 -1
- diffusers/models/unets/unet_2d_condition.py +420 -323
- diffusers/models/unets/unet_2d_condition_flax.py +21 -12
- diffusers/models/unets/unet_3d_blocks.py +50 -40
- diffusers/models/unets/unet_3d_condition.py +47 -8
- diffusers/models/unets/unet_i2vgen_xl.py +75 -30
- diffusers/models/unets/unet_kandinsky3.py +1 -1
- diffusers/models/unets/unet_motion_model.py +48 -8
- diffusers/models/unets/unet_spatio_temporal_condition.py +1 -1
- diffusers/models/unets/unet_stable_cascade.py +610 -0
- diffusers/models/unets/uvit_2d.py +1 -1
- diffusers/models/upsampling.py +10 -16
- diffusers/models/vae_flax.py +1 -1
- diffusers/models/vq_model.py +1 -1
- diffusers/optimization.py +1 -1
- diffusers/pipelines/__init__.py +26 -0
- diffusers/pipelines/amused/pipeline_amused.py +1 -1
- diffusers/pipelines/amused/pipeline_amused_img2img.py +1 -1
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +1 -1
- diffusers/pipelines/animatediff/pipeline_animatediff.py +162 -417
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +165 -137
- diffusers/pipelines/animatediff/pipeline_output.py +7 -6
- diffusers/pipelines/audioldm/pipeline_audioldm.py +3 -19
- diffusers/pipelines/audioldm2/modeling_audioldm2.py +1 -1
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +3 -3
- diffusers/pipelines/auto_pipeline.py +7 -16
- diffusers/pipelines/blip_diffusion/blip_image_processing.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_blip2.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +2 -2
- diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +2 -2
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -1
- diffusers/pipelines/controlnet/pipeline_controlnet.py +90 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +2 -2
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +98 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +92 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +145 -70
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +126 -89
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +108 -96
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +2 -2
- diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -1
- diffusers/pipelines/ddim/pipeline_ddim.py +1 -1
- diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +5 -5
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +5 -5
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +5 -5
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +10 -120
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +10 -91
- diffusers/pipelines/deprecated/audio_diffusion/mel.py +1 -1
- diffusers/pipelines/deprecated/audio_diffusion/pipeline_audio_diffusion.py +1 -1
- diffusers/pipelines/deprecated/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py +1 -1
- diffusers/pipelines/deprecated/pndm/pipeline_pndm.py +1 -1
- diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +1 -1
- diffusers/pipelines/deprecated/score_sde_ve/pipeline_score_sde_ve.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/continuous_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/midi_utils.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/notes_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -1
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +5 -4
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +5 -4
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +7 -22
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +5 -39
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +5 -5
- diffusers/pipelines/deprecated/stochastic_karras_ve/pipeline_stochastic_karras_ve.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +31 -22
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +1 -2
- diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +1 -1
- diffusers/pipelines/dit/pipeline_dit.py +1 -1
- diffusers/pipelines/free_init_utils.py +184 -0
- diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +22 -104
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +2 -2
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +1 -1
- 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/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +2 -2
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +104 -93
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +112 -74
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -1
- diffusers/pipelines/ledits_pp/__init__.py +55 -0
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +1505 -0
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +1797 -0
- diffusers/pipelines/ledits_pp/pipeline_output.py +43 -0
- diffusers/pipelines/musicldm/pipeline_musicldm.py +3 -19
- diffusers/pipelines/onnx_utils.py +1 -1
- diffusers/pipelines/paint_by_example/image_encoder.py +1 -1
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +3 -3
- diffusers/pipelines/pia/pipeline_pia.py +168 -327
- diffusers/pipelines/pipeline_flax_utils.py +1 -1
- diffusers/pipelines/pipeline_loading_utils.py +508 -0
- diffusers/pipelines/pipeline_utils.py +188 -534
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +56 -10
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +3 -3
- diffusers/pipelines/shap_e/camera.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +1 -1
- diffusers/pipelines/shap_e/renderer.py +1 -1
- diffusers/pipelines/stable_cascade/__init__.py +50 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +482 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +311 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +638 -0
- diffusers/pipelines/stable_diffusion/clip_image_project_model.py +1 -1
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +4 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_img2img.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +90 -146
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +5 -4
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +4 -32
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -119
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +92 -119
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +13 -59
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +3 -31
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +5 -33
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -21
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +7 -21
- diffusers/pipelines/stable_diffusion/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion/safety_checker_flax.py +1 -1
- diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py +1 -1
- diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +5 -21
- diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +9 -38
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +5 -34
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +6 -35
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +7 -6
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +4 -124
- diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +282 -80
- diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +94 -46
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +3 -3
- diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +6 -22
- diffusers/pipelines/stable_diffusion_xl/pipeline_flax_stable_diffusion_xl.py +1 -1
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +96 -148
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +98 -154
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +98 -153
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +25 -87
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +89 -80
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +5 -49
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +80 -88
- diffusers/pipelines/text_to_video_synthesis/pipeline_output.py +8 -6
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +15 -86
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +20 -93
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +5 -5
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +3 -19
- diffusers/pipelines/unclip/pipeline_unclip.py +1 -1
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -1
- diffusers/pipelines/unclip/text_proj.py +1 -1
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +35 -35
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +4 -21
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_diffnext.py +2 -2
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +4 -5
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +8 -8
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +1 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +2 -2
- diffusers/schedulers/__init__.py +7 -1
- diffusers/schedulers/deprecated/scheduling_karras_ve.py +1 -1
- diffusers/schedulers/deprecated/scheduling_sde_vp.py +1 -1
- diffusers/schedulers/scheduling_consistency_models.py +42 -19
- diffusers/schedulers/scheduling_ddim.py +2 -4
- diffusers/schedulers/scheduling_ddim_flax.py +13 -5
- diffusers/schedulers/scheduling_ddim_inverse.py +2 -4
- diffusers/schedulers/scheduling_ddim_parallel.py +2 -4
- diffusers/schedulers/scheduling_ddpm.py +2 -4
- diffusers/schedulers/scheduling_ddpm_flax.py +1 -1
- diffusers/schedulers/scheduling_ddpm_parallel.py +2 -4
- diffusers/schedulers/scheduling_ddpm_wuerstchen.py +1 -1
- diffusers/schedulers/scheduling_deis_multistep.py +46 -19
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +107 -21
- diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +1 -1
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +9 -7
- diffusers/schedulers/scheduling_dpmsolver_sde.py +35 -35
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +49 -18
- diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +683 -0
- diffusers/schedulers/scheduling_edm_euler.py +381 -0
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +43 -15
- diffusers/schedulers/scheduling_euler_discrete.py +42 -17
- diffusers/schedulers/scheduling_euler_discrete_flax.py +1 -1
- diffusers/schedulers/scheduling_heun_discrete.py +35 -35
- diffusers/schedulers/scheduling_ipndm.py +37 -11
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +44 -44
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +44 -44
- diffusers/schedulers/scheduling_karras_ve_flax.py +1 -1
- diffusers/schedulers/scheduling_lcm.py +38 -14
- diffusers/schedulers/scheduling_lms_discrete.py +43 -15
- diffusers/schedulers/scheduling_lms_discrete_flax.py +1 -1
- diffusers/schedulers/scheduling_pndm.py +2 -4
- diffusers/schedulers/scheduling_pndm_flax.py +2 -4
- diffusers/schedulers/scheduling_repaint.py +1 -1
- diffusers/schedulers/scheduling_sasolver.py +41 -9
- diffusers/schedulers/scheduling_sde_ve.py +1 -1
- diffusers/schedulers/scheduling_sde_ve_flax.py +1 -1
- diffusers/schedulers/scheduling_tcd.py +686 -0
- diffusers/schedulers/scheduling_unclip.py +1 -1
- diffusers/schedulers/scheduling_unipc_multistep.py +46 -19
- diffusers/schedulers/scheduling_utils.py +2 -1
- diffusers/schedulers/scheduling_utils_flax.py +1 -1
- diffusers/schedulers/scheduling_vq_diffusion.py +1 -1
- diffusers/training_utils.py +9 -2
- diffusers/utils/__init__.py +2 -1
- diffusers/utils/accelerate_utils.py +1 -1
- diffusers/utils/constants.py +1 -1
- diffusers/utils/doc_utils.py +1 -1
- diffusers/utils/dummy_pt_objects.py +60 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +75 -0
- diffusers/utils/dynamic_modules_utils.py +1 -1
- diffusers/utils/export_utils.py +3 -3
- diffusers/utils/hub_utils.py +60 -16
- diffusers/utils/import_utils.py +15 -1
- diffusers/utils/loading_utils.py +2 -0
- diffusers/utils/logging.py +1 -1
- diffusers/utils/model_card_template.md +24 -0
- diffusers/utils/outputs.py +14 -7
- diffusers/utils/peft_utils.py +1 -1
- diffusers/utils/state_dict_utils.py +1 -1
- diffusers/utils/testing_utils.py +2 -0
- diffusers/utils/torch_utils.py +1 -1
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/METADATA +46 -46
- diffusers-0.27.0.dist-info/RECORD +399 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/WHEEL +1 -1
- diffusers-0.26.3.dist-info/RECORD +0 -384
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/LICENSE +0 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/entry_points.txt +0 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -55,7 +55,7 @@ from ...utils import (
|
|
55
55
|
unscale_lora_layers,
|
56
56
|
)
|
57
57
|
from ...utils.torch_utils import is_compiled_module, is_torch_version, randn_tensor
|
58
|
-
from ..pipeline_utils import DiffusionPipeline
|
58
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
59
59
|
from ..stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
|
60
60
|
|
61
61
|
|
@@ -116,6 +116,7 @@ EXAMPLE_DOC_STRING = """
|
|
116
116
|
|
117
117
|
class StableDiffusionXLControlNetPipeline(
|
118
118
|
DiffusionPipeline,
|
119
|
+
StableDiffusionMixin,
|
119
120
|
TextualInversionLoaderMixin,
|
120
121
|
StableDiffusionXLLoraLoaderMixin,
|
121
122
|
IPAdapterMixin,
|
@@ -222,39 +223,6 @@ class StableDiffusionXLControlNetPipeline(
|
|
222
223
|
|
223
224
|
self.register_to_config(force_zeros_for_empty_prompt=force_zeros_for_empty_prompt)
|
224
225
|
|
225
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
226
|
-
def enable_vae_slicing(self):
|
227
|
-
r"""
|
228
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
229
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
230
|
-
"""
|
231
|
-
self.vae.enable_slicing()
|
232
|
-
|
233
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
234
|
-
def disable_vae_slicing(self):
|
235
|
-
r"""
|
236
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
237
|
-
computing decoding in one step.
|
238
|
-
"""
|
239
|
-
self.vae.disable_slicing()
|
240
|
-
|
241
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
242
|
-
def enable_vae_tiling(self):
|
243
|
-
r"""
|
244
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
245
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
246
|
-
processing larger images.
|
247
|
-
"""
|
248
|
-
self.vae.enable_tiling()
|
249
|
-
|
250
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
251
|
-
def disable_vae_tiling(self):
|
252
|
-
r"""
|
253
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
254
|
-
computing decoding in one step.
|
255
|
-
"""
|
256
|
-
self.vae.disable_tiling()
|
257
|
-
|
258
226
|
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.encode_prompt
|
259
227
|
def encode_prompt(
|
260
228
|
self,
|
@@ -351,7 +319,7 @@ class StableDiffusionXLControlNetPipeline(
|
|
351
319
|
prompt_2 = prompt_2 or prompt
|
352
320
|
prompt_2 = [prompt_2] if isinstance(prompt_2, str) else prompt_2
|
353
321
|
|
354
|
-
# textual inversion:
|
322
|
+
# textual inversion: process multi-vector tokens if necessary
|
355
323
|
prompt_embeds_list = []
|
356
324
|
prompts = [prompt, prompt_2]
|
357
325
|
for prompt, tokenizer, text_encoder in zip(prompts, tokenizers, text_encoders):
|
@@ -516,31 +484,54 @@ class StableDiffusionXLControlNetPipeline(
|
|
516
484
|
return image_embeds, uncond_image_embeds
|
517
485
|
|
518
486
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
|
519
|
-
def prepare_ip_adapter_image_embeds(
|
520
|
-
|
521
|
-
|
487
|
+
def prepare_ip_adapter_image_embeds(
|
488
|
+
self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
|
489
|
+
):
|
490
|
+
if ip_adapter_image_embeds is None:
|
491
|
+
if not isinstance(ip_adapter_image, list):
|
492
|
+
ip_adapter_image = [ip_adapter_image]
|
522
493
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
494
|
+
if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
|
495
|
+
raise ValueError(
|
496
|
+
f"`ip_adapter_image` must have same length as the number of IP Adapters. Got {len(ip_adapter_image)} images and {len(self.unet.encoder_hid_proj.image_projection_layers)} IP Adapters."
|
497
|
+
)
|
527
498
|
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
499
|
+
image_embeds = []
|
500
|
+
for single_ip_adapter_image, image_proj_layer in zip(
|
501
|
+
ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
|
502
|
+
):
|
503
|
+
output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
|
504
|
+
single_image_embeds, single_negative_image_embeds = self.encode_image(
|
505
|
+
single_ip_adapter_image, device, 1, output_hidden_state
|
506
|
+
)
|
507
|
+
single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
|
508
|
+
single_negative_image_embeds = torch.stack(
|
509
|
+
[single_negative_image_embeds] * num_images_per_prompt, dim=0
|
510
|
+
)
|
538
511
|
|
539
|
-
|
540
|
-
|
541
|
-
|
512
|
+
if do_classifier_free_guidance:
|
513
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
514
|
+
single_image_embeds = single_image_embeds.to(device)
|
542
515
|
|
543
|
-
|
516
|
+
image_embeds.append(single_image_embeds)
|
517
|
+
else:
|
518
|
+
repeat_dims = [1]
|
519
|
+
image_embeds = []
|
520
|
+
for single_image_embeds in ip_adapter_image_embeds:
|
521
|
+
if do_classifier_free_guidance:
|
522
|
+
single_negative_image_embeds, single_image_embeds = single_image_embeds.chunk(2)
|
523
|
+
single_image_embeds = single_image_embeds.repeat(
|
524
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
525
|
+
)
|
526
|
+
single_negative_image_embeds = single_negative_image_embeds.repeat(
|
527
|
+
num_images_per_prompt, *(repeat_dims * len(single_negative_image_embeds.shape[1:]))
|
528
|
+
)
|
529
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
530
|
+
else:
|
531
|
+
single_image_embeds = single_image_embeds.repeat(
|
532
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
533
|
+
)
|
534
|
+
image_embeds.append(single_image_embeds)
|
544
535
|
|
545
536
|
return image_embeds
|
546
537
|
|
@@ -573,6 +564,8 @@ class StableDiffusionXLControlNetPipeline(
|
|
573
564
|
prompt_embeds=None,
|
574
565
|
negative_prompt_embeds=None,
|
575
566
|
pooled_prompt_embeds=None,
|
567
|
+
ip_adapter_image=None,
|
568
|
+
ip_adapter_image_embeds=None,
|
576
569
|
negative_pooled_prompt_embeds=None,
|
577
570
|
controlnet_conditioning_scale=1.0,
|
578
571
|
control_guidance_start=0.0,
|
@@ -734,6 +727,21 @@ class StableDiffusionXLControlNetPipeline(
|
|
734
727
|
if end > 1.0:
|
735
728
|
raise ValueError(f"control guidance end: {end} can't be larger than 1.0.")
|
736
729
|
|
730
|
+
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
|
731
|
+
raise ValueError(
|
732
|
+
"Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
|
733
|
+
)
|
734
|
+
|
735
|
+
if ip_adapter_image_embeds is not None:
|
736
|
+
if not isinstance(ip_adapter_image_embeds, list):
|
737
|
+
raise ValueError(
|
738
|
+
f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
|
739
|
+
)
|
740
|
+
elif ip_adapter_image_embeds[0].ndim not in [3, 4]:
|
741
|
+
raise ValueError(
|
742
|
+
f"`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is {ip_adapter_image_embeds[0].ndim}D"
|
743
|
+
)
|
744
|
+
|
737
745
|
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet.StableDiffusionControlNetPipeline.check_image
|
738
746
|
def check_image(self, image, prompt, prompt_embeds):
|
739
747
|
image_is_pil = isinstance(image, PIL.Image.Image)
|
@@ -860,34 +868,6 @@ class StableDiffusionXLControlNetPipeline(
|
|
860
868
|
self.vae.decoder.conv_in.to(dtype)
|
861
869
|
self.vae.decoder.mid_block.to(dtype)
|
862
870
|
|
863
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
864
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
865
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
866
|
-
|
867
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
868
|
-
|
869
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
870
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
871
|
-
|
872
|
-
Args:
|
873
|
-
s1 (`float`):
|
874
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
875
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
876
|
-
s2 (`float`):
|
877
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
878
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
879
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
880
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
881
|
-
"""
|
882
|
-
if not hasattr(self, "unet"):
|
883
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
884
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
885
|
-
|
886
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
887
|
-
def disable_freeu(self):
|
888
|
-
"""Disables the FreeU mechanism if enabled."""
|
889
|
-
self.unet.disable_freeu()
|
890
|
-
|
891
871
|
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
|
892
872
|
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
893
873
|
"""
|
@@ -936,6 +916,10 @@ class StableDiffusionXLControlNetPipeline(
|
|
936
916
|
def cross_attention_kwargs(self):
|
937
917
|
return self._cross_attention_kwargs
|
938
918
|
|
919
|
+
@property
|
920
|
+
def denoising_end(self):
|
921
|
+
return self._denoising_end
|
922
|
+
|
939
923
|
@property
|
940
924
|
def num_timesteps(self):
|
941
925
|
return self._num_timesteps
|
@@ -950,6 +934,7 @@ class StableDiffusionXLControlNetPipeline(
|
|
950
934
|
height: Optional[int] = None,
|
951
935
|
width: Optional[int] = None,
|
952
936
|
num_inference_steps: int = 50,
|
937
|
+
denoising_end: Optional[float] = None,
|
953
938
|
guidance_scale: float = 5.0,
|
954
939
|
negative_prompt: Optional[Union[str, List[str]]] = None,
|
955
940
|
negative_prompt_2: Optional[Union[str, List[str]]] = None,
|
@@ -962,6 +947,7 @@ class StableDiffusionXLControlNetPipeline(
|
|
962
947
|
pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
|
963
948
|
negative_pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
|
964
949
|
ip_adapter_image: Optional[PipelineImageInput] = None,
|
950
|
+
ip_adapter_image_embeds: Optional[List[torch.FloatTensor]] = None,
|
965
951
|
output_type: Optional[str] = "pil",
|
966
952
|
return_dict: bool = True,
|
967
953
|
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
@@ -1008,6 +994,13 @@ class StableDiffusionXLControlNetPipeline(
|
|
1008
994
|
num_inference_steps (`int`, *optional*, defaults to 50):
|
1009
995
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
1010
996
|
expense of slower inference.
|
997
|
+
denoising_end (`float`, *optional*):
|
998
|
+
When specified, determines the fraction (between 0.0 and 1.0) of the total denoising process to be
|
999
|
+
completed before it is intentionally prematurely terminated. As a result, the returned sample will
|
1000
|
+
still retain a substantial amount of noise as determined by the discrete timesteps selected by the
|
1001
|
+
scheduler. The denoising_end parameter should ideally be utilized when this pipeline forms a part of a
|
1002
|
+
"Mixture of Denoisers" multi-pipeline setup, as elaborated in [**Refining the Image
|
1003
|
+
Output**](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl#refining-the-image-output)
|
1011
1004
|
guidance_scale (`float`, *optional*, defaults to 5.0):
|
1012
1005
|
A higher guidance scale value encourages the model to generate images closely linked to the text
|
1013
1006
|
`prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`.
|
@@ -1043,6 +1036,11 @@ class StableDiffusionXLControlNetPipeline(
|
|
1043
1036
|
weighting). If not provided, pooled `negative_prompt_embeds` are generated from `negative_prompt` input
|
1044
1037
|
argument.
|
1045
1038
|
ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
|
1039
|
+
ip_adapter_image_embeds (`List[torch.FloatTensor]`, *optional*):
|
1040
|
+
Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of IP-adapters.
|
1041
|
+
Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should contain the negative image embedding
|
1042
|
+
if `do_classifier_free_guidance` is set to `True`.
|
1043
|
+
If not provided, embeddings are computed from the `ip_adapter_image` input argument.
|
1046
1044
|
output_type (`str`, *optional*, defaults to `"pil"`):
|
1047
1045
|
The output format of the generated image. Choose between `PIL.Image` or `np.array`.
|
1048
1046
|
return_dict (`bool`, *optional*, defaults to `True`):
|
@@ -1153,6 +1151,8 @@ class StableDiffusionXLControlNetPipeline(
|
|
1153
1151
|
prompt_embeds,
|
1154
1152
|
negative_prompt_embeds,
|
1155
1153
|
pooled_prompt_embeds,
|
1154
|
+
ip_adapter_image,
|
1155
|
+
ip_adapter_image_embeds,
|
1156
1156
|
negative_pooled_prompt_embeds,
|
1157
1157
|
controlnet_conditioning_scale,
|
1158
1158
|
control_guidance_start,
|
@@ -1163,6 +1163,7 @@ class StableDiffusionXLControlNetPipeline(
|
|
1163
1163
|
self._guidance_scale = guidance_scale
|
1164
1164
|
self._clip_skip = clip_skip
|
1165
1165
|
self._cross_attention_kwargs = cross_attention_kwargs
|
1166
|
+
self._denoising_end = denoising_end
|
1166
1167
|
|
1167
1168
|
# 2. Define call parameters
|
1168
1169
|
if prompt is not None and isinstance(prompt, str):
|
@@ -1210,9 +1211,13 @@ class StableDiffusionXLControlNetPipeline(
|
|
1210
1211
|
)
|
1211
1212
|
|
1212
1213
|
# 3.2 Encode ip_adapter_image
|
1213
|
-
if ip_adapter_image is not None:
|
1214
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1214
1215
|
image_embeds = self.prepare_ip_adapter_image_embeds(
|
1215
|
-
ip_adapter_image,
|
1216
|
+
ip_adapter_image,
|
1217
|
+
ip_adapter_image_embeds,
|
1218
|
+
device,
|
1219
|
+
batch_size * num_images_per_prompt,
|
1220
|
+
self.do_classifier_free_guidance,
|
1216
1221
|
)
|
1217
1222
|
|
1218
1223
|
# 4. Prepare image
|
@@ -1333,6 +1338,23 @@ class StableDiffusionXLControlNetPipeline(
|
|
1333
1338
|
|
1334
1339
|
# 8. Denoising loop
|
1335
1340
|
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
|
1341
|
+
|
1342
|
+
# 8.1 Apply denoising_end
|
1343
|
+
if (
|
1344
|
+
self.denoising_end is not None
|
1345
|
+
and isinstance(self.denoising_end, float)
|
1346
|
+
and self.denoising_end > 0
|
1347
|
+
and self.denoising_end < 1
|
1348
|
+
):
|
1349
|
+
discrete_timestep_cutoff = int(
|
1350
|
+
round(
|
1351
|
+
self.scheduler.config.num_train_timesteps
|
1352
|
+
- (self.denoising_end * self.scheduler.config.num_train_timesteps)
|
1353
|
+
)
|
1354
|
+
)
|
1355
|
+
num_inference_steps = len(list(filter(lambda ts: ts >= discrete_timestep_cutoff, timesteps)))
|
1356
|
+
timesteps = timesteps[:num_inference_steps]
|
1357
|
+
|
1336
1358
|
is_unet_compiled = is_compiled_module(self.unet)
|
1337
1359
|
is_controlnet_compiled = is_compiled_module(self.controlnet)
|
1338
1360
|
is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1")
|
@@ -1389,7 +1411,7 @@ class StableDiffusionXLControlNetPipeline(
|
|
1389
1411
|
down_block_res_samples = [torch.cat([torch.zeros_like(d), d]) for d in down_block_res_samples]
|
1390
1412
|
mid_block_res_sample = torch.cat([torch.zeros_like(mid_block_res_sample), mid_block_res_sample])
|
1391
1413
|
|
1392
|
-
if ip_adapter_image is not None:
|
1414
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1393
1415
|
added_cond_kwargs["image_embeds"] = image_embeds
|
1394
1416
|
|
1395
1417
|
# predict the noise residual
|
@@ -1438,7 +1460,22 @@ class StableDiffusionXLControlNetPipeline(
|
|
1438
1460
|
self.upcast_vae()
|
1439
1461
|
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
|
1440
1462
|
|
1441
|
-
|
1463
|
+
# unscale/denormalize the latents
|
1464
|
+
# denormalize with the mean and std if available and not None
|
1465
|
+
has_latents_mean = hasattr(self.vae.config, "latents_mean") and self.vae.config.latents_mean is not None
|
1466
|
+
has_latents_std = hasattr(self.vae.config, "latents_std") and self.vae.config.latents_std is not None
|
1467
|
+
if has_latents_mean and has_latents_std:
|
1468
|
+
latents_mean = (
|
1469
|
+
torch.tensor(self.vae.config.latents_mean).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
1470
|
+
)
|
1471
|
+
latents_std = (
|
1472
|
+
torch.tensor(self.vae.config.latents_std).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
1473
|
+
)
|
1474
|
+
latents = latents * latents_std / self.vae.config.scaling_factor + latents_mean
|
1475
|
+
else:
|
1476
|
+
latents = latents / self.vae.config.scaling_factor
|
1477
|
+
|
1478
|
+
image = self.vae.decode(latents, return_dict=False)[0]
|
1442
1479
|
|
1443
1480
|
# cast back to fp16 if needed
|
1444
1481
|
if needs_upcasting:
|