diffusers 0.23.1__py3-none-any.whl → 0.25.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 +26 -2
- diffusers/commands/fp16_safetensors.py +10 -11
- diffusers/configuration_utils.py +13 -8
- diffusers/dependency_versions_check.py +0 -1
- diffusers/dependency_versions_table.py +5 -5
- diffusers/experimental/rl/value_guided_sampling.py +1 -1
- diffusers/image_processor.py +463 -51
- diffusers/loaders/__init__.py +82 -0
- diffusers/loaders/ip_adapter.py +159 -0
- diffusers/loaders/lora.py +1553 -0
- diffusers/loaders/lora_conversion_utils.py +284 -0
- diffusers/loaders/single_file.py +637 -0
- diffusers/loaders/textual_inversion.py +455 -0
- diffusers/loaders/unet.py +828 -0
- diffusers/loaders/utils.py +59 -0
- diffusers/models/__init__.py +26 -9
- diffusers/models/activations.py +9 -6
- diffusers/models/attention.py +301 -29
- diffusers/models/attention_flax.py +9 -1
- diffusers/models/attention_processor.py +378 -6
- diffusers/models/autoencoders/__init__.py +5 -0
- diffusers/models/{autoencoder_asym_kl.py → autoencoders/autoencoder_asym_kl.py} +17 -12
- diffusers/models/{autoencoder_kl.py → autoencoders/autoencoder_kl.py} +47 -23
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +402 -0
- diffusers/models/{autoencoder_tiny.py → autoencoders/autoencoder_tiny.py} +24 -28
- diffusers/models/{consistency_decoder_vae.py → autoencoders/consistency_decoder_vae.py} +51 -44
- diffusers/models/{vae.py → autoencoders/vae.py} +71 -17
- diffusers/models/controlnet.py +59 -39
- diffusers/models/controlnet_flax.py +19 -18
- diffusers/models/downsampling.py +338 -0
- diffusers/models/embeddings.py +112 -29
- diffusers/models/embeddings_flax.py +2 -0
- diffusers/models/lora.py +131 -1
- diffusers/models/modeling_flax_utils.py +14 -8
- diffusers/models/modeling_outputs.py +17 -0
- diffusers/models/modeling_utils.py +37 -29
- diffusers/models/normalization.py +110 -4
- diffusers/models/resnet.py +299 -652
- diffusers/models/transformer_2d.py +22 -5
- diffusers/models/transformer_temporal.py +183 -1
- diffusers/models/unet_2d_blocks_flax.py +5 -0
- diffusers/models/unet_2d_condition.py +46 -0
- diffusers/models/unet_2d_condition_flax.py +13 -13
- diffusers/models/unet_3d_blocks.py +957 -173
- diffusers/models/unet_3d_condition.py +16 -8
- diffusers/models/unet_kandinsky3.py +535 -0
- diffusers/models/unet_motion_model.py +48 -33
- diffusers/models/unet_spatio_temporal_condition.py +489 -0
- diffusers/models/upsampling.py +454 -0
- diffusers/models/uvit_2d.py +471 -0
- diffusers/models/vae_flax.py +7 -0
- diffusers/models/vq_model.py +12 -3
- diffusers/optimization.py +16 -9
- diffusers/pipelines/__init__.py +137 -76
- diffusers/pipelines/amused/__init__.py +62 -0
- diffusers/pipelines/amused/pipeline_amused.py +328 -0
- diffusers/pipelines/amused/pipeline_amused_img2img.py +347 -0
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +378 -0
- diffusers/pipelines/animatediff/pipeline_animatediff.py +66 -8
- diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
- diffusers/pipelines/auto_pipeline.py +23 -13
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
- diffusers/pipelines/controlnet/pipeline_controlnet.py +238 -35
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +148 -37
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +155 -41
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +123 -43
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +216 -39
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +106 -34
- diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
- diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
- diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
- diffusers/pipelines/deprecated/__init__.py +153 -0
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/__init__.py +3 -3
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion.py +177 -34
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py +182 -37
- diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_output.py +1 -1
- diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/__init__.py +1 -1
- diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/mel.py +2 -2
- diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py +4 -4
- diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/__init__.py +1 -1
- diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/pipeline_latent_diffusion_uncond.py +4 -4
- diffusers/pipelines/{pndm → deprecated/pndm}/__init__.py +1 -1
- diffusers/pipelines/{pndm → deprecated/pndm}/pipeline_pndm.py +4 -4
- diffusers/pipelines/{repaint → deprecated/repaint}/__init__.py +1 -1
- diffusers/pipelines/{repaint → deprecated/repaint}/pipeline_repaint.py +5 -5
- diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/__init__.py +1 -1
- diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/pipeline_score_sde_ve.py +5 -4
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/__init__.py +6 -6
- diffusers/pipelines/{spectrogram_diffusion/continous_encoder.py → deprecated/spectrogram_diffusion/continuous_encoder.py} +2 -2
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/midi_utils.py +1 -1
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py +2 -2
- diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/pipeline_spectrogram_diffusion.py +8 -7
- diffusers/pipelines/deprecated/stable_diffusion_variants/__init__.py +55 -0
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_cycle_diffusion.py +34 -13
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_onnx_stable_diffusion_inpaint_legacy.py +7 -6
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_inpaint_legacy.py +12 -11
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_model_editing.py +17 -11
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_paradigms.py +11 -10
- diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_pix2pix_zero.py +14 -13
- diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/__init__.py +1 -1
- diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/pipeline_stochastic_karras_ve.py +4 -4
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/__init__.py +3 -3
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/modeling_text_unet.py +83 -51
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion.py +4 -4
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_dual_guided.py +7 -6
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_image_variation.py +7 -6
- diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_text_to_image.py +7 -6
- diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/__init__.py +3 -3
- diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/pipeline_vq_diffusion.py +5 -5
- diffusers/pipelines/dit/pipeline_dit.py +1 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
- diffusers/pipelines/kandinsky3/__init__.py +49 -0
- diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +98 -0
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +589 -0
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +654 -0
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +111 -11
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +102 -9
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
- diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
- diffusers/pipelines/onnx_utils.py +8 -5
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
- diffusers/pipelines/pipeline_flax_utils.py +11 -8
- diffusers/pipelines/pipeline_utils.py +63 -42
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +247 -38
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +3 -3
- diffusers/pipelines/stable_diffusion/__init__.py +37 -65
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +75 -78
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +174 -11
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +178 -11
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +224 -13
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +74 -20
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +4 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +7 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -0
- diffusers/pipelines/stable_diffusion_attend_and_excite/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_attend_and_excite}/pipeline_stable_diffusion_attend_and_excite.py +6 -2
- diffusers/pipelines/stable_diffusion_diffedit/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_diffedit}/pipeline_stable_diffusion_diffedit.py +3 -3
- diffusers/pipelines/stable_diffusion_gligen/__init__.py +50 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py +3 -2
- diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen_text_image.py +4 -3
- diffusers/pipelines/stable_diffusion_k_diffusion/__init__.py +60 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_k_diffusion}/pipeline_stable_diffusion_k_diffusion.py +7 -1
- diffusers/pipelines/stable_diffusion_ldm3d/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py +51 -7
- diffusers/pipelines/stable_diffusion_panorama/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_panorama}/pipeline_stable_diffusion_panorama.py +57 -8
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +58 -6
- diffusers/pipelines/stable_diffusion_sag/__init__.py +48 -0
- diffusers/pipelines/{stable_diffusion → stable_diffusion_sag}/pipeline_stable_diffusion_sag.py +68 -10
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +194 -17
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +205 -16
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +206 -17
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +23 -17
- diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +652 -0
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +115 -14
- diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +6 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +23 -3
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +334 -10
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +1331 -0
- diffusers/pipelines/unclip/pipeline_unclip.py +2 -1
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -0
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +5 -1
- diffusers/schedulers/__init__.py +4 -4
- diffusers/schedulers/deprecated/__init__.py +50 -0
- diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
- diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
- diffusers/schedulers/scheduling_amused.py +162 -0
- diffusers/schedulers/scheduling_consistency_models.py +2 -0
- diffusers/schedulers/scheduling_ddim.py +1 -3
- diffusers/schedulers/scheduling_ddim_inverse.py +2 -7
- diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
- diffusers/schedulers/scheduling_ddpm.py +47 -3
- diffusers/schedulers/scheduling_ddpm_parallel.py +47 -3
- diffusers/schedulers/scheduling_deis_multistep.py +28 -6
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +28 -6
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +28 -6
- diffusers/schedulers/scheduling_dpmsolver_sde.py +3 -3
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +28 -6
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +59 -3
- diffusers/schedulers/scheduling_euler_discrete.py +102 -16
- diffusers/schedulers/scheduling_heun_discrete.py +17 -5
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +17 -5
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +17 -5
- diffusers/schedulers/scheduling_lcm.py +123 -29
- diffusers/schedulers/scheduling_lms_discrete.py +3 -3
- diffusers/schedulers/scheduling_pndm.py +1 -3
- diffusers/schedulers/scheduling_repaint.py +1 -3
- diffusers/schedulers/scheduling_unipc_multistep.py +28 -6
- diffusers/schedulers/scheduling_utils.py +3 -1
- diffusers/schedulers/scheduling_utils_flax.py +3 -1
- diffusers/training_utils.py +1 -1
- diffusers/utils/__init__.py +1 -2
- diffusers/utils/constants.py +10 -12
- diffusers/utils/dummy_pt_objects.py +75 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +105 -0
- diffusers/utils/dynamic_modules_utils.py +18 -22
- diffusers/utils/export_utils.py +8 -3
- diffusers/utils/hub_utils.py +24 -36
- diffusers/utils/logging.py +11 -11
- diffusers/utils/outputs.py +5 -5
- diffusers/utils/peft_utils.py +88 -44
- diffusers/utils/state_dict_utils.py +8 -0
- diffusers/utils/testing_utils.py +199 -1
- diffusers/utils/torch_utils.py +4 -4
- {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/METADATA +86 -69
- diffusers-0.25.0.dist-info/RECORD +360 -0
- {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/WHEEL +1 -1
- {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/entry_points.txt +0 -1
- diffusers/loaders.py +0 -3336
- diffusers-0.23.1.dist-info/RECORD +0 -323
- /diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/modeling_roberta_series.py +0 -0
- {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/LICENSE +0 -0
- {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/top_level.txt +0 -0
@@ -76,6 +76,12 @@ class StableDiffusionUpscalePipeline(
|
|
76
76
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
|
77
77
|
implemented for all pipelines (downloading, saving, running on a particular device, etc.).
|
78
78
|
|
79
|
+
The pipeline also inherits the following loading methods:
|
80
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
81
|
+
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
82
|
+
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
83
|
+
- [`~loaders.FromSingleFileMixin.from_single_file`] for loading `.ckpt` files
|
84
|
+
|
79
85
|
Args:
|
80
86
|
vae ([`AutoencoderKL`]):
|
81
87
|
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
|
@@ -92,6 +98,7 @@ class StableDiffusionUpscalePipeline(
|
|
92
98
|
A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
|
93
99
|
[`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
|
94
100
|
"""
|
101
|
+
|
95
102
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
96
103
|
_optional_components = ["watermarker", "safety_checker", "feature_extractor"]
|
97
104
|
_exclude_from_cpu_offload = ["safety_checker"]
|
@@ -65,6 +65,11 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
65
65
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
|
66
66
|
implemented for all pipelines (downloading, saving, running on a particular device, etc.).
|
67
67
|
|
68
|
+
The pipeline also inherits the following loading methods:
|
69
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
70
|
+
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
71
|
+
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
72
|
+
|
68
73
|
Args:
|
69
74
|
prior_tokenizer ([`CLIPTokenizer`]):
|
70
75
|
A [`CLIPTokenizer`].
|
@@ -76,6 +76,11 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
|
|
76
76
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
|
77
77
|
implemented for all pipelines (downloading, saving, running on a particular device, etc.).
|
78
78
|
|
79
|
+
The pipeline also inherits the following loading methods:
|
80
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
81
|
+
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
82
|
+
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
83
|
+
|
79
84
|
Args:
|
80
85
|
feature_extractor ([`CLIPImageProcessor`]):
|
81
86
|
Feature extractor for image pre-processing before being encoded.
|
@@ -0,0 +1,48 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from ...utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
|
+
OptionalDependencyNotAvailable,
|
6
|
+
_LazyModule,
|
7
|
+
get_objects_from_module,
|
8
|
+
is_torch_available,
|
9
|
+
is_transformers_available,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
_dummy_objects = {}
|
14
|
+
_import_structure = {}
|
15
|
+
|
16
|
+
|
17
|
+
try:
|
18
|
+
if not (is_transformers_available() and is_torch_available()):
|
19
|
+
raise OptionalDependencyNotAvailable()
|
20
|
+
except OptionalDependencyNotAvailable:
|
21
|
+
from ...utils import dummy_torch_and_transformers_objects # noqa F403
|
22
|
+
|
23
|
+
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
24
|
+
else:
|
25
|
+
_import_structure["pipeline_stable_diffusion_attend_and_excite"] = ["StableDiffusionAttendAndExcitePipeline"]
|
26
|
+
|
27
|
+
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
28
|
+
try:
|
29
|
+
if not (is_transformers_available() and is_torch_available()):
|
30
|
+
raise OptionalDependencyNotAvailable()
|
31
|
+
|
32
|
+
except OptionalDependencyNotAvailable:
|
33
|
+
from ...utils.dummy_torch_and_transformers_objects import *
|
34
|
+
else:
|
35
|
+
from .pipeline_stable_diffusion_attend_and_excite import StableDiffusionAttendAndExcitePipeline
|
36
|
+
|
37
|
+
else:
|
38
|
+
import sys
|
39
|
+
|
40
|
+
sys.modules[__name__] = _LazyModule(
|
41
|
+
__name__,
|
42
|
+
globals()["__file__"],
|
43
|
+
_import_structure,
|
44
|
+
module_spec=__spec__,
|
45
|
+
)
|
46
|
+
|
47
|
+
for name, value in _dummy_objects.items():
|
48
|
+
setattr(sys.modules[__name__], name, value)
|
@@ -37,8 +37,8 @@ from ...utils import (
|
|
37
37
|
)
|
38
38
|
from ...utils.torch_utils import randn_tensor
|
39
39
|
from ..pipeline_utils import DiffusionPipeline
|
40
|
-
from
|
41
|
-
from .safety_checker import StableDiffusionSafetyChecker
|
40
|
+
from ..stable_diffusion import StableDiffusionPipelineOutput
|
41
|
+
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
42
42
|
|
43
43
|
|
44
44
|
logger = logging.get_logger(__name__)
|
@@ -177,6 +177,9 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
|
|
177
177
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
|
178
178
|
implemented for all pipelines (downloading, saving, running on a particular device, etc.).
|
179
179
|
|
180
|
+
The pipeline also inherits the following loading methods:
|
181
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
182
|
+
|
180
183
|
Args:
|
181
184
|
vae ([`AutoencoderKL`]):
|
182
185
|
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
|
@@ -196,6 +199,7 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
|
|
196
199
|
feature_extractor ([`~transformers.CLIPImageProcessor`]):
|
197
200
|
A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
|
198
201
|
"""
|
202
|
+
|
199
203
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
200
204
|
_optional_components = ["safety_checker", "feature_extractor"]
|
201
205
|
_exclude_from_cpu_offload = ["safety_checker"]
|
@@ -0,0 +1,48 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from ...utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
|
+
OptionalDependencyNotAvailable,
|
6
|
+
_LazyModule,
|
7
|
+
get_objects_from_module,
|
8
|
+
is_torch_available,
|
9
|
+
is_transformers_available,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
_dummy_objects = {}
|
14
|
+
_import_structure = {}
|
15
|
+
|
16
|
+
|
17
|
+
try:
|
18
|
+
if not (is_transformers_available() and is_torch_available()):
|
19
|
+
raise OptionalDependencyNotAvailable()
|
20
|
+
except OptionalDependencyNotAvailable:
|
21
|
+
from ...utils import dummy_torch_and_transformers_objects # noqa F403
|
22
|
+
|
23
|
+
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
24
|
+
else:
|
25
|
+
_import_structure["pipeline_stable_diffusion_diffedit"] = ["StableDiffusionDiffEditPipeline"]
|
26
|
+
|
27
|
+
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
28
|
+
try:
|
29
|
+
if not (is_transformers_available() and is_torch_available()):
|
30
|
+
raise OptionalDependencyNotAvailable()
|
31
|
+
|
32
|
+
except OptionalDependencyNotAvailable:
|
33
|
+
from ...utils.dummy_torch_and_transformers_objects import *
|
34
|
+
else:
|
35
|
+
from .pipeline_stable_diffusion_diffedit import StableDiffusionDiffEditPipeline
|
36
|
+
|
37
|
+
else:
|
38
|
+
import sys
|
39
|
+
|
40
|
+
sys.modules[__name__] = _LazyModule(
|
41
|
+
__name__,
|
42
|
+
globals()["__file__"],
|
43
|
+
_import_structure,
|
44
|
+
module_spec=__spec__,
|
45
|
+
)
|
46
|
+
|
47
|
+
for name, value in _dummy_objects.items():
|
48
|
+
setattr(sys.modules[__name__], name, value)
|
@@ -40,8 +40,8 @@ from ...utils import (
|
|
40
40
|
)
|
41
41
|
from ...utils.torch_utils import randn_tensor
|
42
42
|
from ..pipeline_utils import DiffusionPipeline
|
43
|
-
from
|
44
|
-
from .safety_checker import StableDiffusionSafetyChecker
|
43
|
+
from ..stable_diffusion import StableDiffusionPipelineOutput
|
44
|
+
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
45
45
|
|
46
46
|
|
47
47
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -273,6 +273,7 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
273
273
|
feature_extractor ([`~transformers.CLIPImageProcessor`]):
|
274
274
|
A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
|
275
275
|
"""
|
276
|
+
|
276
277
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
277
278
|
_optional_components = ["safety_checker", "feature_extractor", "inverse_scheduler"]
|
278
279
|
_exclude_from_cpu_offload = ["safety_checker"]
|
@@ -787,7 +788,6 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
|
|
787
788
|
latents = latents * self.scheduler.init_noise_sigma
|
788
789
|
return latents
|
789
790
|
|
790
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_pix2pix_zero.StableDiffusionPix2PixZeroPipeline.prepare_image_latents
|
791
791
|
def prepare_image_latents(self, image, batch_size, dtype, device, generator=None):
|
792
792
|
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
|
793
793
|
raise ValueError(
|
@@ -0,0 +1,50 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from ...utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
|
+
OptionalDependencyNotAvailable,
|
6
|
+
_LazyModule,
|
7
|
+
get_objects_from_module,
|
8
|
+
is_torch_available,
|
9
|
+
is_transformers_available,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
_dummy_objects = {}
|
14
|
+
_import_structure = {}
|
15
|
+
|
16
|
+
|
17
|
+
try:
|
18
|
+
if not (is_transformers_available() and is_torch_available()):
|
19
|
+
raise OptionalDependencyNotAvailable()
|
20
|
+
except OptionalDependencyNotAvailable:
|
21
|
+
from ...utils import dummy_torch_and_transformers_objects # noqa F403
|
22
|
+
|
23
|
+
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
24
|
+
else:
|
25
|
+
_import_structure["pipeline_stable_diffusion_gligen"] = ["StableDiffusionGLIGENPipeline"]
|
26
|
+
_import_structure["pipeline_stable_diffusion_gligen_text_image"] = ["StableDiffusionGLIGENTextImagePipeline"]
|
27
|
+
|
28
|
+
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
29
|
+
try:
|
30
|
+
if not (is_transformers_available() and is_torch_available()):
|
31
|
+
raise OptionalDependencyNotAvailable()
|
32
|
+
|
33
|
+
except OptionalDependencyNotAvailable:
|
34
|
+
from ...utils.dummy_torch_and_transformers_objects import *
|
35
|
+
else:
|
36
|
+
from .pipeline_stable_diffusion_gligen import StableDiffusionGLIGENPipeline
|
37
|
+
from .pipeline_stable_diffusion_gligen_text_image import StableDiffusionGLIGENTextImagePipeline
|
38
|
+
|
39
|
+
else:
|
40
|
+
import sys
|
41
|
+
|
42
|
+
sys.modules[__name__] = _LazyModule(
|
43
|
+
__name__,
|
44
|
+
globals()["__file__"],
|
45
|
+
_import_structure,
|
46
|
+
module_spec=__spec__,
|
47
|
+
)
|
48
|
+
|
49
|
+
for name, value in _dummy_objects.items():
|
50
|
+
setattr(sys.modules[__name__], name, value)
|
diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py
RENAMED
@@ -36,8 +36,8 @@ from ...utils import (
|
|
36
36
|
)
|
37
37
|
from ...utils.torch_utils import randn_tensor
|
38
38
|
from ..pipeline_utils import DiffusionPipeline
|
39
|
-
from
|
40
|
-
from .safety_checker import StableDiffusionSafetyChecker
|
39
|
+
from ..stable_diffusion import StableDiffusionPipelineOutput
|
40
|
+
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
41
41
|
|
42
42
|
|
43
43
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -125,6 +125,7 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
|
|
125
125
|
feature_extractor ([`~transformers.CLIPImageProcessor`]):
|
126
126
|
A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
|
127
127
|
"""
|
128
|
+
|
128
129
|
_optional_components = ["safety_checker", "feature_extractor"]
|
129
130
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
130
131
|
_exclude_from_cpu_offload = ["safety_checker"]
|
@@ -35,9 +35,9 @@ from ...schedulers import KarrasDiffusionSchedulers
|
|
35
35
|
from ...utils import USE_PEFT_BACKEND, logging, replace_example_docstring, scale_lora_layers, unscale_lora_layers
|
36
36
|
from ...utils.torch_utils import randn_tensor
|
37
37
|
from ..pipeline_utils import DiffusionPipeline
|
38
|
-
from
|
39
|
-
from .clip_image_project_model import CLIPImageProjection
|
40
|
-
from .safety_checker import StableDiffusionSafetyChecker
|
38
|
+
from ..stable_diffusion import StableDiffusionPipelineOutput
|
39
|
+
from ..stable_diffusion.clip_image_project_model import CLIPImageProjection
|
40
|
+
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
41
41
|
|
42
42
|
|
43
43
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -177,6 +177,7 @@ class StableDiffusionGLIGENTextImagePipeline(DiffusionPipeline):
|
|
177
177
|
feature_extractor ([`~transformers.CLIPImageProcessor`]):
|
178
178
|
A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
|
179
179
|
"""
|
180
|
+
|
180
181
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
181
182
|
_optional_components = ["safety_checker", "feature_extractor"]
|
182
183
|
_exclude_from_cpu_offload = ["safety_checker"]
|
@@ -0,0 +1,60 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from ...utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
|
+
OptionalDependencyNotAvailable,
|
6
|
+
_LazyModule,
|
7
|
+
get_objects_from_module,
|
8
|
+
is_k_diffusion_available,
|
9
|
+
is_k_diffusion_version,
|
10
|
+
is_torch_available,
|
11
|
+
is_transformers_available,
|
12
|
+
)
|
13
|
+
|
14
|
+
|
15
|
+
_dummy_objects = {}
|
16
|
+
_import_structure = {}
|
17
|
+
|
18
|
+
|
19
|
+
try:
|
20
|
+
if not (
|
21
|
+
is_transformers_available()
|
22
|
+
and is_torch_available()
|
23
|
+
and is_k_diffusion_available()
|
24
|
+
and is_k_diffusion_version(">=", "0.0.12")
|
25
|
+
):
|
26
|
+
raise OptionalDependencyNotAvailable()
|
27
|
+
except OptionalDependencyNotAvailable:
|
28
|
+
from ...utils import dummy_torch_and_transformers_and_k_diffusion_objects # noqa F403
|
29
|
+
|
30
|
+
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_and_k_diffusion_objects))
|
31
|
+
else:
|
32
|
+
_import_structure["pipeline_stable_diffusion_k_diffusion"] = ["StableDiffusionKDiffusionPipeline"]
|
33
|
+
|
34
|
+
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
35
|
+
try:
|
36
|
+
if not (
|
37
|
+
is_transformers_available()
|
38
|
+
and is_torch_available()
|
39
|
+
and is_k_diffusion_available()
|
40
|
+
and is_k_diffusion_version(">=", "0.0.12")
|
41
|
+
):
|
42
|
+
raise OptionalDependencyNotAvailable()
|
43
|
+
|
44
|
+
except OptionalDependencyNotAvailable:
|
45
|
+
from ...utils.dummy_torch_and_transformers_and_k_diffusion_objects import *
|
46
|
+
else:
|
47
|
+
from .pipeline_stable_diffusion_k_diffusion import StableDiffusionKDiffusionPipeline
|
48
|
+
|
49
|
+
else:
|
50
|
+
import sys
|
51
|
+
|
52
|
+
sys.modules[__name__] = _LazyModule(
|
53
|
+
__name__,
|
54
|
+
globals()["__file__"],
|
55
|
+
_import_structure,
|
56
|
+
module_spec=__spec__,
|
57
|
+
)
|
58
|
+
|
59
|
+
for name, value in _dummy_objects.items():
|
60
|
+
setattr(sys.modules[__name__], name, value)
|
@@ -27,7 +27,7 @@ from ...schedulers import LMSDiscreteScheduler
|
|
27
27
|
from ...utils import USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
|
28
28
|
from ...utils.torch_utils import randn_tensor
|
29
29
|
from ..pipeline_utils import DiffusionPipeline
|
30
|
-
from
|
30
|
+
from ..stable_diffusion import StableDiffusionPipelineOutput
|
31
31
|
|
32
32
|
|
33
33
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -54,6 +54,11 @@ class StableDiffusionKDiffusionPipeline(DiffusionPipeline, TextualInversionLoade
|
|
54
54
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
|
55
55
|
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
|
56
56
|
|
57
|
+
The pipeline also inherits the following loading methods:
|
58
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
59
|
+
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
60
|
+
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
61
|
+
|
57
62
|
<Tip warning={true}>
|
58
63
|
|
59
64
|
This is an experimental pipeline and is likely to change in the future.
|
@@ -80,6 +85,7 @@ class StableDiffusionKDiffusionPipeline(DiffusionPipeline, TextualInversionLoade
|
|
80
85
|
feature_extractor ([`CLIPImageProcessor`]):
|
81
86
|
Model that extracts features from generated images to be used as inputs for the `safety_checker`.
|
82
87
|
"""
|
88
|
+
|
83
89
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
84
90
|
_optional_components = ["safety_checker", "feature_extractor"]
|
85
91
|
_exclude_from_cpu_offload = ["safety_checker"]
|
@@ -0,0 +1,48 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from ...utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
|
+
OptionalDependencyNotAvailable,
|
6
|
+
_LazyModule,
|
7
|
+
get_objects_from_module,
|
8
|
+
is_torch_available,
|
9
|
+
is_transformers_available,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
_dummy_objects = {}
|
14
|
+
_import_structure = {}
|
15
|
+
|
16
|
+
|
17
|
+
try:
|
18
|
+
if not (is_transformers_available() and is_torch_available()):
|
19
|
+
raise OptionalDependencyNotAvailable()
|
20
|
+
except OptionalDependencyNotAvailable:
|
21
|
+
from ...utils import dummy_torch_and_transformers_objects # noqa F403
|
22
|
+
|
23
|
+
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
24
|
+
else:
|
25
|
+
_import_structure["pipeline_stable_diffusion_ldm3d"] = ["StableDiffusionLDM3DPipeline"]
|
26
|
+
|
27
|
+
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
28
|
+
try:
|
29
|
+
if not (is_transformers_available() and is_torch_available()):
|
30
|
+
raise OptionalDependencyNotAvailable()
|
31
|
+
|
32
|
+
except OptionalDependencyNotAvailable:
|
33
|
+
from ...utils.dummy_torch_and_transformers_objects import *
|
34
|
+
else:
|
35
|
+
from .pipeline_stable_diffusion_ldm3d import StableDiffusionLDM3DPipeline
|
36
|
+
|
37
|
+
else:
|
38
|
+
import sys
|
39
|
+
|
40
|
+
sys.modules[__name__] = _LazyModule(
|
41
|
+
__name__,
|
42
|
+
globals()["__file__"],
|
43
|
+
_import_structure,
|
44
|
+
module_spec=__spec__,
|
45
|
+
)
|
46
|
+
|
47
|
+
for name, value in _dummy_objects.items():
|
48
|
+
setattr(sys.modules[__name__], name, value)
|
diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py
RENAMED
@@ -19,11 +19,11 @@ from typing import Any, Callable, Dict, List, Optional, Union
|
|
19
19
|
import numpy as np
|
20
20
|
import PIL.Image
|
21
21
|
import torch
|
22
|
-
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
|
22
|
+
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
|
23
23
|
|
24
|
-
from ...image_processor import VaeImageProcessorLDM3D
|
25
|
-
from ...loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
26
|
-
from ...models import AutoencoderKL, UNet2DConditionModel
|
24
|
+
from ...image_processor import PipelineImageInput, VaeImageProcessorLDM3D
|
25
|
+
from ...loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
26
|
+
from ...models import AutoencoderKL, ImageProjection, UNet2DConditionModel
|
27
27
|
from ...models.lora import adjust_lora_scale_text_encoder
|
28
28
|
from ...schedulers import KarrasDiffusionSchedulers
|
29
29
|
from ...utils import (
|
@@ -37,7 +37,7 @@ from ...utils import (
|
|
37
37
|
)
|
38
38
|
from ...utils.torch_utils import randn_tensor
|
39
39
|
from ..pipeline_utils import DiffusionPipeline
|
40
|
-
from .safety_checker import StableDiffusionSafetyChecker
|
40
|
+
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
41
41
|
|
42
42
|
|
43
43
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -82,7 +82,7 @@ class LDM3DPipelineOutput(BaseOutput):
|
|
82
82
|
|
83
83
|
|
84
84
|
class StableDiffusionLDM3DPipeline(
|
85
|
-
DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
|
85
|
+
DiffusionPipeline, TextualInversionLoaderMixin, IPAdapterMixin, LoraLoaderMixin, FromSingleFileMixin
|
86
86
|
):
|
87
87
|
r"""
|
88
88
|
Pipeline for text-to-image and 3D generation using LDM3D.
|
@@ -95,6 +95,7 @@ class StableDiffusionLDM3DPipeline(
|
|
95
95
|
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
96
96
|
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
97
97
|
- [`~loaders.FromSingleFileMixin.from_single_file`] for loading `.ckpt` files
|
98
|
+
- [`~loaders.IPAdapterMixin.load_ip_adapter`] for loading IP Adapters
|
98
99
|
|
99
100
|
Args:
|
100
101
|
vae ([`AutoencoderKL`]):
|
@@ -115,8 +116,9 @@ class StableDiffusionLDM3DPipeline(
|
|
115
116
|
feature_extractor ([`~transformers.CLIPImageProcessor`]):
|
116
117
|
A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
|
117
118
|
"""
|
119
|
+
|
118
120
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
119
|
-
_optional_components = ["safety_checker", "feature_extractor"]
|
121
|
+
_optional_components = ["safety_checker", "feature_extractor", "image_encoder"]
|
120
122
|
_exclude_from_cpu_offload = ["safety_checker"]
|
121
123
|
|
122
124
|
def __init__(
|
@@ -128,6 +130,7 @@ class StableDiffusionLDM3DPipeline(
|
|
128
130
|
scheduler: KarrasDiffusionSchedulers,
|
129
131
|
safety_checker: StableDiffusionSafetyChecker,
|
130
132
|
feature_extractor: CLIPImageProcessor,
|
133
|
+
image_encoder: Optional[CLIPVisionModelWithProjection],
|
131
134
|
requires_safety_checker: bool = True,
|
132
135
|
):
|
133
136
|
super().__init__()
|
@@ -156,6 +159,7 @@ class StableDiffusionLDM3DPipeline(
|
|
156
159
|
scheduler=scheduler,
|
157
160
|
safety_checker=safety_checker,
|
158
161
|
feature_extractor=feature_extractor,
|
162
|
+
image_encoder=image_encoder,
|
159
163
|
)
|
160
164
|
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
|
161
165
|
self.image_processor = VaeImageProcessorLDM3D(vae_scale_factor=self.vae_scale_factor)
|
@@ -409,6 +413,31 @@ class StableDiffusionLDM3DPipeline(
|
|
409
413
|
|
410
414
|
return prompt_embeds, negative_prompt_embeds
|
411
415
|
|
416
|
+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.encode_image
|
417
|
+
def encode_image(self, image, device, num_images_per_prompt, output_hidden_states=None):
|
418
|
+
dtype = next(self.image_encoder.parameters()).dtype
|
419
|
+
|
420
|
+
if not isinstance(image, torch.Tensor):
|
421
|
+
image = self.feature_extractor(image, return_tensors="pt").pixel_values
|
422
|
+
|
423
|
+
image = image.to(device=device, dtype=dtype)
|
424
|
+
if output_hidden_states:
|
425
|
+
image_enc_hidden_states = self.image_encoder(image, output_hidden_states=True).hidden_states[-2]
|
426
|
+
image_enc_hidden_states = image_enc_hidden_states.repeat_interleave(num_images_per_prompt, dim=0)
|
427
|
+
uncond_image_enc_hidden_states = self.image_encoder(
|
428
|
+
torch.zeros_like(image), output_hidden_states=True
|
429
|
+
).hidden_states[-2]
|
430
|
+
uncond_image_enc_hidden_states = uncond_image_enc_hidden_states.repeat_interleave(
|
431
|
+
num_images_per_prompt, dim=0
|
432
|
+
)
|
433
|
+
return image_enc_hidden_states, uncond_image_enc_hidden_states
|
434
|
+
else:
|
435
|
+
image_embeds = self.image_encoder(image).image_embeds
|
436
|
+
image_embeds = image_embeds.repeat_interleave(num_images_per_prompt, dim=0)
|
437
|
+
uncond_image_embeds = torch.zeros_like(image_embeds)
|
438
|
+
|
439
|
+
return image_embeds, uncond_image_embeds
|
440
|
+
|
412
441
|
def run_safety_checker(self, image, device, dtype):
|
413
442
|
if self.safety_checker is None:
|
414
443
|
has_nsfw_concept = None
|
@@ -528,6 +557,7 @@ class StableDiffusionLDM3DPipeline(
|
|
528
557
|
latents: Optional[torch.FloatTensor] = None,
|
529
558
|
prompt_embeds: Optional[torch.FloatTensor] = None,
|
530
559
|
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
560
|
+
ip_adapter_image: Optional[PipelineImageInput] = None,
|
531
561
|
output_type: Optional[str] = "pil",
|
532
562
|
return_dict: bool = True,
|
533
563
|
callback: Optional[Callable[[int, int, torch.FloatTensor], None]] = None,
|
@@ -572,6 +602,8 @@ class StableDiffusionLDM3DPipeline(
|
|
572
602
|
negative_prompt_embeds (`torch.FloatTensor`, *optional*):
|
573
603
|
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
|
574
604
|
not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
|
605
|
+
ip_adapter_image: (`PipelineImageInput`, *optional*):
|
606
|
+
Optional image input to work with IP Adapters.
|
575
607
|
output_type (`str`, *optional*, defaults to `"pil"`):
|
576
608
|
The output format of the generated image. Choose between `PIL.Image` or `np.array`.
|
577
609
|
return_dict (`bool`, *optional*, defaults to `True`):
|
@@ -621,6 +653,14 @@ class StableDiffusionLDM3DPipeline(
|
|
621
653
|
# corresponds to doing no classifier free guidance.
|
622
654
|
do_classifier_free_guidance = guidance_scale > 1.0
|
623
655
|
|
656
|
+
if ip_adapter_image is not None:
|
657
|
+
output_hidden_state = False if isinstance(self.unet.encoder_hid_proj, ImageProjection) else True
|
658
|
+
image_embeds, negative_image_embeds = self.encode_image(
|
659
|
+
ip_adapter_image, device, num_images_per_prompt, output_hidden_state
|
660
|
+
)
|
661
|
+
if do_classifier_free_guidance:
|
662
|
+
image_embeds = torch.cat([negative_image_embeds, image_embeds])
|
663
|
+
|
624
664
|
# 3. Encode input prompt
|
625
665
|
prompt_embeds, negative_prompt_embeds = self.encode_prompt(
|
626
666
|
prompt,
|
@@ -658,6 +698,9 @@ class StableDiffusionLDM3DPipeline(
|
|
658
698
|
# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
659
699
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
660
700
|
|
701
|
+
# 6.1 Add image embeds for IP-Adapter
|
702
|
+
added_cond_kwargs = {"image_embeds": image_embeds} if ip_adapter_image is not None else None
|
703
|
+
|
661
704
|
# 7. Denoising loop
|
662
705
|
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
|
663
706
|
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
@@ -672,6 +715,7 @@ class StableDiffusionLDM3DPipeline(
|
|
672
715
|
t,
|
673
716
|
encoder_hidden_states=prompt_embeds,
|
674
717
|
cross_attention_kwargs=cross_attention_kwargs,
|
718
|
+
added_cond_kwargs=added_cond_kwargs,
|
675
719
|
return_dict=False,
|
676
720
|
)[0]
|
677
721
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from ...utils import (
|
4
|
+
DIFFUSERS_SLOW_IMPORT,
|
5
|
+
OptionalDependencyNotAvailable,
|
6
|
+
_LazyModule,
|
7
|
+
get_objects_from_module,
|
8
|
+
is_torch_available,
|
9
|
+
is_transformers_available,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
_dummy_objects = {}
|
14
|
+
_import_structure = {}
|
15
|
+
|
16
|
+
|
17
|
+
try:
|
18
|
+
if not (is_transformers_available() and is_torch_available()):
|
19
|
+
raise OptionalDependencyNotAvailable()
|
20
|
+
except OptionalDependencyNotAvailable:
|
21
|
+
from ...utils import dummy_torch_and_transformers_objects # noqa F403
|
22
|
+
|
23
|
+
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
24
|
+
else:
|
25
|
+
_import_structure["pipeline_stable_diffusion_panorama"] = ["StableDiffusionPanoramaPipeline"]
|
26
|
+
|
27
|
+
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
28
|
+
try:
|
29
|
+
if not (is_transformers_available() and is_torch_available()):
|
30
|
+
raise OptionalDependencyNotAvailable()
|
31
|
+
|
32
|
+
except OptionalDependencyNotAvailable:
|
33
|
+
from ...utils.dummy_torch_and_transformers_objects import *
|
34
|
+
else:
|
35
|
+
from .pipeline_stable_diffusion_panorama import StableDiffusionPanoramaPipeline
|
36
|
+
|
37
|
+
else:
|
38
|
+
import sys
|
39
|
+
|
40
|
+
sys.modules[__name__] = _LazyModule(
|
41
|
+
__name__,
|
42
|
+
globals()["__file__"],
|
43
|
+
_import_structure,
|
44
|
+
module_spec=__spec__,
|
45
|
+
)
|
46
|
+
|
47
|
+
for name, value in _dummy_objects.items():
|
48
|
+
setattr(sys.modules[__name__], name, value)
|