diffusers 0.26.3__py3-none-any.whl → 0.27.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diffusers/__init__.py +20 -1
- diffusers/commands/__init__.py +1 -1
- diffusers/commands/diffusers_cli.py +1 -1
- diffusers/commands/env.py +1 -1
- diffusers/commands/fp16_safetensors.py +1 -1
- diffusers/configuration_utils.py +7 -3
- diffusers/dependency_versions_check.py +1 -1
- diffusers/dependency_versions_table.py +2 -2
- diffusers/experimental/rl/value_guided_sampling.py +1 -1
- diffusers/image_processor.py +110 -4
- diffusers/loaders/autoencoder.py +7 -8
- diffusers/loaders/controlnet.py +17 -8
- diffusers/loaders/ip_adapter.py +86 -23
- diffusers/loaders/lora.py +105 -310
- diffusers/loaders/lora_conversion_utils.py +1 -1
- diffusers/loaders/peft.py +1 -1
- diffusers/loaders/single_file.py +51 -12
- diffusers/loaders/single_file_utils.py +274 -49
- diffusers/loaders/textual_inversion.py +23 -4
- diffusers/loaders/unet.py +195 -41
- diffusers/loaders/utils.py +1 -1
- diffusers/models/__init__.py +3 -1
- diffusers/models/activations.py +9 -9
- diffusers/models/attention.py +26 -36
- diffusers/models/attention_flax.py +1 -1
- diffusers/models/attention_processor.py +171 -114
- diffusers/models/autoencoders/autoencoder_asym_kl.py +1 -1
- diffusers/models/autoencoders/autoencoder_kl.py +3 -1
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +1 -1
- diffusers/models/autoencoders/autoencoder_tiny.py +4 -2
- diffusers/models/autoencoders/consistency_decoder_vae.py +1 -1
- diffusers/models/autoencoders/vae.py +1 -1
- diffusers/models/controlnet.py +1 -1
- diffusers/models/controlnet_flax.py +1 -1
- diffusers/models/downsampling.py +8 -12
- diffusers/models/dual_transformer_2d.py +1 -1
- diffusers/models/embeddings.py +3 -4
- diffusers/models/embeddings_flax.py +1 -1
- diffusers/models/lora.py +33 -10
- diffusers/models/modeling_flax_pytorch_utils.py +1 -1
- diffusers/models/modeling_flax_utils.py +1 -1
- diffusers/models/modeling_pytorch_flax_utils.py +1 -1
- diffusers/models/modeling_utils.py +4 -6
- diffusers/models/normalization.py +1 -1
- diffusers/models/resnet.py +31 -58
- diffusers/models/resnet_flax.py +1 -1
- diffusers/models/t5_film_transformer.py +1 -1
- diffusers/models/transformer_2d.py +1 -1
- diffusers/models/transformer_temporal.py +1 -1
- diffusers/models/transformers/dual_transformer_2d.py +1 -1
- diffusers/models/transformers/t5_film_transformer.py +1 -1
- diffusers/models/transformers/transformer_2d.py +29 -31
- diffusers/models/transformers/transformer_temporal.py +1 -1
- diffusers/models/unet_1d.py +1 -1
- diffusers/models/unet_1d_blocks.py +1 -1
- diffusers/models/unet_2d.py +1 -1
- diffusers/models/unet_2d_blocks.py +1 -1
- diffusers/models/unet_2d_condition.py +1 -1
- diffusers/models/unets/__init__.py +1 -0
- diffusers/models/unets/unet_1d.py +1 -1
- diffusers/models/unets/unet_1d_blocks.py +1 -1
- diffusers/models/unets/unet_2d.py +4 -4
- diffusers/models/unets/unet_2d_blocks.py +238 -98
- diffusers/models/unets/unet_2d_blocks_flax.py +1 -1
- diffusers/models/unets/unet_2d_condition.py +420 -323
- diffusers/models/unets/unet_2d_condition_flax.py +21 -12
- diffusers/models/unets/unet_3d_blocks.py +50 -40
- diffusers/models/unets/unet_3d_condition.py +47 -8
- diffusers/models/unets/unet_i2vgen_xl.py +75 -30
- diffusers/models/unets/unet_kandinsky3.py +1 -1
- diffusers/models/unets/unet_motion_model.py +48 -8
- diffusers/models/unets/unet_spatio_temporal_condition.py +1 -1
- diffusers/models/unets/unet_stable_cascade.py +610 -0
- diffusers/models/unets/uvit_2d.py +1 -1
- diffusers/models/upsampling.py +10 -16
- diffusers/models/vae_flax.py +1 -1
- diffusers/models/vq_model.py +1 -1
- diffusers/optimization.py +1 -1
- diffusers/pipelines/__init__.py +26 -0
- diffusers/pipelines/amused/pipeline_amused.py +1 -1
- diffusers/pipelines/amused/pipeline_amused_img2img.py +1 -1
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +1 -1
- diffusers/pipelines/animatediff/pipeline_animatediff.py +162 -417
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +165 -137
- diffusers/pipelines/animatediff/pipeline_output.py +7 -6
- diffusers/pipelines/audioldm/pipeline_audioldm.py +3 -19
- diffusers/pipelines/audioldm2/modeling_audioldm2.py +1 -1
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +3 -3
- diffusers/pipelines/auto_pipeline.py +7 -16
- diffusers/pipelines/blip_diffusion/blip_image_processing.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_blip2.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +2 -2
- diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +2 -2
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -1
- diffusers/pipelines/controlnet/pipeline_controlnet.py +90 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +2 -2
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +98 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +92 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +145 -70
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +126 -89
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +108 -96
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +2 -2
- diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -1
- diffusers/pipelines/ddim/pipeline_ddim.py +1 -1
- diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +5 -5
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +5 -5
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +5 -5
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +10 -120
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +10 -91
- diffusers/pipelines/deprecated/audio_diffusion/mel.py +1 -1
- diffusers/pipelines/deprecated/audio_diffusion/pipeline_audio_diffusion.py +1 -1
- diffusers/pipelines/deprecated/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py +1 -1
- diffusers/pipelines/deprecated/pndm/pipeline_pndm.py +1 -1
- diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +1 -1
- diffusers/pipelines/deprecated/score_sde_ve/pipeline_score_sde_ve.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/continuous_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/midi_utils.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/notes_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -1
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +5 -4
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +5 -4
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +7 -22
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +5 -39
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +5 -5
- diffusers/pipelines/deprecated/stochastic_karras_ve/pipeline_stochastic_karras_ve.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +31 -22
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +1 -2
- diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +1 -1
- diffusers/pipelines/dit/pipeline_dit.py +1 -1
- diffusers/pipelines/free_init_utils.py +184 -0
- diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +22 -104
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +2 -2
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +2 -2
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +104 -93
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +112 -74
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -1
- diffusers/pipelines/ledits_pp/__init__.py +55 -0
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +1505 -0
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +1797 -0
- diffusers/pipelines/ledits_pp/pipeline_output.py +43 -0
- diffusers/pipelines/musicldm/pipeline_musicldm.py +3 -19
- diffusers/pipelines/onnx_utils.py +1 -1
- diffusers/pipelines/paint_by_example/image_encoder.py +1 -1
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +3 -3
- diffusers/pipelines/pia/pipeline_pia.py +168 -327
- diffusers/pipelines/pipeline_flax_utils.py +1 -1
- diffusers/pipelines/pipeline_loading_utils.py +508 -0
- diffusers/pipelines/pipeline_utils.py +188 -534
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +56 -10
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +3 -3
- diffusers/pipelines/shap_e/camera.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +1 -1
- diffusers/pipelines/shap_e/renderer.py +1 -1
- diffusers/pipelines/stable_cascade/__init__.py +50 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +482 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +311 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +638 -0
- diffusers/pipelines/stable_diffusion/clip_image_project_model.py +1 -1
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +4 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_img2img.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +90 -146
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +5 -4
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +4 -32
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -119
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +92 -119
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +13 -59
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +3 -31
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +5 -33
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -21
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +7 -21
- diffusers/pipelines/stable_diffusion/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion/safety_checker_flax.py +1 -1
- diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py +1 -1
- diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +5 -21
- diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +9 -38
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +5 -34
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +6 -35
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +7 -6
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +4 -124
- diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +282 -80
- diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +94 -46
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +3 -3
- diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +6 -22
- diffusers/pipelines/stable_diffusion_xl/pipeline_flax_stable_diffusion_xl.py +1 -1
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +96 -148
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +98 -154
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +98 -153
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +25 -87
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +89 -80
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +5 -49
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +80 -88
- diffusers/pipelines/text_to_video_synthesis/pipeline_output.py +8 -6
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +15 -86
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +20 -93
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +5 -5
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +3 -19
- diffusers/pipelines/unclip/pipeline_unclip.py +1 -1
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -1
- diffusers/pipelines/unclip/text_proj.py +1 -1
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +35 -35
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +4 -21
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_diffnext.py +2 -2
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +4 -5
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +8 -8
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +1 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +2 -2
- diffusers/schedulers/__init__.py +7 -1
- diffusers/schedulers/deprecated/scheduling_karras_ve.py +1 -1
- diffusers/schedulers/deprecated/scheduling_sde_vp.py +1 -1
- diffusers/schedulers/scheduling_consistency_models.py +42 -19
- diffusers/schedulers/scheduling_ddim.py +2 -4
- diffusers/schedulers/scheduling_ddim_flax.py +13 -5
- diffusers/schedulers/scheduling_ddim_inverse.py +2 -4
- diffusers/schedulers/scheduling_ddim_parallel.py +2 -4
- diffusers/schedulers/scheduling_ddpm.py +2 -4
- diffusers/schedulers/scheduling_ddpm_flax.py +1 -1
- diffusers/schedulers/scheduling_ddpm_parallel.py +2 -4
- diffusers/schedulers/scheduling_ddpm_wuerstchen.py +1 -1
- diffusers/schedulers/scheduling_deis_multistep.py +46 -19
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +107 -21
- diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +1 -1
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +9 -7
- diffusers/schedulers/scheduling_dpmsolver_sde.py +35 -35
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +49 -18
- diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +683 -0
- diffusers/schedulers/scheduling_edm_euler.py +381 -0
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +43 -15
- diffusers/schedulers/scheduling_euler_discrete.py +42 -17
- diffusers/schedulers/scheduling_euler_discrete_flax.py +1 -1
- diffusers/schedulers/scheduling_heun_discrete.py +35 -35
- diffusers/schedulers/scheduling_ipndm.py +37 -11
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +44 -44
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +44 -44
- diffusers/schedulers/scheduling_karras_ve_flax.py +1 -1
- diffusers/schedulers/scheduling_lcm.py +38 -14
- diffusers/schedulers/scheduling_lms_discrete.py +43 -15
- diffusers/schedulers/scheduling_lms_discrete_flax.py +1 -1
- diffusers/schedulers/scheduling_pndm.py +2 -4
- diffusers/schedulers/scheduling_pndm_flax.py +2 -4
- diffusers/schedulers/scheduling_repaint.py +1 -1
- diffusers/schedulers/scheduling_sasolver.py +41 -9
- diffusers/schedulers/scheduling_sde_ve.py +1 -1
- diffusers/schedulers/scheduling_sde_ve_flax.py +1 -1
- diffusers/schedulers/scheduling_tcd.py +686 -0
- diffusers/schedulers/scheduling_unclip.py +1 -1
- diffusers/schedulers/scheduling_unipc_multistep.py +46 -19
- diffusers/schedulers/scheduling_utils.py +2 -1
- diffusers/schedulers/scheduling_utils_flax.py +1 -1
- diffusers/schedulers/scheduling_vq_diffusion.py +1 -1
- diffusers/training_utils.py +9 -2
- diffusers/utils/__init__.py +2 -1
- diffusers/utils/accelerate_utils.py +1 -1
- diffusers/utils/constants.py +1 -1
- diffusers/utils/doc_utils.py +1 -1
- diffusers/utils/dummy_pt_objects.py +60 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +75 -0
- diffusers/utils/dynamic_modules_utils.py +1 -1
- diffusers/utils/export_utils.py +3 -3
- diffusers/utils/hub_utils.py +60 -16
- diffusers/utils/import_utils.py +15 -1
- diffusers/utils/loading_utils.py +2 -0
- diffusers/utils/logging.py +1 -1
- diffusers/utils/model_card_template.md +24 -0
- diffusers/utils/outputs.py +14 -7
- diffusers/utils/peft_utils.py +1 -1
- diffusers/utils/state_dict_utils.py +1 -1
- diffusers/utils/testing_utils.py +2 -0
- diffusers/utils/torch_utils.py +1 -1
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/METADATA +46 -46
- diffusers-0.27.0.dist-info/RECORD +399 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/WHEEL +1 -1
- diffusers-0.26.3.dist-info/RECORD +0 -384
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/LICENSE +0 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/entry_points.txt +0 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -34,7 +34,7 @@ from ...utils import (
|
|
34
34
|
unscale_lora_layers,
|
35
35
|
)
|
36
36
|
from ...utils.torch_utils import randn_tensor
|
37
|
-
from ..pipeline_utils import DiffusionPipeline
|
37
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
38
38
|
from . import TextToVideoSDPipelineOutput
|
39
39
|
|
40
40
|
|
@@ -52,7 +52,7 @@ EXAMPLE_DOC_STRING = """
|
|
52
52
|
>>> pipe.to("cuda")
|
53
53
|
|
54
54
|
>>> prompt = "spiderman running in the desert"
|
55
|
-
>>> video_frames = pipe(prompt, num_inference_steps=40, height=320, width=576, num_frames=24).frames
|
55
|
+
>>> video_frames = pipe(prompt, num_inference_steps=40, height=320, width=576, num_frames=24).frames[0]
|
56
56
|
>>> # safe low-res video
|
57
57
|
>>> video_path = export_to_video(video_frames, output_video_path="./video_576_spiderman.mp4")
|
58
58
|
|
@@ -73,7 +73,7 @@ EXAMPLE_DOC_STRING = """
|
|
73
73
|
>>> video = [Image.fromarray(frame).resize((1024, 576)) for frame in video_frames]
|
74
74
|
|
75
75
|
>>> # and denoise it
|
76
|
-
>>> video_frames = pipe(prompt, video=video, strength=0.6).frames
|
76
|
+
>>> video_frames = pipe(prompt, video=video, strength=0.6).frames[0]
|
77
77
|
>>> video_path = export_to_video(video_frames, output_video_path="./video_1024_spiderman.mp4")
|
78
78
|
>>> video_path
|
79
79
|
```
|
@@ -111,7 +111,7 @@ def tensor2vid(video: torch.Tensor, processor: "VaeImageProcessor", output_type:
|
|
111
111
|
outputs = torch.stack(outputs)
|
112
112
|
|
113
113
|
elif not output_type == "pil":
|
114
|
-
raise ValueError(f"{output_type} does not exist. Please choose one of ['np', 'pt', 'pil]")
|
114
|
+
raise ValueError(f"{output_type} does not exist. Please choose one of ['np', 'pt', 'pil']")
|
115
115
|
|
116
116
|
return outputs
|
117
117
|
|
@@ -157,7 +157,7 @@ def preprocess_video(video):
|
|
157
157
|
return video
|
158
158
|
|
159
159
|
|
160
|
-
class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin):
|
160
|
+
class VideoToVideoSDPipeline(DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin):
|
161
161
|
r"""
|
162
162
|
Pipeline for text-guided video-to-video generation.
|
163
163
|
|
@@ -205,39 +205,6 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
205
205
|
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
|
206
206
|
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
|
207
207
|
|
208
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
209
|
-
def enable_vae_slicing(self):
|
210
|
-
r"""
|
211
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
212
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
213
|
-
"""
|
214
|
-
self.vae.enable_slicing()
|
215
|
-
|
216
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
217
|
-
def disable_vae_slicing(self):
|
218
|
-
r"""
|
219
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
220
|
-
computing decoding in one step.
|
221
|
-
"""
|
222
|
-
self.vae.disable_slicing()
|
223
|
-
|
224
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
225
|
-
def enable_vae_tiling(self):
|
226
|
-
r"""
|
227
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
228
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
229
|
-
processing larger images.
|
230
|
-
"""
|
231
|
-
self.vae.enable_tiling()
|
232
|
-
|
233
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
234
|
-
def disable_vae_tiling(self):
|
235
|
-
r"""
|
236
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
237
|
-
computing decoding in one step.
|
238
|
-
"""
|
239
|
-
self.vae.disable_tiling()
|
240
|
-
|
241
208
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
242
209
|
def _encode_prompt(
|
243
210
|
self,
|
@@ -332,7 +299,7 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
332
299
|
batch_size = prompt_embeds.shape[0]
|
333
300
|
|
334
301
|
if prompt_embeds is None:
|
335
|
-
# textual inversion:
|
302
|
+
# textual inversion: process multi-vector tokens if necessary
|
336
303
|
if isinstance(self, TextualInversionLoaderMixin):
|
337
304
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
338
305
|
|
@@ -414,7 +381,7 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
414
381
|
else:
|
415
382
|
uncond_tokens = negative_prompt
|
416
383
|
|
417
|
-
# textual inversion:
|
384
|
+
# textual inversion: process multi-vector tokens if necessary
|
418
385
|
if isinstance(self, TextualInversionLoaderMixin):
|
419
386
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
420
387
|
|
@@ -461,18 +428,7 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
461
428
|
latents = latents.permute(0, 2, 1, 3, 4).reshape(batch_size * num_frames, channels, height, width)
|
462
429
|
|
463
430
|
image = self.vae.decode(latents).sample
|
464
|
-
video = (
|
465
|
-
image[None, :]
|
466
|
-
.reshape(
|
467
|
-
(
|
468
|
-
batch_size,
|
469
|
-
num_frames,
|
470
|
-
-1,
|
471
|
-
)
|
472
|
-
+ image.shape[2:]
|
473
|
-
)
|
474
|
-
.permute(0, 2, 1, 3, 4)
|
475
|
-
)
|
431
|
+
video = image[None, :].reshape((batch_size, num_frames, -1) + image.shape[2:]).permute(0, 2, 1, 3, 4)
|
476
432
|
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
|
477
433
|
video = video.float()
|
478
434
|
return video
|
@@ -495,7 +451,6 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
495
451
|
extra_step_kwargs["generator"] = generator
|
496
452
|
return extra_step_kwargs
|
497
453
|
|
498
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline.check_inputs
|
499
454
|
def check_inputs(
|
500
455
|
self,
|
501
456
|
prompt,
|
@@ -554,6 +509,8 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
554
509
|
|
555
510
|
t_start = max(num_inference_steps - init_timestep, 0)
|
556
511
|
timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
|
512
|
+
if hasattr(self.scheduler, "set_begin_index"):
|
513
|
+
self.scheduler.set_begin_index(t_start * self.scheduler.order)
|
557
514
|
|
558
515
|
return timesteps, num_inference_steps - t_start
|
559
516
|
|
@@ -601,34 +558,6 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
601
558
|
|
602
559
|
return latents
|
603
560
|
|
604
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
|
605
|
-
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
|
606
|
-
r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
|
607
|
-
|
608
|
-
The suffixes after the scaling factors represent the stages where they are being applied.
|
609
|
-
|
610
|
-
Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
|
611
|
-
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
|
612
|
-
|
613
|
-
Args:
|
614
|
-
s1 (`float`):
|
615
|
-
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
|
616
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
617
|
-
s2 (`float`):
|
618
|
-
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
|
619
|
-
mitigate "oversmoothing effect" in the enhanced denoising process.
|
620
|
-
b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
|
621
|
-
b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
|
622
|
-
"""
|
623
|
-
if not hasattr(self, "unet"):
|
624
|
-
raise ValueError("The pipeline must have `unet` for using FreeU.")
|
625
|
-
self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
|
626
|
-
|
627
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
|
628
|
-
def disable_freeu(self):
|
629
|
-
"""Disables the FreeU mechanism if enabled."""
|
630
|
-
self.unet.disable_freeu()
|
631
|
-
|
632
561
|
@torch.no_grad()
|
633
562
|
@replace_example_docstring(EXAMPLE_DOC_STRING)
|
634
563
|
def __call__(
|
@@ -765,13 +694,13 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
765
694
|
timesteps, num_inference_steps = self.get_timesteps(num_inference_steps, strength, device)
|
766
695
|
latent_timestep = timesteps[:1].repeat(batch_size * num_images_per_prompt)
|
767
696
|
|
768
|
-
#
|
697
|
+
# 6. Prepare latent variables
|
769
698
|
latents = self.prepare_latents(video, latent_timestep, batch_size, prompt_embeds.dtype, device, generator)
|
770
699
|
|
771
|
-
#
|
700
|
+
# 7. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
772
701
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
773
702
|
|
774
|
-
#
|
703
|
+
# 8. Denoising loop
|
775
704
|
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
|
776
705
|
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
777
706
|
for i, t in enumerate(timesteps):
|
@@ -811,20 +740,18 @@ class VideoToVideoSDPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lor
|
|
811
740
|
step_idx = i // getattr(self.scheduler, "order", 1)
|
812
741
|
callback(step_idx, t, latents)
|
813
742
|
|
814
|
-
if output_type == "latent":
|
815
|
-
return TextToVideoSDPipelineOutput(frames=latents)
|
816
|
-
|
817
743
|
# manually for max memory savings
|
818
744
|
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
|
819
745
|
self.unet.to("cpu")
|
820
746
|
|
747
|
+
# 9. Post processing
|
821
748
|
if output_type == "latent":
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
749
|
+
video = latents
|
750
|
+
else:
|
751
|
+
video_tensor = self.decode_latents(latents)
|
752
|
+
video = tensor2vid(video_tensor, self.image_processor, output_type)
|
826
753
|
|
827
|
-
# Offload all models
|
754
|
+
# 10. Offload all models
|
828
755
|
self.maybe_free_model_hooks()
|
829
756
|
|
830
757
|
if not return_dict:
|
@@ -17,7 +17,7 @@ from ...models.lora import adjust_lora_scale_text_encoder
|
|
17
17
|
from ...schedulers import KarrasDiffusionSchedulers
|
18
18
|
from ...utils import USE_PEFT_BACKEND, BaseOutput, logging, scale_lora_layers, unscale_lora_layers
|
19
19
|
from ...utils.torch_utils import randn_tensor
|
20
|
-
from ..pipeline_utils import DiffusionPipeline
|
20
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
21
21
|
from ..stable_diffusion import StableDiffusionSafetyChecker
|
22
22
|
|
23
23
|
|
@@ -281,7 +281,7 @@ def create_motion_field_and_warp_latents(motion_field_strength_x, motion_field_s
|
|
281
281
|
return warped_latents
|
282
282
|
|
283
283
|
|
284
|
-
class TextToVideoZeroPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin):
|
284
|
+
class TextToVideoZeroPipeline(DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin):
|
285
285
|
r"""
|
286
286
|
Pipeline for zero-shot text-to-video generation using Stable Diffusion.
|
287
287
|
|
@@ -447,7 +447,7 @@ class TextToVideoZeroPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lo
|
|
447
447
|
callback(step_idx, t, latents)
|
448
448
|
return latents.clone().detach()
|
449
449
|
|
450
|
-
# Copied from diffusers.pipelines.
|
450
|
+
# Copied from diffusers.pipelines.stable_diffusion_k_diffusion.pipeline_stable_diffusion_k_diffusion.StableDiffusionKDiffusionPipeline.check_inputs
|
451
451
|
def check_inputs(
|
452
452
|
self,
|
453
453
|
prompt,
|
@@ -839,7 +839,7 @@ class TextToVideoZeroPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lo
|
|
839
839
|
batch_size = prompt_embeds.shape[0]
|
840
840
|
|
841
841
|
if prompt_embeds is None:
|
842
|
-
# textual inversion:
|
842
|
+
# textual inversion: process multi-vector tokens if necessary
|
843
843
|
if isinstance(self, TextualInversionLoaderMixin):
|
844
844
|
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
845
845
|
|
@@ -921,7 +921,7 @@ class TextToVideoZeroPipeline(DiffusionPipeline, TextualInversionLoaderMixin, Lo
|
|
921
921
|
else:
|
922
922
|
uncond_tokens = negative_prompt
|
923
923
|
|
924
|
-
# textual inversion:
|
924
|
+
# textual inversion: process multi-vector tokens if necessary
|
925
925
|
if isinstance(self, TextualInversionLoaderMixin):
|
926
926
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
927
927
|
|
@@ -37,7 +37,7 @@ from ...utils import (
|
|
37
37
|
unscale_lora_layers,
|
38
38
|
)
|
39
39
|
from ...utils.torch_utils import randn_tensor
|
40
|
-
from ..pipeline_utils import DiffusionPipeline
|
40
|
+
from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
|
41
41
|
|
42
42
|
|
43
43
|
if is_invisible_watermark_available():
|
@@ -327,6 +327,7 @@ def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
|
|
327
327
|
|
328
328
|
class TextToVideoZeroSDXLPipeline(
|
329
329
|
DiffusionPipeline,
|
330
|
+
StableDiffusionMixin,
|
330
331
|
StableDiffusionXLLoraLoaderMixin,
|
331
332
|
TextualInversionLoaderMixin,
|
332
333
|
):
|
@@ -436,22 +437,6 @@ class TextToVideoZeroSDXLPipeline(
|
|
436
437
|
extra_step_kwargs["generator"] = generator
|
437
438
|
return extra_step_kwargs
|
438
439
|
|
439
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
440
|
-
def enable_vae_slicing(self):
|
441
|
-
r"""
|
442
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
443
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
444
|
-
"""
|
445
|
-
self.vae.enable_slicing()
|
446
|
-
|
447
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
448
|
-
def disable_vae_slicing(self):
|
449
|
-
r"""
|
450
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
451
|
-
computing decoding in one step.
|
452
|
-
"""
|
453
|
-
self.vae.disable_slicing()
|
454
|
-
|
455
440
|
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.upcast_vae
|
456
441
|
def upcast_vae(self):
|
457
442
|
dtype = self.vae.dtype
|
@@ -510,7 +495,6 @@ class TextToVideoZeroSDXLPipeline(
|
|
510
495
|
latents = latents * self.scheduler.init_noise_sigma
|
511
496
|
return latents
|
512
497
|
|
513
|
-
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.check_inputs
|
514
498
|
def check_inputs(
|
515
499
|
self,
|
516
500
|
prompt,
|
@@ -686,7 +670,7 @@ class TextToVideoZeroSDXLPipeline(
|
|
686
670
|
prompt_2 = prompt_2 or prompt
|
687
671
|
prompt_2 = [prompt_2] if isinstance(prompt_2, str) else prompt_2
|
688
672
|
|
689
|
-
# textual inversion:
|
673
|
+
# textual inversion: process multi-vector tokens if necessary
|
690
674
|
prompt_embeds_list = []
|
691
675
|
prompts = [prompt, prompt_2]
|
692
676
|
for prompt, tokenizer, text_encoder in zip(prompts, tokenizers, text_encoders):
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 Kakao Brain and The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 Kakao Brain and The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 Kakao Brain and The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -135,39 +135,6 @@ class UniDiffuserPipeline(DiffusionPipeline):
|
|
135
135
|
# TODO: handle safety checking?
|
136
136
|
self.safety_checker = None
|
137
137
|
|
138
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
139
|
-
def enable_vae_slicing(self):
|
140
|
-
r"""
|
141
|
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
142
|
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
143
|
-
"""
|
144
|
-
self.vae.enable_slicing()
|
145
|
-
|
146
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
147
|
-
def disable_vae_slicing(self):
|
148
|
-
r"""
|
149
|
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
150
|
-
computing decoding in one step.
|
151
|
-
"""
|
152
|
-
self.vae.disable_slicing()
|
153
|
-
|
154
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
155
|
-
def enable_vae_tiling(self):
|
156
|
-
r"""
|
157
|
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
158
|
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
159
|
-
processing larger images.
|
160
|
-
"""
|
161
|
-
self.vae.enable_tiling()
|
162
|
-
|
163
|
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
164
|
-
def disable_vae_tiling(self):
|
165
|
-
r"""
|
166
|
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
167
|
-
computing decoding in one step.
|
168
|
-
"""
|
169
|
-
self.vae.disable_tiling()
|
170
|
-
|
171
138
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_extra_step_kwargs
|
172
139
|
def prepare_extra_step_kwargs(self, generator, eta):
|
173
140
|
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
|
@@ -244,6 +211,39 @@ class UniDiffuserPipeline(DiffusionPipeline):
|
|
244
211
|
|
245
212
|
return mode
|
246
213
|
|
214
|
+
# Copied from diffusers.pipelines.pipeline_utils.StableDiffusionMixin.enable_vae_slicing
|
215
|
+
def enable_vae_slicing(self):
|
216
|
+
r"""
|
217
|
+
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
218
|
+
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
219
|
+
"""
|
220
|
+
self.vae.enable_slicing()
|
221
|
+
|
222
|
+
# Copied from diffusers.pipelines.pipeline_utils.StableDiffusionMixin.disable_vae_slicing
|
223
|
+
def disable_vae_slicing(self):
|
224
|
+
r"""
|
225
|
+
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
226
|
+
computing decoding in one step.
|
227
|
+
"""
|
228
|
+
self.vae.disable_slicing()
|
229
|
+
|
230
|
+
# Copied from diffusers.pipelines.pipeline_utils.StableDiffusionMixin.enable_vae_tiling
|
231
|
+
def enable_vae_tiling(self):
|
232
|
+
r"""
|
233
|
+
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
234
|
+
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
235
|
+
processing larger images.
|
236
|
+
"""
|
237
|
+
self.vae.enable_tiling()
|
238
|
+
|
239
|
+
# Copied from diffusers.pipelines.pipeline_utils.StableDiffusionMixin.disable_vae_tiling
|
240
|
+
def disable_vae_tiling(self):
|
241
|
+
r"""
|
242
|
+
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
243
|
+
computing decoding in one step.
|
244
|
+
"""
|
245
|
+
self.vae.disable_tiling()
|
246
|
+
|
247
247
|
# Functions to manually set the mode
|
248
248
|
def set_text_mode(self):
|
249
249
|
r"""Manually set the generation mode to unconditional ("marginal") text generation."""
|
@@ -439,7 +439,7 @@ class UniDiffuserPipeline(DiffusionPipeline):
|
|
439
439
|
batch_size = prompt_embeds.shape[0]
|
440
440
|
|
441
441
|
if prompt_embeds is None:
|
442
|
-
# textual inversion:
|
442
|
+
# textual inversion: process multi-vector tokens if necessary
|
443
443
|
if isinstance(self, TextualInversionLoaderMixin):
|
444
444
|
prompt = self.maybe_convert_prompt(prompt, self.clip_tokenizer)
|
445
445
|
|
@@ -521,7 +521,7 @@ class UniDiffuserPipeline(DiffusionPipeline):
|
|
521
521
|
else:
|
522
522
|
uncond_tokens = negative_prompt
|
523
523
|
|
524
|
-
# textual inversion:
|
524
|
+
# textual inversion: process multi-vector tokens if necessary
|
525
525
|
if isinstance(self, TextualInversionLoaderMixin):
|
526
526
|
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.clip_tokenizer)
|
527
527
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2022 Dominic Rampas MIT License
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -1,24 +1,7 @@
|
|
1
|
-
# Copyright (c) 2023 Dominic Rampas MIT License
|
2
|
-
# Copyright 2023 The HuggingFace Team. All rights reserved.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
|
16
1
|
import torch
|
17
2
|
import torch.nn as nn
|
18
3
|
|
19
4
|
from ...models.attention_processor import Attention
|
20
|
-
from ...models.lora import LoRACompatibleConv, LoRACompatibleLinear
|
21
|
-
from ...utils import USE_PEFT_BACKEND
|
22
5
|
|
23
6
|
|
24
7
|
class WuerstchenLayerNorm(nn.LayerNorm):
|
@@ -34,7 +17,7 @@ class WuerstchenLayerNorm(nn.LayerNorm):
|
|
34
17
|
class TimestepBlock(nn.Module):
|
35
18
|
def __init__(self, c, c_timestep):
|
36
19
|
super().__init__()
|
37
|
-
linear_cls = nn.Linear
|
20
|
+
linear_cls = nn.Linear
|
38
21
|
self.mapper = linear_cls(c_timestep, c * 2)
|
39
22
|
|
40
23
|
def forward(self, x, t):
|
@@ -46,8 +29,8 @@ class ResBlock(nn.Module):
|
|
46
29
|
def __init__(self, c, c_skip=0, kernel_size=3, dropout=0.0):
|
47
30
|
super().__init__()
|
48
31
|
|
49
|
-
conv_cls = nn.Conv2d
|
50
|
-
linear_cls = nn.Linear
|
32
|
+
conv_cls = nn.Conv2d
|
33
|
+
linear_cls = nn.Linear
|
51
34
|
|
52
35
|
self.depthwise = conv_cls(c + c_skip, c, kernel_size=kernel_size, padding=kernel_size // 2, groups=c)
|
53
36
|
self.norm = WuerstchenLayerNorm(c, elementwise_affine=False, eps=1e-6)
|
@@ -81,7 +64,7 @@ class AttnBlock(nn.Module):
|
|
81
64
|
def __init__(self, c, c_cond, nhead, self_attn=True, dropout=0.0):
|
82
65
|
super().__init__()
|
83
66
|
|
84
|
-
linear_cls = nn.Linear
|
67
|
+
linear_cls = nn.Linear
|
85
68
|
|
86
69
|
self.self_attn = self_attn
|
87
70
|
self.norm = WuerstchenLayerNorm(c, elementwise_affine=False, eps=1e-6)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2023 Dominic Rampas MIT License
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -233,7 +233,7 @@ class WuerstchenDiffNeXt(ModelMixin, ConfigMixin):
|
|
233
233
|
|
234
234
|
|
235
235
|
class ResBlockStageB(nn.Module):
|
236
|
-
def __init__(self, c, c_skip=
|
236
|
+
def __init__(self, c, c_skip=0, kernel_size=3, dropout=0.0):
|
237
237
|
super().__init__()
|
238
238
|
self.depthwise = nn.Conv2d(c, c, kernel_size=kernel_size, padding=kernel_size // 2, groups=c)
|
239
239
|
self.norm = WuerstchenLayerNorm(c, elementwise_affine=False, eps=1e-6)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2023 Dominic Rampas MIT License
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -28,9 +28,8 @@ from ...models.attention_processor import (
|
|
28
28
|
AttnAddedKVProcessor,
|
29
29
|
AttnProcessor,
|
30
30
|
)
|
31
|
-
from ...models.lora import LoRACompatibleConv, LoRACompatibleLinear
|
32
31
|
from ...models.modeling_utils import ModelMixin
|
33
|
-
from ...utils import
|
32
|
+
from ...utils import is_torch_version
|
34
33
|
from .modeling_wuerstchen_common import AttnBlock, ResBlock, TimestepBlock, WuerstchenLayerNorm
|
35
34
|
|
36
35
|
|
@@ -41,8 +40,8 @@ class WuerstchenPrior(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin, Peft
|
|
41
40
|
@register_to_config
|
42
41
|
def __init__(self, c_in=16, c=1280, c_cond=1024, c_r=64, depth=16, nhead=16, dropout=0.1):
|
43
42
|
super().__init__()
|
44
|
-
conv_cls = nn.Conv2d
|
45
|
-
linear_cls = nn.Linear
|
43
|
+
conv_cls = nn.Conv2d
|
44
|
+
linear_cls = nn.Linear
|
46
45
|
|
47
46
|
self.c_r = c_r
|
48
47
|
self.projection = conv_cls(c_in, c, kernel_size=1)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -349,6 +349,11 @@ class WuerstchenDecoderPipeline(DiffusionPipeline):
|
|
349
349
|
text_encoder_hidden_states = (
|
350
350
|
torch.cat([prompt_embeds, negative_prompt_embeds]) if negative_prompt_embeds is not None else prompt_embeds
|
351
351
|
)
|
352
|
+
effnet = (
|
353
|
+
torch.cat([image_embeddings, torch.zeros_like(image_embeddings)])
|
354
|
+
if self.do_classifier_free_guidance
|
355
|
+
else image_embeddings
|
356
|
+
)
|
352
357
|
|
353
358
|
# 3. Determine latent shape of latents
|
354
359
|
latent_height = int(image_embeddings.size(2) * self.config.latent_dim_scale)
|
@@ -371,11 +376,6 @@ class WuerstchenDecoderPipeline(DiffusionPipeline):
|
|
371
376
|
self._num_timesteps = len(timesteps[:-1])
|
372
377
|
for i, t in enumerate(self.progress_bar(timesteps[:-1])):
|
373
378
|
ratio = t.expand(latents.size(0)).to(dtype)
|
374
|
-
effnet = (
|
375
|
-
torch.cat([image_embeddings, torch.zeros_like(image_embeddings)])
|
376
|
-
if self.do_classifier_free_guidance
|
377
|
-
else image_embeddings
|
378
|
-
)
|
379
379
|
# 7. Denoise latents
|
380
380
|
predicted_latents = self.decoder(
|
381
381
|
torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents,
|
@@ -423,9 +423,9 @@ class WuerstchenDecoderPipeline(DiffusionPipeline):
|
|
423
423
|
latents = self.vqgan.config.scale_factor * latents
|
424
424
|
images = self.vqgan.decode(latents).sample.clamp(0, 1)
|
425
425
|
if output_type == "np":
|
426
|
-
images = images.permute(0, 2, 3, 1).cpu().numpy()
|
426
|
+
images = images.permute(0, 2, 3, 1).cpu().float().numpy()
|
427
427
|
elif output_type == "pil":
|
428
|
-
images = images.permute(0, 2, 3, 1).cpu().numpy()
|
428
|
+
images = images.permute(0, 2, 3, 1).cpu().float().numpy()
|
429
429
|
images = self.numpy_to_pil(images)
|
430
430
|
else:
|
431
431
|
images = latents
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -508,7 +508,7 @@ class WuerstchenPriorPipeline(DiffusionPipeline, LoraLoaderMixin):
|
|
508
508
|
self.maybe_free_model_hooks()
|
509
509
|
|
510
510
|
if output_type == "np":
|
511
|
-
latents = latents.cpu().numpy()
|
511
|
+
latents = latents.cpu().float().numpy()
|
512
512
|
|
513
513
|
if not return_dict:
|
514
514
|
return (latents,)
|
diffusers/schedulers/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -52,6 +52,8 @@ else:
|
|
52
52
|
_import_structure["scheduling_dpmsolver_multistep"] = ["DPMSolverMultistepScheduler"]
|
53
53
|
_import_structure["scheduling_dpmsolver_multistep_inverse"] = ["DPMSolverMultistepInverseScheduler"]
|
54
54
|
_import_structure["scheduling_dpmsolver_singlestep"] = ["DPMSolverSinglestepScheduler"]
|
55
|
+
_import_structure["scheduling_edm_dpmsolver_multistep"] = ["EDMDPMSolverMultistepScheduler"]
|
56
|
+
_import_structure["scheduling_edm_euler"] = ["EDMEulerScheduler"]
|
55
57
|
_import_structure["scheduling_euler_ancestral_discrete"] = ["EulerAncestralDiscreteScheduler"]
|
56
58
|
_import_structure["scheduling_euler_discrete"] = ["EulerDiscreteScheduler"]
|
57
59
|
_import_structure["scheduling_heun_discrete"] = ["HeunDiscreteScheduler"]
|
@@ -63,6 +65,7 @@ else:
|
|
63
65
|
_import_structure["scheduling_repaint"] = ["RePaintScheduler"]
|
64
66
|
_import_structure["scheduling_sasolver"] = ["SASolverScheduler"]
|
65
67
|
_import_structure["scheduling_sde_ve"] = ["ScoreSdeVeScheduler"]
|
68
|
+
_import_structure["scheduling_tcd"] = ["TCDScheduler"]
|
66
69
|
_import_structure["scheduling_unclip"] = ["UnCLIPScheduler"]
|
67
70
|
_import_structure["scheduling_unipc_multistep"] = ["UniPCMultistepScheduler"]
|
68
71
|
_import_structure["scheduling_utils"] = ["KarrasDiffusionSchedulers", "SchedulerMixin"]
|
@@ -144,6 +147,8 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
144
147
|
from .scheduling_dpmsolver_multistep import DPMSolverMultistepScheduler
|
145
148
|
from .scheduling_dpmsolver_multistep_inverse import DPMSolverMultistepInverseScheduler
|
146
149
|
from .scheduling_dpmsolver_singlestep import DPMSolverSinglestepScheduler
|
150
|
+
from .scheduling_edm_dpmsolver_multistep import EDMDPMSolverMultistepScheduler
|
151
|
+
from .scheduling_edm_euler import EDMEulerScheduler
|
147
152
|
from .scheduling_euler_ancestral_discrete import EulerAncestralDiscreteScheduler
|
148
153
|
from .scheduling_euler_discrete import EulerDiscreteScheduler
|
149
154
|
from .scheduling_heun_discrete import HeunDiscreteScheduler
|
@@ -155,6 +160,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
155
160
|
from .scheduling_repaint import RePaintScheduler
|
156
161
|
from .scheduling_sasolver import SASolverScheduler
|
157
162
|
from .scheduling_sde_ve import ScoreSdeVeScheduler
|
163
|
+
from .scheduling_tcd import TCDScheduler
|
158
164
|
from .scheduling_unclip import UnCLIPScheduler
|
159
165
|
from .scheduling_unipc_multistep import UniPCMultistepScheduler
|
160
166
|
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 NVIDIA and The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|