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 InstructPix2Pix Authors 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.
|
@@ -26,7 +26,7 @@ from ...models import AutoencoderKL, ImageProjection, UNet2DConditionModel
|
|
26
26
|
from ...schedulers import KarrasDiffusionSchedulers
|
27
27
|
from ...utils import PIL_INTERPOLATION, deprecate, logging
|
28
28
|
from ...utils.torch_utils import randn_tensor
|
29
|
-
from ..pipeline_utils import DiffusionPipeline
|
29
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
30
30
|
from . import StableDiffusionPipelineOutput
|
31
31
|
from .safety_checker import StableDiffusionSafetyChecker
|
32
32
|
|
@@ -73,7 +73,7 @@ def retrieve_latents(
|
|
73
73
|
|
74
74
|
|
75
75
|
class StableDiffusionInstructPix2PixPipeline(
|
76
|
-
DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, IPAdapterMixin
|
76
|
+
DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin, IPAdapterMixin
|
77
77
|
):
|
78
78
|
r"""
|
79
79
|
Pipeline for pixel-level image editing by following text instructions (based on Stable Diffusion).
|
@@ -323,8 +323,6 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
323
323
|
batch_size = prompt_embeds.shape[0]
|
324
324
|
|
325
325
|
device = self._execution_device
|
326
|
-
# check if scheduler is in sigmas space
|
327
|
-
scheduler_is_in_sigma_space = hasattr(self.scheduler, "sigmas")
|
328
326
|
|
329
327
|
# 2. Encode input prompt
|
330
328
|
prompt_embeds = self._encode_prompt(
|
@@ -411,15 +409,6 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
411
409
|
return_dict=False,
|
412
410
|
)[0]
|
413
411
|
|
414
|
-
# Hack:
|
415
|
-
# For karras style schedulers the model does classifer free guidance using the
|
416
|
-
# predicted_original_sample instead of the noise_pred. So we need to compute the
|
417
|
-
# predicted_original_sample here if we are using a karras style scheduler.
|
418
|
-
if scheduler_is_in_sigma_space:
|
419
|
-
step_index = (self.scheduler.timesteps == t).nonzero()[0].item()
|
420
|
-
sigma = self.scheduler.sigmas[step_index]
|
421
|
-
noise_pred = latent_model_input - sigma * noise_pred
|
422
|
-
|
423
412
|
# perform guidance
|
424
413
|
if self.do_classifier_free_guidance:
|
425
414
|
noise_pred_text, noise_pred_image, noise_pred_uncond = noise_pred.chunk(3)
|
@@ -429,15 +418,6 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
429
418
|
+ self.image_guidance_scale * (noise_pred_image - noise_pred_uncond)
|
430
419
|
)
|
431
420
|
|
432
|
-
# Hack:
|
433
|
-
# For karras style schedulers the model does classifer free guidance using the
|
434
|
-
# predicted_original_sample instead of the noise_pred. But the scheduler.step function
|
435
|
-
# expects the noise_pred and computes the predicted_original_sample internally. So we
|
436
|
-
# need to overwrite the noise_pred here such that the value of the computed
|
437
|
-
# predicted_original_sample is correct.
|
438
|
-
if scheduler_is_in_sigma_space:
|
439
|
-
noise_pred = (noise_pred - latents) / (-sigma)
|
440
|
-
|
441
421
|
# compute the previous noisy sample x_t -> x_t-1
|
442
422
|
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
|
443
423
|
|
@@ -523,7 +503,7 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
523
503
|
batch_size = prompt_embeds.shape[0]
|
524
504
|
|
525
505
|
if prompt_embeds is None:
|
526
|
-
# textual inversion:
|
506
|
+
# textual inversion: process multi-vector tokens if necessary
|
527
507
|
if isinstance(self, TextualInversionLoaderMixin):
|
528
508
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
529
509
|
|
@@ -553,13 +533,15 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
553
533
|
else:
|
554
534
|
attention_mask = None
|
555
535
|
|
556
|
-
prompt_embeds = self.text_encoder(
|
557
|
-
text_input_ids.to(device),
|
558
|
-
attention_mask=attention_mask,
|
559
|
-
)
|
536
|
+
prompt_embeds = self.text_encoder(text_input_ids.to(device), attention_mask=attention_mask)
|
560
537
|
prompt_embeds = prompt_embeds[0]
|
561
538
|
|
562
|
-
|
539
|
+
if self.text_encoder is not None:
|
540
|
+
prompt_embeds_dtype = self.text_encoder.dtype
|
541
|
+
else:
|
542
|
+
prompt_embeds_dtype = self.unet.dtype
|
543
|
+
|
544
|
+
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
563
545
|
|
564
546
|
bs_embed, seq_len, _ = prompt_embeds.shape
|
565
547
|
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
@@ -587,7 +569,7 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
587
569
|
else:
|
588
570
|
uncond_tokens = negative_prompt
|
589
571
|
|
590
|
-
# textual inversion:
|
572
|
+
# textual inversion: process multi-vector tokens if necessary
|
591
573
|
if isinstance(self, TextualInversionLoaderMixin):
|
592
574
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
593
575
|
|
@@ -615,7 +597,7 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
615
597
|
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
616
598
|
seq_len = negative_prompt_embeds.shape[1]
|
617
599
|
|
618
|
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=
|
600
|
+
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
|
619
601
|
|
620
602
|
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
621
603
|
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
@@ -805,34 +787,6 @@ class StableDiffusionInstructPix2PixPipeline(
|
|
805
787
|
|
806
788
|
return image_latents
|
807
789
|
|
808
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
809
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
810
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
811
|
-
|
812
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
813
|
-
|
814
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
815
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
816
|
-
|
817
|
-
Args:
|
818
|
-
s1 (`float`):
|
819
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
820
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
821
|
-
s2 (`float`):
|
822
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
823
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
824
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
825
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
826
|
-
"""
|
827
|
-
if not hasattr(self, "unet"):
|
828
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
829
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
830
|
-
|
831
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
832
|
-
def disable_freeu(self):
|
833
|
-
"""Disables the FreeU mechanism if enabled."""
|
834
|
-
self.unet.disable_freeu()
|
835
|
-
|
836
790
|
@property
|
837
791
|
def guidance_scale(self):
|
838
792
|
return self._guidance_scale
|
@@ -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.
|
@@ -27,7 +27,7 @@ from ...models import AutoencoderKL, UNet2DConditionModel
|
|
27
27
|
from ...schedulers import EulerDiscreteScheduler
|
28
28
|
from ...utils import deprecate, logging
|
29
29
|
from ...utils.torch_utils import randn_tensor
|
30
|
-
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
30
|
+
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput, StableDiffusionMixin
|
31
31
|
|
32
32
|
|
33
33
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -60,7 +60,7 @@ def preprocess(image):
|
|
60
60
|
return image
|
61
61
|
|
62
62
|
|
63
|
-
class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, FromSingleFileMixin):
|
63
|
+
class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, StableDiffusionMixin, FromSingleFileMixin):
|
64
64
|
r"""
|
65
65
|
Pipeline for upscaling Stable Diffusion output image resolution by a factor of 2.
|
66
66
|
|
@@ -258,34 +258,6 @@ class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, FromSingleFileMixi
|
|
258
258
|
latents = latents * self.scheduler.init_noise_sigma
|
259
259
|
return latents
|
260
260
|
|
261
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
262
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
263
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
264
|
-
|
265
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
266
|
-
|
267
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
268
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
269
|
-
|
270
|
-
Args:
|
271
|
-
s1 (`float`):
|
272
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
273
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
274
|
-
s2 (`float`):
|
275
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
276
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
277
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
278
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
279
|
-
"""
|
280
|
-
if not hasattr(self, "unet"):
|
281
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
282
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
283
|
-
|
284
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
285
|
-
def disable_freeu(self):
|
286
|
-
"""Disables the FreeU mechanism if enabled."""
|
287
|
-
self.unet.disable_freeu()
|
288
|
-
|
289
261
|
@torch.no_grad()
|
290
262
|
def __call__(
|
291
263
|
self,
|
@@ -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.
|
@@ -34,7 +34,7 @@ from ...models.lora import adjust_lora_scale_text_encoder
|
|
34
34
|
from ...schedulers import DDPMScheduler, KarrasDiffusionSchedulers
|
35
35
|
from ...utils import USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
|
36
36
|
from ...utils.torch_utils import randn_tensor
|
37
|
-
from ..pipeline_utils import DiffusionPipeline
|
37
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
38
38
|
from . import StableDiffusionPipelineOutput
|
39
39
|
|
40
40
|
|
@@ -68,7 +68,7 @@ def preprocess(image):
|
|
68
68
|
|
69
69
|
|
70
70
|
class StableDiffusionUpscalePipeline(
|
71
|
-
DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
|
71
|
+
DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
|
72
72
|
):
|
73
73
|
r"""
|
74
74
|
Pipeline for text-guided image super-resolution using Stable Diffusion 2.
|
@@ -262,7 +262,7 @@ class StableDiffusionUpscalePipeline(
|
|
262
262
|
batch_size = prompt_embeds.shape[0]
|
263
263
|
|
264
264
|
if prompt_embeds is None:
|
265
|
-
# textual inversion:
|
265
|
+
# textual inversion: process multi-vector tokens if necessary
|
266
266
|
if isinstance(self, TextualInversionLoaderMixin):
|
267
267
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
268
268
|
|
@@ -344,7 +344,7 @@ class StableDiffusionUpscalePipeline(
|
|
344
344
|
else:
|
345
345
|
uncond_tokens = negative_prompt
|
346
346
|
|
347
|
-
# textual inversion:
|
347
|
+
# textual inversion: process multi-vector tokens if necessary
|
348
348
|
if isinstance(self, TextualInversionLoaderMixin):
|
349
349
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
350
350
|
|
@@ -530,34 +530,6 @@ class StableDiffusionUpscalePipeline(
|
|
530
530
|
self.vae.decoder.conv_in.to(dtype)
|
531
531
|
self.vae.decoder.mid_block.to(dtype)
|
532
532
|
|
533
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
534
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
535
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
536
|
-
|
537
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
538
|
-
|
539
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
540
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
541
|
-
|
542
|
-
Args:
|
543
|
-
s1 (`float`):
|
544
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
545
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
546
|
-
s2 (`float`):
|
547
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
548
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
549
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
550
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
551
|
-
"""
|
552
|
-
if not hasattr(self, "unet"):
|
553
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
554
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
555
|
-
|
556
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
557
|
-
def disable_freeu(self):
|
558
|
-
"""Disables the FreeU mechanism if enabled."""
|
559
|
-
self.unet.disable_freeu()
|
560
|
-
|
561
533
|
@torch.no_grad()
|
562
534
|
def __call__(
|
563
535
|
self,
|
@@ -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.
|
@@ -34,7 +34,7 @@ from ...utils import (
|
|
34
34
|
unscale_lora_layers,
|
35
35
|
)
|
36
36
|
from ...utils.torch_utils import randn_tensor
|
37
|
-
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
37
|
+
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput, StableDiffusionMixin
|
38
38
|
from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
|
39
39
|
|
40
40
|
|
@@ -58,7 +58,7 @@ EXAMPLE_DOC_STRING = """
|
|
58
58
|
"""
|
59
59
|
|
60
60
|
|
61
|
-
class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin):
|
61
|
+
class StableUnCLIPPipeline(DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin):
|
62
62
|
"""
|
63
63
|
Pipeline for text-to-image generation using stable unCLIP.
|
64
64
|
|
@@ -155,22 +155,6 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
155
155
|
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
|
156
156
|
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
|
157
157
|
|
158
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
159
|
-
def enable_vae_slicing(self):
|
160
|
-
r"""
|
161
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
162
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
163
|
-
"""
|
164
|
-
self.vae.enable_slicing()
|
165
|
-
|
166
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
167
|
-
def disable_vae_slicing(self):
|
168
|
-
r"""
|
169
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
170
|
-
computing decoding in one step.
|
171
|
-
"""
|
172
|
-
self.vae.disable_slicing()
|
173
|
-
|
174
158
|
# Copied from diffusers.pipelines.unclip.pipeline_unclip.UnCLIPPipeline._encode_prompt with _encode_prompt->_encode_prior_prompt, tokenizer->prior_tokenizer, text_encoder->prior_text_encoder
|
175
159
|
def _encode_prior_prompt(
|
176
160
|
self,
|
@@ -359,7 +343,7 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
359
343
|
batch_size = prompt_embeds.shape[0]
|
360
344
|
|
361
345
|
if prompt_embeds is None:
|
362
|
-
# textual inversion:
|
346
|
+
# textual inversion: process multi-vector tokens if necessary
|
363
347
|
if isinstance(self, TextualInversionLoaderMixin):
|
364
348
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
365
349
|
|
@@ -441,7 +425,7 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
441
425
|
else:
|
442
426
|
uncond_tokens = negative_prompt
|
443
427
|
|
444
|
-
# textual inversion:
|
428
|
+
# textual inversion: process multi-vector tokens if necessary
|
445
429
|
if isinstance(self, TextualInversionLoaderMixin):
|
446
430
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
447
431
|
|
@@ -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.
|
@@ -34,7 +34,7 @@ from ...utils import (
|
|
34
34
|
unscale_lora_layers,
|
35
35
|
)
|
36
36
|
from ...utils.torch_utils import randn_tensor
|
37
|
-
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
37
|
+
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput, StableDiffusionMixin
|
38
38
|
from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
|
39
39
|
|
40
40
|
|
@@ -69,7 +69,9 @@ EXAMPLE_DOC_STRING = """
|
|
69
69
|
"""
|
70
70
|
|
71
71
|
|
72
|
-
class StableUnCLIPImg2ImgPipeline(
|
72
|
+
class StableUnCLIPImg2ImgPipeline(
|
73
|
+
DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin
|
74
|
+
):
|
73
75
|
"""
|
74
76
|
Pipeline for text-guided image-to-image generation using stable unCLIP.
|
75
77
|
|
@@ -156,22 +158,6 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
|
|
156
158
|
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
|
157
159
|
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
|
158
160
|
|
159
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
160
|
-
def enable_vae_slicing(self):
|
161
|
-
r"""
|
162
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
163
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
164
|
-
"""
|
165
|
-
self.vae.enable_slicing()
|
166
|
-
|
167
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
168
|
-
def disable_vae_slicing(self):
|
169
|
-
r"""
|
170
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
171
|
-
computing decoding in one step.
|
172
|
-
"""
|
173
|
-
self.vae.disable_slicing()
|
174
|
-
|
175
161
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
176
162
|
def _encode_prompt(
|
177
163
|
self,
|
@@ -321,7 +307,7 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
|
|
321
307
|
batch_size = prompt_embeds.shape[0]
|
322
308
|
|
323
309
|
if prompt_embeds is None:
|
324
|
-
# textual inversion:
|
310
|
+
# textual inversion: process multi-vector tokens if necessary
|
325
311
|
if isinstance(self, TextualInversionLoaderMixin):
|
326
312
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
327
313
|
|
@@ -403,7 +389,7 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
|
|
403
389
|
else:
|
404
390
|
uncond_tokens = negative_prompt
|
405
391
|
|
406
|
-
# textual inversion:
|
392
|
+
# textual inversion: process multi-vector tokens if necessary
|
407
393
|
if isinstance(self, TextualInversionLoaderMixin):
|
408
394
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
409
395
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -36,7 +36,7 @@ from ...utils import (
|
|
36
36
|
unscale_lora_layers,
|
37
37
|
)
|
38
38
|
from ...utils.torch_utils import randn_tensor
|
39
|
-
from ..pipeline_utils import DiffusionPipeline
|
39
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
40
40
|
from ..stable_diffusion import StableDiffusionPipelineOutput
|
41
41
|
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
42
42
|
|
@@ -170,7 +170,7 @@ class AttendExciteAttnProcessor:
|
|
170
170
|
return hidden_states
|
171
171
|
|
172
172
|
|
173
|
-
class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversionLoaderMixin):
|
173
|
+
class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin):
|
174
174
|
r"""
|
175
175
|
Pipeline for text-to-image generation using Stable Diffusion and Attend-and-Excite.
|
176
176
|
|
@@ -246,22 +246,6 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
|
|
246
246
|
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
|
247
247
|
self.register_to_config(requires_safety_checker=requires_safety_checker)
|
248
248
|
|
249
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
250
|
-
def enable_vae_slicing(self):
|
251
|
-
r"""
|
252
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
253
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
254
|
-
"""
|
255
|
-
self.vae.enable_slicing()
|
256
|
-
|
257
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
258
|
-
def disable_vae_slicing(self):
|
259
|
-
r"""
|
260
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
261
|
-
computing decoding in one step.
|
262
|
-
"""
|
263
|
-
self.vae.disable_slicing()
|
264
|
-
|
265
249
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
266
250
|
def _encode_prompt(
|
267
251
|
self,
|
@@ -356,7 +340,7 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
|
|
356
340
|
batch_size = prompt_embeds.shape[0]
|
357
341
|
|
358
342
|
if prompt_embeds is None:
|
359
|
-
# textual inversion:
|
343
|
+
# textual inversion: process multi-vector tokens if necessary
|
360
344
|
if isinstance(self, TextualInversionLoaderMixin):
|
361
345
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
362
346
|
|
@@ -438,7 +422,7 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
|
|
438
422
|
else:
|
439
423
|
uncond_tokens = negative_prompt
|
440
424
|
|
441
|
-
# textual inversion:
|
425
|
+
# textual inversion: process multi-vector tokens if necessary
|
442
426
|
if isinstance(self, TextualInversionLoaderMixin):
|
443
427
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
444
428
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 DiffEdit Authors and Pix2Pix Zero Authors 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.
|
@@ -39,7 +39,7 @@ from ...utils import (
|
|
39
39
|
unscale_lora_layers,
|
40
40
|
)
|
41
41
|
from ...utils.torch_utils import randn_tensor
|
42
|
-
from ..pipeline_utils import DiffusionPipeline
|
42
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
43
43
|
from ..stable_diffusion import StableDiffusionPipelineOutput
|
44
44
|
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
45
45
|
|
@@ -235,7 +235,9 @@ def preprocess_mask(mask, batch_size: int = 1):
|
|
235
235
|
return mask
|
236
236
|
|
237
237
|
|
238
|
-
class StableDiffusionDiffEditPipeline(
|
238
|
+
class StableDiffusionDiffEditPipeline(
|
239
|
+
DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin
|
240
|
+
):
|
239
241
|
r"""
|
240
242
|
<Tip warning={true}>
|
241
243
|
|
@@ -371,39 +373,6 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
371
373
|
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
|
372
374
|
self.register_to_config(requires_safety_checker=requires_safety_checker)
|
373
375
|
|
374
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
375
|
-
def enable_vae_slicing(self):
|
376
|
-
r"""
|
377
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
378
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
379
|
-
"""
|
380
|
-
self.vae.enable_slicing()
|
381
|
-
|
382
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
383
|
-
def disable_vae_slicing(self):
|
384
|
-
r"""
|
385
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
386
|
-
computing decoding in one step.
|
387
|
-
"""
|
388
|
-
self.vae.disable_slicing()
|
389
|
-
|
390
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
391
|
-
def enable_vae_tiling(self):
|
392
|
-
r"""
|
393
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
394
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
395
|
-
processing larger images.
|
396
|
-
"""
|
397
|
-
self.vae.enable_tiling()
|
398
|
-
|
399
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
400
|
-
def disable_vae_tiling(self):
|
401
|
-
r"""
|
402
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
403
|
-
computing decoding in one step.
|
404
|
-
"""
|
405
|
-
self.vae.disable_tiling()
|
406
|
-
|
407
376
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
408
377
|
def _encode_prompt(
|
409
378
|
self,
|
@@ -498,7 +467,7 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
498
467
|
batch_size = prompt_embeds.shape[0]
|
499
468
|
|
500
469
|
if prompt_embeds is None:
|
501
|
-
# textual inversion:
|
470
|
+
# textual inversion: process multi-vector tokens if necessary
|
502
471
|
if isinstance(self, TextualInversionLoaderMixin):
|
503
472
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
504
473
|
|
@@ -580,7 +549,7 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
580
549
|
else:
|
581
550
|
uncond_tokens = negative_prompt
|
582
551
|
|
583
|
-
# textual inversion:
|
552
|
+
# textual inversion: process multi-vector tokens if necessary
|
584
553
|
if isinstance(self, TextualInversionLoaderMixin):
|
585
554
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
586
555
|
|
@@ -754,6 +723,8 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
754
723
|
|
755
724
|
t_start = max(num_inference_steps - init_timestep, 0)
|
756
725
|
timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
|
726
|
+
if hasattr(self.scheduler, "set_begin_index"):
|
727
|
+
self.scheduler.set_begin_index(t_start * self.scheduler.order)
|
757
728
|
|
758
729
|
return timesteps, num_inference_steps - t_start
|
759
730
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The GLIGEN Authors and HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -35,7 +35,7 @@ from ...utils import (
|
|
35
35
|
unscale_lora_layers,
|
36
36
|
)
|
37
37
|
from ...utils.torch_utils import randn_tensor
|
38
|
-
from ..pipeline_utils import DiffusionPipeline
|
38
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
39
39
|
from ..stable_diffusion import StableDiffusionPipelineOutput
|
40
40
|
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
41
41
|
|
@@ -99,7 +99,7 @@ EXAMPLE_DOC_STRING = """
|
|
99
99
|
"""
|
100
100
|
|
101
101
|
|
102
|
-
class StableDiffusionGLIGENPipeline(DiffusionPipeline):
|
102
|
+
class StableDiffusionGLIGENPipeline(DiffusionPipeline, StableDiffusionMixin):
|
103
103
|
r"""
|
104
104
|
Pipeline for text-to-image generation using Stable Diffusion with Grounded-Language-to-Image Generation (GLIGEN).
|
105
105
|
|
@@ -172,35 +172,6 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
|
|
172
172
|
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor, do_convert_rgb=True)
|
173
173
|
self.register_to_config(requires_safety_checker=requires_safety_checker)
|
174
174
|
|
175
|
-
def enable_vae_slicing(self):
|
176
|
-
r"""
|
177
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
178
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
179
|
-
"""
|
180
|
-
self.vae.enable_slicing()
|
181
|
-
|
182
|
-
def disable_vae_slicing(self):
|
183
|
-
r"""
|
184
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
185
|
-
computing decoding in one step.
|
186
|
-
"""
|
187
|
-
self.vae.disable_slicing()
|
188
|
-
|
189
|
-
def enable_vae_tiling(self):
|
190
|
-
r"""
|
191
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
192
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
193
|
-
processing larger images.
|
194
|
-
"""
|
195
|
-
self.vae.enable_tiling()
|
196
|
-
|
197
|
-
def disable_vae_tiling(self):
|
198
|
-
r"""
|
199
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
200
|
-
computing decoding in one step.
|
201
|
-
"""
|
202
|
-
self.vae.disable_tiling()
|
203
|
-
|
204
175
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
205
176
|
def _encode_prompt(
|
206
177
|
self,
|
@@ -295,7 +266,7 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
|
|
295
266
|
batch_size = prompt_embeds.shape[0]
|
296
267
|
|
297
268
|
if prompt_embeds is None:
|
298
|
-
# textual inversion:
|
269
|
+
# textual inversion: process multi-vector tokens if necessary
|
299
270
|
if isinstance(self, TextualInversionLoaderMixin):
|
300
271
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
301
272
|
|
@@ -377,7 +348,7 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
|
|
377
348
|
else:
|
378
349
|
uncond_tokens = negative_prompt
|
379
350
|
|
380
|
-
# textual inversion:
|
351
|
+
# textual inversion: process multi-vector tokens if necessary
|
381
352
|
if isinstance(self, TextualInversionLoaderMixin):
|
382
353
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
383
354
|
|