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
@@ -0,0 +1,445 @@
|
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
from typing import Any, Dict, Optional, Union
|
15
|
+
|
16
|
+
import torch
|
17
|
+
from torch import nn
|
18
|
+
|
19
|
+
from ...configuration_utils import ConfigMixin, register_to_config
|
20
|
+
from ...utils import is_torch_version, logging
|
21
|
+
from ..attention import BasicTransformerBlock
|
22
|
+
from ..attention_processor import Attention, AttentionProcessor, AttnProcessor, FusedAttnProcessor2_0
|
23
|
+
from ..embeddings import PatchEmbed, PixArtAlphaTextProjection
|
24
|
+
from ..modeling_outputs import Transformer2DModelOutput
|
25
|
+
from ..modeling_utils import ModelMixin
|
26
|
+
from ..normalization import AdaLayerNormSingle
|
27
|
+
|
28
|
+
|
29
|
+
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
30
|
+
|
31
|
+
|
32
|
+
class PixArtTransformer2DModel(ModelMixin, ConfigMixin):
|
33
|
+
r"""
|
34
|
+
A 2D Transformer model as introduced in PixArt family of models (https://arxiv.org/abs/2310.00426,
|
35
|
+
https://arxiv.org/abs/2403.04692).
|
36
|
+
|
37
|
+
Parameters:
|
38
|
+
num_attention_heads (int, optional, defaults to 16): The number of heads to use for multi-head attention.
|
39
|
+
attention_head_dim (int, optional, defaults to 72): The number of channels in each head.
|
40
|
+
in_channels (int, defaults to 4): The number of channels in the input.
|
41
|
+
out_channels (int, optional):
|
42
|
+
The number of channels in the output. Specify this parameter if the output channel number differs from the
|
43
|
+
input.
|
44
|
+
num_layers (int, optional, defaults to 28): The number of layers of Transformer blocks to use.
|
45
|
+
dropout (float, optional, defaults to 0.0): The dropout probability to use within the Transformer blocks.
|
46
|
+
norm_num_groups (int, optional, defaults to 32):
|
47
|
+
Number of groups for group normalization within Transformer blocks.
|
48
|
+
cross_attention_dim (int, optional):
|
49
|
+
The dimensionality for cross-attention layers, typically matching the encoder's hidden dimension.
|
50
|
+
attention_bias (bool, optional, defaults to True):
|
51
|
+
Configure if the Transformer blocks' attention should contain a bias parameter.
|
52
|
+
sample_size (int, defaults to 128):
|
53
|
+
The width of the latent images. This parameter is fixed during training.
|
54
|
+
patch_size (int, defaults to 2):
|
55
|
+
Size of the patches the model processes, relevant for architectures working on non-sequential data.
|
56
|
+
activation_fn (str, optional, defaults to "gelu-approximate"):
|
57
|
+
Activation function to use in feed-forward networks within Transformer blocks.
|
58
|
+
num_embeds_ada_norm (int, optional, defaults to 1000):
|
59
|
+
Number of embeddings for AdaLayerNorm, fixed during training and affects the maximum denoising steps during
|
60
|
+
inference.
|
61
|
+
upcast_attention (bool, optional, defaults to False):
|
62
|
+
If true, upcasts the attention mechanism dimensions for potentially improved performance.
|
63
|
+
norm_type (str, optional, defaults to "ada_norm_zero"):
|
64
|
+
Specifies the type of normalization used, can be 'ada_norm_zero'.
|
65
|
+
norm_elementwise_affine (bool, optional, defaults to False):
|
66
|
+
If true, enables element-wise affine parameters in the normalization layers.
|
67
|
+
norm_eps (float, optional, defaults to 1e-6):
|
68
|
+
A small constant added to the denominator in normalization layers to prevent division by zero.
|
69
|
+
interpolation_scale (int, optional): Scale factor to use during interpolating the position embeddings.
|
70
|
+
use_additional_conditions (bool, optional): If we're using additional conditions as inputs.
|
71
|
+
attention_type (str, optional, defaults to "default"): Kind of attention mechanism to be used.
|
72
|
+
caption_channels (int, optional, defaults to None):
|
73
|
+
Number of channels to use for projecting the caption embeddings.
|
74
|
+
use_linear_projection (bool, optional, defaults to False):
|
75
|
+
Deprecated argument. Will be removed in a future version.
|
76
|
+
num_vector_embeds (bool, optional, defaults to False):
|
77
|
+
Deprecated argument. Will be removed in a future version.
|
78
|
+
"""
|
79
|
+
|
80
|
+
_supports_gradient_checkpointing = True
|
81
|
+
_no_split_modules = ["BasicTransformerBlock", "PatchEmbed"]
|
82
|
+
|
83
|
+
@register_to_config
|
84
|
+
def __init__(
|
85
|
+
self,
|
86
|
+
num_attention_heads: int = 16,
|
87
|
+
attention_head_dim: int = 72,
|
88
|
+
in_channels: int = 4,
|
89
|
+
out_channels: Optional[int] = 8,
|
90
|
+
num_layers: int = 28,
|
91
|
+
dropout: float = 0.0,
|
92
|
+
norm_num_groups: int = 32,
|
93
|
+
cross_attention_dim: Optional[int] = 1152,
|
94
|
+
attention_bias: bool = True,
|
95
|
+
sample_size: int = 128,
|
96
|
+
patch_size: int = 2,
|
97
|
+
activation_fn: str = "gelu-approximate",
|
98
|
+
num_embeds_ada_norm: Optional[int] = 1000,
|
99
|
+
upcast_attention: bool = False,
|
100
|
+
norm_type: str = "ada_norm_single",
|
101
|
+
norm_elementwise_affine: bool = False,
|
102
|
+
norm_eps: float = 1e-6,
|
103
|
+
interpolation_scale: Optional[int] = None,
|
104
|
+
use_additional_conditions: Optional[bool] = None,
|
105
|
+
caption_channels: Optional[int] = None,
|
106
|
+
attention_type: Optional[str] = "default",
|
107
|
+
):
|
108
|
+
super().__init__()
|
109
|
+
|
110
|
+
# Validate inputs.
|
111
|
+
if norm_type != "ada_norm_single":
|
112
|
+
raise NotImplementedError(
|
113
|
+
f"Forward pass is not implemented when `patch_size` is not None and `norm_type` is '{norm_type}'."
|
114
|
+
)
|
115
|
+
elif norm_type == "ada_norm_single" and num_embeds_ada_norm is None:
|
116
|
+
raise ValueError(
|
117
|
+
f"When using a `patch_size` and this `norm_type` ({norm_type}), `num_embeds_ada_norm` cannot be None."
|
118
|
+
)
|
119
|
+
|
120
|
+
# Set some common variables used across the board.
|
121
|
+
self.attention_head_dim = attention_head_dim
|
122
|
+
self.inner_dim = self.config.num_attention_heads * self.config.attention_head_dim
|
123
|
+
self.out_channels = in_channels if out_channels is None else out_channels
|
124
|
+
if use_additional_conditions is None:
|
125
|
+
if sample_size == 128:
|
126
|
+
use_additional_conditions = True
|
127
|
+
else:
|
128
|
+
use_additional_conditions = False
|
129
|
+
self.use_additional_conditions = use_additional_conditions
|
130
|
+
|
131
|
+
self.gradient_checkpointing = False
|
132
|
+
|
133
|
+
# 2. Initialize the position embedding and transformer blocks.
|
134
|
+
self.height = self.config.sample_size
|
135
|
+
self.width = self.config.sample_size
|
136
|
+
|
137
|
+
interpolation_scale = (
|
138
|
+
self.config.interpolation_scale
|
139
|
+
if self.config.interpolation_scale is not None
|
140
|
+
else max(self.config.sample_size // 64, 1)
|
141
|
+
)
|
142
|
+
self.pos_embed = PatchEmbed(
|
143
|
+
height=self.config.sample_size,
|
144
|
+
width=self.config.sample_size,
|
145
|
+
patch_size=self.config.patch_size,
|
146
|
+
in_channels=self.config.in_channels,
|
147
|
+
embed_dim=self.inner_dim,
|
148
|
+
interpolation_scale=interpolation_scale,
|
149
|
+
)
|
150
|
+
|
151
|
+
self.transformer_blocks = nn.ModuleList(
|
152
|
+
[
|
153
|
+
BasicTransformerBlock(
|
154
|
+
self.inner_dim,
|
155
|
+
self.config.num_attention_heads,
|
156
|
+
self.config.attention_head_dim,
|
157
|
+
dropout=self.config.dropout,
|
158
|
+
cross_attention_dim=self.config.cross_attention_dim,
|
159
|
+
activation_fn=self.config.activation_fn,
|
160
|
+
num_embeds_ada_norm=self.config.num_embeds_ada_norm,
|
161
|
+
attention_bias=self.config.attention_bias,
|
162
|
+
upcast_attention=self.config.upcast_attention,
|
163
|
+
norm_type=norm_type,
|
164
|
+
norm_elementwise_affine=self.config.norm_elementwise_affine,
|
165
|
+
norm_eps=self.config.norm_eps,
|
166
|
+
attention_type=self.config.attention_type,
|
167
|
+
)
|
168
|
+
for _ in range(self.config.num_layers)
|
169
|
+
]
|
170
|
+
)
|
171
|
+
|
172
|
+
# 3. Output blocks.
|
173
|
+
self.norm_out = nn.LayerNorm(self.inner_dim, elementwise_affine=False, eps=1e-6)
|
174
|
+
self.scale_shift_table = nn.Parameter(torch.randn(2, self.inner_dim) / self.inner_dim**0.5)
|
175
|
+
self.proj_out = nn.Linear(self.inner_dim, self.config.patch_size * self.config.patch_size * self.out_channels)
|
176
|
+
|
177
|
+
self.adaln_single = AdaLayerNormSingle(
|
178
|
+
self.inner_dim, use_additional_conditions=self.use_additional_conditions
|
179
|
+
)
|
180
|
+
self.caption_projection = None
|
181
|
+
if self.config.caption_channels is not None:
|
182
|
+
self.caption_projection = PixArtAlphaTextProjection(
|
183
|
+
in_features=self.config.caption_channels, hidden_size=self.inner_dim
|
184
|
+
)
|
185
|
+
|
186
|
+
def _set_gradient_checkpointing(self, module, value=False):
|
187
|
+
if hasattr(module, "gradient_checkpointing"):
|
188
|
+
module.gradient_checkpointing = value
|
189
|
+
|
190
|
+
@property
|
191
|
+
# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.attn_processors
|
192
|
+
def attn_processors(self) -> Dict[str, AttentionProcessor]:
|
193
|
+
r"""
|
194
|
+
Returns:
|
195
|
+
`dict` of attention processors: A dictionary containing all attention processors used in the model with
|
196
|
+
indexed by its weight name.
|
197
|
+
"""
|
198
|
+
# set recursively
|
199
|
+
processors = {}
|
200
|
+
|
201
|
+
def fn_recursive_add_processors(name: str, module: torch.nn.Module, processors: Dict[str, AttentionProcessor]):
|
202
|
+
if hasattr(module, "get_processor"):
|
203
|
+
processors[f"{name}.processor"] = module.get_processor()
|
204
|
+
|
205
|
+
for sub_name, child in module.named_children():
|
206
|
+
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)
|
207
|
+
|
208
|
+
return processors
|
209
|
+
|
210
|
+
for name, module in self.named_children():
|
211
|
+
fn_recursive_add_processors(name, module, processors)
|
212
|
+
|
213
|
+
return processors
|
214
|
+
|
215
|
+
# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_attn_processor
|
216
|
+
def set_attn_processor(self, processor: Union[AttentionProcessor, Dict[str, AttentionProcessor]]):
|
217
|
+
r"""
|
218
|
+
Sets the attention processor to use to compute attention.
|
219
|
+
|
220
|
+
Parameters:
|
221
|
+
processor (`dict` of `AttentionProcessor` or only `AttentionProcessor`):
|
222
|
+
The instantiated processor class or a dictionary of processor classes that will be set as the processor
|
223
|
+
for **all** `Attention` layers.
|
224
|
+
|
225
|
+
If `processor` is a dict, the key needs to define the path to the corresponding cross attention
|
226
|
+
processor. This is strongly recommended when setting trainable attention processors.
|
227
|
+
|
228
|
+
"""
|
229
|
+
count = len(self.attn_processors.keys())
|
230
|
+
|
231
|
+
if isinstance(processor, dict) and len(processor) != count:
|
232
|
+
raise ValueError(
|
233
|
+
f"A dict of processors was passed, but the number of processors {len(processor)} does not match the"
|
234
|
+
f" number of attention layers: {count}. Please make sure to pass {count} processor classes."
|
235
|
+
)
|
236
|
+
|
237
|
+
def fn_recursive_attn_processor(name: str, module: torch.nn.Module, processor):
|
238
|
+
if hasattr(module, "set_processor"):
|
239
|
+
if not isinstance(processor, dict):
|
240
|
+
module.set_processor(processor)
|
241
|
+
else:
|
242
|
+
module.set_processor(processor.pop(f"{name}.processor"))
|
243
|
+
|
244
|
+
for sub_name, child in module.named_children():
|
245
|
+
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)
|
246
|
+
|
247
|
+
for name, module in self.named_children():
|
248
|
+
fn_recursive_attn_processor(name, module, processor)
|
249
|
+
|
250
|
+
def set_default_attn_processor(self):
|
251
|
+
"""
|
252
|
+
Disables custom attention processors and sets the default attention implementation.
|
253
|
+
|
254
|
+
Safe to just use `AttnProcessor()` as PixArt doesn't have any exotic attention processors in default model.
|
255
|
+
"""
|
256
|
+
self.set_attn_processor(AttnProcessor())
|
257
|
+
|
258
|
+
# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.fuse_qkv_projections
|
259
|
+
def fuse_qkv_projections(self):
|
260
|
+
"""
|
261
|
+
Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query, key, value)
|
262
|
+
are fused. For cross-attention modules, key and value projection matrices are fused.
|
263
|
+
|
264
|
+
<Tip warning={true}>
|
265
|
+
|
266
|
+
This API is 🧪 experimental.
|
267
|
+
|
268
|
+
</Tip>
|
269
|
+
"""
|
270
|
+
self.original_attn_processors = None
|
271
|
+
|
272
|
+
for _, attn_processor in self.attn_processors.items():
|
273
|
+
if "Added" in str(attn_processor.__class__.__name__):
|
274
|
+
raise ValueError("`fuse_qkv_projections()` is not supported for models having added KV projections.")
|
275
|
+
|
276
|
+
self.original_attn_processors = self.attn_processors
|
277
|
+
|
278
|
+
for module in self.modules():
|
279
|
+
if isinstance(module, Attention):
|
280
|
+
module.fuse_projections(fuse=True)
|
281
|
+
|
282
|
+
self.set_attn_processor(FusedAttnProcessor2_0())
|
283
|
+
|
284
|
+
# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.unfuse_qkv_projections
|
285
|
+
def unfuse_qkv_projections(self):
|
286
|
+
"""Disables the fused QKV projection if enabled.
|
287
|
+
|
288
|
+
<Tip warning={true}>
|
289
|
+
|
290
|
+
This API is 🧪 experimental.
|
291
|
+
|
292
|
+
</Tip>
|
293
|
+
|
294
|
+
"""
|
295
|
+
if self.original_attn_processors is not None:
|
296
|
+
self.set_attn_processor(self.original_attn_processors)
|
297
|
+
|
298
|
+
def forward(
|
299
|
+
self,
|
300
|
+
hidden_states: torch.Tensor,
|
301
|
+
encoder_hidden_states: Optional[torch.Tensor] = None,
|
302
|
+
timestep: Optional[torch.LongTensor] = None,
|
303
|
+
added_cond_kwargs: Dict[str, torch.Tensor] = None,
|
304
|
+
cross_attention_kwargs: Dict[str, Any] = None,
|
305
|
+
attention_mask: Optional[torch.Tensor] = None,
|
306
|
+
encoder_attention_mask: Optional[torch.Tensor] = None,
|
307
|
+
return_dict: bool = True,
|
308
|
+
):
|
309
|
+
"""
|
310
|
+
The [`PixArtTransformer2DModel`] forward method.
|
311
|
+
|
312
|
+
Args:
|
313
|
+
hidden_states (`torch.FloatTensor` of shape `(batch size, channel, height, width)`):
|
314
|
+
Input `hidden_states`.
|
315
|
+
encoder_hidden_states (`torch.FloatTensor` of shape `(batch size, sequence len, embed dims)`, *optional*):
|
316
|
+
Conditional embeddings for cross attention layer. If not given, cross-attention defaults to
|
317
|
+
self-attention.
|
318
|
+
timestep (`torch.LongTensor`, *optional*):
|
319
|
+
Used to indicate denoising step. Optional timestep to be applied as an embedding in `AdaLayerNorm`.
|
320
|
+
added_cond_kwargs: (`Dict[str, Any]`, *optional*): Additional conditions to be used as inputs.
|
321
|
+
cross_attention_kwargs ( `Dict[str, Any]`, *optional*):
|
322
|
+
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
323
|
+
`self.processor` in
|
324
|
+
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
325
|
+
attention_mask ( `torch.Tensor`, *optional*):
|
326
|
+
An attention mask of shape `(batch, key_tokens)` is applied to `encoder_hidden_states`. If `1` the mask
|
327
|
+
is kept, otherwise if `0` it is discarded. Mask will be converted into a bias, which adds large
|
328
|
+
negative values to the attention scores corresponding to "discard" tokens.
|
329
|
+
encoder_attention_mask ( `torch.Tensor`, *optional*):
|
330
|
+
Cross-attention mask applied to `encoder_hidden_states`. Two formats supported:
|
331
|
+
|
332
|
+
* Mask `(batch, sequence_length)` True = keep, False = discard.
|
333
|
+
* Bias `(batch, 1, sequence_length)` 0 = keep, -10000 = discard.
|
334
|
+
|
335
|
+
If `ndim == 2`: will be interpreted as a mask, then converted into a bias consistent with the format
|
336
|
+
above. This bias will be added to the cross-attention scores.
|
337
|
+
return_dict (`bool`, *optional*, defaults to `True`):
|
338
|
+
Whether or not to return a [`~models.unets.unet_2d_condition.UNet2DConditionOutput`] instead of a plain
|
339
|
+
tuple.
|
340
|
+
|
341
|
+
Returns:
|
342
|
+
If `return_dict` is True, an [`~models.transformer_2d.Transformer2DModelOutput`] is returned, otherwise a
|
343
|
+
`tuple` where the first element is the sample tensor.
|
344
|
+
"""
|
345
|
+
if self.use_additional_conditions and added_cond_kwargs is None:
|
346
|
+
raise ValueError("`added_cond_kwargs` cannot be None when using additional conditions for `adaln_single`.")
|
347
|
+
|
348
|
+
# ensure attention_mask is a bias, and give it a singleton query_tokens dimension.
|
349
|
+
# we may have done this conversion already, e.g. if we came here via UNet2DConditionModel#forward.
|
350
|
+
# we can tell by counting dims; if ndim == 2: it's a mask rather than a bias.
|
351
|
+
# expects mask of shape:
|
352
|
+
# [batch, key_tokens]
|
353
|
+
# adds singleton query_tokens dimension:
|
354
|
+
# [batch, 1, key_tokens]
|
355
|
+
# this helps to broadcast it as a bias over attention scores, which will be in one of the following shapes:
|
356
|
+
# [batch, heads, query_tokens, key_tokens] (e.g. torch sdp attn)
|
357
|
+
# [batch * heads, query_tokens, key_tokens] (e.g. xformers or classic attn)
|
358
|
+
if attention_mask is not None and attention_mask.ndim == 2:
|
359
|
+
# assume that mask is expressed as:
|
360
|
+
# (1 = keep, 0 = discard)
|
361
|
+
# convert mask into a bias that can be added to attention scores:
|
362
|
+
# (keep = +0, discard = -10000.0)
|
363
|
+
attention_mask = (1 - attention_mask.to(hidden_states.dtype)) * -10000.0
|
364
|
+
attention_mask = attention_mask.unsqueeze(1)
|
365
|
+
|
366
|
+
# convert encoder_attention_mask to a bias the same way we do for attention_mask
|
367
|
+
if encoder_attention_mask is not None and encoder_attention_mask.ndim == 2:
|
368
|
+
encoder_attention_mask = (1 - encoder_attention_mask.to(hidden_states.dtype)) * -10000.0
|
369
|
+
encoder_attention_mask = encoder_attention_mask.unsqueeze(1)
|
370
|
+
|
371
|
+
# 1. Input
|
372
|
+
batch_size = hidden_states.shape[0]
|
373
|
+
height, width = (
|
374
|
+
hidden_states.shape[-2] // self.config.patch_size,
|
375
|
+
hidden_states.shape[-1] // self.config.patch_size,
|
376
|
+
)
|
377
|
+
hidden_states = self.pos_embed(hidden_states)
|
378
|
+
|
379
|
+
timestep, embedded_timestep = self.adaln_single(
|
380
|
+
timestep, added_cond_kwargs, batch_size=batch_size, hidden_dtype=hidden_states.dtype
|
381
|
+
)
|
382
|
+
|
383
|
+
if self.caption_projection is not None:
|
384
|
+
encoder_hidden_states = self.caption_projection(encoder_hidden_states)
|
385
|
+
encoder_hidden_states = encoder_hidden_states.view(batch_size, -1, hidden_states.shape[-1])
|
386
|
+
|
387
|
+
# 2. Blocks
|
388
|
+
for block in self.transformer_blocks:
|
389
|
+
if torch.is_grad_enabled() and self.gradient_checkpointing:
|
390
|
+
|
391
|
+
def create_custom_forward(module, return_dict=None):
|
392
|
+
def custom_forward(*inputs):
|
393
|
+
if return_dict is not None:
|
394
|
+
return module(*inputs, return_dict=return_dict)
|
395
|
+
else:
|
396
|
+
return module(*inputs)
|
397
|
+
|
398
|
+
return custom_forward
|
399
|
+
|
400
|
+
ckpt_kwargs: Dict[str, Any] = {"use_reentrant": False} if is_torch_version(">=", "1.11.0") else {}
|
401
|
+
hidden_states = torch.utils.checkpoint.checkpoint(
|
402
|
+
create_custom_forward(block),
|
403
|
+
hidden_states,
|
404
|
+
attention_mask,
|
405
|
+
encoder_hidden_states,
|
406
|
+
encoder_attention_mask,
|
407
|
+
timestep,
|
408
|
+
cross_attention_kwargs,
|
409
|
+
None,
|
410
|
+
**ckpt_kwargs,
|
411
|
+
)
|
412
|
+
else:
|
413
|
+
hidden_states = block(
|
414
|
+
hidden_states,
|
415
|
+
attention_mask=attention_mask,
|
416
|
+
encoder_hidden_states=encoder_hidden_states,
|
417
|
+
encoder_attention_mask=encoder_attention_mask,
|
418
|
+
timestep=timestep,
|
419
|
+
cross_attention_kwargs=cross_attention_kwargs,
|
420
|
+
class_labels=None,
|
421
|
+
)
|
422
|
+
|
423
|
+
# 3. Output
|
424
|
+
shift, scale = (
|
425
|
+
self.scale_shift_table[None] + embedded_timestep[:, None].to(self.scale_shift_table.device)
|
426
|
+
).chunk(2, dim=1)
|
427
|
+
hidden_states = self.norm_out(hidden_states)
|
428
|
+
# Modulation
|
429
|
+
hidden_states = hidden_states * (1 + scale.to(hidden_states.device)) + shift.to(hidden_states.device)
|
430
|
+
hidden_states = self.proj_out(hidden_states)
|
431
|
+
hidden_states = hidden_states.squeeze(1)
|
432
|
+
|
433
|
+
# unpatchify
|
434
|
+
hidden_states = hidden_states.reshape(
|
435
|
+
shape=(-1, height, width, self.config.patch_size, self.config.patch_size, self.out_channels)
|
436
|
+
)
|
437
|
+
hidden_states = torch.einsum("nhwpqc->nchpwq", hidden_states)
|
438
|
+
output = hidden_states.reshape(
|
439
|
+
shape=(-1, self.out_channels, height * self.config.patch_size, width * self.config.patch_size)
|
440
|
+
)
|
441
|
+
|
442
|
+
if not return_dict:
|
443
|
+
return (output,)
|
444
|
+
|
445
|
+
return Transformer2DModelOutput(sample=output)
|
@@ -26,11 +26,11 @@ class PriorTransformerOutput(BaseOutput):
|
|
26
26
|
The output of [`PriorTransformer`].
|
27
27
|
|
28
28
|
Args:
|
29
|
-
predicted_image_embedding (`torch.
|
29
|
+
predicted_image_embedding (`torch.Tensor` of shape `(batch_size, embedding_dim)`):
|
30
30
|
The predicted CLIP image embedding conditioned on the CLIP text embedding input.
|
31
31
|
"""
|
32
32
|
|
33
|
-
predicted_image_embedding: torch.
|
33
|
+
predicted_image_embedding: torch.Tensor
|
34
34
|
|
35
35
|
|
36
36
|
class PriorTransformer(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin, PeftAdapterMixin):
|
@@ -179,7 +179,7 @@ class PriorTransformer(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin, Pef
|
|
179
179
|
|
180
180
|
def fn_recursive_add_processors(name: str, module: torch.nn.Module, processors: Dict[str, AttentionProcessor]):
|
181
181
|
if hasattr(module, "get_processor"):
|
182
|
-
processors[f"{name}.processor"] = module.get_processor(
|
182
|
+
processors[f"{name}.processor"] = module.get_processor()
|
183
183
|
|
184
184
|
for sub_name, child in module.named_children():
|
185
185
|
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)
|
@@ -246,8 +246,8 @@ class PriorTransformer(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin, Pef
|
|
246
246
|
self,
|
247
247
|
hidden_states,
|
248
248
|
timestep: Union[torch.Tensor, float, int],
|
249
|
-
proj_embedding: torch.
|
250
|
-
encoder_hidden_states: Optional[torch.
|
249
|
+
proj_embedding: torch.Tensor,
|
250
|
+
encoder_hidden_states: Optional[torch.Tensor] = None,
|
251
251
|
attention_mask: Optional[torch.BoolTensor] = None,
|
252
252
|
return_dict: bool = True,
|
253
253
|
):
|
@@ -255,24 +255,24 @@ class PriorTransformer(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin, Pef
|
|
255
255
|
The [`PriorTransformer`] forward method.
|
256
256
|
|
257
257
|
Args:
|
258
|
-
hidden_states (`torch.
|
258
|
+
hidden_states (`torch.Tensor` of shape `(batch_size, embedding_dim)`):
|
259
259
|
The currently predicted image embeddings.
|
260
260
|
timestep (`torch.LongTensor`):
|
261
261
|
Current denoising step.
|
262
|
-
proj_embedding (`torch.
|
262
|
+
proj_embedding (`torch.Tensor` of shape `(batch_size, embedding_dim)`):
|
263
263
|
Projected embedding vector the denoising process is conditioned on.
|
264
|
-
encoder_hidden_states (`torch.
|
264
|
+
encoder_hidden_states (`torch.Tensor` of shape `(batch_size, num_embeddings, embedding_dim)`):
|
265
265
|
Hidden states of the text embeddings the denoising process is conditioned on.
|
266
266
|
attention_mask (`torch.BoolTensor` of shape `(batch_size, num_embeddings)`):
|
267
267
|
Text mask for the text embeddings.
|
268
268
|
return_dict (`bool`, *optional*, defaults to `True`):
|
269
|
-
Whether or not to return a [`~models.prior_transformer.PriorTransformerOutput`] instead of
|
270
|
-
tuple.
|
269
|
+
Whether or not to return a [`~models.transformers.prior_transformer.PriorTransformerOutput`] instead of
|
270
|
+
a plain tuple.
|
271
271
|
|
272
272
|
Returns:
|
273
|
-
[`~models.prior_transformer.PriorTransformerOutput`] or `tuple`:
|
274
|
-
If return_dict is True, a [`~models.prior_transformer.PriorTransformerOutput`] is
|
275
|
-
tuple is returned where the first element is the sample tensor.
|
273
|
+
[`~models.transformers.prior_transformer.PriorTransformerOutput`] or `tuple`:
|
274
|
+
If return_dict is True, a [`~models.transformers.prior_transformer.PriorTransformerOutput`] is
|
275
|
+
returned, otherwise a tuple is returned where the first element is the sample tensor.
|
276
276
|
"""
|
277
277
|
batch_size = hidden_states.shape[0]
|
278
278
|
|