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.
|
@@ -36,7 +36,6 @@ from ...loaders import (
|
|
36
36
|
from ...models import AutoencoderKL, ImageProjection, UNet2DConditionModel
|
37
37
|
from ...models.attention_processor import (
|
38
38
|
AttnProcessor2_0,
|
39
|
-
FusedAttnProcessor2_0,
|
40
39
|
LoRAAttnProcessor2_0,
|
41
40
|
LoRAXFormersAttnProcessor,
|
42
41
|
XFormersAttnProcessor,
|
@@ -54,7 +53,7 @@ from ...utils import (
|
|
54
53
|
unscale_lora_layers,
|
55
54
|
)
|
56
55
|
from ...utils.torch_utils import randn_tensor
|
57
|
-
from ..pipeline_utils import DiffusionPipeline
|
56
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
58
57
|
from .pipeline_output import StableDiffusionXLPipelineOutput
|
59
58
|
|
60
59
|
|
@@ -311,6 +310,7 @@ def retrieve_timesteps(
|
|
311
310
|
|
312
311
|
class StableDiffusionXLInpaintPipeline(
|
313
312
|
DiffusionPipeline,
|
313
|
+
StableDiffusionMixin,
|
314
314
|
TextualInversionLoaderMixin,
|
315
315
|
StableDiffusionXLLoraLoaderMixin,
|
316
316
|
FromSingleFileMixin,
|
@@ -429,39 +429,6 @@ class StableDiffusionXLInpaintPipeline(
|
|
429
429
|
else:
|
430
430
|
self.watermark = None
|
431
431
|
|
432
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
433
|
-
def enable_vae_slicing(self):
|
434
|
-
r"""
|
435
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
436
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
437
|
-
"""
|
438
|
-
self.vae.enable_slicing()
|
439
|
-
|
440
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
441
|
-
def disable_vae_slicing(self):
|
442
|
-
r"""
|
443
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
444
|
-
computing decoding in one step.
|
445
|
-
"""
|
446
|
-
self.vae.disable_slicing()
|
447
|
-
|
448
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
449
|
-
def enable_vae_tiling(self):
|
450
|
-
r"""
|
451
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
452
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
453
|
-
processing larger images.
|
454
|
-
"""
|
455
|
-
self.vae.enable_tiling()
|
456
|
-
|
457
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
458
|
-
def disable_vae_tiling(self):
|
459
|
-
r"""
|
460
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
461
|
-
computing decoding in one step.
|
462
|
-
"""
|
463
|
-
self.vae.disable_tiling()
|
464
|
-
|
465
432
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.encode_image
|
466
433
|
def encode_image(self, image, device, num_images_per_prompt, output_hidden_states=None):
|
467
434
|
dtype = next(self.image_encoder.parameters()).dtype
|
@@ -488,31 +455,54 @@ class StableDiffusionXLInpaintPipeline(
|
|
488
455
|
return image_embeds, uncond_image_embeds
|
489
456
|
|
490
457
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
|
491
|
-
def prepare_ip_adapter_image_embeds(
|
492
|
-
|
493
|
-
|
458
|
+
def prepare_ip_adapter_image_embeds(
|
459
|
+
self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
|
460
|
+
):
|
461
|
+
if ip_adapter_image_embeds is None:
|
462
|
+
if not isinstance(ip_adapter_image, list):
|
463
|
+
ip_adapter_image = [ip_adapter_image]
|
494
464
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
465
|
+
if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
|
466
|
+
raise ValueError(
|
467
|
+
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."
|
468
|
+
)
|
499
469
|
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
470
|
+
image_embeds = []
|
471
|
+
for single_ip_adapter_image, image_proj_layer in zip(
|
472
|
+
ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
|
473
|
+
):
|
474
|
+
output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
|
475
|
+
single_image_embeds, single_negative_image_embeds = self.encode_image(
|
476
|
+
single_ip_adapter_image, device, 1, output_hidden_state
|
477
|
+
)
|
478
|
+
single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
|
479
|
+
single_negative_image_embeds = torch.stack(
|
480
|
+
[single_negative_image_embeds] * num_images_per_prompt, dim=0
|
481
|
+
)
|
510
482
|
|
511
|
-
|
512
|
-
|
513
|
-
|
483
|
+
if do_classifier_free_guidance:
|
484
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
485
|
+
single_image_embeds = single_image_embeds.to(device)
|
514
486
|
|
515
|
-
|
487
|
+
image_embeds.append(single_image_embeds)
|
488
|
+
else:
|
489
|
+
repeat_dims = [1]
|
490
|
+
image_embeds = []
|
491
|
+
for single_image_embeds in ip_adapter_image_embeds:
|
492
|
+
if do_classifier_free_guidance:
|
493
|
+
single_negative_image_embeds, single_image_embeds = single_image_embeds.chunk(2)
|
494
|
+
single_image_embeds = single_image_embeds.repeat(
|
495
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
496
|
+
)
|
497
|
+
single_negative_image_embeds = single_negative_image_embeds.repeat(
|
498
|
+
num_images_per_prompt, *(repeat_dims * len(single_negative_image_embeds.shape[1:]))
|
499
|
+
)
|
500
|
+
single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
|
501
|
+
else:
|
502
|
+
single_image_embeds = single_image_embeds.repeat(
|
503
|
+
num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
|
504
|
+
)
|
505
|
+
image_embeds.append(single_image_embeds)
|
516
506
|
|
517
507
|
return image_embeds
|
518
508
|
|
@@ -612,7 +602,7 @@ class StableDiffusionXLInpaintPipeline(
|
|
612
602
|
prompt_2 = prompt_2 or prompt
|
613
603
|
prompt_2 = [prompt_2] if isinstance(prompt_2, str) else prompt_2
|
614
604
|
|
615
|
-
# textual inversion:
|
605
|
+
# textual inversion: process multi-vector tokens if necessary
|
616
606
|
prompt_embeds_list = []
|
617
607
|
prompts = [prompt, prompt_2]
|
618
608
|
for prompt, tokenizer, text_encoder in zip(prompts, tokenizers, text_encoders):
|
@@ -784,6 +774,8 @@ class StableDiffusionXLInpaintPipeline(
|
|
784
774
|
negative_prompt_2=None,
|
785
775
|
prompt_embeds=None,
|
786
776
|
negative_prompt_embeds=None,
|
777
|
+
ip_adapter_image=None,
|
778
|
+
ip_adapter_image_embeds=None,
|
787
779
|
callback_on_step_end_tensor_inputs=None,
|
788
780
|
padding_mask_crop=None,
|
789
781
|
):
|
@@ -856,6 +848,21 @@ class StableDiffusionXLInpaintPipeline(
|
|
856
848
|
if output_type != "pil":
|
857
849
|
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is" f" {output_type}.")
|
858
850
|
|
851
|
+
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
|
852
|
+
raise ValueError(
|
853
|
+
"Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
|
854
|
+
)
|
855
|
+
|
856
|
+
if ip_adapter_image_embeds is not None:
|
857
|
+
if not isinstance(ip_adapter_image_embeds, list):
|
858
|
+
raise ValueError(
|
859
|
+
f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
|
860
|
+
)
|
861
|
+
elif ip_adapter_image_embeds[0].ndim not in [3, 4]:
|
862
|
+
raise ValueError(
|
863
|
+
f"`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is {ip_adapter_image_embeds[0].ndim}D"
|
864
|
+
)
|
865
|
+
|
859
866
|
def prepare_latents(
|
860
867
|
self,
|
861
868
|
batch_size,
|
@@ -1102,95 +1109,6 @@ class StableDiffusionXLInpaintPipeline(
|
|
1102
1109
|
self.vae.decoder.conv_in.to(dtype)
|
1103
1110
|
self.vae.decoder.mid_block.to(dtype)
|
1104
1111
|
|
1105
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
1106
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
1107
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
1108
|
-
|
1109
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
1110
|
-
|
1111
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
1112
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
1113
|
-
|
1114
|
-
Args:
|
1115
|
-
s1 (`float`):
|
1116
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
1117
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
1118
|
-
s2 (`float`):
|
1119
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
1120
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
1121
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
1122
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
1123
|
-
"""
|
1124
|
-
if not hasattr(self, "unet"):
|
1125
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
1126
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
1127
|
-
|
1128
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
1129
|
-
def disable_freeu(self):
|
1130
|
-
"""Disables the FreeU mechanism if enabled."""
|
1131
|
-
self.unet.disable_freeu()
|
1132
|
-
|
1133
|
-
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.fuse_qkv_projections
|
1134
|
-
def fuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
1135
|
-
"""
|
1136
|
-
Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query,
|
1137
|
-
key, value) are fused. For cross-attention modules, key and value projection matrices are fused.
|
1138
|
-
|
1139
|
-
<Tip warning={true}>
|
1140
|
-
|
1141
|
-
This API is 🧪 experimental.
|
1142
|
-
|
1143
|
-
</Tip>
|
1144
|
-
|
1145
|
-
Args:
|
1146
|
-
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
1147
|
-
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
1148
|
-
"""
|
1149
|
-
self.fusing_unet = False
|
1150
|
-
self.fusing_vae = False
|
1151
|
-
|
1152
|
-
if unet:
|
1153
|
-
self.fusing_unet = True
|
1154
|
-
self.unet.fuse_qkv_projections()
|
1155
|
-
self.unet.set_attn_processor(FusedAttnProcessor2_0())
|
1156
|
-
|
1157
|
-
if vae:
|
1158
|
-
if not isinstance(self.vae, AutoencoderKL):
|
1159
|
-
raise ValueError("`fuse_qkv_projections()` is only supported for the VAE of type `AutoencoderKL`.")
|
1160
|
-
|
1161
|
-
self.fusing_vae = True
|
1162
|
-
self.vae.fuse_qkv_projections()
|
1163
|
-
self.vae.set_attn_processor(FusedAttnProcessor2_0())
|
1164
|
-
|
1165
|
-
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.unfuse_qkv_projections
|
1166
|
-
def unfuse_qkv_projections(self, unet: bool = True, vae: bool = True):
|
1167
|
-
"""Disable QKV projection fusion if enabled.
|
1168
|
-
|
1169
|
-
<Tip warning={true}>
|
1170
|
-
|
1171
|
-
This API is 🧪 experimental.
|
1172
|
-
|
1173
|
-
</Tip>
|
1174
|
-
|
1175
|
-
Args:
|
1176
|
-
unet (`bool`, defaults to `True`): To apply fusion on the UNet.
|
1177
|
-
vae (`bool`, defaults to `True`): To apply fusion on the VAE.
|
1178
|
-
|
1179
|
-
"""
|
1180
|
-
if unet:
|
1181
|
-
if not self.fusing_unet:
|
1182
|
-
logger.warning("The UNet was not initially fused for QKV projections. Doing nothing.")
|
1183
|
-
else:
|
1184
|
-
self.unet.unfuse_qkv_projections()
|
1185
|
-
self.fusing_unet = False
|
1186
|
-
|
1187
|
-
if vae:
|
1188
|
-
if not self.fusing_vae:
|
1189
|
-
logger.warning("The VAE was not initially fused for QKV projections. Doing nothing.")
|
1190
|
-
else:
|
1191
|
-
self.vae.unfuse_qkv_projections()
|
1192
|
-
self.fusing_vae = False
|
1193
|
-
|
1194
1112
|
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
|
1195
1113
|
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
1196
1114
|
"""
|
@@ -1288,6 +1206,7 @@ class StableDiffusionXLInpaintPipeline(
|
|
1288
1206
|
pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
|
1289
1207
|
negative_pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
|
1290
1208
|
ip_adapter_image: Optional[PipelineImageInput] = None,
|
1209
|
+
ip_adapter_image_embeds: Optional[List[torch.FloatTensor]] = None,
|
1291
1210
|
output_type: Optional[str] = "pil",
|
1292
1211
|
return_dict: bool = True,
|
1293
1212
|
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
@@ -1397,6 +1316,11 @@ class StableDiffusionXLInpaintPipeline(
|
|
1397
1316
|
weighting. If not provided, pooled negative_prompt_embeds will be generated from `negative_prompt`
|
1398
1317
|
input argument.
|
1399
1318
|
ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
|
1319
|
+
ip_adapter_image_embeds (`List[torch.FloatTensor]`, *optional*):
|
1320
|
+
Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of IP-adapters.
|
1321
|
+
Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should contain the negative image embedding
|
1322
|
+
if `do_classifier_free_guidance` is set to `True`.
|
1323
|
+
If not provided, embeddings are computed from the `ip_adapter_image` input argument.
|
1400
1324
|
num_images_per_prompt (`int`, *optional*, defaults to 1):
|
1401
1325
|
The number of images to generate per prompt.
|
1402
1326
|
eta (`float`, *optional*, defaults to 0.0):
|
@@ -1512,6 +1436,8 @@ class StableDiffusionXLInpaintPipeline(
|
|
1512
1436
|
negative_prompt_2,
|
1513
1437
|
prompt_embeds,
|
1514
1438
|
negative_prompt_embeds,
|
1439
|
+
ip_adapter_image,
|
1440
|
+
ip_adapter_image_embeds,
|
1515
1441
|
callback_on_step_end_tensor_inputs,
|
1516
1442
|
padding_mask_crop,
|
1517
1443
|
)
|
@@ -1562,14 +1488,14 @@ class StableDiffusionXLInpaintPipeline(
|
|
1562
1488
|
|
1563
1489
|
# 4. set timesteps
|
1564
1490
|
def denoising_value_valid(dnv):
|
1565
|
-
return isinstance(
|
1491
|
+
return isinstance(dnv, float) and 0 < dnv < 1
|
1566
1492
|
|
1567
1493
|
timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, timesteps)
|
1568
1494
|
timesteps, num_inference_steps = self.get_timesteps(
|
1569
1495
|
num_inference_steps,
|
1570
1496
|
strength,
|
1571
1497
|
device,
|
1572
|
-
denoising_start=self.denoising_start if denoising_value_valid else None,
|
1498
|
+
denoising_start=self.denoising_start if denoising_value_valid(self.denoising_start) else None,
|
1573
1499
|
)
|
1574
1500
|
# check that number of inference steps is not < 1 - as this doesn't make sense
|
1575
1501
|
if num_inference_steps < 1:
|
@@ -1713,9 +1639,13 @@ class StableDiffusionXLInpaintPipeline(
|
|
1713
1639
|
add_text_embeds = add_text_embeds.to(device)
|
1714
1640
|
add_time_ids = add_time_ids.to(device)
|
1715
1641
|
|
1716
|
-
if ip_adapter_image is not None:
|
1642
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1717
1643
|
image_embeds = self.prepare_ip_adapter_image_embeds(
|
1718
|
-
ip_adapter_image,
|
1644
|
+
ip_adapter_image,
|
1645
|
+
ip_adapter_image_embeds,
|
1646
|
+
device,
|
1647
|
+
batch_size * num_images_per_prompt,
|
1648
|
+
self.do_classifier_free_guidance,
|
1719
1649
|
)
|
1720
1650
|
|
1721
1651
|
# 11. Denoising loop
|
@@ -1766,7 +1696,7 @@ class StableDiffusionXLInpaintPipeline(
|
|
1766
1696
|
|
1767
1697
|
# predict the noise residual
|
1768
1698
|
added_cond_kwargs = {"text_embeds": add_text_embeds, "time_ids": add_time_ids}
|
1769
|
-
if ip_adapter_image is not None:
|
1699
|
+
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
|
1770
1700
|
added_cond_kwargs["image_embeds"] = image_embeds
|
1771
1701
|
noise_pred = self.unet(
|
1772
1702
|
latent_model_input,
|
@@ -1841,7 +1771,22 @@ class StableDiffusionXLInpaintPipeline(
|
|
1841
1771
|
self.upcast_vae()
|
1842
1772
|
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
|
1843
1773
|
|
1844
|
-
|
1774
|
+
# unscale/denormalize the latents
|
1775
|
+
# denormalize with the mean and std if available and not None
|
1776
|
+
has_latents_mean = hasattr(self.vae.config, "latents_mean") and self.vae.config.latents_mean is not None
|
1777
|
+
has_latents_std = hasattr(self.vae.config, "latents_std") and self.vae.config.latents_std is not None
|
1778
|
+
if has_latents_mean and has_latents_std:
|
1779
|
+
latents_mean = (
|
1780
|
+
torch.tensor(self.vae.config.latents_mean).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
1781
|
+
)
|
1782
|
+
latents_std = (
|
1783
|
+
torch.tensor(self.vae.config.latents_std).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
1784
|
+
)
|
1785
|
+
latents = latents * latents_std / self.vae.config.scaling_factor + latents_mean
|
1786
|
+
else:
|
1787
|
+
latents = latents / self.vae.config.scaling_factor
|
1788
|
+
|
1789
|
+
image = self.vae.decode(latents, return_dict=False)[0]
|
1845
1790
|
|
1846
1791
|
# cast back to fp16 if needed
|
1847
1792
|
if needs_upcasting:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 Harutatsu Akiyama and 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.
|
@@ -41,7 +41,7 @@ from ...utils import (
|
|
41
41
|
scale_lora_layers,
|
42
42
|
)
|
43
43
|
from ...utils.torch_utils import randn_tensor
|
44
|
-
from ..pipeline_utils import DiffusionPipeline
|
44
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
45
45
|
from .pipeline_output import StableDiffusionXLPipelineOutput
|
46
46
|
|
47
47
|
|
@@ -118,7 +118,11 @@ def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
|
|
118
118
|
|
119
119
|
|
120
120
|
class StableDiffusionXLInstructPix2PixPipeline(
|
121
|
-
DiffusionPipeline,
|
121
|
+
DiffusionPipeline,
|
122
|
+
StableDiffusionMixin,
|
123
|
+
TextualInversionLoaderMixin,
|
124
|
+
FromSingleFileMixin,
|
125
|
+
StableDiffusionXLLoraLoaderMixin,
|
122
126
|
):
|
123
127
|
r"""
|
124
128
|
Pipeline for pixel-level image editing by following text instructions. Based on Stable Diffusion XL.
|
@@ -205,38 +209,6 @@ class StableDiffusionXLInstructPix2PixPipeline(
|
|
205
209
|
else:
|
206
210
|
self.watermark = None
|
207
211
|
|
208
|
-
def enable_vae_slicing(self):
|
209
|
-
r"""
|
210
|
-
Enable sliced VAE decoding.
|
211
|
-
|
212
|
-
When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several
|
213
|
-
steps. This is useful to save some memory and allow larger batch sizes.
|
214
|
-
"""
|
215
|
-
self.vae.enable_slicing()
|
216
|
-
|
217
|
-
def disable_vae_slicing(self):
|
218
|
-
r"""
|
219
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously invoked, this method will go back to
|
220
|
-
computing decoding in one step.
|
221
|
-
"""
|
222
|
-
self.vae.disable_slicing()
|
223
|
-
|
224
|
-
def enable_vae_tiling(self):
|
225
|
-
r"""
|
226
|
-
Enable tiled VAE decoding.
|
227
|
-
|
228
|
-
When this option is enabled, the VAE will split the input tensor into tiles to compute decoding and encoding in
|
229
|
-
several steps. This is useful to save a large amount of memory and to allow the processing of larger images.
|
230
|
-
"""
|
231
|
-
self.vae.enable_tiling()
|
232
|
-
|
233
|
-
def disable_vae_tiling(self):
|
234
|
-
r"""
|
235
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously invoked, this method will go back to
|
236
|
-
computing decoding in one step.
|
237
|
-
"""
|
238
|
-
self.vae.disable_tiling()
|
239
|
-
|
240
212
|
def encode_prompt(
|
241
213
|
self,
|
242
214
|
prompt: str,
|
@@ -326,7 +298,7 @@ class StableDiffusionXLInstructPix2PixPipeline(
|
|
326
298
|
|
327
299
|
if prompt_embeds is None:
|
328
300
|
prompt_2 = prompt_2 or prompt
|
329
|
-
# textual inversion:
|
301
|
+
# textual inversion: process multi-vector tokens if necessary
|
330
302
|
prompt_embeds_list = []
|
331
303
|
prompts = [prompt, prompt_2]
|
332
304
|
for prompt, tokenizer, text_encoder in zip(prompts, tokenizers, text_encoders):
|
@@ -621,34 +593,6 @@ class StableDiffusionXLInstructPix2PixPipeline(
|
|
621
593
|
self.vae.decoder.conv_in.to(dtype)
|
622
594
|
self.vae.decoder.mid_block.to(dtype)
|
623
595
|
|
624
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
625
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
626
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
627
|
-
|
628
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
629
|
-
|
630
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
631
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
632
|
-
|
633
|
-
Args:
|
634
|
-
s1 (`float`):
|
635
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
636
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
637
|
-
s2 (`float`):
|
638
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
639
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
640
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
641
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
642
|
-
"""
|
643
|
-
if not hasattr(self, "unet"):
|
644
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
645
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
646
|
-
|
647
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
648
|
-
def disable_freeu(self):
|
649
|
-
"""Disables the FreeU mechanism if enabled."""
|
650
|
-
self.unet.disable_freeu()
|
651
|
-
|
652
596
|
@torch.no_grad()
|
653
597
|
@replace_example_docstring(EXAMPLE_DOC_STRING)
|
654
598
|
def __call__(
|
@@ -830,8 +774,6 @@ class StableDiffusionXLInstructPix2PixPipeline(
|
|
830
774
|
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
|
831
775
|
# corresponds to doing no classifier free guidance.
|
832
776
|
do_classifier_free_guidance = guidance_scale > 1.0 and image_guidance_scale >= 1.0
|
833
|
-
# check if scheduler is in sigmas space
|
834
|
-
scheduler_is_in_sigma_space = hasattr(self.scheduler, "sigmas")
|
835
777
|
|
836
778
|
# 3. Encode input prompt
|
837
779
|
text_encoder_lora_scale = (
|
@@ -962,15 +904,6 @@ class StableDiffusionXLInstructPix2PixPipeline(
|
|
962
904
|
return_dict=False,
|
963
905
|
)[0]
|
964
906
|
|
965
|
-
# Hack:
|
966
|
-
# For karras style schedulers the model does classifer free guidance using the
|
967
|
-
# predicted_original_sample instead of the noise_pred. So we need to compute the
|
968
|
-
# predicted_original_sample here if we are using a karras style scheduler.
|
969
|
-
if scheduler_is_in_sigma_space:
|
970
|
-
step_index = (self.scheduler.timesteps == t).nonzero()[0].item()
|
971
|
-
sigma = self.scheduler.sigmas[step_index]
|
972
|
-
noise_pred = latent_model_input - sigma * noise_pred
|
973
|
-
|
974
907
|
# perform guidance
|
975
908
|
if do_classifier_free_guidance:
|
976
909
|
noise_pred_text, noise_pred_image, noise_pred_uncond = noise_pred.chunk(3)
|
@@ -984,15 +917,6 @@ class StableDiffusionXLInstructPix2PixPipeline(
|
|
984
917
|
# Based on 3.4. in https://arxiv.org/pdf/2305.08891.pdf
|
985
918
|
noise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=guidance_rescale)
|
986
919
|
|
987
|
-
# Hack:
|
988
|
-
# For karras style schedulers the model does classifer free guidance using the
|
989
|
-
# predicted_original_sample instead of the noise_pred. But the scheduler.step function
|
990
|
-
# expects the noise_pred and computes the predicted_original_sample internally. So we
|
991
|
-
# need to overwrite the noise_pred here such that the value of the computed
|
992
|
-
# predicted_original_sample is correct.
|
993
|
-
if scheduler_is_in_sigma_space:
|
994
|
-
noise_pred = (noise_pred - latents) / (-sigma)
|
995
|
-
|
996
920
|
# compute the previous noisy sample x_t -> x_t-1
|
997
921
|
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
|
998
922
|
|
@@ -1014,14 +938,28 @@ class StableDiffusionXLInstructPix2PixPipeline(
|
|
1014
938
|
self.upcast_vae()
|
1015
939
|
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
|
1016
940
|
|
1017
|
-
|
941
|
+
# unscale/denormalize the latents
|
942
|
+
# denormalize with the mean and std if available and not None
|
943
|
+
has_latents_mean = hasattr(self.vae.config, "latents_mean") and self.vae.config.latents_mean is not None
|
944
|
+
has_latents_std = hasattr(self.vae.config, "latents_std") and self.vae.config.latents_std is not None
|
945
|
+
if has_latents_mean and has_latents_std:
|
946
|
+
latents_mean = (
|
947
|
+
torch.tensor(self.vae.config.latents_mean).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
948
|
+
)
|
949
|
+
latents_std = (
|
950
|
+
torch.tensor(self.vae.config.latents_std).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
951
|
+
)
|
952
|
+
latents = latents * latents_std / self.vae.config.scaling_factor + latents_mean
|
953
|
+
else:
|
954
|
+
latents = latents / self.vae.config.scaling_factor
|
955
|
+
|
956
|
+
image = self.vae.decode(latents, return_dict=False)[0]
|
1018
957
|
|
1019
958
|
# cast back to fp16 if needed
|
1020
959
|
if needs_upcasting:
|
1021
960
|
self.vae.to(dtype=torch.float16)
|
1022
961
|
else:
|
1023
|
-
|
1024
|
-
return StableDiffusionXLPipelineOutput(images=image)
|
962
|
+
return StableDiffusionXLPipelineOutput(images=latents)
|
1025
963
|
|
1026
964
|
# apply watermark if available
|
1027
965
|
if self.watermark is not None:
|