diffusers 0.27.1__py3-none-any.whl → 0.32.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diffusers/__init__.py +233 -6
- diffusers/callbacks.py +209 -0
- diffusers/commands/env.py +102 -6
- diffusers/configuration_utils.py +45 -16
- diffusers/dependency_versions_table.py +4 -3
- diffusers/image_processor.py +434 -110
- diffusers/loaders/__init__.py +42 -9
- diffusers/loaders/ip_adapter.py +626 -36
- diffusers/loaders/lora_base.py +900 -0
- diffusers/loaders/lora_conversion_utils.py +991 -125
- diffusers/loaders/lora_pipeline.py +3812 -0
- diffusers/loaders/peft.py +571 -7
- diffusers/loaders/single_file.py +405 -173
- diffusers/loaders/single_file_model.py +385 -0
- diffusers/loaders/single_file_utils.py +1783 -713
- diffusers/loaders/textual_inversion.py +41 -23
- diffusers/loaders/transformer_flux.py +181 -0
- diffusers/loaders/transformer_sd3.py +89 -0
- diffusers/loaders/unet.py +464 -540
- diffusers/loaders/unet_loader_utils.py +163 -0
- diffusers/models/__init__.py +76 -7
- diffusers/models/activations.py +65 -10
- diffusers/models/adapter.py +53 -53
- diffusers/models/attention.py +605 -18
- diffusers/models/attention_flax.py +1 -1
- diffusers/models/attention_processor.py +4304 -687
- diffusers/models/autoencoders/__init__.py +8 -0
- diffusers/models/autoencoders/autoencoder_asym_kl.py +15 -17
- diffusers/models/autoencoders/autoencoder_dc.py +620 -0
- diffusers/models/autoencoders/autoencoder_kl.py +110 -28
- diffusers/models/autoencoders/autoencoder_kl_allegro.py +1149 -0
- diffusers/models/autoencoders/autoencoder_kl_cogvideox.py +1482 -0
- diffusers/models/autoencoders/autoencoder_kl_hunyuan_video.py +1176 -0
- diffusers/models/autoencoders/autoencoder_kl_ltx.py +1338 -0
- diffusers/models/autoencoders/autoencoder_kl_mochi.py +1166 -0
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +19 -24
- diffusers/models/autoencoders/autoencoder_oobleck.py +464 -0
- diffusers/models/autoencoders/autoencoder_tiny.py +21 -18
- diffusers/models/autoencoders/consistency_decoder_vae.py +45 -20
- diffusers/models/autoencoders/vae.py +41 -29
- diffusers/models/autoencoders/vq_model.py +182 -0
- diffusers/models/controlnet.py +47 -800
- diffusers/models/controlnet_flux.py +70 -0
- diffusers/models/controlnet_sd3.py +68 -0
- diffusers/models/controlnet_sparsectrl.py +116 -0
- diffusers/models/controlnets/__init__.py +23 -0
- diffusers/models/controlnets/controlnet.py +872 -0
- diffusers/models/{controlnet_flax.py → controlnets/controlnet_flax.py} +9 -9
- diffusers/models/controlnets/controlnet_flux.py +536 -0
- diffusers/models/controlnets/controlnet_hunyuan.py +401 -0
- diffusers/models/controlnets/controlnet_sd3.py +489 -0
- diffusers/models/controlnets/controlnet_sparsectrl.py +788 -0
- diffusers/models/controlnets/controlnet_union.py +832 -0
- diffusers/models/controlnets/controlnet_xs.py +1946 -0
- diffusers/models/controlnets/multicontrolnet.py +183 -0
- diffusers/models/downsampling.py +85 -18
- diffusers/models/embeddings.py +1856 -158
- diffusers/models/embeddings_flax.py +23 -9
- diffusers/models/model_loading_utils.py +480 -0
- diffusers/models/modeling_flax_pytorch_utils.py +2 -1
- diffusers/models/modeling_flax_utils.py +2 -7
- diffusers/models/modeling_outputs.py +14 -0
- diffusers/models/modeling_pytorch_flax_utils.py +1 -1
- diffusers/models/modeling_utils.py +611 -146
- diffusers/models/normalization.py +361 -20
- diffusers/models/resnet.py +18 -23
- diffusers/models/transformers/__init__.py +16 -0
- diffusers/models/transformers/auraflow_transformer_2d.py +544 -0
- diffusers/models/transformers/cogvideox_transformer_3d.py +542 -0
- diffusers/models/transformers/dit_transformer_2d.py +240 -0
- diffusers/models/transformers/dual_transformer_2d.py +9 -8
- diffusers/models/transformers/hunyuan_transformer_2d.py +578 -0
- diffusers/models/transformers/latte_transformer_3d.py +327 -0
- diffusers/models/transformers/lumina_nextdit2d.py +340 -0
- diffusers/models/transformers/pixart_transformer_2d.py +445 -0
- diffusers/models/transformers/prior_transformer.py +13 -13
- diffusers/models/transformers/sana_transformer.py +488 -0
- diffusers/models/transformers/stable_audio_transformer.py +458 -0
- diffusers/models/transformers/t5_film_transformer.py +17 -19
- diffusers/models/transformers/transformer_2d.py +297 -187
- diffusers/models/transformers/transformer_allegro.py +422 -0
- diffusers/models/transformers/transformer_cogview3plus.py +386 -0
- diffusers/models/transformers/transformer_flux.py +593 -0
- diffusers/models/transformers/transformer_hunyuan_video.py +791 -0
- diffusers/models/transformers/transformer_ltx.py +469 -0
- diffusers/models/transformers/transformer_mochi.py +499 -0
- diffusers/models/transformers/transformer_sd3.py +461 -0
- diffusers/models/transformers/transformer_temporal.py +21 -19
- diffusers/models/unets/unet_1d.py +8 -8
- diffusers/models/unets/unet_1d_blocks.py +31 -31
- diffusers/models/unets/unet_2d.py +17 -10
- diffusers/models/unets/unet_2d_blocks.py +225 -149
- diffusers/models/unets/unet_2d_condition.py +41 -40
- diffusers/models/unets/unet_2d_condition_flax.py +6 -5
- diffusers/models/unets/unet_3d_blocks.py +192 -1057
- diffusers/models/unets/unet_3d_condition.py +22 -27
- diffusers/models/unets/unet_i2vgen_xl.py +22 -18
- diffusers/models/unets/unet_kandinsky3.py +2 -2
- diffusers/models/unets/unet_motion_model.py +1413 -89
- diffusers/models/unets/unet_spatio_temporal_condition.py +40 -16
- diffusers/models/unets/unet_stable_cascade.py +19 -18
- diffusers/models/unets/uvit_2d.py +2 -2
- diffusers/models/upsampling.py +95 -26
- diffusers/models/vq_model.py +12 -164
- diffusers/optimization.py +1 -1
- diffusers/pipelines/__init__.py +202 -3
- diffusers/pipelines/allegro/__init__.py +48 -0
- diffusers/pipelines/allegro/pipeline_allegro.py +938 -0
- diffusers/pipelines/allegro/pipeline_output.py +23 -0
- diffusers/pipelines/amused/pipeline_amused.py +12 -12
- diffusers/pipelines/amused/pipeline_amused_img2img.py +14 -12
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +13 -11
- diffusers/pipelines/animatediff/__init__.py +8 -0
- diffusers/pipelines/animatediff/pipeline_animatediff.py +122 -109
- diffusers/pipelines/animatediff/pipeline_animatediff_controlnet.py +1106 -0
- diffusers/pipelines/animatediff/pipeline_animatediff_sdxl.py +1288 -0
- diffusers/pipelines/animatediff/pipeline_animatediff_sparsectrl.py +1010 -0
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +236 -180
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video_controlnet.py +1341 -0
- diffusers/pipelines/animatediff/pipeline_output.py +3 -2
- diffusers/pipelines/audioldm/pipeline_audioldm.py +14 -14
- diffusers/pipelines/audioldm2/modeling_audioldm2.py +58 -39
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +121 -36
- diffusers/pipelines/aura_flow/__init__.py +48 -0
- diffusers/pipelines/aura_flow/pipeline_aura_flow.py +584 -0
- diffusers/pipelines/auto_pipeline.py +196 -28
- diffusers/pipelines/blip_diffusion/blip_image_processing.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_blip2.py +6 -6
- diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +1 -1
- diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +2 -2
- diffusers/pipelines/cogvideo/__init__.py +54 -0
- diffusers/pipelines/cogvideo/pipeline_cogvideox.py +772 -0
- diffusers/pipelines/cogvideo/pipeline_cogvideox_fun_control.py +825 -0
- diffusers/pipelines/cogvideo/pipeline_cogvideox_image2video.py +885 -0
- diffusers/pipelines/cogvideo/pipeline_cogvideox_video2video.py +851 -0
- diffusers/pipelines/cogvideo/pipeline_output.py +20 -0
- diffusers/pipelines/cogview3/__init__.py +47 -0
- diffusers/pipelines/cogview3/pipeline_cogview3plus.py +674 -0
- diffusers/pipelines/cogview3/pipeline_output.py +21 -0
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +6 -6
- diffusers/pipelines/controlnet/__init__.py +86 -80
- diffusers/pipelines/controlnet/multicontrolnet.py +7 -182
- diffusers/pipelines/controlnet/pipeline_controlnet.py +134 -87
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +2 -2
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +93 -77
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +88 -197
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +136 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +176 -80
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +125 -89
- diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py +1790 -0
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py +1501 -0
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl_img2img.py +1627 -0
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +2 -2
- diffusers/pipelines/controlnet_hunyuandit/__init__.py +48 -0
- diffusers/pipelines/controlnet_hunyuandit/pipeline_hunyuandit_controlnet.py +1060 -0
- diffusers/pipelines/controlnet_sd3/__init__.py +57 -0
- diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet.py +1133 -0
- diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet_inpainting.py +1153 -0
- diffusers/pipelines/controlnet_xs/__init__.py +68 -0
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs.py +916 -0
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs_sd_xl.py +1111 -0
- diffusers/pipelines/ddpm/pipeline_ddpm.py +2 -2
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +16 -30
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +20 -35
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +23 -41
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +22 -38
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +25 -41
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +19 -34
- diffusers/pipelines/deepfloyd_if/pipeline_output.py +6 -5
- diffusers/pipelines/deepfloyd_if/watermark.py +1 -1
- diffusers/pipelines/deprecated/alt_diffusion/modeling_roberta_series.py +11 -11
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +70 -30
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +48 -25
- diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +2 -2
- diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +7 -7
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +21 -20
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +27 -29
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +33 -27
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +33 -23
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +36 -30
- diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +102 -69
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion.py +13 -13
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +10 -5
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +11 -6
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +10 -5
- diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +5 -5
- diffusers/pipelines/dit/pipeline_dit.py +7 -4
- diffusers/pipelines/flux/__init__.py +69 -0
- diffusers/pipelines/flux/modeling_flux.py +47 -0
- diffusers/pipelines/flux/pipeline_flux.py +957 -0
- diffusers/pipelines/flux/pipeline_flux_control.py +889 -0
- diffusers/pipelines/flux/pipeline_flux_control_img2img.py +945 -0
- diffusers/pipelines/flux/pipeline_flux_control_inpaint.py +1141 -0
- diffusers/pipelines/flux/pipeline_flux_controlnet.py +1006 -0
- diffusers/pipelines/flux/pipeline_flux_controlnet_image_to_image.py +998 -0
- diffusers/pipelines/flux/pipeline_flux_controlnet_inpainting.py +1204 -0
- diffusers/pipelines/flux/pipeline_flux_fill.py +969 -0
- diffusers/pipelines/flux/pipeline_flux_img2img.py +856 -0
- diffusers/pipelines/flux/pipeline_flux_inpaint.py +1022 -0
- diffusers/pipelines/flux/pipeline_flux_prior_redux.py +492 -0
- diffusers/pipelines/flux/pipeline_output.py +37 -0
- diffusers/pipelines/free_init_utils.py +41 -38
- diffusers/pipelines/free_noise_utils.py +596 -0
- diffusers/pipelines/hunyuan_video/__init__.py +48 -0
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video.py +687 -0
- diffusers/pipelines/hunyuan_video/pipeline_output.py +20 -0
- diffusers/pipelines/hunyuandit/__init__.py +48 -0
- diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py +916 -0
- diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +33 -48
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +8 -8
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +32 -29
- diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +11 -11
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +12 -12
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +10 -10
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +6 -6
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +34 -31
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +10 -10
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +10 -10
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +6 -6
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +8 -8
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +7 -7
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py +6 -6
- diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +3 -3
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +22 -35
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +26 -37
- diffusers/pipelines/kolors/__init__.py +54 -0
- diffusers/pipelines/kolors/pipeline_kolors.py +1070 -0
- diffusers/pipelines/kolors/pipeline_kolors_img2img.py +1250 -0
- diffusers/pipelines/kolors/pipeline_output.py +21 -0
- diffusers/pipelines/kolors/text_encoder.py +889 -0
- diffusers/pipelines/kolors/tokenizer.py +338 -0
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +82 -62
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +77 -60
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +12 -12
- diffusers/pipelines/latte/__init__.py +48 -0
- diffusers/pipelines/latte/pipeline_latte.py +881 -0
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +80 -74
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +85 -76
- diffusers/pipelines/ledits_pp/pipeline_output.py +2 -2
- diffusers/pipelines/ltx/__init__.py +50 -0
- diffusers/pipelines/ltx/pipeline_ltx.py +789 -0
- diffusers/pipelines/ltx/pipeline_ltx_image2video.py +885 -0
- diffusers/pipelines/ltx/pipeline_output.py +20 -0
- diffusers/pipelines/lumina/__init__.py +48 -0
- diffusers/pipelines/lumina/pipeline_lumina.py +890 -0
- diffusers/pipelines/marigold/__init__.py +50 -0
- diffusers/pipelines/marigold/marigold_image_processing.py +576 -0
- diffusers/pipelines/marigold/pipeline_marigold_depth.py +813 -0
- diffusers/pipelines/marigold/pipeline_marigold_normals.py +690 -0
- diffusers/pipelines/mochi/__init__.py +48 -0
- diffusers/pipelines/mochi/pipeline_mochi.py +748 -0
- diffusers/pipelines/mochi/pipeline_output.py +20 -0
- diffusers/pipelines/musicldm/pipeline_musicldm.py +14 -14
- diffusers/pipelines/pag/__init__.py +80 -0
- diffusers/pipelines/pag/pag_utils.py +243 -0
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py +1328 -0
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_inpaint.py +1543 -0
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py +1610 -0
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl_img2img.py +1683 -0
- diffusers/pipelines/pag/pipeline_pag_hunyuandit.py +969 -0
- diffusers/pipelines/pag/pipeline_pag_kolors.py +1136 -0
- diffusers/pipelines/pag/pipeline_pag_pixart_sigma.py +865 -0
- diffusers/pipelines/pag/pipeline_pag_sana.py +886 -0
- diffusers/pipelines/pag/pipeline_pag_sd.py +1062 -0
- diffusers/pipelines/pag/pipeline_pag_sd_3.py +994 -0
- diffusers/pipelines/pag/pipeline_pag_sd_3_img2img.py +1058 -0
- diffusers/pipelines/pag/pipeline_pag_sd_animatediff.py +866 -0
- diffusers/pipelines/pag/pipeline_pag_sd_img2img.py +1094 -0
- diffusers/pipelines/pag/pipeline_pag_sd_inpaint.py +1356 -0
- diffusers/pipelines/pag/pipeline_pag_sd_xl.py +1345 -0
- diffusers/pipelines/pag/pipeline_pag_sd_xl_img2img.py +1544 -0
- diffusers/pipelines/pag/pipeline_pag_sd_xl_inpaint.py +1776 -0
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +17 -12
- diffusers/pipelines/pia/pipeline_pia.py +74 -164
- diffusers/pipelines/pipeline_flax_utils.py +5 -10
- diffusers/pipelines/pipeline_loading_utils.py +515 -53
- diffusers/pipelines/pipeline_utils.py +411 -222
- diffusers/pipelines/pixart_alpha/__init__.py +8 -1
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +76 -93
- diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py +873 -0
- diffusers/pipelines/sana/__init__.py +47 -0
- diffusers/pipelines/sana/pipeline_output.py +21 -0
- diffusers/pipelines/sana/pipeline_sana.py +884 -0
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +27 -23
- diffusers/pipelines/shap_e/pipeline_shap_e.py +3 -3
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +14 -14
- diffusers/pipelines/shap_e/renderer.py +1 -1
- diffusers/pipelines/stable_audio/__init__.py +50 -0
- diffusers/pipelines/stable_audio/modeling_stable_audio.py +158 -0
- diffusers/pipelines/stable_audio/pipeline_stable_audio.py +756 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +71 -25
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +23 -19
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +35 -34
- diffusers/pipelines/stable_diffusion/__init__.py +0 -1
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +20 -11
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +6 -6
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +145 -79
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +43 -28
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +13 -8
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +100 -68
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +109 -201
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +131 -32
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +247 -87
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +30 -29
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +35 -27
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +49 -42
- diffusers/pipelines/stable_diffusion/safety_checker.py +2 -1
- diffusers/pipelines/stable_diffusion_3/__init__.py +54 -0
- diffusers/pipelines/stable_diffusion_3/pipeline_output.py +21 -0
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +1140 -0
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +1036 -0
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +1250 -0
- diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +29 -20
- diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +59 -58
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +31 -25
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +38 -22
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +30 -24
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +24 -23
- diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +107 -67
- diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +316 -69
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +10 -5
- diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +98 -30
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +121 -83
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +161 -105
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +142 -218
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +45 -29
- diffusers/pipelines/stable_diffusion_xl/watermark.py +9 -3
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +110 -57
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +69 -39
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +105 -74
- diffusers/pipelines/text_to_video_synthesis/pipeline_output.py +3 -2
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +29 -49
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +32 -93
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +37 -25
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +54 -40
- diffusers/pipelines/unclip/pipeline_unclip.py +6 -6
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +6 -6
- diffusers/pipelines/unidiffuser/modeling_text_decoder.py +1 -1
- diffusers/pipelines/unidiffuser/modeling_uvit.py +12 -12
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +29 -28
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +5 -5
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +5 -10
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +6 -8
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +4 -4
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +12 -12
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +15 -14
- diffusers/{models/dual_transformer_2d.py → quantizers/__init__.py} +2 -6
- diffusers/quantizers/auto.py +139 -0
- diffusers/quantizers/base.py +233 -0
- diffusers/quantizers/bitsandbytes/__init__.py +2 -0
- diffusers/quantizers/bitsandbytes/bnb_quantizer.py +561 -0
- diffusers/quantizers/bitsandbytes/utils.py +306 -0
- diffusers/quantizers/gguf/__init__.py +1 -0
- diffusers/quantizers/gguf/gguf_quantizer.py +159 -0
- diffusers/quantizers/gguf/utils.py +456 -0
- diffusers/quantizers/quantization_config.py +669 -0
- diffusers/quantizers/torchao/__init__.py +15 -0
- diffusers/quantizers/torchao/torchao_quantizer.py +292 -0
- diffusers/schedulers/__init__.py +12 -2
- diffusers/schedulers/deprecated/__init__.py +1 -1
- diffusers/schedulers/deprecated/scheduling_karras_ve.py +25 -25
- diffusers/schedulers/scheduling_amused.py +5 -5
- diffusers/schedulers/scheduling_consistency_decoder.py +11 -11
- diffusers/schedulers/scheduling_consistency_models.py +23 -25
- diffusers/schedulers/scheduling_cosine_dpmsolver_multistep.py +572 -0
- diffusers/schedulers/scheduling_ddim.py +27 -26
- diffusers/schedulers/scheduling_ddim_cogvideox.py +452 -0
- diffusers/schedulers/scheduling_ddim_flax.py +2 -1
- diffusers/schedulers/scheduling_ddim_inverse.py +16 -16
- diffusers/schedulers/scheduling_ddim_parallel.py +32 -31
- diffusers/schedulers/scheduling_ddpm.py +27 -30
- diffusers/schedulers/scheduling_ddpm_flax.py +7 -3
- diffusers/schedulers/scheduling_ddpm_parallel.py +33 -36
- diffusers/schedulers/scheduling_ddpm_wuerstchen.py +14 -14
- diffusers/schedulers/scheduling_deis_multistep.py +150 -50
- diffusers/schedulers/scheduling_dpm_cogvideox.py +489 -0
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +221 -84
- diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +2 -2
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +158 -52
- diffusers/schedulers/scheduling_dpmsolver_sde.py +153 -34
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +275 -86
- diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +81 -57
- diffusers/schedulers/scheduling_edm_euler.py +62 -39
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +30 -29
- diffusers/schedulers/scheduling_euler_discrete.py +255 -74
- diffusers/schedulers/scheduling_flow_match_euler_discrete.py +458 -0
- diffusers/schedulers/scheduling_flow_match_heun_discrete.py +320 -0
- diffusers/schedulers/scheduling_heun_discrete.py +174 -46
- diffusers/schedulers/scheduling_ipndm.py +9 -9
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +138 -29
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +132 -26
- diffusers/schedulers/scheduling_karras_ve_flax.py +6 -6
- diffusers/schedulers/scheduling_lcm.py +23 -29
- diffusers/schedulers/scheduling_lms_discrete.py +105 -28
- diffusers/schedulers/scheduling_pndm.py +20 -20
- diffusers/schedulers/scheduling_repaint.py +21 -21
- diffusers/schedulers/scheduling_sasolver.py +157 -60
- diffusers/schedulers/scheduling_sde_ve.py +19 -19
- diffusers/schedulers/scheduling_tcd.py +41 -36
- diffusers/schedulers/scheduling_unclip.py +19 -16
- diffusers/schedulers/scheduling_unipc_multistep.py +243 -47
- diffusers/schedulers/scheduling_utils.py +12 -5
- diffusers/schedulers/scheduling_utils_flax.py +1 -3
- diffusers/schedulers/scheduling_vq_diffusion.py +10 -10
- diffusers/training_utils.py +214 -30
- diffusers/utils/__init__.py +17 -1
- diffusers/utils/constants.py +3 -0
- diffusers/utils/doc_utils.py +1 -0
- diffusers/utils/dummy_pt_objects.py +592 -7
- diffusers/utils/dummy_torch_and_torchsde_objects.py +15 -0
- diffusers/utils/dummy_torch_and_transformers_and_sentencepiece_objects.py +47 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +1001 -71
- diffusers/utils/dynamic_modules_utils.py +34 -29
- diffusers/utils/export_utils.py +50 -6
- diffusers/utils/hub_utils.py +131 -17
- diffusers/utils/import_utils.py +210 -8
- diffusers/utils/loading_utils.py +118 -5
- diffusers/utils/logging.py +4 -2
- diffusers/utils/peft_utils.py +37 -7
- diffusers/utils/state_dict_utils.py +13 -2
- diffusers/utils/testing_utils.py +193 -11
- diffusers/utils/torch_utils.py +4 -0
- diffusers/video_processor.py +113 -0
- {diffusers-0.27.1.dist-info → diffusers-0.32.2.dist-info}/METADATA +82 -91
- diffusers-0.32.2.dist-info/RECORD +550 -0
- {diffusers-0.27.1.dist-info → diffusers-0.32.2.dist-info}/WHEEL +1 -1
- diffusers/loaders/autoencoder.py +0 -146
- diffusers/loaders/controlnet.py +0 -136
- diffusers/loaders/lora.py +0 -1349
- diffusers/models/prior_transformer.py +0 -12
- diffusers/models/t5_film_transformer.py +0 -70
- diffusers/models/transformer_2d.py +0 -25
- diffusers/models/transformer_temporal.py +0 -34
- diffusers/models/unet_1d.py +0 -26
- diffusers/models/unet_1d_blocks.py +0 -203
- diffusers/models/unet_2d.py +0 -27
- diffusers/models/unet_2d_blocks.py +0 -375
- diffusers/models/unet_2d_condition.py +0 -25
- diffusers-0.27.1.dist-info/RECORD +0 -399
- {diffusers-0.27.1.dist-info → diffusers-0.32.2.dist-info}/LICENSE +0 -0
- {diffusers-0.27.1.dist-info → diffusers-0.32.2.dist-info}/entry_points.txt +0 -0
- {diffusers-0.27.1.dist-info → diffusers-0.32.2.dist-info}/top_level.txt +0 -0
@@ -31,23 +31,103 @@ class AdaLayerNorm(nn.Module):
|
|
31
31
|
|
32
32
|
Parameters:
|
33
33
|
embedding_dim (`int`): The size of each embedding vector.
|
34
|
-
num_embeddings (`int
|
34
|
+
num_embeddings (`int`, *optional*): The size of the embeddings dictionary.
|
35
|
+
output_dim (`int`, *optional*):
|
36
|
+
norm_elementwise_affine (`bool`, defaults to `False):
|
37
|
+
norm_eps (`bool`, defaults to `False`):
|
38
|
+
chunk_dim (`int`, defaults to `0`):
|
35
39
|
"""
|
36
40
|
|
37
|
-
def __init__(
|
41
|
+
def __init__(
|
42
|
+
self,
|
43
|
+
embedding_dim: int,
|
44
|
+
num_embeddings: Optional[int] = None,
|
45
|
+
output_dim: Optional[int] = None,
|
46
|
+
norm_elementwise_affine: bool = False,
|
47
|
+
norm_eps: float = 1e-5,
|
48
|
+
chunk_dim: int = 0,
|
49
|
+
):
|
38
50
|
super().__init__()
|
39
|
-
|
51
|
+
|
52
|
+
self.chunk_dim = chunk_dim
|
53
|
+
output_dim = output_dim or embedding_dim * 2
|
54
|
+
|
55
|
+
if num_embeddings is not None:
|
56
|
+
self.emb = nn.Embedding(num_embeddings, embedding_dim)
|
57
|
+
else:
|
58
|
+
self.emb = None
|
59
|
+
|
40
60
|
self.silu = nn.SiLU()
|
41
|
-
self.linear = nn.Linear(embedding_dim,
|
42
|
-
self.norm = nn.LayerNorm(
|
61
|
+
self.linear = nn.Linear(embedding_dim, output_dim)
|
62
|
+
self.norm = nn.LayerNorm(output_dim // 2, norm_eps, norm_elementwise_affine)
|
63
|
+
|
64
|
+
def forward(
|
65
|
+
self, x: torch.Tensor, timestep: Optional[torch.Tensor] = None, temb: Optional[torch.Tensor] = None
|
66
|
+
) -> torch.Tensor:
|
67
|
+
if self.emb is not None:
|
68
|
+
temb = self.emb(timestep)
|
69
|
+
|
70
|
+
temb = self.linear(self.silu(temb))
|
71
|
+
|
72
|
+
if self.chunk_dim == 1:
|
73
|
+
# This is a bit weird why we have the order of "shift, scale" here and "scale, shift" in the
|
74
|
+
# other if-branch. This branch is specific to CogVideoX for now.
|
75
|
+
shift, scale = temb.chunk(2, dim=1)
|
76
|
+
shift = shift[:, None, :]
|
77
|
+
scale = scale[:, None, :]
|
78
|
+
else:
|
79
|
+
scale, shift = temb.chunk(2, dim=0)
|
43
80
|
|
44
|
-
def forward(self, x: torch.Tensor, timestep: torch.Tensor) -> torch.Tensor:
|
45
|
-
emb = self.linear(self.silu(self.emb(timestep)))
|
46
|
-
scale, shift = torch.chunk(emb, 2)
|
47
81
|
x = self.norm(x) * (1 + scale) + shift
|
48
82
|
return x
|
49
83
|
|
50
84
|
|
85
|
+
class FP32LayerNorm(nn.LayerNorm):
|
86
|
+
def forward(self, inputs: torch.Tensor) -> torch.Tensor:
|
87
|
+
origin_dtype = inputs.dtype
|
88
|
+
return F.layer_norm(
|
89
|
+
inputs.float(),
|
90
|
+
self.normalized_shape,
|
91
|
+
self.weight.float() if self.weight is not None else None,
|
92
|
+
self.bias.float() if self.bias is not None else None,
|
93
|
+
self.eps,
|
94
|
+
).to(origin_dtype)
|
95
|
+
|
96
|
+
|
97
|
+
class SD35AdaLayerNormZeroX(nn.Module):
|
98
|
+
r"""
|
99
|
+
Norm layer adaptive layer norm zero (AdaLN-Zero).
|
100
|
+
|
101
|
+
Parameters:
|
102
|
+
embedding_dim (`int`): The size of each embedding vector.
|
103
|
+
num_embeddings (`int`): The size of the embeddings dictionary.
|
104
|
+
"""
|
105
|
+
|
106
|
+
def __init__(self, embedding_dim: int, norm_type: str = "layer_norm", bias: bool = True) -> None:
|
107
|
+
super().__init__()
|
108
|
+
|
109
|
+
self.silu = nn.SiLU()
|
110
|
+
self.linear = nn.Linear(embedding_dim, 9 * embedding_dim, bias=bias)
|
111
|
+
if norm_type == "layer_norm":
|
112
|
+
self.norm = nn.LayerNorm(embedding_dim, elementwise_affine=False, eps=1e-6)
|
113
|
+
else:
|
114
|
+
raise ValueError(f"Unsupported `norm_type` ({norm_type}) provided. Supported ones are: 'layer_norm'.")
|
115
|
+
|
116
|
+
def forward(
|
117
|
+
self,
|
118
|
+
hidden_states: torch.Tensor,
|
119
|
+
emb: Optional[torch.Tensor] = None,
|
120
|
+
) -> Tuple[torch.Tensor, ...]:
|
121
|
+
emb = self.linear(self.silu(emb))
|
122
|
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp, shift_msa2, scale_msa2, gate_msa2 = emb.chunk(
|
123
|
+
9, dim=1
|
124
|
+
)
|
125
|
+
norm_hidden_states = self.norm(hidden_states)
|
126
|
+
hidden_states = norm_hidden_states * (1 + scale_msa[:, None]) + shift_msa[:, None]
|
127
|
+
norm_hidden_states2 = norm_hidden_states * (1 + scale_msa2[:, None]) + shift_msa2[:, None]
|
128
|
+
return hidden_states, gate_msa, shift_mlp, scale_mlp, gate_mlp, norm_hidden_states2, gate_msa2
|
129
|
+
|
130
|
+
|
51
131
|
class AdaLayerNormZero(nn.Module):
|
52
132
|
r"""
|
53
133
|
Norm layer adaptive layer norm zero (adaLN-Zero).
|
@@ -57,28 +137,103 @@ class AdaLayerNormZero(nn.Module):
|
|
57
137
|
num_embeddings (`int`): The size of the embeddings dictionary.
|
58
138
|
"""
|
59
139
|
|
60
|
-
def __init__(self, embedding_dim: int, num_embeddings: int):
|
140
|
+
def __init__(self, embedding_dim: int, num_embeddings: Optional[int] = None, norm_type="layer_norm", bias=True):
|
61
141
|
super().__init__()
|
62
|
-
|
63
|
-
|
142
|
+
if num_embeddings is not None:
|
143
|
+
self.emb = CombinedTimestepLabelEmbeddings(num_embeddings, embedding_dim)
|
144
|
+
else:
|
145
|
+
self.emb = None
|
64
146
|
|
65
147
|
self.silu = nn.SiLU()
|
66
|
-
self.linear = nn.Linear(embedding_dim, 6 * embedding_dim, bias=
|
67
|
-
|
148
|
+
self.linear = nn.Linear(embedding_dim, 6 * embedding_dim, bias=bias)
|
149
|
+
if norm_type == "layer_norm":
|
150
|
+
self.norm = nn.LayerNorm(embedding_dim, elementwise_affine=False, eps=1e-6)
|
151
|
+
elif norm_type == "fp32_layer_norm":
|
152
|
+
self.norm = FP32LayerNorm(embedding_dim, elementwise_affine=False, bias=False)
|
153
|
+
else:
|
154
|
+
raise ValueError(
|
155
|
+
f"Unsupported `norm_type` ({norm_type}) provided. Supported ones are: 'layer_norm', 'fp32_layer_norm'."
|
156
|
+
)
|
68
157
|
|
69
158
|
def forward(
|
70
159
|
self,
|
71
160
|
x: torch.Tensor,
|
72
|
-
timestep: torch.Tensor,
|
73
|
-
class_labels: torch.LongTensor,
|
161
|
+
timestep: Optional[torch.Tensor] = None,
|
162
|
+
class_labels: Optional[torch.LongTensor] = None,
|
74
163
|
hidden_dtype: Optional[torch.dtype] = None,
|
164
|
+
emb: Optional[torch.Tensor] = None,
|
75
165
|
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
76
|
-
|
166
|
+
if self.emb is not None:
|
167
|
+
emb = self.emb(timestep, class_labels, hidden_dtype=hidden_dtype)
|
168
|
+
emb = self.linear(self.silu(emb))
|
77
169
|
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = emb.chunk(6, dim=1)
|
78
170
|
x = self.norm(x) * (1 + scale_msa[:, None]) + shift_msa[:, None]
|
79
171
|
return x, gate_msa, shift_mlp, scale_mlp, gate_mlp
|
80
172
|
|
81
173
|
|
174
|
+
class AdaLayerNormZeroSingle(nn.Module):
|
175
|
+
r"""
|
176
|
+
Norm layer adaptive layer norm zero (adaLN-Zero).
|
177
|
+
|
178
|
+
Parameters:
|
179
|
+
embedding_dim (`int`): The size of each embedding vector.
|
180
|
+
num_embeddings (`int`): The size of the embeddings dictionary.
|
181
|
+
"""
|
182
|
+
|
183
|
+
def __init__(self, embedding_dim: int, norm_type="layer_norm", bias=True):
|
184
|
+
super().__init__()
|
185
|
+
|
186
|
+
self.silu = nn.SiLU()
|
187
|
+
self.linear = nn.Linear(embedding_dim, 3 * embedding_dim, bias=bias)
|
188
|
+
if norm_type == "layer_norm":
|
189
|
+
self.norm = nn.LayerNorm(embedding_dim, elementwise_affine=False, eps=1e-6)
|
190
|
+
else:
|
191
|
+
raise ValueError(
|
192
|
+
f"Unsupported `norm_type` ({norm_type}) provided. Supported ones are: 'layer_norm', 'fp32_layer_norm'."
|
193
|
+
)
|
194
|
+
|
195
|
+
def forward(
|
196
|
+
self,
|
197
|
+
x: torch.Tensor,
|
198
|
+
emb: Optional[torch.Tensor] = None,
|
199
|
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
200
|
+
emb = self.linear(self.silu(emb))
|
201
|
+
shift_msa, scale_msa, gate_msa = emb.chunk(3, dim=1)
|
202
|
+
x = self.norm(x) * (1 + scale_msa[:, None]) + shift_msa[:, None]
|
203
|
+
return x, gate_msa
|
204
|
+
|
205
|
+
|
206
|
+
class LuminaRMSNormZero(nn.Module):
|
207
|
+
"""
|
208
|
+
Norm layer adaptive RMS normalization zero.
|
209
|
+
|
210
|
+
Parameters:
|
211
|
+
embedding_dim (`int`): The size of each embedding vector.
|
212
|
+
"""
|
213
|
+
|
214
|
+
def __init__(self, embedding_dim: int, norm_eps: float, norm_elementwise_affine: bool):
|
215
|
+
super().__init__()
|
216
|
+
self.silu = nn.SiLU()
|
217
|
+
self.linear = nn.Linear(
|
218
|
+
min(embedding_dim, 1024),
|
219
|
+
4 * embedding_dim,
|
220
|
+
bias=True,
|
221
|
+
)
|
222
|
+
self.norm = RMSNorm(embedding_dim, eps=norm_eps, elementwise_affine=norm_elementwise_affine)
|
223
|
+
|
224
|
+
def forward(
|
225
|
+
self,
|
226
|
+
x: torch.Tensor,
|
227
|
+
emb: Optional[torch.Tensor] = None,
|
228
|
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
229
|
+
# emb = self.emb(timestep, encoder_hidden_states, encoder_mask)
|
230
|
+
emb = self.linear(self.silu(emb))
|
231
|
+
scale_msa, gate_msa, scale_mlp, gate_mlp = emb.chunk(4, dim=1)
|
232
|
+
x = self.norm(x) * (1 + scale_msa[:, None])
|
233
|
+
|
234
|
+
return x, gate_msa, scale_mlp, gate_mlp
|
235
|
+
|
236
|
+
|
82
237
|
class AdaLayerNormSingle(nn.Module):
|
83
238
|
r"""
|
84
239
|
Norm layer adaptive layer norm single (adaLN-single).
|
@@ -108,6 +263,7 @@ class AdaLayerNormSingle(nn.Module):
|
|
108
263
|
hidden_dtype: Optional[torch.dtype] = None,
|
109
264
|
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
110
265
|
# No modulation happening here.
|
266
|
+
added_cond_kwargs = added_cond_kwargs or {"resolution": None, "aspect_ratio": None}
|
111
267
|
embedded_timestep = self.emb(timestep, **added_cond_kwargs, batch_size=batch_size, hidden_dtype=hidden_dtype)
|
112
268
|
return self.linear(self.silu(embedded_timestep)), embedded_timestep
|
113
269
|
|
@@ -176,12 +332,131 @@ class AdaLayerNormContinuous(nn.Module):
|
|
176
332
|
raise ValueError(f"unknown norm_type {norm_type}")
|
177
333
|
|
178
334
|
def forward(self, x: torch.Tensor, conditioning_embedding: torch.Tensor) -> torch.Tensor:
|
179
|
-
|
335
|
+
# convert back to the original dtype in case `conditioning_embedding`` is upcasted to float32 (needed for hunyuanDiT)
|
336
|
+
emb = self.linear(self.silu(conditioning_embedding).to(x.dtype))
|
180
337
|
scale, shift = torch.chunk(emb, 2, dim=1)
|
181
338
|
x = self.norm(x) * (1 + scale)[:, None, :] + shift[:, None, :]
|
182
339
|
return x
|
183
340
|
|
184
341
|
|
342
|
+
class LuminaLayerNormContinuous(nn.Module):
|
343
|
+
def __init__(
|
344
|
+
self,
|
345
|
+
embedding_dim: int,
|
346
|
+
conditioning_embedding_dim: int,
|
347
|
+
# NOTE: It is a bit weird that the norm layer can be configured to have scale and shift parameters
|
348
|
+
# because the output is immediately scaled and shifted by the projected conditioning embeddings.
|
349
|
+
# Note that AdaLayerNorm does not let the norm layer have scale and shift parameters.
|
350
|
+
# However, this is how it was implemented in the original code, and it's rather likely you should
|
351
|
+
# set `elementwise_affine` to False.
|
352
|
+
elementwise_affine=True,
|
353
|
+
eps=1e-5,
|
354
|
+
bias=True,
|
355
|
+
norm_type="layer_norm",
|
356
|
+
out_dim: Optional[int] = None,
|
357
|
+
):
|
358
|
+
super().__init__()
|
359
|
+
|
360
|
+
# AdaLN
|
361
|
+
self.silu = nn.SiLU()
|
362
|
+
self.linear_1 = nn.Linear(conditioning_embedding_dim, embedding_dim, bias=bias)
|
363
|
+
|
364
|
+
if norm_type == "layer_norm":
|
365
|
+
self.norm = LayerNorm(embedding_dim, eps, elementwise_affine, bias)
|
366
|
+
elif norm_type == "rms_norm":
|
367
|
+
self.norm = RMSNorm(embedding_dim, eps=eps, elementwise_affine=elementwise_affine)
|
368
|
+
else:
|
369
|
+
raise ValueError(f"unknown norm_type {norm_type}")
|
370
|
+
|
371
|
+
self.linear_2 = None
|
372
|
+
if out_dim is not None:
|
373
|
+
self.linear_2 = nn.Linear(embedding_dim, out_dim, bias=bias)
|
374
|
+
|
375
|
+
def forward(
|
376
|
+
self,
|
377
|
+
x: torch.Tensor,
|
378
|
+
conditioning_embedding: torch.Tensor,
|
379
|
+
) -> torch.Tensor:
|
380
|
+
# convert back to the original dtype in case `conditioning_embedding`` is upcasted to float32 (needed for hunyuanDiT)
|
381
|
+
emb = self.linear_1(self.silu(conditioning_embedding).to(x.dtype))
|
382
|
+
scale = emb
|
383
|
+
x = self.norm(x) * (1 + scale)[:, None, :]
|
384
|
+
|
385
|
+
if self.linear_2 is not None:
|
386
|
+
x = self.linear_2(x)
|
387
|
+
|
388
|
+
return x
|
389
|
+
|
390
|
+
|
391
|
+
class CogView3PlusAdaLayerNormZeroTextImage(nn.Module):
|
392
|
+
r"""
|
393
|
+
Norm layer adaptive layer norm zero (adaLN-Zero).
|
394
|
+
|
395
|
+
Parameters:
|
396
|
+
embedding_dim (`int`): The size of each embedding vector.
|
397
|
+
num_embeddings (`int`): The size of the embeddings dictionary.
|
398
|
+
"""
|
399
|
+
|
400
|
+
def __init__(self, embedding_dim: int, dim: int):
|
401
|
+
super().__init__()
|
402
|
+
|
403
|
+
self.silu = nn.SiLU()
|
404
|
+
self.linear = nn.Linear(embedding_dim, 12 * dim, bias=True)
|
405
|
+
self.norm_x = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-5)
|
406
|
+
self.norm_c = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-5)
|
407
|
+
|
408
|
+
def forward(
|
409
|
+
self,
|
410
|
+
x: torch.Tensor,
|
411
|
+
context: torch.Tensor,
|
412
|
+
emb: Optional[torch.Tensor] = None,
|
413
|
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
414
|
+
emb = self.linear(self.silu(emb))
|
415
|
+
(
|
416
|
+
shift_msa,
|
417
|
+
scale_msa,
|
418
|
+
gate_msa,
|
419
|
+
shift_mlp,
|
420
|
+
scale_mlp,
|
421
|
+
gate_mlp,
|
422
|
+
c_shift_msa,
|
423
|
+
c_scale_msa,
|
424
|
+
c_gate_msa,
|
425
|
+
c_shift_mlp,
|
426
|
+
c_scale_mlp,
|
427
|
+
c_gate_mlp,
|
428
|
+
) = emb.chunk(12, dim=1)
|
429
|
+
normed_x = self.norm_x(x)
|
430
|
+
normed_context = self.norm_c(context)
|
431
|
+
x = normed_x * (1 + scale_msa[:, None]) + shift_msa[:, None]
|
432
|
+
context = normed_context * (1 + c_scale_msa[:, None]) + c_shift_msa[:, None]
|
433
|
+
return x, gate_msa, shift_mlp, scale_mlp, gate_mlp, context, c_gate_msa, c_shift_mlp, c_scale_mlp, c_gate_mlp
|
434
|
+
|
435
|
+
|
436
|
+
class CogVideoXLayerNormZero(nn.Module):
|
437
|
+
def __init__(
|
438
|
+
self,
|
439
|
+
conditioning_dim: int,
|
440
|
+
embedding_dim: int,
|
441
|
+
elementwise_affine: bool = True,
|
442
|
+
eps: float = 1e-5,
|
443
|
+
bias: bool = True,
|
444
|
+
) -> None:
|
445
|
+
super().__init__()
|
446
|
+
|
447
|
+
self.silu = nn.SiLU()
|
448
|
+
self.linear = nn.Linear(conditioning_dim, 6 * embedding_dim, bias=bias)
|
449
|
+
self.norm = nn.LayerNorm(embedding_dim, eps=eps, elementwise_affine=elementwise_affine)
|
450
|
+
|
451
|
+
def forward(
|
452
|
+
self, hidden_states: torch.Tensor, encoder_hidden_states: torch.Tensor, temb: torch.Tensor
|
453
|
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
454
|
+
shift, scale, gate, enc_shift, enc_scale, enc_gate = self.linear(self.silu(temb)).chunk(6, dim=1)
|
455
|
+
hidden_states = self.norm(hidden_states) * (1 + scale)[:, None, :] + shift[:, None, :]
|
456
|
+
encoder_hidden_states = self.norm(encoder_hidden_states) * (1 + enc_scale)[:, None, :] + enc_shift[:, None, :]
|
457
|
+
return hidden_states, encoder_hidden_states, gate[:, None, :], enc_gate[:, None, :]
|
458
|
+
|
459
|
+
|
185
460
|
if is_torch_version(">=", "2.1.0"):
|
186
461
|
LayerNorm = nn.LayerNorm
|
187
462
|
else:
|
@@ -210,20 +485,24 @@ else:
|
|
210
485
|
|
211
486
|
|
212
487
|
class RMSNorm(nn.Module):
|
213
|
-
def __init__(self, dim, eps: float, elementwise_affine: bool = True):
|
488
|
+
def __init__(self, dim, eps: float, elementwise_affine: bool = True, bias: bool = False):
|
214
489
|
super().__init__()
|
215
490
|
|
216
491
|
self.eps = eps
|
492
|
+
self.elementwise_affine = elementwise_affine
|
217
493
|
|
218
494
|
if isinstance(dim, numbers.Integral):
|
219
495
|
dim = (dim,)
|
220
496
|
|
221
497
|
self.dim = torch.Size(dim)
|
222
498
|
|
499
|
+
self.weight = None
|
500
|
+
self.bias = None
|
501
|
+
|
223
502
|
if elementwise_affine:
|
224
503
|
self.weight = nn.Parameter(torch.ones(dim))
|
225
|
-
|
226
|
-
|
504
|
+
if bias:
|
505
|
+
self.bias = nn.Parameter(torch.zeros(dim))
|
227
506
|
|
228
507
|
def forward(self, hidden_states):
|
229
508
|
input_dtype = hidden_states.dtype
|
@@ -235,12 +514,44 @@ class RMSNorm(nn.Module):
|
|
235
514
|
if self.weight.dtype in [torch.float16, torch.bfloat16]:
|
236
515
|
hidden_states = hidden_states.to(self.weight.dtype)
|
237
516
|
hidden_states = hidden_states * self.weight
|
517
|
+
if self.bias is not None:
|
518
|
+
hidden_states = hidden_states + self.bias
|
238
519
|
else:
|
239
520
|
hidden_states = hidden_states.to(input_dtype)
|
240
521
|
|
241
522
|
return hidden_states
|
242
523
|
|
243
524
|
|
525
|
+
# TODO: (Dhruv) This can be replaced with regular RMSNorm in Mochi once `_keep_in_fp32_modules` is supported
|
526
|
+
# for sharded checkpoints, see: https://github.com/huggingface/diffusers/issues/10013
|
527
|
+
class MochiRMSNorm(nn.Module):
|
528
|
+
def __init__(self, dim, eps: float, elementwise_affine: bool = True):
|
529
|
+
super().__init__()
|
530
|
+
|
531
|
+
self.eps = eps
|
532
|
+
|
533
|
+
if isinstance(dim, numbers.Integral):
|
534
|
+
dim = (dim,)
|
535
|
+
|
536
|
+
self.dim = torch.Size(dim)
|
537
|
+
|
538
|
+
if elementwise_affine:
|
539
|
+
self.weight = nn.Parameter(torch.ones(dim))
|
540
|
+
else:
|
541
|
+
self.weight = None
|
542
|
+
|
543
|
+
def forward(self, hidden_states):
|
544
|
+
input_dtype = hidden_states.dtype
|
545
|
+
variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)
|
546
|
+
hidden_states = hidden_states * torch.rsqrt(variance + self.eps)
|
547
|
+
|
548
|
+
if self.weight is not None:
|
549
|
+
hidden_states = hidden_states * self.weight
|
550
|
+
hidden_states = hidden_states.to(input_dtype)
|
551
|
+
|
552
|
+
return hidden_states
|
553
|
+
|
554
|
+
|
244
555
|
class GlobalResponseNorm(nn.Module):
|
245
556
|
# Taken from https://github.com/facebookresearch/ConvNeXt-V2/blob/3608f67cc1dae164790c5d0aead7bf2d73d9719b/models/utils.py#L105
|
246
557
|
def __init__(self, dim):
|
@@ -252,3 +563,33 @@ class GlobalResponseNorm(nn.Module):
|
|
252
563
|
gx = torch.norm(x, p=2, dim=(1, 2), keepdim=True)
|
253
564
|
nx = gx / (gx.mean(dim=-1, keepdim=True) + 1e-6)
|
254
565
|
return self.gamma * (x * nx) + self.beta + x
|
566
|
+
|
567
|
+
|
568
|
+
class LpNorm(nn.Module):
|
569
|
+
def __init__(self, p: int = 2, dim: int = -1, eps: float = 1e-12):
|
570
|
+
super().__init__()
|
571
|
+
|
572
|
+
self.p = p
|
573
|
+
self.dim = dim
|
574
|
+
self.eps = eps
|
575
|
+
|
576
|
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
577
|
+
return F.normalize(hidden_states, p=self.p, dim=self.dim, eps=self.eps)
|
578
|
+
|
579
|
+
|
580
|
+
def get_normalization(
|
581
|
+
norm_type: str = "batch_norm",
|
582
|
+
num_features: Optional[int] = None,
|
583
|
+
eps: float = 1e-5,
|
584
|
+
elementwise_affine: bool = True,
|
585
|
+
bias: bool = True,
|
586
|
+
) -> nn.Module:
|
587
|
+
if norm_type == "rms_norm":
|
588
|
+
norm = RMSNorm(num_features, eps=eps, elementwise_affine=elementwise_affine, bias=bias)
|
589
|
+
elif norm_type == "layer_norm":
|
590
|
+
norm = nn.LayerNorm(num_features, eps=eps, elementwise_affine=elementwise_affine, bias=bias)
|
591
|
+
elif norm_type == "batch_norm":
|
592
|
+
norm = nn.BatchNorm2d(num_features, eps=eps, affine=elementwise_affine)
|
593
|
+
else:
|
594
|
+
raise ValueError(f"{norm_type=} is not supported.")
|
595
|
+
return norm
|
diffusers/models/resnet.py
CHANGED
@@ -58,7 +58,7 @@ class ResnetBlockCondNorm2D(nn.Module):
|
|
58
58
|
non_linearity (`str`, *optional*, default to `"swish"`): the activation function to use.
|
59
59
|
time_embedding_norm (`str`, *optional*, default to `"ada_group"` ):
|
60
60
|
The normalization layer for time embedding `temb`. Currently only support "ada_group" or "spatial".
|
61
|
-
kernel (`torch.
|
61
|
+
kernel (`torch.Tensor`, optional, default to None): FIR filter, see
|
62
62
|
[`~models.resnet.FirUpsample2D`] and [`~models.resnet.FirDownsample2D`].
|
63
63
|
output_scale_factor (`float`, *optional*, default to be `1.0`): the scale factor to use for the output.
|
64
64
|
use_in_shortcut (`bool`, *optional*, default to `True`):
|
@@ -101,8 +101,6 @@ class ResnetBlockCondNorm2D(nn.Module):
|
|
101
101
|
self.output_scale_factor = output_scale_factor
|
102
102
|
self.time_embedding_norm = time_embedding_norm
|
103
103
|
|
104
|
-
conv_cls = nn.Conv2d
|
105
|
-
|
106
104
|
if groups_out is None:
|
107
105
|
groups_out = groups
|
108
106
|
|
@@ -113,7 +111,7 @@ class ResnetBlockCondNorm2D(nn.Module):
|
|
113
111
|
else:
|
114
112
|
raise ValueError(f" unsupported time_embedding_norm: {self.time_embedding_norm}")
|
115
113
|
|
116
|
-
self.conv1 =
|
114
|
+
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1)
|
117
115
|
|
118
116
|
if self.time_embedding_norm == "ada_group": # ada_group
|
119
117
|
self.norm2 = AdaGroupNorm(temb_channels, out_channels, groups_out, eps=eps)
|
@@ -125,7 +123,7 @@ class ResnetBlockCondNorm2D(nn.Module):
|
|
125
123
|
self.dropout = torch.nn.Dropout(dropout)
|
126
124
|
|
127
125
|
conv_2d_out_channels = conv_2d_out_channels or out_channels
|
128
|
-
self.conv2 =
|
126
|
+
self.conv2 = nn.Conv2d(out_channels, conv_2d_out_channels, kernel_size=3, stride=1, padding=1)
|
129
127
|
|
130
128
|
self.nonlinearity = get_activation(non_linearity)
|
131
129
|
|
@@ -139,7 +137,7 @@ class ResnetBlockCondNorm2D(nn.Module):
|
|
139
137
|
|
140
138
|
self.conv_shortcut = None
|
141
139
|
if self.use_in_shortcut:
|
142
|
-
self.conv_shortcut =
|
140
|
+
self.conv_shortcut = nn.Conv2d(
|
143
141
|
in_channels,
|
144
142
|
conv_2d_out_channels,
|
145
143
|
kernel_size=1,
|
@@ -148,7 +146,7 @@ class ResnetBlockCondNorm2D(nn.Module):
|
|
148
146
|
bias=conv_shortcut_bias,
|
149
147
|
)
|
150
148
|
|
151
|
-
def forward(self, input_tensor: torch.
|
149
|
+
def forward(self, input_tensor: torch.Tensor, temb: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
152
150
|
if len(args) > 0 or kwargs.get("scale", None) is not None:
|
153
151
|
deprecation_message = "The `scale` argument is deprecated and will be ignored. Please remove it, as passing it will raise an error in the future. `scale` should directly be passed while calling the underlying pipeline component i.e., via `cross_attention_kwargs`."
|
154
152
|
deprecate("scale", "1.0.0", deprecation_message)
|
@@ -204,9 +202,9 @@ class ResnetBlock2D(nn.Module):
|
|
204
202
|
eps (`float`, *optional*, defaults to `1e-6`): The epsilon to use for the normalization.
|
205
203
|
non_linearity (`str`, *optional*, default to `"swish"`): the activation function to use.
|
206
204
|
time_embedding_norm (`str`, *optional*, default to `"default"` ): Time scale shift config.
|
207
|
-
By default, apply timestep embedding conditioning with a simple shift mechanism. Choose "scale_shift"
|
208
|
-
|
209
|
-
kernel (`torch.
|
205
|
+
By default, apply timestep embedding conditioning with a simple shift mechanism. Choose "scale_shift" for a
|
206
|
+
stronger conditioning with scale and shift.
|
207
|
+
kernel (`torch.Tensor`, optional, default to None): FIR filter, see
|
210
208
|
[`~models.resnet.FirUpsample2D`] and [`~models.resnet.FirDownsample2D`].
|
211
209
|
output_scale_factor (`float`, *optional*, default to be `1.0`): the scale factor to use for the output.
|
212
210
|
use_in_shortcut (`bool`, *optional*, default to `True`):
|
@@ -234,7 +232,7 @@ class ResnetBlock2D(nn.Module):
|
|
234
232
|
non_linearity: str = "swish",
|
235
233
|
skip_time_act: bool = False,
|
236
234
|
time_embedding_norm: str = "default", # default, scale_shift,
|
237
|
-
kernel: Optional[torch.
|
235
|
+
kernel: Optional[torch.Tensor] = None,
|
238
236
|
output_scale_factor: float = 1.0,
|
239
237
|
use_in_shortcut: Optional[bool] = None,
|
240
238
|
up: bool = False,
|
@@ -263,21 +261,18 @@ class ResnetBlock2D(nn.Module):
|
|
263
261
|
self.time_embedding_norm = time_embedding_norm
|
264
262
|
self.skip_time_act = skip_time_act
|
265
263
|
|
266
|
-
linear_cls = nn.Linear
|
267
|
-
conv_cls = nn.Conv2d
|
268
|
-
|
269
264
|
if groups_out is None:
|
270
265
|
groups_out = groups
|
271
266
|
|
272
267
|
self.norm1 = torch.nn.GroupNorm(num_groups=groups, num_channels=in_channels, eps=eps, affine=True)
|
273
268
|
|
274
|
-
self.conv1 =
|
269
|
+
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1)
|
275
270
|
|
276
271
|
if temb_channels is not None:
|
277
272
|
if self.time_embedding_norm == "default":
|
278
|
-
self.time_emb_proj =
|
273
|
+
self.time_emb_proj = nn.Linear(temb_channels, out_channels)
|
279
274
|
elif self.time_embedding_norm == "scale_shift":
|
280
|
-
self.time_emb_proj =
|
275
|
+
self.time_emb_proj = nn.Linear(temb_channels, 2 * out_channels)
|
281
276
|
else:
|
282
277
|
raise ValueError(f"unknown time_embedding_norm : {self.time_embedding_norm} ")
|
283
278
|
else:
|
@@ -287,7 +282,7 @@ class ResnetBlock2D(nn.Module):
|
|
287
282
|
|
288
283
|
self.dropout = torch.nn.Dropout(dropout)
|
289
284
|
conv_2d_out_channels = conv_2d_out_channels or out_channels
|
290
|
-
self.conv2 =
|
285
|
+
self.conv2 = nn.Conv2d(out_channels, conv_2d_out_channels, kernel_size=3, stride=1, padding=1)
|
291
286
|
|
292
287
|
self.nonlinearity = get_activation(non_linearity)
|
293
288
|
|
@@ -313,7 +308,7 @@ class ResnetBlock2D(nn.Module):
|
|
313
308
|
|
314
309
|
self.conv_shortcut = None
|
315
310
|
if self.use_in_shortcut:
|
316
|
-
self.conv_shortcut =
|
311
|
+
self.conv_shortcut = nn.Conv2d(
|
317
312
|
in_channels,
|
318
313
|
conv_2d_out_channels,
|
319
314
|
kernel_size=1,
|
@@ -322,7 +317,7 @@ class ResnetBlock2D(nn.Module):
|
|
322
317
|
bias=conv_shortcut_bias,
|
323
318
|
)
|
324
319
|
|
325
|
-
def forward(self, input_tensor: torch.
|
320
|
+
def forward(self, input_tensor: torch.Tensor, temb: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
326
321
|
if len(args) > 0 or kwargs.get("scale", None) is not None:
|
327
322
|
deprecation_message = "The `scale` argument is deprecated and will be ignored. Please remove it, as passing it will raise an error in the future. `scale` should directly be passed while calling the underlying pipeline component i.e., via `cross_attention_kwargs`."
|
328
323
|
deprecate("scale", "1.0.0", deprecation_message)
|
@@ -610,7 +605,7 @@ class TemporalResnetBlock(nn.Module):
|
|
610
605
|
padding=0,
|
611
606
|
)
|
612
607
|
|
613
|
-
def forward(self, input_tensor: torch.
|
608
|
+
def forward(self, input_tensor: torch.Tensor, temb: torch.Tensor) -> torch.Tensor:
|
614
609
|
hidden_states = input_tensor
|
615
610
|
|
616
611
|
hidden_states = self.norm1(hidden_states)
|
@@ -690,8 +685,8 @@ class SpatioTemporalResBlock(nn.Module):
|
|
690
685
|
|
691
686
|
def forward(
|
692
687
|
self,
|
693
|
-
hidden_states: torch.
|
694
|
-
temb: Optional[torch.
|
688
|
+
hidden_states: torch.Tensor,
|
689
|
+
temb: Optional[torch.Tensor] = None,
|
695
690
|
image_only_indicator: Optional[torch.Tensor] = None,
|
696
691
|
):
|
697
692
|
num_frames = image_only_indicator.shape[-1]
|
@@ -2,8 +2,24 @@ from ...utils import is_torch_available
|
|
2
2
|
|
3
3
|
|
4
4
|
if is_torch_available():
|
5
|
+
from .auraflow_transformer_2d import AuraFlowTransformer2DModel
|
6
|
+
from .cogvideox_transformer_3d import CogVideoXTransformer3DModel
|
7
|
+
from .dit_transformer_2d import DiTTransformer2DModel
|
5
8
|
from .dual_transformer_2d import DualTransformer2DModel
|
9
|
+
from .hunyuan_transformer_2d import HunyuanDiT2DModel
|
10
|
+
from .latte_transformer_3d import LatteTransformer3DModel
|
11
|
+
from .lumina_nextdit2d import LuminaNextDiT2DModel
|
12
|
+
from .pixart_transformer_2d import PixArtTransformer2DModel
|
6
13
|
from .prior_transformer import PriorTransformer
|
14
|
+
from .sana_transformer import SanaTransformer2DModel
|
15
|
+
from .stable_audio_transformer import StableAudioDiTModel
|
7
16
|
from .t5_film_transformer import T5FilmDecoder
|
8
17
|
from .transformer_2d import Transformer2DModel
|
18
|
+
from .transformer_allegro import AllegroTransformer3DModel
|
19
|
+
from .transformer_cogview3plus import CogView3PlusTransformer2DModel
|
20
|
+
from .transformer_flux import FluxTransformer2DModel
|
21
|
+
from .transformer_hunyuan_video import HunyuanVideoTransformer3DModel
|
22
|
+
from .transformer_ltx import LTXVideoTransformer3DModel
|
23
|
+
from .transformer_mochi import MochiTransformer3DModel
|
24
|
+
from .transformer_sd3 import SD3Transformer2DModel
|
9
25
|
from .transformer_temporal import TransformerTemporalModel
|