diffusers 0.26.2__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 +28 -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 +278 -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 +52 -21
- 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.2.dist-info → diffusers-0.27.0.dist-info}/METADATA +5 -5
- diffusers-0.27.0.dist-info/RECORD +399 -0
- diffusers-0.26.2.dist-info/RECORD +0 -384
- {diffusers-0.26.2.dist-info → diffusers-0.27.0.dist-info}/LICENSE +0 -0
- {diffusers-0.26.2.dist-info → diffusers-0.27.0.dist-info}/WHEEL +0 -0
- {diffusers-0.26.2.dist-info → diffusers-0.27.0.dist-info}/entry_points.txt +0 -0
- {diffusers-0.26.2.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.
|
@@ -36,7 +36,7 @@ from ...utils import (
|
|
36
36
|
unscale_lora_layers,
|
37
37
|
)
|
38
38
|
from ...utils.torch_utils import is_compiled_module, is_torch_version, randn_tensor
|
39
|
-
from ..pipeline_utils import DiffusionPipeline
|
39
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
40
40
|
from ..stable_diffusion.pipeline_output import StableDiffusionPipelineOutput
|
41
41
|
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
42
42
|
from .multicontrolnet import MultiControlNetModel
|
@@ -137,7 +137,12 @@ def retrieve_timesteps(
|
|
137
137
|
|
138
138
|
|
139
139
|
class StableDiffusionControlNetPipeline(
|
140
|
-
DiffusionPipeline,
|
140
|
+
DiffusionPipeline,
|
141
|
+
StableDiffusionMixin,
|
142
|
+
TextualInversionLoaderMixin,
|
143
|
+
LoraLoaderMixin,
|
144
|
+
IPAdapterMixin,
|
145
|
+
FromSingleFileMixin,
|
141
146
|
):
|
142
147
|
r"""
|
143
148
|
Pipeline for text-to-image generation using Stable Diffusion with ControlNet guidance.
|
@@ -233,39 +238,6 @@ class StableDiffusionControlNetPipeline(
|
|
233
238
|
)
|
234
239
|
self.register_to_config(requires_safety_checker=requires_safety_checker)
|
235
240
|
|
236
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
237
|
-
def enable_vae_slicing(self):
|
238
|
-
r"""
|
239
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
240
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
241
|
-
"""
|
242
|
-
self.vae.enable_slicing()
|
243
|
-
|
244
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
245
|
-
def disable_vae_slicing(self):
|
246
|
-
r"""
|
247
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
248
|
-
computing decoding in one step.
|
249
|
-
"""
|
250
|
-
self.vae.disable_slicing()
|
251
|
-
|
252
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
253
|
-
def enable_vae_tiling(self):
|
254
|
-
r"""
|
255
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
256
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
257
|
-
processing larger images.
|
258
|
-
"""
|
259
|
-
self.vae.enable_tiling()
|
260
|
-
|
261
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
262
|
-
def disable_vae_tiling(self):
|
263
|
-
r"""
|
264
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
265
|
-
computing decoding in one step.
|
266
|
-
"""
|
267
|
-
self.vae.disable_tiling()
|
268
|
-
|
269
241
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
270
242
|
def _encode_prompt(
|
271
243
|
self,
|
@@ -360,7 +332,7 @@ class StableDiffusionControlNetPipeline(
|
|
360
332
|
batch_size = prompt_embeds.shape[0]
|
361
333
|
|
362
334
|
if prompt_embeds is None:
|
363
|
-
# textual inversion:
|
335
|
+
# textual inversion: process multi-vector tokens if necessary
|
364
336
|
if isinstance(self, TextualInversionLoaderMixin):
|
365
337
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
366
338
|
|
@@ -442,7 +414,7 @@ class StableDiffusionControlNetPipeline(
|
|
442
414
|
else:
|
443
415
|
uncond_tokens = negative_prompt
|
444
416
|
|
445
|
-
# textual inversion:
|
417
|
+
# textual inversion: process multi-vector tokens if necessary
|
446
418
|
if isinstance(self, TextualInversionLoaderMixin):
|
447
419
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
448
420
|
|
@@ -507,31 +479,54 @@ class StableDiffusionControlNetPipeline(
|
|
507
479
|
return image_embeds, uncond_image_embeds
|
508
480
|
|
509
481
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
|
510
|
-
def prepare_ip_adapter_image_embeds(
|
511
|
-
|
512
|
-
|
482
|
+
def prepare_ip_adapter_image_embeds(
|
483
|
+
self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
|
484
|
+
):
|
485
|
+
if ip_adapter_image_embeds is None:
|
486
|
+
if not isinstance(ip_adapter_image, list):
|
487
|
+
ip_adapter_image = [ip_adapter_image]
|
513
488
|
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
489
|
+
if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
|
490
|
+
raise ValueError(
|
491
|
+
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."
|
492
|
+
)
|
518
493
|
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
494
|
+
image_embeds = []
|
495
|
+
for single_ip_adapter_image, image_proj_layer in zip(
|
496
|
+
ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
|
497
|
+
):
|
498
|
+
output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
|
499
|
+
single_image_embeds, single_negative_image_embeds = self.encode_image(
|
500
|
+
single_ip_adapter_image, device, 1, output_hidden_state
|
501
|
+
)
|
502
|
+
single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
|
503
|
+
single_negative_image_embeds = torch.stack(
|
504
|
+
[single_negative_image_embeds] * num_images_per_prompt, dim=0
|
505
|
+
)
|
529
506
|
|
530
|
-
|
531
|
-
|
532
|
-
|
507
|
+
if do_classifier_free_guidance:
|
508
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
509
|
+
single_image_embeds = single_image_embeds.to(device)
|
533
510
|
|
534
|
-
|
511
|
+
image_embeds.append(single_image_embeds)
|
512
|
+
else:
|
513
|
+
repeat_dims = [1]
|
514
|
+
image_embeds = []
|
515
|
+
for single_image_embeds in ip_adapter_image_embeds:
|
516
|
+
if do_classifier_free_guidance:
|
517
|
+
single_negative_image_embeds, single_image_embeds = single_image_embeds.chunk(2)
|
518
|
+
single_image_embeds = single_image_embeds.repeat(
|
519
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
520
|
+
)
|
521
|
+
single_negative_image_embeds = single_negative_image_embeds.repeat(
|
522
|
+
num_images_per_prompt, *(repeat_dims * len(single_negative_image_embeds.shape[1:]))
|
523
|
+
)
|
524
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
525
|
+
else:
|
526
|
+
single_image_embeds = single_image_embeds.repeat(
|
527
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
528
|
+
)
|
529
|
+
image_embeds.append(single_image_embeds)
|
535
530
|
|
536
531
|
return image_embeds
|
537
532
|
|
@@ -588,6 +583,8 @@ class StableDiffusionControlNetPipeline(
|
|
588
583
|
negative_prompt=None,
|
589
584
|
prompt_embeds=None,
|
590
585
|
negative_prompt_embeds=None,
|
586
|
+
ip_adapter_image=None,
|
587
|
+
ip_adapter_image_embeds=None,
|
591
588
|
controlnet_conditioning_scale=1.0,
|
592
589
|
control_guidance_start=0.0,
|
593
590
|
control_guidance_end=1.0,
|
@@ -726,6 +723,21 @@ class StableDiffusionControlNetPipeline(
|
|
726
723
|
if end > 1.0:
|
727
724
|
raise ValueError(f"control guidance end: {end} can't be larger than 1.0.")
|
728
725
|
|
726
|
+
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
|
727
|
+
raise ValueError(
|
728
|
+
"Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
|
729
|
+
)
|
730
|
+
|
731
|
+
if ip_adapter_image_embeds is not None:
|
732
|
+
if not isinstance(ip_adapter_image_embeds, list):
|
733
|
+
raise ValueError(
|
734
|
+
f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
|
735
|
+
)
|
736
|
+
elif ip_adapter_image_embeds[0].ndim not in [3, 4]:
|
737
|
+
raise ValueError(
|
738
|
+
f"`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is {ip_adapter_image_embeds[0].ndim}D"
|
739
|
+
)
|
740
|
+
|
729
741
|
def check_image(self, image, prompt, prompt_embeds):
|
730
742
|
image_is_pil = isinstance(image, PIL.Image.Image)
|
731
743
|
image_is_tensor = isinstance(image, torch.Tensor)
|
@@ -811,34 +823,6 @@ class StableDiffusionControlNetPipeline(
|
|
811
823
|
latents = latents * self.scheduler.init_noise_sigma
|
812
824
|
return latents
|
813
825
|
|
814
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
815
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
816
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
817
|
-
|
818
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
819
|
-
|
820
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
821
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
822
|
-
|
823
|
-
Args:
|
824
|
-
s1 (`float`):
|
825
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
826
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
827
|
-
s2 (`float`):
|
828
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
829
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
830
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
831
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
832
|
-
"""
|
833
|
-
if not hasattr(self, "unet"):
|
834
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
835
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
836
|
-
|
837
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
838
|
-
def disable_freeu(self):
|
839
|
-
"""Disables the FreeU mechanism if enabled."""
|
840
|
-
self.unet.disable_freeu()
|
841
|
-
|
842
826
|
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
|
843
827
|
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
844
828
|
"""
|
@@ -910,6 +894,7 @@ class StableDiffusionControlNetPipeline(
|
|
910
894
|
prompt_embeds: Optional[torch.FloatTensor] = None,
|
911
895
|
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
912
896
|
ip_adapter_image: Optional[PipelineImageInput] = None,
|
897
|
+
ip_adapter_image_embeds: Optional[List[torch.FloatTensor]] = None,
|
913
898
|
output_type: Optional[str] = "pil",
|
914
899
|
return_dict: bool = True,
|
915
900
|
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
@@ -974,6 +959,11 @@ class StableDiffusionControlNetPipeline(
|
|
974
959
|
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
|
975
960
|
not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
|
976
961
|
ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
|
962
|
+
ip_adapter_image_embeds (`List[torch.FloatTensor]`, *optional*):
|
963
|
+
Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of IP-adapters.
|
964
|
+
Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should contain the negative image embedding
|
965
|
+
if `do_classifier_free_guidance` is set to `True`.
|
966
|
+
If not provided, embeddings are computed from the `ip_adapter_image` input argument.
|
977
967
|
output_type (`str`, *optional*, defaults to `"pil"`):
|
978
968
|
The output format of the generated image. Choose between `PIL.Image` or `np.array`.
|
979
969
|
return_dict (`bool`, *optional*, defaults to `True`):
|
@@ -1060,6 +1050,8 @@ class StableDiffusionControlNetPipeline(
|
|
1060
1050
|
negative_prompt,
|
1061
1051
|
prompt_embeds,
|
1062
1052
|
negative_prompt_embeds,
|
1053
|
+
ip_adapter_image,
|
1054
|
+
ip_adapter_image_embeds,
|
1063
1055
|
controlnet_conditioning_scale,
|
1064
1056
|
control_guidance_start,
|
1065
1057
|
control_guidance_end,
|
@@ -1111,9 +1103,13 @@ class StableDiffusionControlNetPipeline(
|
|
1111
1103
|
if self.do_classifier_free_guidance:
|
1112
1104
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
1113
1105
|
|
1114
|
-
if ip_adapter_image is not None:
|
1106
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1115
1107
|
image_embeds = self.prepare_ip_adapter_image_embeds(
|
1116
|
-
ip_adapter_image,
|
1108
|
+
ip_adapter_image,
|
1109
|
+
ip_adapter_image_embeds,
|
1110
|
+
device,
|
1111
|
+
batch_size * num_images_per_prompt,
|
1112
|
+
self.do_classifier_free_guidance,
|
1117
1113
|
)
|
1118
1114
|
|
1119
1115
|
# 4. Prepare image
|
@@ -1187,7 +1183,11 @@ class StableDiffusionControlNetPipeline(
|
|
1187
1183
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
1188
1184
|
|
1189
1185
|
# 7.1 Add image embeds for IP-Adapter
|
1190
|
-
added_cond_kwargs =
|
1186
|
+
added_cond_kwargs = (
|
1187
|
+
{"image_embeds": image_embeds}
|
1188
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None
|
1189
|
+
else None
|
1190
|
+
)
|
1191
1191
|
|
1192
1192
|
# 7.2 Create tensor stating which controlnets to keep
|
1193
1193
|
controlnet_keep = []
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright
|
2
|
-
# Copyright
|
1
|
+
# Copyright 2024 Salesforce.com, inc.
|
2
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -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.
|
@@ -35,7 +35,7 @@ from ...utils import (
|
|
35
35
|
unscale_lora_layers,
|
36
36
|
)
|
37
37
|
from ...utils.torch_utils import is_compiled_module, randn_tensor
|
38
|
-
from ..pipeline_utils import DiffusionPipeline
|
38
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
39
39
|
from ..stable_diffusion import StableDiffusionPipelineOutput
|
40
40
|
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
41
41
|
from .multicontrolnet import MultiControlNetModel
|
@@ -130,7 +130,12 @@ def prepare_image(image):
|
|
130
130
|
|
131
131
|
|
132
132
|
class StableDiffusionControlNetImg2ImgPipeline(
|
133
|
-
DiffusionPipeline,
|
133
|
+
DiffusionPipeline,
|
134
|
+
StableDiffusionMixin,
|
135
|
+
TextualInversionLoaderMixin,
|
136
|
+
LoraLoaderMixin,
|
137
|
+
IPAdapterMixin,
|
138
|
+
FromSingleFileMixin,
|
134
139
|
):
|
135
140
|
r"""
|
136
141
|
Pipeline for image-to-image generation using Stable Diffusion with ControlNet guidance.
|
@@ -226,39 +231,6 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
226
231
|
)
|
227
232
|
self.register_to_config(requires_safety_checker=requires_safety_checker)
|
228
233
|
|
229
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
230
|
-
def enable_vae_slicing(self):
|
231
|
-
r"""
|
232
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
233
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
234
|
-
"""
|
235
|
-
self.vae.enable_slicing()
|
236
|
-
|
237
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
238
|
-
def disable_vae_slicing(self):
|
239
|
-
r"""
|
240
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
241
|
-
computing decoding in one step.
|
242
|
-
"""
|
243
|
-
self.vae.disable_slicing()
|
244
|
-
|
245
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
246
|
-
def enable_vae_tiling(self):
|
247
|
-
r"""
|
248
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
249
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
250
|
-
processing larger images.
|
251
|
-
"""
|
252
|
-
self.vae.enable_tiling()
|
253
|
-
|
254
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
255
|
-
def disable_vae_tiling(self):
|
256
|
-
r"""
|
257
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
258
|
-
computing decoding in one step.
|
259
|
-
"""
|
260
|
-
self.vae.disable_tiling()
|
261
|
-
|
262
234
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
263
235
|
def _encode_prompt(
|
264
236
|
self,
|
@@ -353,7 +325,7 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
353
325
|
batch_size = prompt_embeds.shape[0]
|
354
326
|
|
355
327
|
if prompt_embeds is None:
|
356
|
-
# textual inversion:
|
328
|
+
# textual inversion: process multi-vector tokens if necessary
|
357
329
|
if isinstance(self, TextualInversionLoaderMixin):
|
358
330
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
359
331
|
|
@@ -435,7 +407,7 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
435
407
|
else:
|
436
408
|
uncond_tokens = negative_prompt
|
437
409
|
|
438
|
-
# textual inversion:
|
410
|
+
# textual inversion: process multi-vector tokens if necessary
|
439
411
|
if isinstance(self, TextualInversionLoaderMixin):
|
440
412
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
441
413
|
|
@@ -500,31 +472,54 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
500
472
|
return image_embeds, uncond_image_embeds
|
501
473
|
|
502
474
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
|
503
|
-
def prepare_ip_adapter_image_embeds(
|
504
|
-
|
505
|
-
|
475
|
+
def prepare_ip_adapter_image_embeds(
|
476
|
+
self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
|
477
|
+
):
|
478
|
+
if ip_adapter_image_embeds is None:
|
479
|
+
if not isinstance(ip_adapter_image, list):
|
480
|
+
ip_adapter_image = [ip_adapter_image]
|
506
481
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
482
|
+
if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
|
483
|
+
raise ValueError(
|
484
|
+
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."
|
485
|
+
)
|
511
486
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
487
|
+
image_embeds = []
|
488
|
+
for single_ip_adapter_image, image_proj_layer in zip(
|
489
|
+
ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
|
490
|
+
):
|
491
|
+
output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
|
492
|
+
single_image_embeds, single_negative_image_embeds = self.encode_image(
|
493
|
+
single_ip_adapter_image, device, 1, output_hidden_state
|
494
|
+
)
|
495
|
+
single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
|
496
|
+
single_negative_image_embeds = torch.stack(
|
497
|
+
[single_negative_image_embeds] * num_images_per_prompt, dim=0
|
498
|
+
)
|
522
499
|
|
523
|
-
|
524
|
-
|
525
|
-
|
500
|
+
if do_classifier_free_guidance:
|
501
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
502
|
+
single_image_embeds = single_image_embeds.to(device)
|
526
503
|
|
527
|
-
|
504
|
+
image_embeds.append(single_image_embeds)
|
505
|
+
else:
|
506
|
+
repeat_dims = [1]
|
507
|
+
image_embeds = []
|
508
|
+
for single_image_embeds in ip_adapter_image_embeds:
|
509
|
+
if do_classifier_free_guidance:
|
510
|
+
single_negative_image_embeds, single_image_embeds = single_image_embeds.chunk(2)
|
511
|
+
single_image_embeds = single_image_embeds.repeat(
|
512
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
513
|
+
)
|
514
|
+
single_negative_image_embeds = single_negative_image_embeds.repeat(
|
515
|
+
num_images_per_prompt, *(repeat_dims * len(single_negative_image_embeds.shape[1:]))
|
516
|
+
)
|
517
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
518
|
+
else:
|
519
|
+
single_image_embeds = single_image_embeds.repeat(
|
520
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
521
|
+
)
|
522
|
+
image_embeds.append(single_image_embeds)
|
528
523
|
|
529
524
|
return image_embeds
|
530
525
|
|
@@ -581,6 +576,8 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
581
576
|
negative_prompt=None,
|
582
577
|
prompt_embeds=None,
|
583
578
|
negative_prompt_embeds=None,
|
579
|
+
ip_adapter_image=None,
|
580
|
+
ip_adapter_image_embeds=None,
|
584
581
|
controlnet_conditioning_scale=1.0,
|
585
582
|
control_guidance_start=0.0,
|
586
583
|
control_guidance_end=1.0,
|
@@ -713,6 +710,21 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
713
710
|
if end > 1.0:
|
714
711
|
raise ValueError(f"control guidance end: {end} can't be larger than 1.0.")
|
715
712
|
|
713
|
+
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
|
714
|
+
raise ValueError(
|
715
|
+
"Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
|
716
|
+
)
|
717
|
+
|
718
|
+
if ip_adapter_image_embeds is not None:
|
719
|
+
if not isinstance(ip_adapter_image_embeds, list):
|
720
|
+
raise ValueError(
|
721
|
+
f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
|
722
|
+
)
|
723
|
+
elif ip_adapter_image_embeds[0].ndim not in [3, 4]:
|
724
|
+
raise ValueError(
|
725
|
+
f"`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is {ip_adapter_image_embeds[0].ndim}D"
|
726
|
+
)
|
727
|
+
|
716
728
|
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet.StableDiffusionControlNetPipeline.check_image
|
717
729
|
def check_image(self, image, prompt, prompt_embeds):
|
718
730
|
image_is_pil = isinstance(image, PIL.Image.Image)
|
@@ -789,6 +801,8 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
789
801
|
|
790
802
|
t_start = max(num_inference_steps - init_timestep, 0)
|
791
803
|
timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
|
804
|
+
if hasattr(self.scheduler, "set_begin_index"):
|
805
|
+
self.scheduler.set_begin_index(t_start * self.scheduler.order)
|
792
806
|
|
793
807
|
return timesteps, num_inference_steps - t_start
|
794
808
|
|
@@ -851,34 +865,6 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
851
865
|
|
852
866
|
return latents
|
853
867
|
|
854
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
855
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
856
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
857
|
-
|
858
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
859
|
-
|
860
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
861
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
862
|
-
|
863
|
-
Args:
|
864
|
-
s1 (`float`):
|
865
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
866
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
867
|
-
s2 (`float`):
|
868
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
869
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
870
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
871
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
872
|
-
"""
|
873
|
-
if not hasattr(self, "unet"):
|
874
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
875
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
876
|
-
|
877
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
878
|
-
def disable_freeu(self):
|
879
|
-
"""Disables the FreeU mechanism if enabled."""
|
880
|
-
self.unet.disable_freeu()
|
881
|
-
|
882
868
|
@property
|
883
869
|
def guidance_scale(self):
|
884
870
|
return self._guidance_scale
|
@@ -922,6 +908,7 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
922
908
|
prompt_embeds: Optional[torch.FloatTensor] = None,
|
923
909
|
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
924
910
|
ip_adapter_image: Optional[PipelineImageInput] = None,
|
911
|
+
ip_adapter_image_embeds: Optional[List[torch.FloatTensor]] = None,
|
925
912
|
output_type: Optional[str] = "pil",
|
926
913
|
return_dict: bool = True,
|
927
914
|
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
@@ -956,6 +943,12 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
956
943
|
The height in pixels of the generated image.
|
957
944
|
width (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
|
958
945
|
The width in pixels of the generated image.
|
946
|
+
strength (`float`, *optional*, defaults to 0.8):
|
947
|
+
Indicates extent to transform the reference `image`. Must be between 0 and 1. `image` is used as a
|
948
|
+
starting point and more noise is added the higher the `strength`. The number of denoising steps depends
|
949
|
+
on the amount of noise initially added. When `strength` is 1, added noise is maximum and the denoising
|
950
|
+
process runs for the full number of iterations specified in `num_inference_steps`. A value of 1
|
951
|
+
essentially ignores `image`.
|
959
952
|
num_inference_steps (`int`, *optional*, defaults to 50):
|
960
953
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
961
954
|
expense of slower inference.
|
@@ -984,6 +977,11 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
984
977
|
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
|
985
978
|
not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
|
986
979
|
ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
|
980
|
+
ip_adapter_image_embeds (`List[torch.FloatTensor]`, *optional*):
|
981
|
+
Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of IP-adapters.
|
982
|
+
Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should contain the negative image embedding
|
983
|
+
if `do_classifier_free_guidance` is set to `True`.
|
984
|
+
If not provided, embeddings are computed from the `ip_adapter_image` input argument.
|
987
985
|
output_type (`str`, *optional*, defaults to `"pil"`):
|
988
986
|
The output format of the generated image. Choose between `PIL.Image` or `np.array`.
|
989
987
|
return_dict (`bool`, *optional*, defaults to `True`):
|
@@ -1064,6 +1062,8 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
1064
1062
|
negative_prompt,
|
1065
1063
|
prompt_embeds,
|
1066
1064
|
negative_prompt_embeds,
|
1065
|
+
ip_adapter_image,
|
1066
|
+
ip_adapter_image_embeds,
|
1067
1067
|
controlnet_conditioning_scale,
|
1068
1068
|
control_guidance_start,
|
1069
1069
|
control_guidance_end,
|
@@ -1115,9 +1115,13 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
1115
1115
|
if self.do_classifier_free_guidance:
|
1116
1116
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
1117
1117
|
|
1118
|
-
if ip_adapter_image is not None:
|
1118
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1119
1119
|
image_embeds = self.prepare_ip_adapter_image_embeds(
|
1120
|
-
ip_adapter_image,
|
1120
|
+
ip_adapter_image,
|
1121
|
+
ip_adapter_image_embeds,
|
1122
|
+
device,
|
1123
|
+
batch_size * num_images_per_prompt,
|
1124
|
+
self.do_classifier_free_guidance,
|
1121
1125
|
)
|
1122
1126
|
|
1123
1127
|
# 4. Prepare image
|
@@ -1179,7 +1183,11 @@ class StableDiffusionControlNetImg2ImgPipeline(
|
|
1179
1183
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
1180
1184
|
|
1181
1185
|
# 7.1 Add image embeds for IP-Adapter
|
1182
|
-
added_cond_kwargs =
|
1186
|
+
added_cond_kwargs = (
|
1187
|
+
{"image_embeds": image_embeds}
|
1188
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None
|
1189
|
+
else None
|
1190
|
+
)
|
1183
1191
|
|
1184
1192
|
# 7.2 Create tensor stating which controlnets to keep
|
1185
1193
|
controlnet_keep = []
|