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.
|
@@ -25,7 +25,6 @@ from ...configuration_utils import FrozenDict
|
|
25
25
|
from ...image_processor import PipelineImageInput, VaeImageProcessor
|
26
26
|
from ...loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
27
27
|
from ...models import AutoencoderKL, ImageProjection, UNet2DConditionModel
|
28
|
-
from ...models.attention_processor import FusedAttnProcessor2_0
|
29
28
|
from ...models.lora import adjust_lora_scale_text_encoder
|
30
29
|
from ...schedulers import KarrasDiffusionSchedulers
|
31
30
|
from ...utils import (
|
@@ -38,7 +37,7 @@ from ...utils import (
|
|
38
37
|
unscale_lora_layers,
|
39
38
|
)
|
40
39
|
from ...utils.torch_utils import randn_tensor
|
41
|
-
from ..pipeline_utils import DiffusionPipeline
|
40
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
42
41
|
from . import StableDiffusionPipelineOutput
|
43
42
|
from .safety_checker import StableDiffusionSafetyChecker
|
44
43
|
|
@@ -156,7 +155,12 @@ def retrieve_timesteps(
|
|
156
155
|
|
157
156
|
|
158
157
|
class StableDiffusionImg2ImgPipeline(
|
159
|
-
DiffusionPipeline,
|
158
|
+
DiffusionPipeline,
|
159
|
+
StableDiffusionMixin,
|
160
|
+
TextualInversionLoaderMixin,
|
161
|
+
IPAdapterMixin,
|
162
|
+
LoraLoaderMixin,
|
163
|
+
FromSingleFileMixin,
|
160
164
|
):
|
161
165
|
r"""
|
162
166
|
Pipeline for text-guided image-to-image generation using Stable Diffusion.
|
@@ -382,7 +386,7 @@ class StableDiffusionImg2ImgPipeline(
|
|
382
386
|
batch_size = prompt_embeds.shape[0]
|
383
387
|
|
384
388
|
if prompt_embeds is None:
|
385
|
-
# textual inversion:
|
389
|
+
# textual inversion: process multi-vector tokens if necessary
|
386
390
|
if isinstance(self, TextualInversionLoaderMixin):
|
387
391
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
388
392
|
|
@@ -464,7 +468,7 @@ class StableDiffusionImg2ImgPipeline(
|
|
464
468
|
else:
|
465
469
|
uncond_tokens = negative_prompt
|
466
470
|
|
467
|
-
# textual inversion:
|
471
|
+
# textual inversion: process multi-vector tokens if necessary
|
468
472
|
if isinstance(self, TextualInversionLoaderMixin):
|
469
473
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
470
474
|
|
@@ -529,31 +533,54 @@ class StableDiffusionImg2ImgPipeline(
|
|
529
533
|
return image_embeds, uncond_image_embeds
|
530
534
|
|
531
535
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
|
532
|
-
def prepare_ip_adapter_image_embeds(
|
533
|
-
|
534
|
-
|
536
|
+
def prepare_ip_adapter_image_embeds(
|
537
|
+
self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
|
538
|
+
):
|
539
|
+
if ip_adapter_image_embeds is None:
|
540
|
+
if not isinstance(ip_adapter_image, list):
|
541
|
+
ip_adapter_image = [ip_adapter_image]
|
535
542
|
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
543
|
+
if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
|
544
|
+
raise ValueError(
|
545
|
+
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."
|
546
|
+
)
|
540
547
|
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
548
|
+
image_embeds = []
|
549
|
+
for single_ip_adapter_image, image_proj_layer in zip(
|
550
|
+
ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
|
551
|
+
):
|
552
|
+
output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
|
553
|
+
single_image_embeds, single_negative_image_embeds = self.encode_image(
|
554
|
+
single_ip_adapter_image, device, 1, output_hidden_state
|
555
|
+
)
|
556
|
+
single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
|
557
|
+
single_negative_image_embeds = torch.stack(
|
558
|
+
[single_negative_image_embeds] * num_images_per_prompt, dim=0
|
559
|
+
)
|
551
560
|
|
552
|
-
|
553
|
-
|
554
|
-
|
561
|
+
if do_classifier_free_guidance:
|
562
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
563
|
+
single_image_embeds = single_image_embeds.to(device)
|
555
564
|
|
556
|
-
|
565
|
+
image_embeds.append(single_image_embeds)
|
566
|
+
else:
|
567
|
+
repeat_dims = [1]
|
568
|
+
image_embeds = []
|
569
|
+
for single_image_embeds in ip_adapter_image_embeds:
|
570
|
+
if do_classifier_free_guidance:
|
571
|
+
single_negative_image_embeds, single_image_embeds = single_image_embeds.chunk(2)
|
572
|
+
single_image_embeds = single_image_embeds.repeat(
|
573
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
574
|
+
)
|
575
|
+
single_negative_image_embeds = single_negative_image_embeds.repeat(
|
576
|
+
num_images_per_prompt, *(repeat_dims * len(single_negative_image_embeds.shape[1:]))
|
577
|
+
)
|
578
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
579
|
+
else:
|
580
|
+
single_image_embeds = single_image_embeds.repeat(
|
581
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
582
|
+
)
|
583
|
+
image_embeds.append(single_image_embeds)
|
557
584
|
|
558
585
|
return image_embeds
|
559
586
|
|
@@ -610,6 +637,8 @@ class StableDiffusionImg2ImgPipeline(
|
|
610
637
|
negative_prompt=None,
|
611
638
|
prompt_embeds=None,
|
612
639
|
negative_prompt_embeds=None,
|
640
|
+
ip_adapter_image=None,
|
641
|
+
ip_adapter_image_embeds=None,
|
613
642
|
callback_on_step_end_tensor_inputs=None,
|
614
643
|
):
|
615
644
|
if strength < 0 or strength > 1:
|
@@ -653,12 +682,29 @@ class StableDiffusionImg2ImgPipeline(
|
|
653
682
|
f" {negative_prompt_embeds.shape}."
|
654
683
|
)
|
655
684
|
|
685
|
+
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
|
686
|
+
raise ValueError(
|
687
|
+
"Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
|
688
|
+
)
|
689
|
+
|
690
|
+
if ip_adapter_image_embeds is not None:
|
691
|
+
if not isinstance(ip_adapter_image_embeds, list):
|
692
|
+
raise ValueError(
|
693
|
+
f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
|
694
|
+
)
|
695
|
+
elif ip_adapter_image_embeds[0].ndim not in [3, 4]:
|
696
|
+
raise ValueError(
|
697
|
+
f"`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is {ip_adapter_image_embeds[0].ndim}D"
|
698
|
+
)
|
699
|
+
|
656
700
|
def get_timesteps(self, num_inference_steps, strength, device):
|
657
701
|
# get the original timestep using init_timestep
|
658
702
|
init_timestep = min(int(num_inference_steps * strength), num_inference_steps)
|
659
703
|
|
660
704
|
t_start = max(num_inference_steps - init_timestep, 0)
|
661
705
|
timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
|
706
|
+
if hasattr(self.scheduler, "set_begin_index"):
|
707
|
+
self.scheduler.set_begin_index(t_start * self.scheduler.order)
|
662
708
|
|
663
709
|
return timesteps, num_inference_steps - t_start
|
664
710
|
|
@@ -720,95 +766,6 @@ class StableDiffusionImg2ImgPipeline(
|
|
720
766
|
|
721
767
|
return latents
|
722
768
|
|
723
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
724
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
725
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
726
|
-
|
727
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
728
|
-
|
729
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
730
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
731
|
-
|
732
|
-
Args:
|
733
|
-
s1 (`float`):
|
734
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
735
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
736
|
-
s2 (`float`):
|
737
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
738
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
739
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
740
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
741
|
-
"""
|
742
|
-
if not hasattr(self, "unet"):
|
743
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
744
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
745
|
-
|
746
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
747
|
-
def disable_freeu(self):
|
748
|
-
"""Disables the FreeU mechanism if enabled."""
|
749
|
-
self.unet.disable_freeu()
|
750
|
-
|
751
|
-
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.fuse_qkv_projections
|
752
|
-
def fuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
753
|
-
"""
|
754
|
-
Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query,
|
755
|
-
key, value) are fused. For cross-attention modules, key and value projection matrices are fused.
|
756
|
-
|
757
|
-
<Tip warning={true}>
|
758
|
-
|
759
|
-
This API is 🧪 experimental.
|
760
|
-
|
761
|
-
</Tip>
|
762
|
-
|
763
|
-
Args:
|
764
|
-
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
765
|
-
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
766
|
-
"""
|
767
|
-
self.fusing_unet = False
|
768
|
-
self.fusing_vae = False
|
769
|
-
|
770
|
-
if unet:
|
771
|
-
self.fusing_unet = True
|
772
|
-
self.unet.fuse_qkv_projections()
|
773
|
-
self.unet.set_attn_processor(FusedAttnProcessor2_0())
|
774
|
-
|
775
|
-
if vae:
|
776
|
-
if not isinstance(self.vae, AutoencoderKL):
|
777
|
-
raise ValueError("`fuse_qkv_projections()` is only supported for the VAE of type `AutoencoderKL`.")
|
778
|
-
|
779
|
-
self.fusing_vae = True
|
780
|
-
self.vae.fuse_qkv_projections()
|
781
|
-
self.vae.set_attn_processor(FusedAttnProcessor2_0())
|
782
|
-
|
783
|
-
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.unfuse_qkv_projections
|
784
|
-
def unfuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
785
|
-
"""Disable QKV projection fusion if enabled.
|
786
|
-
|
787
|
-
<Tip warning={true}>
|
788
|
-
|
789
|
-
This API is 🧪 experimental.
|
790
|
-
|
791
|
-
</Tip>
|
792
|
-
|
793
|
-
Args:
|
794
|
-
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
795
|
-
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
796
|
-
|
797
|
-
"""
|
798
|
-
if unet:
|
799
|
-
if not self.fusing_unet:
|
800
|
-
logger.warning("The UNet was not initially fused for QKV projections. Doing nothing.")
|
801
|
-
else:
|
802
|
-
self.unet.unfuse_qkv_projections()
|
803
|
-
self.fusing_unet = False
|
804
|
-
|
805
|
-
if vae:
|
806
|
-
if not self.fusing_vae:
|
807
|
-
logger.warning("The VAE was not initially fused for QKV projections. Doing nothing.")
|
808
|
-
else:
|
809
|
-
self.vae.unfuse_qkv_projections()
|
810
|
-
self.fusing_vae = False
|
811
|
-
|
812
769
|
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
|
813
770
|
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
814
771
|
"""
|
@@ -882,6 +839,7 @@ class StableDiffusionImg2ImgPipeline(
|
|
882
839
|
prompt_embeds: Optional[torch.FloatTensor] = None,
|
883
840
|
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
884
841
|
ip_adapter_image: Optional[PipelineImageInput] = None,
|
842
|
+
ip_adapter_image_embeds: Optional[List[torch.FloatTensor]] = None,
|
885
843
|
output_type: Optional[str] = "pil",
|
886
844
|
return_dict: bool = True,
|
887
845
|
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
@@ -936,6 +894,11 @@ class StableDiffusionImg2ImgPipeline(
|
|
936
894
|
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
|
937
895
|
not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
|
938
896
|
ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
|
897
|
+
ip_adapter_image_embeds (`List[torch.FloatTensor]`, *optional*):
|
898
|
+
Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of IP-adapters.
|
899
|
+
Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should contain the negative image embedding
|
900
|
+
if `do_classifier_free_guidance` is set to `True`.
|
901
|
+
If not provided, embeddings are computed from the `ip_adapter_image` input argument.
|
939
902
|
output_type (`str`, *optional*, defaults to `"pil"`):
|
940
903
|
The output format of the generated image. Choose between `PIL.Image` or `np.array`.
|
941
904
|
return_dict (`bool`, *optional*, defaults to `True`):
|
@@ -990,6 +953,8 @@ class StableDiffusionImg2ImgPipeline(
|
|
990
953
|
negative_prompt,
|
991
954
|
prompt_embeds,
|
992
955
|
negative_prompt_embeds,
|
956
|
+
ip_adapter_image,
|
957
|
+
ip_adapter_image_embeds,
|
993
958
|
callback_on_step_end_tensor_inputs,
|
994
959
|
)
|
995
960
|
|
@@ -1029,9 +994,13 @@ class StableDiffusionImg2ImgPipeline(
|
|
1029
994
|
if self.do_classifier_free_guidance:
|
1030
995
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
1031
996
|
|
1032
|
-
if ip_adapter_image is not None:
|
997
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1033
998
|
image_embeds = self.prepare_ip_adapter_image_embeds(
|
1034
|
-
ip_adapter_image,
|
999
|
+
ip_adapter_image,
|
1000
|
+
ip_adapter_image_embeds,
|
1001
|
+
device,
|
1002
|
+
batch_size * num_images_per_prompt,
|
1003
|
+
self.do_classifier_free_guidance,
|
1035
1004
|
)
|
1036
1005
|
|
1037
1006
|
# 4. Preprocess image
|
@@ -1057,7 +1026,11 @@ class StableDiffusionImg2ImgPipeline(
|
|
1057
1026
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
1058
1027
|
|
1059
1028
|
# 7.1 Add image embeds for IP-Adapter
|
1060
|
-
added_cond_kwargs =
|
1029
|
+
added_cond_kwargs = (
|
1030
|
+
{"image_embeds": image_embeds}
|
1031
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None
|
1032
|
+
else None
|
1033
|
+
)
|
1061
1034
|
|
1062
1035
|
# 7.2 Optionally get Guidance Scale Embedding
|
1063
1036
|
timestep_cond = None
|
@@ -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.
|
@@ -25,12 +25,11 @@ from ...configuration_utils import FrozenDict
|
|
25
25
|
from ...image_processor import PipelineImageInput, VaeImageProcessor
|
26
26
|
from ...loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
27
27
|
from ...models import AsymmetricAutoencoderKL, AutoencoderKL, ImageProjection, UNet2DConditionModel
|
28
|
-
from ...models.attention_processor import FusedAttnProcessor2_0
|
29
28
|
from ...models.lora import adjust_lora_scale_text_encoder
|
30
29
|
from ...schedulers import KarrasDiffusionSchedulers
|
31
30
|
from ...utils import USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
|
32
31
|
from ...utils.torch_utils import randn_tensor
|
33
|
-
from ..pipeline_utils import DiffusionPipeline
|
32
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
34
33
|
from . import StableDiffusionPipelineOutput
|
35
34
|
from .safety_checker import StableDiffusionSafetyChecker
|
36
35
|
|
@@ -220,7 +219,12 @@ def retrieve_timesteps(
|
|
220
219
|
|
221
220
|
|
222
221
|
class StableDiffusionInpaintPipeline(
|
223
|
-
DiffusionPipeline,
|
222
|
+
DiffusionPipeline,
|
223
|
+
StableDiffusionMixin,
|
224
|
+
TextualInversionLoaderMixin,
|
225
|
+
IPAdapterMixin,
|
226
|
+
LoraLoaderMixin,
|
227
|
+
FromSingleFileMixin,
|
224
228
|
):
|
225
229
|
r"""
|
226
230
|
Pipeline for text-guided image inpainting using Stable Diffusion.
|
@@ -454,7 +458,7 @@ class StableDiffusionInpaintPipeline(
|
|
454
458
|
batch_size = prompt_embeds.shape[0]
|
455
459
|
|
456
460
|
if prompt_embeds is None:
|
457
|
-
# textual inversion:
|
461
|
+
# textual inversion: process multi-vector tokens if necessary
|
458
462
|
if isinstance(self, TextualInversionLoaderMixin):
|
459
463
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
460
464
|
|
@@ -536,7 +540,7 @@ class StableDiffusionInpaintPipeline(
|
|
536
540
|
else:
|
537
541
|
uncond_tokens = negative_prompt
|
538
542
|
|
539
|
-
# textual inversion:
|
543
|
+
# textual inversion: process multi-vector tokens if necessary
|
540
544
|
if isinstance(self, TextualInversionLoaderMixin):
|
541
545
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
542
546
|
|
@@ -601,31 +605,54 @@ class StableDiffusionInpaintPipeline(
|
|
601
605
|
return image_embeds, uncond_image_embeds
|
602
606
|
|
603
607
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
|
604
|
-
def prepare_ip_adapter_image_embeds(
|
605
|
-
|
606
|
-
|
608
|
+
def prepare_ip_adapter_image_embeds(
|
609
|
+
self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
|
610
|
+
):
|
611
|
+
if ip_adapter_image_embeds is None:
|
612
|
+
if not isinstance(ip_adapter_image, list):
|
613
|
+
ip_adapter_image = [ip_adapter_image]
|
607
614
|
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
615
|
+
if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
|
616
|
+
raise ValueError(
|
617
|
+
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."
|
618
|
+
)
|
612
619
|
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
620
|
+
image_embeds = []
|
621
|
+
for single_ip_adapter_image, image_proj_layer in zip(
|
622
|
+
ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
|
623
|
+
):
|
624
|
+
output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
|
625
|
+
single_image_embeds, single_negative_image_embeds = self.encode_image(
|
626
|
+
single_ip_adapter_image, device, 1, output_hidden_state
|
627
|
+
)
|
628
|
+
single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
|
629
|
+
single_negative_image_embeds = torch.stack(
|
630
|
+
[single_negative_image_embeds] * num_images_per_prompt, dim=0
|
631
|
+
)
|
623
632
|
|
624
|
-
|
625
|
-
|
626
|
-
|
633
|
+
if do_classifier_free_guidance:
|
634
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
635
|
+
single_image_embeds = single_image_embeds.to(device)
|
627
636
|
|
628
|
-
|
637
|
+
image_embeds.append(single_image_embeds)
|
638
|
+
else:
|
639
|
+
repeat_dims = [1]
|
640
|
+
image_embeds = []
|
641
|
+
for single_image_embeds in ip_adapter_image_embeds:
|
642
|
+
if do_classifier_free_guidance:
|
643
|
+
single_negative_image_embeds, single_image_embeds = single_image_embeds.chunk(2)
|
644
|
+
single_image_embeds = single_image_embeds.repeat(
|
645
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
646
|
+
)
|
647
|
+
single_negative_image_embeds = single_negative_image_embeds.repeat(
|
648
|
+
num_images_per_prompt, *(repeat_dims * len(single_negative_image_embeds.shape[1:]))
|
649
|
+
)
|
650
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
651
|
+
else:
|
652
|
+
single_image_embeds = single_image_embeds.repeat(
|
653
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
654
|
+
)
|
655
|
+
image_embeds.append(single_image_embeds)
|
629
656
|
|
630
657
|
return image_embeds
|
631
658
|
|
@@ -675,6 +702,8 @@ class StableDiffusionInpaintPipeline(
|
|
675
702
|
negative_prompt=None,
|
676
703
|
prompt_embeds=None,
|
677
704
|
negative_prompt_embeds=None,
|
705
|
+
ip_adapter_image=None,
|
706
|
+
ip_adapter_image_embeds=None,
|
678
707
|
callback_on_step_end_tensor_inputs=None,
|
679
708
|
padding_mask_crop=None,
|
680
709
|
):
|
@@ -735,6 +764,21 @@ class StableDiffusionInpaintPipeline(
|
|
735
764
|
if output_type != "pil":
|
736
765
|
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is" f" {output_type}.")
|
737
766
|
|
767
|
+
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
|
768
|
+
raise ValueError(
|
769
|
+
"Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
|
770
|
+
)
|
771
|
+
|
772
|
+
if ip_adapter_image_embeds is not None:
|
773
|
+
if not isinstance(ip_adapter_image_embeds, list):
|
774
|
+
raise ValueError(
|
775
|
+
f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
|
776
|
+
)
|
777
|
+
elif ip_adapter_image_embeds[0].ndim not in [3, 4]:
|
778
|
+
raise ValueError(
|
779
|
+
f"`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is {ip_adapter_image_embeds[0].ndim}D"
|
780
|
+
)
|
781
|
+
|
738
782
|
def prepare_latents(
|
739
783
|
self,
|
740
784
|
batch_size,
|
@@ -859,98 +903,11 @@ class StableDiffusionInpaintPipeline(
|
|
859
903
|
|
860
904
|
t_start = max(num_inference_steps - init_timestep, 0)
|
861
905
|
timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
|
906
|
+
if hasattr(self.scheduler, "set_begin_index"):
|
907
|
+
self.scheduler.set_begin_index(t_start * self.scheduler.order)
|
862
908
|
|
863
909
|
return timesteps, num_inference_steps - t_start
|
864
910
|
|
865
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
866
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
867
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
868
|
-
|
869
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
870
|
-
|
871
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
872
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
873
|
-
|
874
|
-
Args:
|
875
|
-
s1 (`float`):
|
876
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
877
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
878
|
-
s2 (`float`):
|
879
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
880
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
881
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
882
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
883
|
-
"""
|
884
|
-
if not hasattr(self, "unet"):
|
885
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
886
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
887
|
-
|
888
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
889
|
-
def disable_freeu(self):
|
890
|
-
"""Disables the FreeU mechanism if enabled."""
|
891
|
-
self.unet.disable_freeu()
|
892
|
-
|
893
|
-
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.fuse_qkv_projections
|
894
|
-
def fuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
895
|
-
"""
|
896
|
-
Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query,
|
897
|
-
key, value) are fused. For cross-attention modules, key and value projection matrices are fused.
|
898
|
-
|
899
|
-
<Tip warning={true}>
|
900
|
-
|
901
|
-
This API is 🧪 experimental.
|
902
|
-
|
903
|
-
</Tip>
|
904
|
-
|
905
|
-
Args:
|
906
|
-
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
907
|
-
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
908
|
-
"""
|
909
|
-
self.fusing_unet = False
|
910
|
-
self.fusing_vae = False
|
911
|
-
|
912
|
-
if unet:
|
913
|
-
self.fusing_unet = True
|
914
|
-
self.unet.fuse_qkv_projections()
|
915
|
-
self.unet.set_attn_processor(FusedAttnProcessor2_0())
|
916
|
-
|
917
|
-
if vae:
|
918
|
-
if not isinstance(self.vae, AutoencoderKL):
|
919
|
-
raise ValueError("`fuse_qkv_projections()` is only supported for the VAE of type `AutoencoderKL`.")
|
920
|
-
|
921
|
-
self.fusing_vae = True
|
922
|
-
self.vae.fuse_qkv_projections()
|
923
|
-
self.vae.set_attn_processor(FusedAttnProcessor2_0())
|
924
|
-
|
925
|
-
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.unfuse_qkv_projections
|
926
|
-
def unfuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
927
|
-
"""Disable QKV projection fusion if enabled.
|
928
|
-
|
929
|
-
<Tip warning={true}>
|
930
|
-
|
931
|
-
This API is 🧪 experimental.
|
932
|
-
|
933
|
-
</Tip>
|
934
|
-
|
935
|
-
Args:
|
936
|
-
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
937
|
-
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
938
|
-
|
939
|
-
"""
|
940
|
-
if unet:
|
941
|
-
if not self.fusing_unet:
|
942
|
-
logger.warning("The UNet was not initially fused for QKV projections. Doing nothing.")
|
943
|
-
else:
|
944
|
-
self.unet.unfuse_qkv_projections()
|
945
|
-
self.fusing_unet = False
|
946
|
-
|
947
|
-
if vae:
|
948
|
-
if not self.fusing_vae:
|
949
|
-
logger.warning("The VAE was not initially fused for QKV projections. Doing nothing.")
|
950
|
-
else:
|
951
|
-
self.vae.unfuse_qkv_projections()
|
952
|
-
self.fusing_vae = False
|
953
|
-
|
954
911
|
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
|
955
912
|
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
956
913
|
"""
|
@@ -1029,6 +986,7 @@ class StableDiffusionInpaintPipeline(
|
|
1029
986
|
prompt_embeds: Optional[torch.FloatTensor] = None,
|
1030
987
|
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
1031
988
|
ip_adapter_image: Optional[PipelineImageInput] = None,
|
989
|
+
ip_adapter_image_embeds: Optional[List[torch.FloatTensor]] = None,
|
1032
990
|
output_type: Optional[str] = "pil",
|
1033
991
|
return_dict: bool = True,
|
1034
992
|
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
@@ -1105,6 +1063,11 @@ class StableDiffusionInpaintPipeline(
|
|
1105
1063
|
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
|
1106
1064
|
not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
|
1107
1065
|
ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
|
1066
|
+
ip_adapter_image_embeds (`List[torch.FloatTensor]`, *optional*):
|
1067
|
+
Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of IP-adapters.
|
1068
|
+
Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should contain the negative image embedding
|
1069
|
+
if `do_classifier_free_guidance` is set to `True`.
|
1070
|
+
If not provided, embeddings are computed from the `ip_adapter_image` input argument.
|
1108
1071
|
output_type (`str`, *optional*, defaults to `"pil"`):
|
1109
1072
|
The output format of the generated image. Choose between `PIL.Image` or `np.array`.
|
1110
1073
|
return_dict (`bool`, *optional*, defaults to `True`):
|
@@ -1197,6 +1160,8 @@ class StableDiffusionInpaintPipeline(
|
|
1197
1160
|
negative_prompt,
|
1198
1161
|
prompt_embeds,
|
1199
1162
|
negative_prompt_embeds,
|
1163
|
+
ip_adapter_image,
|
1164
|
+
ip_adapter_image_embeds,
|
1200
1165
|
callback_on_step_end_tensor_inputs,
|
1201
1166
|
padding_mask_crop,
|
1202
1167
|
)
|
@@ -1237,9 +1202,13 @@ class StableDiffusionInpaintPipeline(
|
|
1237
1202
|
if self.do_classifier_free_guidance:
|
1238
1203
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
1239
1204
|
|
1240
|
-
if ip_adapter_image is not None:
|
1205
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1241
1206
|
image_embeds = self.prepare_ip_adapter_image_embeds(
|
1242
|
-
ip_adapter_image,
|
1207
|
+
ip_adapter_image,
|
1208
|
+
ip_adapter_image_embeds,
|
1209
|
+
device,
|
1210
|
+
batch_size * num_images_per_prompt,
|
1211
|
+
self.do_classifier_free_guidance,
|
1243
1212
|
)
|
1244
1213
|
|
1245
1214
|
# 4. set timesteps
|
@@ -1343,7 +1312,11 @@ class StableDiffusionInpaintPipeline(
|
|
1343
1312
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
1344
1313
|
|
1345
1314
|
# 9.1 Add image embeds for IP-Adapter
|
1346
|
-
added_cond_kwargs =
|
1315
|
+
added_cond_kwargs = (
|
1316
|
+
{"image_embeds": image_embeds}
|
1317
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None
|
1318
|
+
else None
|
1319
|
+
)
|
1347
1320
|
|
1348
1321
|
# 9.2 Optionally get Guidance Scale Embedding
|
1349
1322
|
timestep_cond = None
|