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
@@ -118,6 +118,51 @@ def _preprocess_adapter_image(image, height, width):
|
|
118
118
|
return image
|
119
119
|
|
120
120
|
|
121
|
+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.retrieve_timesteps
|
122
|
+
def retrieve_timesteps(
|
123
|
+
scheduler,
|
124
|
+
num_inference_steps: Optional[int] = None,
|
125
|
+
device: Optional[Union[str, torch.device]] = None,
|
126
|
+
timesteps: Optional[List[int]] = None,
|
127
|
+
**kwargs,
|
128
|
+
):
|
129
|
+
"""
|
130
|
+
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
|
131
|
+
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
|
132
|
+
|
133
|
+
Args:
|
134
|
+
scheduler (`SchedulerMixin`):
|
135
|
+
The scheduler to get timesteps from.
|
136
|
+
num_inference_steps (`int`):
|
137
|
+
The number of diffusion steps used when generating samples with a pre-trained model. If used,
|
138
|
+
`timesteps` must be `None`.
|
139
|
+
device (`str` or `torch.device`, *optional*):
|
140
|
+
The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
|
141
|
+
timesteps (`List[int]`, *optional*):
|
142
|
+
Custom timesteps used to support arbitrary spacing between timesteps. If `None`, then the default
|
143
|
+
timestep spacing strategy of the scheduler is used. If `timesteps` is passed, `num_inference_steps`
|
144
|
+
must be `None`.
|
145
|
+
|
146
|
+
Returns:
|
147
|
+
`Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the
|
148
|
+
second element is the number of inference steps.
|
149
|
+
"""
|
150
|
+
if timesteps is not None:
|
151
|
+
accepts_timesteps = "timesteps" in set(inspect.signature(scheduler.set_timesteps).parameters.keys())
|
152
|
+
if not accepts_timesteps:
|
153
|
+
raise ValueError(
|
154
|
+
f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom"
|
155
|
+
f" timestep schedules. Please check whether you are using the correct scheduler."
|
156
|
+
)
|
157
|
+
scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs)
|
158
|
+
timesteps = scheduler.timesteps
|
159
|
+
num_inference_steps = len(timesteps)
|
160
|
+
else:
|
161
|
+
scheduler.set_timesteps(num_inference_steps, device=device, **kwargs)
|
162
|
+
timesteps = scheduler.timesteps
|
163
|
+
return timesteps, num_inference_steps
|
164
|
+
|
165
|
+
|
121
166
|
class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
122
167
|
r"""
|
123
168
|
Pipeline for text-to-image generation using Stable Diffusion augmented with T2I-Adapter
|
@@ -152,6 +197,7 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
152
197
|
feature_extractor ([`CLIPFeatureExtractor`]):
|
153
198
|
Model that extracts features from generated images to be used as inputs for the `safety_checker`.
|
154
199
|
"""
|
200
|
+
|
155
201
|
model_cpu_offload_seq = "text_encoder->adapter->unet->vae"
|
156
202
|
_optional_components = ["safety_checker", "feature_extractor"]
|
157
203
|
|
@@ -610,6 +656,46 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
610
656
|
"""Disables the FreeU mechanism if enabled."""
|
611
657
|
self.unet.disable_freeu()
|
612
658
|
|
659
|
+
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
|
660
|
+
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
661
|
+
"""
|
662
|
+
See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
|
663
|
+
|
664
|
+
Args:
|
665
|
+
timesteps (`torch.Tensor`):
|
666
|
+
generate embedding vectors at these timesteps
|
667
|
+
embedding_dim (`int`, *optional*, defaults to 512):
|
668
|
+
dimension of the embeddings to generate
|
669
|
+
dtype:
|
670
|
+
data type of the generated embeddings
|
671
|
+
|
672
|
+
Returns:
|
673
|
+
`torch.FloatTensor`: Embedding vectors with shape `(len(timesteps), embedding_dim)`
|
674
|
+
"""
|
675
|
+
assert len(w.shape) == 1
|
676
|
+
w = w * 1000.0
|
677
|
+
|
678
|
+
half_dim = embedding_dim // 2
|
679
|
+
emb = torch.log(torch.tensor(10000.0)) / (half_dim - 1)
|
680
|
+
emb = torch.exp(torch.arange(half_dim, dtype=dtype) * -emb)
|
681
|
+
emb = w.to(dtype)[:, None] * emb[None, :]
|
682
|
+
emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1)
|
683
|
+
if embedding_dim % 2 == 1: # zero pad
|
684
|
+
emb = torch.nn.functional.pad(emb, (0, 1))
|
685
|
+
assert emb.shape == (w.shape[0], embedding_dim)
|
686
|
+
return emb
|
687
|
+
|
688
|
+
@property
|
689
|
+
def guidance_scale(self):
|
690
|
+
return self._guidance_scale
|
691
|
+
|
692
|
+
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
|
693
|
+
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
|
694
|
+
# corresponds to doing no classifier free guidance.
|
695
|
+
@property
|
696
|
+
def do_classifier_free_guidance(self):
|
697
|
+
return self._guidance_scale > 1 and self.unet.config.time_cond_proj_dim is None
|
698
|
+
|
613
699
|
@torch.no_grad()
|
614
700
|
@replace_example_docstring(EXAMPLE_DOC_STRING)
|
615
701
|
def __call__(
|
@@ -619,6 +705,7 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
619
705
|
height: Optional[int] = None,
|
620
706
|
width: Optional[int] = None,
|
621
707
|
num_inference_steps: int = 50,
|
708
|
+
timesteps: List[int] = None,
|
622
709
|
guidance_scale: float = 7.5,
|
623
710
|
negative_prompt: Optional[Union[str, List[str]]] = None,
|
624
711
|
num_images_per_prompt: Optional[int] = 1,
|
@@ -653,6 +740,10 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
653
740
|
num_inference_steps (`int`, *optional*, defaults to 50):
|
654
741
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
655
742
|
expense of slower inference.
|
743
|
+
timesteps (`List[int]`, *optional*):
|
744
|
+
Custom timesteps to use for the denoising process with schedulers which support a `timesteps` argument
|
745
|
+
in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is
|
746
|
+
passed will be used. Must be in descending order.
|
656
747
|
guidance_scale (`float`, *optional*, defaults to 7.5):
|
657
748
|
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
|
658
749
|
`guidance_scale` is defined as `w` of equation 2. of [Imagen
|
@@ -723,6 +814,8 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
723
814
|
prompt, height, width, callback_steps, image, negative_prompt, prompt_embeds, negative_prompt_embeds
|
724
815
|
)
|
725
816
|
|
817
|
+
self._guidance_scale = guidance_scale
|
818
|
+
|
726
819
|
if isinstance(self.adapter, MultiAdapter):
|
727
820
|
adapter_input = []
|
728
821
|
|
@@ -742,17 +835,12 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
742
835
|
else:
|
743
836
|
batch_size = prompt_embeds.shape[0]
|
744
837
|
|
745
|
-
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
|
746
|
-
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
|
747
|
-
# corresponds to doing no classifier free guidance.
|
748
|
-
do_classifier_free_guidance = guidance_scale > 1.0
|
749
|
-
|
750
838
|
# 3. Encode input prompt
|
751
839
|
prompt_embeds, negative_prompt_embeds = self.encode_prompt(
|
752
840
|
prompt,
|
753
841
|
device,
|
754
842
|
num_images_per_prompt,
|
755
|
-
do_classifier_free_guidance,
|
843
|
+
self.do_classifier_free_guidance,
|
756
844
|
negative_prompt,
|
757
845
|
prompt_embeds=prompt_embeds,
|
758
846
|
negative_prompt_embeds=negative_prompt_embeds,
|
@@ -761,12 +849,11 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
761
849
|
# For classifier free guidance, we need to do two forward passes.
|
762
850
|
# Here we concatenate the unconditional and text embeddings into a single batch
|
763
851
|
# to avoid doing two forward passes
|
764
|
-
if do_classifier_free_guidance:
|
852
|
+
if self.do_classifier_free_guidance:
|
765
853
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
766
854
|
|
767
855
|
# 4. Prepare timesteps
|
768
|
-
self.scheduler
|
769
|
-
timesteps = self.scheduler.timesteps
|
856
|
+
timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, timesteps)
|
770
857
|
|
771
858
|
# 5. Prepare latent variables
|
772
859
|
num_channels_latents = self.unet.config.in_channels
|
@@ -784,6 +871,14 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
784
871
|
# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
785
872
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
786
873
|
|
874
|
+
# 6.5 Optionally get Guidance Scale Embedding
|
875
|
+
timestep_cond = None
|
876
|
+
if self.unet.config.time_cond_proj_dim is not None:
|
877
|
+
guidance_scale_tensor = torch.tensor(self.guidance_scale - 1).repeat(batch_size * num_images_per_prompt)
|
878
|
+
timestep_cond = self.get_guidance_scale_embedding(
|
879
|
+
guidance_scale_tensor, embedding_dim=self.unet.config.time_cond_proj_dim
|
880
|
+
).to(device=device, dtype=latents.dtype)
|
881
|
+
|
787
882
|
# 7. Denoising loop
|
788
883
|
if isinstance(self.adapter, MultiAdapter):
|
789
884
|
adapter_state = self.adapter(adapter_input, adapter_conditioning_scale)
|
@@ -796,7 +891,7 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
796
891
|
if num_images_per_prompt > 1:
|
797
892
|
for k, v in enumerate(adapter_state):
|
798
893
|
adapter_state[k] = v.repeat(num_images_per_prompt, 1, 1, 1)
|
799
|
-
if do_classifier_free_guidance:
|
894
|
+
if self.do_classifier_free_guidance:
|
800
895
|
for k, v in enumerate(adapter_state):
|
801
896
|
adapter_state[k] = torch.cat([v] * 2, dim=0)
|
802
897
|
|
@@ -804,7 +899,7 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
804
899
|
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
805
900
|
for i, t in enumerate(timesteps):
|
806
901
|
# expand the latents if we are doing classifier free guidance
|
807
|
-
latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents
|
902
|
+
latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents
|
808
903
|
latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
|
809
904
|
|
810
905
|
# predict the noise residual
|
@@ -812,13 +907,14 @@ class StableDiffusionAdapterPipeline(DiffusionPipeline):
|
|
812
907
|
latent_model_input,
|
813
908
|
t,
|
814
909
|
encoder_hidden_states=prompt_embeds,
|
910
|
+
timestep_cond=timestep_cond,
|
815
911
|
cross_attention_kwargs=cross_attention_kwargs,
|
816
912
|
down_intrablock_additional_residuals=[state.clone() for state in adapter_state],
|
817
913
|
return_dict=False,
|
818
914
|
)[0]
|
819
915
|
|
820
916
|
# perform guidance
|
821
|
-
if do_classifier_free_guidance:
|
917
|
+
if self.do_classifier_free_guidance:
|
822
918
|
noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)
|
823
919
|
noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
|
824
920
|
|
@@ -123,6 +123,51 @@ def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
|
|
123
123
|
return noise_cfg
|
124
124
|
|
125
125
|
|
126
|
+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.retrieve_timesteps
|
127
|
+
def retrieve_timesteps(
|
128
|
+
scheduler,
|
129
|
+
num_inference_steps: Optional[int] = None,
|
130
|
+
device: Optional[Union[str, torch.device]] = None,
|
131
|
+
timesteps: Optional[List[int]] = None,
|
132
|
+
**kwargs,
|
133
|
+
):
|
134
|
+
"""
|
135
|
+
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
|
136
|
+
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
|
137
|
+
|
138
|
+
Args:
|
139
|
+
scheduler (`SchedulerMixin`):
|
140
|
+
The scheduler to get timesteps from.
|
141
|
+
num_inference_steps (`int`):
|
142
|
+
The number of diffusion steps used when generating samples with a pre-trained model. If used,
|
143
|
+
`timesteps` must be `None`.
|
144
|
+
device (`str` or `torch.device`, *optional*):
|
145
|
+
The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
|
146
|
+
timesteps (`List[int]`, *optional*):
|
147
|
+
Custom timesteps used to support arbitrary spacing between timesteps. If `None`, then the default
|
148
|
+
timestep spacing strategy of the scheduler is used. If `timesteps` is passed, `num_inference_steps`
|
149
|
+
must be `None`.
|
150
|
+
|
151
|
+
Returns:
|
152
|
+
`Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the
|
153
|
+
second element is the number of inference steps.
|
154
|
+
"""
|
155
|
+
if timesteps is not None:
|
156
|
+
accepts_timesteps = "timesteps" in set(inspect.signature(scheduler.set_timesteps).parameters.keys())
|
157
|
+
if not accepts_timesteps:
|
158
|
+
raise ValueError(
|
159
|
+
f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom"
|
160
|
+
f" timestep schedules. Please check whether you are using the correct scheduler."
|
161
|
+
)
|
162
|
+
scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs)
|
163
|
+
timesteps = scheduler.timesteps
|
164
|
+
num_inference_steps = len(timesteps)
|
165
|
+
else:
|
166
|
+
scheduler.set_timesteps(num_inference_steps, device=device, **kwargs)
|
167
|
+
timesteps = scheduler.timesteps
|
168
|
+
return timesteps, num_inference_steps
|
169
|
+
|
170
|
+
|
126
171
|
class StableDiffusionXLAdapterPipeline(
|
127
172
|
DiffusionPipeline, FromSingleFileMixin, StableDiffusionXLLoraLoaderMixin, TextualInversionLoaderMixin
|
128
173
|
):
|
@@ -133,6 +178,12 @@ class StableDiffusionXLAdapterPipeline(
|
|
133
178
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
|
134
179
|
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
|
135
180
|
|
181
|
+
The pipeline also inherits the following loading methods:
|
182
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
183
|
+
- [`~loaders.FromSingleFileMixin.from_single_file`] for loading `.ckpt` files
|
184
|
+
- [`~loaders.StableDiffusionXLLoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
185
|
+
- [`~loaders.StableDiffusionXLLoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
186
|
+
|
136
187
|
Args:
|
137
188
|
adapter ([`T2IAdapter`] or [`MultiAdapter`] or `List[T2IAdapter]`):
|
138
189
|
Provides additional conditioning to the unet during the denoising process. If you set multiple Adapter as a
|
@@ -159,6 +210,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
159
210
|
feature_extractor ([`CLIPFeatureExtractor`]):
|
160
211
|
Model that extracts features from generated images to be used as inputs for the `safety_checker`.
|
161
212
|
"""
|
213
|
+
|
162
214
|
model_cpu_offload_seq = "text_encoder->text_encoder_2->unet->vae"
|
163
215
|
_optional_components = ["tokenizer", "tokenizer_2", "text_encoder", "text_encoder_2"]
|
164
216
|
|
@@ -670,6 +722,46 @@ class StableDiffusionXLAdapterPipeline(
|
|
670
722
|
"""Disables the FreeU mechanism if enabled."""
|
671
723
|
self.unet.disable_freeu()
|
672
724
|
|
725
|
+
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
|
726
|
+
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
|
727
|
+
"""
|
728
|
+
See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
|
729
|
+
|
730
|
+
Args:
|
731
|
+
timesteps (`torch.Tensor`):
|
732
|
+
generate embedding vectors at these timesteps
|
733
|
+
embedding_dim (`int`, *optional*, defaults to 512):
|
734
|
+
dimension of the embeddings to generate
|
735
|
+
dtype:
|
736
|
+
data type of the generated embeddings
|
737
|
+
|
738
|
+
Returns:
|
739
|
+
`torch.FloatTensor`: Embedding vectors with shape `(len(timesteps), embedding_dim)`
|
740
|
+
"""
|
741
|
+
assert len(w.shape) == 1
|
742
|
+
w = w * 1000.0
|
743
|
+
|
744
|
+
half_dim = embedding_dim // 2
|
745
|
+
emb = torch.log(torch.tensor(10000.0)) / (half_dim - 1)
|
746
|
+
emb = torch.exp(torch.arange(half_dim, dtype=dtype) * -emb)
|
747
|
+
emb = w.to(dtype)[:, None] * emb[None, :]
|
748
|
+
emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1)
|
749
|
+
if embedding_dim % 2 == 1: # zero pad
|
750
|
+
emb = torch.nn.functional.pad(emb, (0, 1))
|
751
|
+
assert emb.shape == (w.shape[0], embedding_dim)
|
752
|
+
return emb
|
753
|
+
|
754
|
+
@property
|
755
|
+
def guidance_scale(self):
|
756
|
+
return self._guidance_scale
|
757
|
+
|
758
|
+
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
|
759
|
+
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
|
760
|
+
# corresponds to doing no classifier free guidance.
|
761
|
+
@property
|
762
|
+
def do_classifier_free_guidance(self):
|
763
|
+
return self._guidance_scale > 1 and self.unet.config.time_cond_proj_dim is None
|
764
|
+
|
673
765
|
@torch.no_grad()
|
674
766
|
@replace_example_docstring(EXAMPLE_DOC_STRING)
|
675
767
|
def __call__(
|
@@ -680,6 +772,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
680
772
|
height: Optional[int] = None,
|
681
773
|
width: Optional[int] = None,
|
682
774
|
num_inference_steps: int = 50,
|
775
|
+
timesteps: List[int] = None,
|
683
776
|
denoising_end: Optional[float] = None,
|
684
777
|
guidance_scale: float = 5.0,
|
685
778
|
negative_prompt: Optional[Union[str, List[str]]] = None,
|
@@ -733,6 +826,10 @@ class StableDiffusionXLAdapterPipeline(
|
|
733
826
|
num_inference_steps (`int`, *optional*, defaults to 50):
|
734
827
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
735
828
|
expense of slower inference.
|
829
|
+
timesteps (`List[int]`, *optional*):
|
830
|
+
Custom timesteps to use for the denoising process with schedulers which support a `timesteps` argument
|
831
|
+
in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is
|
832
|
+
passed will be used. Must be in descending order.
|
736
833
|
denoising_end (`float`, *optional*):
|
737
834
|
When specified, determines the fraction (between 0.0 and 1.0) of the total denoising process to be
|
738
835
|
completed before it is intentionally prematurely terminated. As a result, the returned sample will
|
@@ -882,6 +979,8 @@ class StableDiffusionXLAdapterPipeline(
|
|
882
979
|
negative_pooled_prompt_embeds,
|
883
980
|
)
|
884
981
|
|
982
|
+
self._guidance_scale = guidance_scale
|
983
|
+
|
885
984
|
# 2. Define call parameters
|
886
985
|
if prompt is not None and isinstance(prompt, str):
|
887
986
|
batch_size = 1
|
@@ -892,11 +991,6 @@ class StableDiffusionXLAdapterPipeline(
|
|
892
991
|
|
893
992
|
device = self._execution_device
|
894
993
|
|
895
|
-
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
|
896
|
-
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
|
897
|
-
# corresponds to doing no classifier free guidance.
|
898
|
-
do_classifier_free_guidance = guidance_scale > 1.0
|
899
|
-
|
900
994
|
# 3. Encode input prompt
|
901
995
|
(
|
902
996
|
prompt_embeds,
|
@@ -908,7 +1002,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
908
1002
|
prompt_2=prompt_2,
|
909
1003
|
device=device,
|
910
1004
|
num_images_per_prompt=num_images_per_prompt,
|
911
|
-
do_classifier_free_guidance=do_classifier_free_guidance,
|
1005
|
+
do_classifier_free_guidance=self.do_classifier_free_guidance,
|
912
1006
|
negative_prompt=negative_prompt,
|
913
1007
|
negative_prompt_2=negative_prompt_2,
|
914
1008
|
prompt_embeds=prompt_embeds,
|
@@ -919,9 +1013,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
919
1013
|
)
|
920
1014
|
|
921
1015
|
# 4. Prepare timesteps
|
922
|
-
self.scheduler
|
923
|
-
|
924
|
-
timesteps = self.scheduler.timesteps
|
1016
|
+
timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, timesteps)
|
925
1017
|
|
926
1018
|
# 5. Prepare latent variables
|
927
1019
|
num_channels_latents = self.unet.config.in_channels
|
@@ -939,6 +1031,14 @@ class StableDiffusionXLAdapterPipeline(
|
|
939
1031
|
# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
940
1032
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
941
1033
|
|
1034
|
+
# 6.5 Optionally get Guidance Scale Embedding
|
1035
|
+
timestep_cond = None
|
1036
|
+
if self.unet.config.time_cond_proj_dim is not None:
|
1037
|
+
guidance_scale_tensor = torch.tensor(self.guidance_scale - 1).repeat(batch_size * num_images_per_prompt)
|
1038
|
+
timestep_cond = self.get_guidance_scale_embedding(
|
1039
|
+
guidance_scale_tensor, embedding_dim=self.unet.config.time_cond_proj_dim
|
1040
|
+
).to(device=device, dtype=latents.dtype)
|
1041
|
+
|
942
1042
|
# 7. Prepare added time ids & embeddings & adapter features
|
943
1043
|
if isinstance(self.adapter, MultiAdapter):
|
944
1044
|
adapter_state = self.adapter(adapter_input, adapter_conditioning_scale)
|
@@ -951,7 +1051,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
951
1051
|
if num_images_per_prompt > 1:
|
952
1052
|
for k, v in enumerate(adapter_state):
|
953
1053
|
adapter_state[k] = v.repeat(num_images_per_prompt, 1, 1, 1)
|
954
|
-
if do_classifier_free_guidance:
|
1054
|
+
if self.do_classifier_free_guidance:
|
955
1055
|
for k, v in enumerate(adapter_state):
|
956
1056
|
adapter_state[k] = torch.cat([v] * 2, dim=0)
|
957
1057
|
|
@@ -979,7 +1079,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
979
1079
|
else:
|
980
1080
|
negative_add_time_ids = add_time_ids
|
981
1081
|
|
982
|
-
if do_classifier_free_guidance:
|
1082
|
+
if self.do_classifier_free_guidance:
|
983
1083
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds], dim=0)
|
984
1084
|
add_text_embeds = torch.cat([negative_pooled_prompt_embeds, add_text_embeds], dim=0)
|
985
1085
|
add_time_ids = torch.cat([negative_add_time_ids, add_time_ids], dim=0)
|
@@ -1005,7 +1105,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
1005
1105
|
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
1006
1106
|
for i, t in enumerate(timesteps):
|
1007
1107
|
# expand the latents if we are doing classifier free guidance
|
1008
|
-
latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents
|
1108
|
+
latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents
|
1009
1109
|
|
1010
1110
|
latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
|
1011
1111
|
|
@@ -1021,6 +1121,7 @@ class StableDiffusionXLAdapterPipeline(
|
|
1021
1121
|
latent_model_input,
|
1022
1122
|
t,
|
1023
1123
|
encoder_hidden_states=prompt_embeds,
|
1124
|
+
timestep_cond=timestep_cond,
|
1024
1125
|
cross_attention_kwargs=cross_attention_kwargs,
|
1025
1126
|
added_cond_kwargs=added_cond_kwargs,
|
1026
1127
|
return_dict=False,
|
@@ -1028,11 +1129,11 @@ class StableDiffusionXLAdapterPipeline(
|
|
1028
1129
|
)[0]
|
1029
1130
|
|
1030
1131
|
# perform guidance
|
1031
|
-
if do_classifier_free_guidance:
|
1132
|
+
if self.do_classifier_free_guidance:
|
1032
1133
|
noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)
|
1033
1134
|
noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
|
1034
1135
|
|
1035
|
-
if do_classifier_free_guidance and guidance_rescale > 0.0:
|
1136
|
+
if self.do_classifier_free_guidance and guidance_rescale > 0.0:
|
1036
1137
|
# Based on 3.4. in https://arxiv.org/pdf/2305.08891.pdf
|
1037
1138
|
noise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=guidance_rescale)
|
1038
1139
|
|
@@ -25,6 +25,7 @@ else:
|
|
25
25
|
_import_structure["pipeline_text_to_video_synth"] = ["TextToVideoSDPipeline"]
|
26
26
|
_import_structure["pipeline_text_to_video_synth_img2img"] = ["VideoToVideoSDPipeline"]
|
27
27
|
_import_structure["pipeline_text_to_video_zero"] = ["TextToVideoZeroPipeline"]
|
28
|
+
_import_structure["pipeline_text_to_video_zero_sdxl"] = ["TextToVideoZeroSDXLPipeline"]
|
28
29
|
|
29
30
|
|
30
31
|
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
@@ -38,6 +39,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
38
39
|
from .pipeline_text_to_video_synth import TextToVideoSDPipeline
|
39
40
|
from .pipeline_text_to_video_synth_img2img import VideoToVideoSDPipeline
|
40
41
|
from .pipeline_text_to_video_zero import TextToVideoZeroPipeline
|
42
|
+
from .pipeline_text_to_video_zero_sdxl import TextToVideoZeroSDXLPipeline
|
41
43
|
|
42
44
|
else:
|
43
45
|
import sys
|
@@ -83,6 +83,11 @@ class TextToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lora
|
|
83
83
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
|
84
84
|
implemented for all pipelines (downloading, saving, running on a particular device, etc.).
|
85
85
|
|
86
|
+
The pipeline also inherits the following loading methods:
|
87
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
88
|
+
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
89
|
+
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
90
|
+
|
86
91
|
Args:
|
87
92
|
vae ([`AutoencoderKL`]):
|
88
93
|
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
|
@@ -96,6 +101,7 @@ class TextToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lora
|
|
96
101
|
A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
|
97
102
|
[`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
|
98
103
|
"""
|
104
|
+
|
99
105
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
100
106
|
|
101
107
|
def __init__(
|
@@ -79,6 +79,20 @@ EXAMPLE_DOC_STRING = """
|
|
79
79
|
"""
|
80
80
|
|
81
81
|
|
82
|
+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.retrieve_latents
|
83
|
+
def retrieve_latents(
|
84
|
+
encoder_output: torch.Tensor, generator: Optional[torch.Generator] = None, sample_mode: str = "sample"
|
85
|
+
):
|
86
|
+
if hasattr(encoder_output, "latent_dist") and sample_mode == "sample":
|
87
|
+
return encoder_output.latent_dist.sample(generator)
|
88
|
+
elif hasattr(encoder_output, "latent_dist") and sample_mode == "argmax":
|
89
|
+
return encoder_output.latent_dist.mode()
|
90
|
+
elif hasattr(encoder_output, "latents"):
|
91
|
+
return encoder_output.latents
|
92
|
+
else:
|
93
|
+
raise AttributeError("Could not access latents of provided encoder_output")
|
94
|
+
|
95
|
+
|
82
96
|
def tensor2vid(video: torch.Tensor, mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) -> List[np.ndarray]:
|
83
97
|
# This code is copied from https://github.com/modelscope/modelscope/blob/1509fdb973e5871f37148a4b5e5964cafd43e64d/modelscope/pipelines/multi_modal/text_to_video_synthesis_pipeline.py#L78
|
84
98
|
# reshape to ncfhw
|
@@ -145,6 +159,11 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
145
159
|
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
|
146
160
|
implemented for all pipelines (downloading, saving, running on a particular device, etc.).
|
147
161
|
|
162
|
+
The pipeline also inherits the following loading methods:
|
163
|
+
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
|
164
|
+
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
165
|
+
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
166
|
+
|
148
167
|
Args:
|
149
168
|
vae ([`AutoencoderKL`]):
|
150
169
|
Variational Auto-Encoder (VAE) Model to encode and decode videos to and from latent representations.
|
@@ -158,6 +177,7 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
158
177
|
A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
|
159
178
|
[`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
|
160
179
|
"""
|
180
|
+
|
161
181
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
162
182
|
|
163
183
|
def __init__(
|
@@ -546,14 +566,14 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
546
566
|
f"You have passed a list of generators of length {len(generator)}, but requested an effective batch"
|
547
567
|
f" size of {batch_size}. Make sure the batch size matches the length of the generators."
|
548
568
|
)
|
549
|
-
|
550
569
|
elif isinstance(generator, list):
|
551
570
|
init_latents = [
|
552
|
-
self.vae.encode(video[i : i + 1])
|
571
|
+
retrieve_latents(self.vae.encode(video[i : i + 1]), generator=generator[i])
|
572
|
+
for i in range(batch_size)
|
553
573
|
]
|
554
574
|
init_latents = torch.cat(init_latents, dim=0)
|
555
575
|
else:
|
556
|
-
init_latents = self.vae.encode(video)
|
576
|
+
init_latents = retrieve_latents(self.vae.encode(video), generator=generator)
|
557
577
|
|
558
578
|
init_latents = self.vae.config.scaling_factor * init_latents
|
559
579
|
|