diffusers 0.33.1__py3-none-any.whl → 0.35.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffusers/__init__.py +145 -1
- diffusers/callbacks.py +35 -0
- diffusers/commands/__init__.py +1 -1
- diffusers/commands/custom_blocks.py +134 -0
- diffusers/commands/diffusers_cli.py +3 -1
- diffusers/commands/env.py +1 -1
- diffusers/commands/fp16_safetensors.py +2 -2
- diffusers/configuration_utils.py +11 -2
- diffusers/dependency_versions_check.py +1 -1
- diffusers/dependency_versions_table.py +3 -3
- diffusers/experimental/rl/value_guided_sampling.py +1 -1
- diffusers/guiders/__init__.py +41 -0
- diffusers/guiders/adaptive_projected_guidance.py +188 -0
- diffusers/guiders/auto_guidance.py +190 -0
- diffusers/guiders/classifier_free_guidance.py +141 -0
- diffusers/guiders/classifier_free_zero_star_guidance.py +152 -0
- diffusers/guiders/frequency_decoupled_guidance.py +327 -0
- diffusers/guiders/guider_utils.py +309 -0
- diffusers/guiders/perturbed_attention_guidance.py +271 -0
- diffusers/guiders/skip_layer_guidance.py +262 -0
- diffusers/guiders/smoothed_energy_guidance.py +251 -0
- diffusers/guiders/tangential_classifier_free_guidance.py +143 -0
- diffusers/hooks/__init__.py +17 -0
- diffusers/hooks/_common.py +56 -0
- diffusers/hooks/_helpers.py +293 -0
- diffusers/hooks/faster_cache.py +9 -8
- diffusers/hooks/first_block_cache.py +259 -0
- diffusers/hooks/group_offloading.py +332 -227
- diffusers/hooks/hooks.py +58 -3
- diffusers/hooks/layer_skip.py +263 -0
- diffusers/hooks/layerwise_casting.py +5 -10
- diffusers/hooks/pyramid_attention_broadcast.py +15 -12
- diffusers/hooks/smoothed_energy_guidance_utils.py +167 -0
- diffusers/hooks/utils.py +43 -0
- diffusers/image_processor.py +7 -2
- diffusers/loaders/__init__.py +10 -0
- diffusers/loaders/ip_adapter.py +260 -18
- diffusers/loaders/lora_base.py +261 -127
- diffusers/loaders/lora_conversion_utils.py +657 -35
- diffusers/loaders/lora_pipeline.py +2778 -1246
- diffusers/loaders/peft.py +78 -112
- diffusers/loaders/single_file.py +2 -2
- diffusers/loaders/single_file_model.py +64 -15
- diffusers/loaders/single_file_utils.py +395 -7
- diffusers/loaders/textual_inversion.py +3 -2
- diffusers/loaders/transformer_flux.py +10 -11
- diffusers/loaders/transformer_sd3.py +8 -3
- diffusers/loaders/unet.py +24 -21
- diffusers/loaders/unet_loader_utils.py +6 -3
- diffusers/loaders/utils.py +1 -1
- diffusers/models/__init__.py +23 -1
- diffusers/models/activations.py +5 -5
- diffusers/models/adapter.py +2 -3
- diffusers/models/attention.py +488 -7
- diffusers/models/attention_dispatch.py +1218 -0
- diffusers/models/attention_flax.py +10 -10
- diffusers/models/attention_processor.py +113 -667
- diffusers/models/auto_model.py +49 -12
- diffusers/models/autoencoders/__init__.py +2 -0
- diffusers/models/autoencoders/autoencoder_asym_kl.py +4 -4
- diffusers/models/autoencoders/autoencoder_dc.py +17 -4
- diffusers/models/autoencoders/autoencoder_kl.py +5 -5
- diffusers/models/autoencoders/autoencoder_kl_allegro.py +4 -4
- diffusers/models/autoencoders/autoencoder_kl_cogvideox.py +6 -6
- diffusers/models/autoencoders/autoencoder_kl_cosmos.py +1110 -0
- diffusers/models/autoencoders/autoencoder_kl_hunyuan_video.py +2 -2
- diffusers/models/autoencoders/autoencoder_kl_ltx.py +3 -3
- diffusers/models/autoencoders/autoencoder_kl_magvit.py +4 -4
- diffusers/models/autoencoders/autoencoder_kl_mochi.py +3 -3
- diffusers/models/autoencoders/autoencoder_kl_qwenimage.py +1070 -0
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +4 -4
- diffusers/models/autoencoders/autoencoder_kl_wan.py +626 -62
- diffusers/models/autoencoders/autoencoder_oobleck.py +1 -1
- diffusers/models/autoencoders/autoencoder_tiny.py +3 -3
- diffusers/models/autoencoders/consistency_decoder_vae.py +1 -1
- diffusers/models/autoencoders/vae.py +13 -2
- diffusers/models/autoencoders/vq_model.py +2 -2
- diffusers/models/cache_utils.py +32 -10
- diffusers/models/controlnet.py +1 -1
- diffusers/models/controlnet_flux.py +1 -1
- diffusers/models/controlnet_sd3.py +1 -1
- diffusers/models/controlnet_sparsectrl.py +1 -1
- diffusers/models/controlnets/__init__.py +1 -0
- diffusers/models/controlnets/controlnet.py +3 -3
- diffusers/models/controlnets/controlnet_flax.py +1 -1
- diffusers/models/controlnets/controlnet_flux.py +21 -20
- diffusers/models/controlnets/controlnet_hunyuan.py +2 -2
- diffusers/models/controlnets/controlnet_sana.py +290 -0
- diffusers/models/controlnets/controlnet_sd3.py +1 -1
- diffusers/models/controlnets/controlnet_sparsectrl.py +2 -2
- diffusers/models/controlnets/controlnet_union.py +5 -5
- diffusers/models/controlnets/controlnet_xs.py +7 -7
- diffusers/models/controlnets/multicontrolnet.py +4 -5
- diffusers/models/controlnets/multicontrolnet_union.py +5 -6
- diffusers/models/downsampling.py +2 -2
- diffusers/models/embeddings.py +36 -46
- diffusers/models/embeddings_flax.py +2 -2
- diffusers/models/lora.py +3 -3
- diffusers/models/model_loading_utils.py +233 -1
- diffusers/models/modeling_flax_utils.py +1 -2
- diffusers/models/modeling_utils.py +203 -108
- diffusers/models/normalization.py +4 -4
- diffusers/models/resnet.py +2 -2
- diffusers/models/resnet_flax.py +1 -1
- diffusers/models/transformers/__init__.py +7 -0
- diffusers/models/transformers/auraflow_transformer_2d.py +70 -24
- diffusers/models/transformers/cogvideox_transformer_3d.py +1 -1
- diffusers/models/transformers/consisid_transformer_3d.py +1 -1
- diffusers/models/transformers/dit_transformer_2d.py +2 -2
- diffusers/models/transformers/dual_transformer_2d.py +1 -1
- diffusers/models/transformers/hunyuan_transformer_2d.py +2 -2
- diffusers/models/transformers/latte_transformer_3d.py +4 -5
- diffusers/models/transformers/lumina_nextdit2d.py +2 -2
- diffusers/models/transformers/pixart_transformer_2d.py +3 -3
- diffusers/models/transformers/prior_transformer.py +1 -1
- diffusers/models/transformers/sana_transformer.py +8 -3
- diffusers/models/transformers/stable_audio_transformer.py +5 -9
- diffusers/models/transformers/t5_film_transformer.py +3 -3
- diffusers/models/transformers/transformer_2d.py +1 -1
- diffusers/models/transformers/transformer_allegro.py +1 -1
- diffusers/models/transformers/transformer_chroma.py +641 -0
- diffusers/models/transformers/transformer_cogview3plus.py +5 -10
- diffusers/models/transformers/transformer_cogview4.py +353 -27
- diffusers/models/transformers/transformer_cosmos.py +586 -0
- diffusers/models/transformers/transformer_flux.py +376 -138
- diffusers/models/transformers/transformer_hidream_image.py +942 -0
- diffusers/models/transformers/transformer_hunyuan_video.py +12 -8
- diffusers/models/transformers/transformer_hunyuan_video_framepack.py +416 -0
- diffusers/models/transformers/transformer_ltx.py +105 -24
- diffusers/models/transformers/transformer_lumina2.py +1 -1
- diffusers/models/transformers/transformer_mochi.py +1 -1
- diffusers/models/transformers/transformer_omnigen.py +2 -2
- diffusers/models/transformers/transformer_qwenimage.py +645 -0
- diffusers/models/transformers/transformer_sd3.py +7 -7
- diffusers/models/transformers/transformer_skyreels_v2.py +607 -0
- diffusers/models/transformers/transformer_temporal.py +1 -1
- diffusers/models/transformers/transformer_wan.py +316 -87
- diffusers/models/transformers/transformer_wan_vace.py +387 -0
- diffusers/models/unets/unet_1d.py +1 -1
- diffusers/models/unets/unet_1d_blocks.py +1 -1
- diffusers/models/unets/unet_2d.py +1 -1
- diffusers/models/unets/unet_2d_blocks.py +1 -1
- diffusers/models/unets/unet_2d_blocks_flax.py +8 -7
- diffusers/models/unets/unet_2d_condition.py +4 -3
- diffusers/models/unets/unet_2d_condition_flax.py +2 -2
- diffusers/models/unets/unet_3d_blocks.py +1 -1
- diffusers/models/unets/unet_3d_condition.py +3 -3
- diffusers/models/unets/unet_i2vgen_xl.py +3 -3
- diffusers/models/unets/unet_kandinsky3.py +1 -1
- diffusers/models/unets/unet_motion_model.py +2 -2
- diffusers/models/unets/unet_stable_cascade.py +1 -1
- diffusers/models/upsampling.py +2 -2
- diffusers/models/vae_flax.py +2 -2
- diffusers/models/vq_model.py +1 -1
- diffusers/modular_pipelines/__init__.py +83 -0
- diffusers/modular_pipelines/components_manager.py +1068 -0
- diffusers/modular_pipelines/flux/__init__.py +66 -0
- diffusers/modular_pipelines/flux/before_denoise.py +689 -0
- diffusers/modular_pipelines/flux/decoders.py +109 -0
- diffusers/modular_pipelines/flux/denoise.py +227 -0
- diffusers/modular_pipelines/flux/encoders.py +412 -0
- diffusers/modular_pipelines/flux/modular_blocks.py +181 -0
- diffusers/modular_pipelines/flux/modular_pipeline.py +59 -0
- diffusers/modular_pipelines/modular_pipeline.py +2446 -0
- diffusers/modular_pipelines/modular_pipeline_utils.py +672 -0
- diffusers/modular_pipelines/node_utils.py +665 -0
- diffusers/modular_pipelines/stable_diffusion_xl/__init__.py +77 -0
- diffusers/modular_pipelines/stable_diffusion_xl/before_denoise.py +1874 -0
- diffusers/modular_pipelines/stable_diffusion_xl/decoders.py +208 -0
- diffusers/modular_pipelines/stable_diffusion_xl/denoise.py +771 -0
- diffusers/modular_pipelines/stable_diffusion_xl/encoders.py +887 -0
- diffusers/modular_pipelines/stable_diffusion_xl/modular_blocks.py +380 -0
- diffusers/modular_pipelines/stable_diffusion_xl/modular_pipeline.py +365 -0
- diffusers/modular_pipelines/wan/__init__.py +66 -0
- diffusers/modular_pipelines/wan/before_denoise.py +365 -0
- diffusers/modular_pipelines/wan/decoders.py +105 -0
- diffusers/modular_pipelines/wan/denoise.py +261 -0
- diffusers/modular_pipelines/wan/encoders.py +242 -0
- diffusers/modular_pipelines/wan/modular_blocks.py +144 -0
- diffusers/modular_pipelines/wan/modular_pipeline.py +90 -0
- diffusers/pipelines/__init__.py +68 -6
- diffusers/pipelines/allegro/pipeline_allegro.py +11 -11
- diffusers/pipelines/amused/pipeline_amused.py +7 -6
- diffusers/pipelines/amused/pipeline_amused_img2img.py +6 -5
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +6 -5
- diffusers/pipelines/animatediff/pipeline_animatediff.py +6 -6
- diffusers/pipelines/animatediff/pipeline_animatediff_controlnet.py +6 -6
- diffusers/pipelines/animatediff/pipeline_animatediff_sdxl.py +16 -15
- diffusers/pipelines/animatediff/pipeline_animatediff_sparsectrl.py +6 -6
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +5 -5
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video_controlnet.py +5 -5
- diffusers/pipelines/audioldm/pipeline_audioldm.py +8 -7
- diffusers/pipelines/audioldm2/modeling_audioldm2.py +1 -1
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +22 -13
- diffusers/pipelines/aura_flow/pipeline_aura_flow.py +48 -11
- diffusers/pipelines/auto_pipeline.py +23 -20
- diffusers/pipelines/blip_diffusion/modeling_blip2.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +2 -2
- diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +11 -10
- diffusers/pipelines/chroma/__init__.py +49 -0
- diffusers/pipelines/chroma/pipeline_chroma.py +949 -0
- diffusers/pipelines/chroma/pipeline_chroma_img2img.py +1034 -0
- diffusers/pipelines/chroma/pipeline_output.py +21 -0
- diffusers/pipelines/cogvideo/pipeline_cogvideox.py +17 -16
- diffusers/pipelines/cogvideo/pipeline_cogvideox_fun_control.py +17 -16
- diffusers/pipelines/cogvideo/pipeline_cogvideox_image2video.py +18 -17
- diffusers/pipelines/cogvideo/pipeline_cogvideox_video2video.py +17 -16
- diffusers/pipelines/cogview3/pipeline_cogview3plus.py +9 -9
- diffusers/pipelines/cogview4/pipeline_cogview4.py +23 -22
- diffusers/pipelines/cogview4/pipeline_cogview4_control.py +7 -7
- diffusers/pipelines/consisid/consisid_utils.py +2 -2
- diffusers/pipelines/consisid/pipeline_consisid.py +8 -8
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -1
- diffusers/pipelines/controlnet/pipeline_controlnet.py +7 -7
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +11 -10
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +7 -7
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +7 -7
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +14 -14
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +10 -6
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +13 -13
- diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py +226 -107
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py +12 -8
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl_img2img.py +207 -105
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +1 -1
- diffusers/pipelines/controlnet_hunyuandit/pipeline_hunyuandit_controlnet.py +8 -8
- diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet.py +7 -7
- diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet_inpainting.py +7 -7
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs.py +12 -10
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs_sd_xl.py +9 -7
- diffusers/pipelines/cosmos/__init__.py +54 -0
- diffusers/pipelines/cosmos/pipeline_cosmos2_text2image.py +673 -0
- diffusers/pipelines/cosmos/pipeline_cosmos2_video2world.py +792 -0
- diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py +664 -0
- diffusers/pipelines/cosmos/pipeline_cosmos_video2world.py +826 -0
- diffusers/pipelines/cosmos/pipeline_output.py +40 -0
- diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +5 -4
- diffusers/pipelines/ddim/pipeline_ddim.py +4 -4
- diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +10 -10
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +10 -10
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +10 -10
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +10 -10
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +10 -10
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +10 -10
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +8 -8
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +5 -5
- diffusers/pipelines/deprecated/audio_diffusion/mel.py +1 -1
- diffusers/pipelines/deprecated/audio_diffusion/pipeline_audio_diffusion.py +3 -3
- diffusers/pipelines/deprecated/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py +1 -1
- diffusers/pipelines/deprecated/pndm/pipeline_pndm.py +2 -2
- diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +4 -3
- diffusers/pipelines/deprecated/score_sde_ve/pipeline_score_sde_ve.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/continuous_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/midi_utils.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/notes_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -1
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +8 -8
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_onnx_stable_diffusion_inpaint_legacy.py +9 -9
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +10 -10
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +10 -8
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +5 -5
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +18 -18
- diffusers/pipelines/deprecated/stochastic_karras_ve/pipeline_stochastic_karras_ve.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +2 -2
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion.py +6 -6
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +5 -5
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +5 -5
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +5 -5
- diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +1 -1
- diffusers/pipelines/dit/pipeline_dit.py +4 -2
- diffusers/pipelines/easyanimate/pipeline_easyanimate.py +4 -4
- diffusers/pipelines/easyanimate/pipeline_easyanimate_control.py +4 -4
- diffusers/pipelines/easyanimate/pipeline_easyanimate_inpaint.py +7 -6
- diffusers/pipelines/flux/__init__.py +4 -0
- diffusers/pipelines/flux/modeling_flux.py +1 -1
- diffusers/pipelines/flux/pipeline_flux.py +37 -36
- diffusers/pipelines/flux/pipeline_flux_control.py +9 -9
- diffusers/pipelines/flux/pipeline_flux_control_img2img.py +7 -7
- diffusers/pipelines/flux/pipeline_flux_control_inpaint.py +7 -7
- diffusers/pipelines/flux/pipeline_flux_controlnet.py +7 -7
- diffusers/pipelines/flux/pipeline_flux_controlnet_image_to_image.py +31 -23
- diffusers/pipelines/flux/pipeline_flux_controlnet_inpainting.py +3 -2
- diffusers/pipelines/flux/pipeline_flux_fill.py +7 -7
- diffusers/pipelines/flux/pipeline_flux_img2img.py +40 -7
- diffusers/pipelines/flux/pipeline_flux_inpaint.py +12 -7
- diffusers/pipelines/flux/pipeline_flux_kontext.py +1134 -0
- diffusers/pipelines/flux/pipeline_flux_kontext_inpaint.py +1460 -0
- diffusers/pipelines/flux/pipeline_flux_prior_redux.py +2 -2
- diffusers/pipelines/flux/pipeline_output.py +6 -4
- diffusers/pipelines/free_init_utils.py +2 -2
- diffusers/pipelines/free_noise_utils.py +3 -3
- diffusers/pipelines/hidream_image/__init__.py +47 -0
- diffusers/pipelines/hidream_image/pipeline_hidream_image.py +1026 -0
- diffusers/pipelines/hidream_image/pipeline_output.py +35 -0
- diffusers/pipelines/hunyuan_video/__init__.py +2 -0
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_skyreels_image2video.py +8 -8
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video.py +26 -25
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video_framepack.py +1114 -0
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video_image2video.py +71 -15
- diffusers/pipelines/hunyuan_video/pipeline_output.py +19 -0
- diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py +8 -8
- diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +10 -8
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +6 -6
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +34 -34
- diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +19 -26
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +7 -7
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +11 -11
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +6 -6
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +35 -35
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +6 -6
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +17 -39
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +17 -45
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +7 -7
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +10 -10
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py +10 -10
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +7 -7
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +17 -38
- diffusers/pipelines/kolors/pipeline_kolors.py +10 -10
- diffusers/pipelines/kolors/pipeline_kolors_img2img.py +12 -12
- diffusers/pipelines/kolors/text_encoder.py +3 -3
- diffusers/pipelines/kolors/tokenizer.py +1 -1
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +2 -2
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +2 -2
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -1
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion_superresolution.py +3 -3
- diffusers/pipelines/latte/pipeline_latte.py +12 -12
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +13 -13
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +17 -16
- diffusers/pipelines/ltx/__init__.py +4 -0
- diffusers/pipelines/ltx/modeling_latent_upsampler.py +188 -0
- diffusers/pipelines/ltx/pipeline_ltx.py +64 -18
- diffusers/pipelines/ltx/pipeline_ltx_condition.py +117 -38
- diffusers/pipelines/ltx/pipeline_ltx_image2video.py +63 -18
- diffusers/pipelines/ltx/pipeline_ltx_latent_upsample.py +277 -0
- diffusers/pipelines/lumina/pipeline_lumina.py +13 -13
- diffusers/pipelines/lumina2/pipeline_lumina2.py +10 -10
- diffusers/pipelines/marigold/marigold_image_processing.py +2 -2
- diffusers/pipelines/mochi/pipeline_mochi.py +15 -14
- diffusers/pipelines/musicldm/pipeline_musicldm.py +16 -13
- diffusers/pipelines/omnigen/pipeline_omnigen.py +13 -11
- diffusers/pipelines/omnigen/processor_omnigen.py +8 -3
- diffusers/pipelines/onnx_utils.py +15 -2
- diffusers/pipelines/pag/pag_utils.py +2 -2
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py +12 -8
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_inpaint.py +7 -7
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py +10 -6
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl_img2img.py +14 -14
- diffusers/pipelines/pag/pipeline_pag_hunyuandit.py +8 -8
- diffusers/pipelines/pag/pipeline_pag_kolors.py +10 -10
- diffusers/pipelines/pag/pipeline_pag_pixart_sigma.py +11 -11
- diffusers/pipelines/pag/pipeline_pag_sana.py +18 -12
- diffusers/pipelines/pag/pipeline_pag_sd.py +8 -8
- diffusers/pipelines/pag/pipeline_pag_sd_3.py +7 -7
- diffusers/pipelines/pag/pipeline_pag_sd_3_img2img.py +7 -7
- diffusers/pipelines/pag/pipeline_pag_sd_animatediff.py +6 -6
- diffusers/pipelines/pag/pipeline_pag_sd_img2img.py +5 -5
- diffusers/pipelines/pag/pipeline_pag_sd_inpaint.py +8 -8
- diffusers/pipelines/pag/pipeline_pag_sd_xl.py +16 -15
- diffusers/pipelines/pag/pipeline_pag_sd_xl_img2img.py +18 -17
- diffusers/pipelines/pag/pipeline_pag_sd_xl_inpaint.py +12 -12
- diffusers/pipelines/paint_by_example/image_encoder.py +1 -1
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +8 -7
- diffusers/pipelines/pia/pipeline_pia.py +8 -6
- diffusers/pipelines/pipeline_flax_utils.py +5 -6
- diffusers/pipelines/pipeline_loading_utils.py +113 -15
- diffusers/pipelines/pipeline_utils.py +127 -48
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +14 -12
- diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py +31 -11
- diffusers/pipelines/qwenimage/__init__.py +55 -0
- diffusers/pipelines/qwenimage/pipeline_output.py +21 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage.py +726 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage_edit.py +882 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage_img2img.py +829 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage_inpaint.py +1015 -0
- diffusers/pipelines/sana/__init__.py +4 -0
- diffusers/pipelines/sana/pipeline_sana.py +23 -21
- diffusers/pipelines/sana/pipeline_sana_controlnet.py +1106 -0
- diffusers/pipelines/sana/pipeline_sana_sprint.py +23 -19
- diffusers/pipelines/sana/pipeline_sana_sprint_img2img.py +981 -0
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +7 -6
- diffusers/pipelines/shap_e/camera.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +1 -1
- diffusers/pipelines/shap_e/renderer.py +3 -3
- diffusers/pipelines/skyreels_v2/__init__.py +59 -0
- diffusers/pipelines/skyreels_v2/pipeline_output.py +20 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2.py +610 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing.py +978 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_i2v.py +1059 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_v2v.py +1063 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_i2v.py +745 -0
- diffusers/pipelines/stable_audio/modeling_stable_audio.py +1 -1
- diffusers/pipelines/stable_audio/pipeline_stable_audio.py +5 -5
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +8 -8
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +13 -13
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +9 -9
- diffusers/pipelines/stable_diffusion/__init__.py +0 -7
- diffusers/pipelines/stable_diffusion/clip_image_project_model.py +1 -1
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +11 -4
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_img2img.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +12 -11
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +10 -10
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +11 -11
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +10 -10
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +10 -9
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +5 -5
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +5 -5
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +5 -5
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +5 -5
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +5 -5
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +4 -4
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +5 -5
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +7 -7
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -5
- diffusers/pipelines/stable_diffusion/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion/safety_checker_flax.py +1 -1
- diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py +1 -1
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +13 -12
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +7 -7
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +7 -7
- diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +12 -8
- diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +15 -9
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +11 -9
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +11 -9
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +18 -12
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +11 -8
- diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +11 -8
- diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +15 -12
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +8 -6
- diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +15 -11
- diffusers/pipelines/stable_diffusion_xl/pipeline_flax_stable_diffusion_xl.py +1 -1
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +16 -15
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +18 -17
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +12 -12
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +16 -15
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +3 -3
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +12 -12
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +18 -17
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +12 -7
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +12 -7
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +15 -13
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +24 -21
- diffusers/pipelines/unclip/pipeline_unclip.py +4 -3
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +4 -3
- diffusers/pipelines/unclip/text_proj.py +2 -2
- diffusers/pipelines/unidiffuser/modeling_text_decoder.py +2 -2
- diffusers/pipelines/unidiffuser/modeling_uvit.py +1 -1
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +8 -7
- diffusers/pipelines/visualcloze/__init__.py +52 -0
- diffusers/pipelines/visualcloze/pipeline_visualcloze_combined.py +444 -0
- diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py +952 -0
- diffusers/pipelines/visualcloze/visualcloze_utils.py +251 -0
- diffusers/pipelines/wan/__init__.py +2 -0
- diffusers/pipelines/wan/pipeline_wan.py +91 -30
- diffusers/pipelines/wan/pipeline_wan_i2v.py +145 -45
- diffusers/pipelines/wan/pipeline_wan_vace.py +975 -0
- diffusers/pipelines/wan/pipeline_wan_video2video.py +14 -16
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_diffnext.py +1 -1
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +1 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +8 -8
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +16 -15
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +6 -6
- diffusers/quantizers/__init__.py +3 -1
- diffusers/quantizers/base.py +17 -1
- diffusers/quantizers/bitsandbytes/bnb_quantizer.py +4 -0
- diffusers/quantizers/bitsandbytes/utils.py +10 -7
- diffusers/quantizers/gguf/gguf_quantizer.py +13 -4
- diffusers/quantizers/gguf/utils.py +108 -16
- diffusers/quantizers/pipe_quant_config.py +202 -0
- diffusers/quantizers/quantization_config.py +18 -16
- diffusers/quantizers/quanto/quanto_quantizer.py +4 -0
- diffusers/quantizers/torchao/torchao_quantizer.py +31 -1
- diffusers/schedulers/__init__.py +3 -1
- diffusers/schedulers/deprecated/scheduling_karras_ve.py +4 -3
- diffusers/schedulers/deprecated/scheduling_sde_vp.py +1 -1
- diffusers/schedulers/scheduling_consistency_models.py +1 -1
- diffusers/schedulers/scheduling_cosine_dpmsolver_multistep.py +10 -5
- diffusers/schedulers/scheduling_ddim.py +8 -8
- diffusers/schedulers/scheduling_ddim_cogvideox.py +5 -5
- diffusers/schedulers/scheduling_ddim_flax.py +6 -6
- diffusers/schedulers/scheduling_ddim_inverse.py +6 -6
- diffusers/schedulers/scheduling_ddim_parallel.py +22 -22
- diffusers/schedulers/scheduling_ddpm.py +9 -9
- diffusers/schedulers/scheduling_ddpm_flax.py +7 -7
- diffusers/schedulers/scheduling_ddpm_parallel.py +18 -18
- diffusers/schedulers/scheduling_ddpm_wuerstchen.py +2 -2
- diffusers/schedulers/scheduling_deis_multistep.py +16 -9
- diffusers/schedulers/scheduling_dpm_cogvideox.py +5 -5
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +18 -12
- diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +22 -20
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +11 -11
- diffusers/schedulers/scheduling_dpmsolver_sde.py +2 -2
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +19 -13
- diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +13 -8
- diffusers/schedulers/scheduling_edm_euler.py +20 -11
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +3 -3
- diffusers/schedulers/scheduling_euler_discrete.py +3 -3
- diffusers/schedulers/scheduling_euler_discrete_flax.py +3 -3
- diffusers/schedulers/scheduling_flow_match_euler_discrete.py +20 -5
- diffusers/schedulers/scheduling_flow_match_heun_discrete.py +1 -1
- diffusers/schedulers/scheduling_flow_match_lcm.py +561 -0
- diffusers/schedulers/scheduling_heun_discrete.py +2 -2
- diffusers/schedulers/scheduling_ipndm.py +2 -2
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +2 -2
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +2 -2
- diffusers/schedulers/scheduling_karras_ve_flax.py +5 -5
- diffusers/schedulers/scheduling_lcm.py +3 -3
- diffusers/schedulers/scheduling_lms_discrete.py +2 -2
- diffusers/schedulers/scheduling_lms_discrete_flax.py +1 -1
- diffusers/schedulers/scheduling_pndm.py +4 -4
- diffusers/schedulers/scheduling_pndm_flax.py +4 -4
- diffusers/schedulers/scheduling_repaint.py +9 -9
- diffusers/schedulers/scheduling_sasolver.py +15 -15
- diffusers/schedulers/scheduling_scm.py +1 -2
- diffusers/schedulers/scheduling_sde_ve.py +1 -1
- diffusers/schedulers/scheduling_sde_ve_flax.py +2 -2
- diffusers/schedulers/scheduling_tcd.py +3 -3
- diffusers/schedulers/scheduling_unclip.py +5 -5
- diffusers/schedulers/scheduling_unipc_multistep.py +21 -12
- diffusers/schedulers/scheduling_utils.py +3 -3
- diffusers/schedulers/scheduling_utils_flax.py +2 -2
- diffusers/schedulers/scheduling_vq_diffusion.py +1 -1
- diffusers/training_utils.py +91 -5
- diffusers/utils/__init__.py +15 -0
- diffusers/utils/accelerate_utils.py +1 -1
- diffusers/utils/constants.py +4 -0
- diffusers/utils/doc_utils.py +1 -1
- diffusers/utils/dummy_pt_objects.py +432 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +480 -0
- diffusers/utils/dynamic_modules_utils.py +85 -8
- diffusers/utils/export_utils.py +1 -1
- diffusers/utils/hub_utils.py +33 -17
- diffusers/utils/import_utils.py +151 -18
- diffusers/utils/logging.py +1 -1
- diffusers/utils/outputs.py +2 -1
- diffusers/utils/peft_utils.py +96 -10
- diffusers/utils/state_dict_utils.py +20 -3
- diffusers/utils/testing_utils.py +195 -17
- diffusers/utils/torch_utils.py +43 -5
- diffusers/video_processor.py +2 -2
- {diffusers-0.33.1.dist-info → diffusers-0.35.0.dist-info}/METADATA +72 -57
- diffusers-0.35.0.dist-info/RECORD +703 -0
- {diffusers-0.33.1.dist-info → diffusers-0.35.0.dist-info}/WHEEL +1 -1
- diffusers-0.33.1.dist-info/RECORD +0 -608
- {diffusers-0.33.1.dist-info → diffusers-0.35.0.dist-info}/LICENSE +0 -0
- {diffusers-0.33.1.dist-info → diffusers-0.35.0.dist-info}/entry_points.txt +0 -0
- {diffusers-0.33.1.dist-info → diffusers-0.35.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,771 @@
|
|
1
|
+
# Copyright 2025 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
|
+
|
15
|
+
import inspect
|
16
|
+
from typing import Any, List, Optional, Tuple
|
17
|
+
|
18
|
+
import torch
|
19
|
+
|
20
|
+
from ...configuration_utils import FrozenDict
|
21
|
+
from ...guiders import ClassifierFreeGuidance
|
22
|
+
from ...models import ControlNetModel, UNet2DConditionModel
|
23
|
+
from ...schedulers import EulerDiscreteScheduler
|
24
|
+
from ...utils import logging
|
25
|
+
from ..modular_pipeline import (
|
26
|
+
BlockState,
|
27
|
+
LoopSequentialPipelineBlocks,
|
28
|
+
ModularPipelineBlocks,
|
29
|
+
PipelineState,
|
30
|
+
)
|
31
|
+
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
32
|
+
from .modular_pipeline import StableDiffusionXLModularPipeline
|
33
|
+
|
34
|
+
|
35
|
+
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
36
|
+
|
37
|
+
|
38
|
+
# YiYi experimenting composible denoise loop
|
39
|
+
# loop step (1): prepare latent input for denoiser
|
40
|
+
class StableDiffusionXLLoopBeforeDenoiser(ModularPipelineBlocks):
|
41
|
+
model_name = "stable-diffusion-xl"
|
42
|
+
|
43
|
+
@property
|
44
|
+
def expected_components(self) -> List[ComponentSpec]:
|
45
|
+
return [
|
46
|
+
ComponentSpec("scheduler", EulerDiscreteScheduler),
|
47
|
+
]
|
48
|
+
|
49
|
+
@property
|
50
|
+
def description(self) -> str:
|
51
|
+
return (
|
52
|
+
"step within the denoising loop that prepare the latent input for the denoiser. "
|
53
|
+
"This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` "
|
54
|
+
"object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)"
|
55
|
+
)
|
56
|
+
|
57
|
+
@property
|
58
|
+
def inputs(self) -> List[str]:
|
59
|
+
return [
|
60
|
+
InputParam(
|
61
|
+
"latents",
|
62
|
+
required=True,
|
63
|
+
type_hint=torch.Tensor,
|
64
|
+
description="The initial latents to use for the denoising process. Can be generated in prepare_latent step.",
|
65
|
+
),
|
66
|
+
]
|
67
|
+
|
68
|
+
@torch.no_grad()
|
69
|
+
def __call__(self, components: StableDiffusionXLModularPipeline, block_state: BlockState, i: int, t: int):
|
70
|
+
block_state.scaled_latents = components.scheduler.scale_model_input(block_state.latents, t)
|
71
|
+
|
72
|
+
return components, block_state
|
73
|
+
|
74
|
+
|
75
|
+
# loop step (1): prepare latent input for denoiser (with inpainting)
|
76
|
+
class StableDiffusionXLInpaintLoopBeforeDenoiser(ModularPipelineBlocks):
|
77
|
+
model_name = "stable-diffusion-xl"
|
78
|
+
|
79
|
+
@property
|
80
|
+
def expected_components(self) -> List[ComponentSpec]:
|
81
|
+
return [
|
82
|
+
ComponentSpec("scheduler", EulerDiscreteScheduler),
|
83
|
+
ComponentSpec("unet", UNet2DConditionModel),
|
84
|
+
]
|
85
|
+
|
86
|
+
@property
|
87
|
+
def description(self) -> str:
|
88
|
+
return (
|
89
|
+
"step within the denoising loop that prepare the latent input for the denoiser (for inpainting workflow only). "
|
90
|
+
"This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object"
|
91
|
+
)
|
92
|
+
|
93
|
+
@property
|
94
|
+
def inputs(self) -> List[str]:
|
95
|
+
return [
|
96
|
+
InputParam(
|
97
|
+
"latents",
|
98
|
+
required=True,
|
99
|
+
type_hint=torch.Tensor,
|
100
|
+
description="The initial latents to use for the denoising process. Can be generated in prepare_latent step.",
|
101
|
+
),
|
102
|
+
InputParam(
|
103
|
+
"mask",
|
104
|
+
type_hint=Optional[torch.Tensor],
|
105
|
+
description="The mask to use for the denoising process, for inpainting task only. Can be generated in vae_encode or prepare_latent step.",
|
106
|
+
),
|
107
|
+
InputParam(
|
108
|
+
"masked_image_latents",
|
109
|
+
type_hint=Optional[torch.Tensor],
|
110
|
+
description="The masked image latents to use for the denoising process, for inpainting task only. Can be generated in vae_encode or prepare_latent step.",
|
111
|
+
),
|
112
|
+
]
|
113
|
+
|
114
|
+
@staticmethod
|
115
|
+
def check_inputs(components, block_state):
|
116
|
+
num_channels_unet = components.num_channels_unet
|
117
|
+
if num_channels_unet == 9:
|
118
|
+
# default case for runwayml/stable-diffusion-inpainting
|
119
|
+
if block_state.mask is None or block_state.masked_image_latents is None:
|
120
|
+
raise ValueError("mask and masked_image_latents must be provided for inpainting-specific Unet")
|
121
|
+
num_channels_latents = block_state.latents.shape[1]
|
122
|
+
num_channels_mask = block_state.mask.shape[1]
|
123
|
+
num_channels_masked_image = block_state.masked_image_latents.shape[1]
|
124
|
+
if num_channels_latents + num_channels_mask + num_channels_masked_image != num_channels_unet:
|
125
|
+
raise ValueError(
|
126
|
+
f"Incorrect configuration settings! The config of `components.unet`: {components.unet.config} expects"
|
127
|
+
f" {components.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
|
128
|
+
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
|
129
|
+
f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
|
130
|
+
" `components.unet` or your `mask_image` or `image` input."
|
131
|
+
)
|
132
|
+
|
133
|
+
@torch.no_grad()
|
134
|
+
def __call__(self, components: StableDiffusionXLModularPipeline, block_state: BlockState, i: int, t: int):
|
135
|
+
self.check_inputs(components, block_state)
|
136
|
+
|
137
|
+
block_state.scaled_latents = components.scheduler.scale_model_input(block_state.latents, t)
|
138
|
+
if components.num_channels_unet == 9:
|
139
|
+
block_state.scaled_latents = torch.cat(
|
140
|
+
[block_state.scaled_latents, block_state.mask, block_state.masked_image_latents], dim=1
|
141
|
+
)
|
142
|
+
|
143
|
+
return components, block_state
|
144
|
+
|
145
|
+
|
146
|
+
# loop step (2): denoise the latents with guidance
|
147
|
+
class StableDiffusionXLLoopDenoiser(ModularPipelineBlocks):
|
148
|
+
model_name = "stable-diffusion-xl"
|
149
|
+
|
150
|
+
@property
|
151
|
+
def expected_components(self) -> List[ComponentSpec]:
|
152
|
+
return [
|
153
|
+
ComponentSpec(
|
154
|
+
"guider",
|
155
|
+
ClassifierFreeGuidance,
|
156
|
+
config=FrozenDict({"guidance_scale": 7.5}),
|
157
|
+
default_creation_method="from_config",
|
158
|
+
),
|
159
|
+
ComponentSpec("unet", UNet2DConditionModel),
|
160
|
+
]
|
161
|
+
|
162
|
+
@property
|
163
|
+
def description(self) -> str:
|
164
|
+
return (
|
165
|
+
"Step within the denoising loop that denoise the latents with guidance. "
|
166
|
+
"This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` "
|
167
|
+
"object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)"
|
168
|
+
)
|
169
|
+
|
170
|
+
@property
|
171
|
+
def inputs(self) -> List[Tuple[str, Any]]:
|
172
|
+
return [
|
173
|
+
InputParam("cross_attention_kwargs"),
|
174
|
+
InputParam(
|
175
|
+
"num_inference_steps",
|
176
|
+
required=True,
|
177
|
+
type_hint=int,
|
178
|
+
description="The number of inference steps to use for the denoising process. Can be generated in set_timesteps step.",
|
179
|
+
),
|
180
|
+
InputParam(
|
181
|
+
"timestep_cond",
|
182
|
+
type_hint=Optional[torch.Tensor],
|
183
|
+
description="The guidance scale embedding to use for Latent Consistency Models(LCMs). Can be generated in prepare_additional_conditioning step.",
|
184
|
+
),
|
185
|
+
InputParam(
|
186
|
+
kwargs_type="guider_input_fields",
|
187
|
+
description=(
|
188
|
+
"All conditional model inputs that need to be prepared with guider. "
|
189
|
+
"It should contain prompt_embeds/negative_prompt_embeds, "
|
190
|
+
"add_time_ids/negative_add_time_ids, "
|
191
|
+
"pooled_prompt_embeds/negative_pooled_prompt_embeds, "
|
192
|
+
"and ip_adapter_embeds/negative_ip_adapter_embeds (optional)."
|
193
|
+
"please add `kwargs_type=guider_input_fields` to their parameter spec (`OutputParam`) when they are created and added to the pipeline state"
|
194
|
+
),
|
195
|
+
),
|
196
|
+
]
|
197
|
+
|
198
|
+
@torch.no_grad()
|
199
|
+
def __call__(
|
200
|
+
self, components: StableDiffusionXLModularPipeline, block_state: BlockState, i: int, t: int
|
201
|
+
) -> PipelineState:
|
202
|
+
# Map the keys we'll see on each `guider_state_batch` (e.g. guider_state_batch.prompt_embeds)
|
203
|
+
# to the corresponding (cond, uncond) fields on block_state. (e.g. block_state.prompt_embeds, block_state.negative_prompt_embeds)
|
204
|
+
guider_input_fields = {
|
205
|
+
"prompt_embeds": ("prompt_embeds", "negative_prompt_embeds"),
|
206
|
+
"time_ids": ("add_time_ids", "negative_add_time_ids"),
|
207
|
+
"text_embeds": ("pooled_prompt_embeds", "negative_pooled_prompt_embeds"),
|
208
|
+
"image_embeds": ("ip_adapter_embeds", "negative_ip_adapter_embeds"),
|
209
|
+
}
|
210
|
+
|
211
|
+
components.guider.set_state(step=i, num_inference_steps=block_state.num_inference_steps, timestep=t)
|
212
|
+
|
213
|
+
# Prepare mini‐batches according to guidance method and `guider_input_fields`
|
214
|
+
# Each guider_state_batch will have .prompt_embeds, .time_ids, text_embeds, image_embeds.
|
215
|
+
# e.g. for CFG, we prepare two batches: one for uncond, one for cond
|
216
|
+
# for first batch, guider_state_batch.prompt_embeds correspond to block_state.prompt_embeds
|
217
|
+
# for second batch, guider_state_batch.prompt_embeds correspond to block_state.negative_prompt_embeds
|
218
|
+
guider_state = components.guider.prepare_inputs(block_state, guider_input_fields)
|
219
|
+
|
220
|
+
# run the denoiser for each guidance batch
|
221
|
+
for guider_state_batch in guider_state:
|
222
|
+
components.guider.prepare_models(components.unet)
|
223
|
+
cond_kwargs = guider_state_batch.as_dict()
|
224
|
+
cond_kwargs = {k: v for k, v in cond_kwargs.items() if k in guider_input_fields}
|
225
|
+
prompt_embeds = cond_kwargs.pop("prompt_embeds")
|
226
|
+
|
227
|
+
# Predict the noise residual
|
228
|
+
# store the noise_pred in guider_state_batch so that we can apply guidance across all batches
|
229
|
+
guider_state_batch.noise_pred = components.unet(
|
230
|
+
block_state.scaled_latents,
|
231
|
+
t,
|
232
|
+
encoder_hidden_states=prompt_embeds,
|
233
|
+
timestep_cond=block_state.timestep_cond,
|
234
|
+
cross_attention_kwargs=block_state.cross_attention_kwargs,
|
235
|
+
added_cond_kwargs=cond_kwargs,
|
236
|
+
return_dict=False,
|
237
|
+
)[0]
|
238
|
+
components.guider.cleanup_models(components.unet)
|
239
|
+
|
240
|
+
# Perform guidance
|
241
|
+
block_state.noise_pred, block_state.scheduler_step_kwargs = components.guider(guider_state)
|
242
|
+
|
243
|
+
return components, block_state
|
244
|
+
|
245
|
+
|
246
|
+
# loop step (2): denoise the latents with guidance (with controlnet)
|
247
|
+
class StableDiffusionXLControlNetLoopDenoiser(ModularPipelineBlocks):
|
248
|
+
model_name = "stable-diffusion-xl"
|
249
|
+
|
250
|
+
@property
|
251
|
+
def expected_components(self) -> List[ComponentSpec]:
|
252
|
+
return [
|
253
|
+
ComponentSpec(
|
254
|
+
"guider",
|
255
|
+
ClassifierFreeGuidance,
|
256
|
+
config=FrozenDict({"guidance_scale": 7.5}),
|
257
|
+
default_creation_method="from_config",
|
258
|
+
),
|
259
|
+
ComponentSpec("unet", UNet2DConditionModel),
|
260
|
+
ComponentSpec("controlnet", ControlNetModel),
|
261
|
+
]
|
262
|
+
|
263
|
+
@property
|
264
|
+
def description(self) -> str:
|
265
|
+
return (
|
266
|
+
"step within the denoising loop that denoise the latents with guidance (with controlnet). "
|
267
|
+
"This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` "
|
268
|
+
"object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)"
|
269
|
+
)
|
270
|
+
|
271
|
+
@property
|
272
|
+
def inputs(self) -> List[Tuple[str, Any]]:
|
273
|
+
return [
|
274
|
+
InputParam("cross_attention_kwargs"),
|
275
|
+
InputParam(
|
276
|
+
"controlnet_cond",
|
277
|
+
required=True,
|
278
|
+
type_hint=torch.Tensor,
|
279
|
+
description="The control image to use for the denoising process. Can be generated in prepare_controlnet_inputs step.",
|
280
|
+
),
|
281
|
+
InputParam(
|
282
|
+
"conditioning_scale",
|
283
|
+
type_hint=float,
|
284
|
+
description="The controlnet conditioning scale value to use for the denoising process. Can be generated in prepare_controlnet_inputs step.",
|
285
|
+
),
|
286
|
+
InputParam(
|
287
|
+
"guess_mode",
|
288
|
+
required=True,
|
289
|
+
type_hint=bool,
|
290
|
+
description="The guess mode value to use for the denoising process. Can be generated in prepare_controlnet_inputs step.",
|
291
|
+
),
|
292
|
+
InputParam(
|
293
|
+
"controlnet_keep",
|
294
|
+
required=True,
|
295
|
+
type_hint=List[float],
|
296
|
+
description="The controlnet keep values to use for the denoising process. Can be generated in prepare_controlnet_inputs step.",
|
297
|
+
),
|
298
|
+
InputParam(
|
299
|
+
"timestep_cond",
|
300
|
+
type_hint=Optional[torch.Tensor],
|
301
|
+
description="The guidance scale embedding to use for Latent Consistency Models(LCMs), can be generated by prepare_additional_conditioning step",
|
302
|
+
),
|
303
|
+
InputParam(
|
304
|
+
"num_inference_steps",
|
305
|
+
required=True,
|
306
|
+
type_hint=int,
|
307
|
+
description="The number of inference steps to use for the denoising process. Can be generated in set_timesteps step.",
|
308
|
+
),
|
309
|
+
InputParam(
|
310
|
+
kwargs_type="guider_input_fields",
|
311
|
+
description=(
|
312
|
+
"All conditional model inputs that need to be prepared with guider. "
|
313
|
+
"It should contain prompt_embeds/negative_prompt_embeds, "
|
314
|
+
"add_time_ids/negative_add_time_ids, "
|
315
|
+
"pooled_prompt_embeds/negative_pooled_prompt_embeds, "
|
316
|
+
"and ip_adapter_embeds/negative_ip_adapter_embeds (optional)."
|
317
|
+
"please add `kwargs_type=guider_input_fields` to their parameter spec (`OutputParam`) when they are created and added to the pipeline state"
|
318
|
+
),
|
319
|
+
),
|
320
|
+
InputParam(
|
321
|
+
kwargs_type="controlnet_kwargs",
|
322
|
+
description=(
|
323
|
+
"additional kwargs for controlnet (e.g. control_type_idx and control_type from the controlnet union input step )"
|
324
|
+
"please add `kwargs_type=controlnet_kwargs` to their parameter spec (`OutputParam`) when they are created and added to the pipeline state"
|
325
|
+
),
|
326
|
+
),
|
327
|
+
]
|
328
|
+
|
329
|
+
@staticmethod
|
330
|
+
def prepare_extra_kwargs(func, exclude_kwargs=[], **kwargs):
|
331
|
+
accepted_kwargs = set(inspect.signature(func).parameters.keys())
|
332
|
+
extra_kwargs = {}
|
333
|
+
for key, value in kwargs.items():
|
334
|
+
if key in accepted_kwargs and key not in exclude_kwargs:
|
335
|
+
extra_kwargs[key] = value
|
336
|
+
|
337
|
+
return extra_kwargs
|
338
|
+
|
339
|
+
@torch.no_grad()
|
340
|
+
def __call__(self, components: StableDiffusionXLModularPipeline, block_state: BlockState, i: int, t: int):
|
341
|
+
extra_controlnet_kwargs = self.prepare_extra_kwargs(
|
342
|
+
components.controlnet.forward, **block_state.controlnet_kwargs
|
343
|
+
)
|
344
|
+
|
345
|
+
# Map the keys we'll see on each `guider_state_batch` (e.g. guider_state_batch.prompt_embeds)
|
346
|
+
# to the corresponding (cond, uncond) fields on block_state. (e.g. block_state.prompt_embeds, block_state.negative_prompt_embeds)
|
347
|
+
guider_input_fields = {
|
348
|
+
"prompt_embeds": ("prompt_embeds", "negative_prompt_embeds"),
|
349
|
+
"time_ids": ("add_time_ids", "negative_add_time_ids"),
|
350
|
+
"text_embeds": ("pooled_prompt_embeds", "negative_pooled_prompt_embeds"),
|
351
|
+
"image_embeds": ("ip_adapter_embeds", "negative_ip_adapter_embeds"),
|
352
|
+
}
|
353
|
+
|
354
|
+
# cond_scale for the timestep (controlnet input)
|
355
|
+
if isinstance(block_state.controlnet_keep[i], list):
|
356
|
+
block_state.cond_scale = [
|
357
|
+
c * s for c, s in zip(block_state.conditioning_scale, block_state.controlnet_keep[i])
|
358
|
+
]
|
359
|
+
else:
|
360
|
+
controlnet_cond_scale = block_state.conditioning_scale
|
361
|
+
if isinstance(controlnet_cond_scale, list):
|
362
|
+
controlnet_cond_scale = controlnet_cond_scale[0]
|
363
|
+
block_state.cond_scale = controlnet_cond_scale * block_state.controlnet_keep[i]
|
364
|
+
|
365
|
+
# default controlnet output/unet input for guess mode + conditional path
|
366
|
+
block_state.down_block_res_samples_zeros = None
|
367
|
+
block_state.mid_block_res_sample_zeros = None
|
368
|
+
|
369
|
+
# guided denoiser step
|
370
|
+
components.guider.set_state(step=i, num_inference_steps=block_state.num_inference_steps, timestep=t)
|
371
|
+
|
372
|
+
# Prepare mini‐batches according to guidance method and `guider_input_fields`
|
373
|
+
# Each guider_state_batch will have .prompt_embeds, .time_ids, text_embeds, image_embeds.
|
374
|
+
# e.g. for CFG, we prepare two batches: one for uncond, one for cond
|
375
|
+
# for first batch, guider_state_batch.prompt_embeds correspond to block_state.prompt_embeds
|
376
|
+
# for second batch, guider_state_batch.prompt_embeds correspond to block_state.negative_prompt_embeds
|
377
|
+
guider_state = components.guider.prepare_inputs(block_state, guider_input_fields)
|
378
|
+
|
379
|
+
# run the denoiser for each guidance batch
|
380
|
+
for guider_state_batch in guider_state:
|
381
|
+
components.guider.prepare_models(components.unet)
|
382
|
+
|
383
|
+
# Prepare additional conditionings
|
384
|
+
added_cond_kwargs = {
|
385
|
+
"text_embeds": guider_state_batch.text_embeds,
|
386
|
+
"time_ids": guider_state_batch.time_ids,
|
387
|
+
}
|
388
|
+
if hasattr(guider_state_batch, "image_embeds") and guider_state_batch.image_embeds is not None:
|
389
|
+
added_cond_kwargs["image_embeds"] = guider_state_batch.image_embeds
|
390
|
+
|
391
|
+
# Prepare controlnet additional conditionings
|
392
|
+
controlnet_added_cond_kwargs = {
|
393
|
+
"text_embeds": guider_state_batch.text_embeds,
|
394
|
+
"time_ids": guider_state_batch.time_ids,
|
395
|
+
}
|
396
|
+
# run controlnet for the guidance batch
|
397
|
+
if block_state.guess_mode and not components.guider.is_conditional:
|
398
|
+
# guider always run uncond batch first, so these tensors should be set already
|
399
|
+
down_block_res_samples = block_state.down_block_res_samples_zeros
|
400
|
+
mid_block_res_sample = block_state.mid_block_res_sample_zeros
|
401
|
+
else:
|
402
|
+
down_block_res_samples, mid_block_res_sample = components.controlnet(
|
403
|
+
block_state.scaled_latents,
|
404
|
+
t,
|
405
|
+
encoder_hidden_states=guider_state_batch.prompt_embeds,
|
406
|
+
controlnet_cond=block_state.controlnet_cond,
|
407
|
+
conditioning_scale=block_state.cond_scale,
|
408
|
+
guess_mode=block_state.guess_mode,
|
409
|
+
added_cond_kwargs=controlnet_added_cond_kwargs,
|
410
|
+
return_dict=False,
|
411
|
+
**extra_controlnet_kwargs,
|
412
|
+
)
|
413
|
+
|
414
|
+
# assign it to block_state so it will be available for the uncond guidance batch
|
415
|
+
if block_state.down_block_res_samples_zeros is None:
|
416
|
+
block_state.down_block_res_samples_zeros = [torch.zeros_like(d) for d in down_block_res_samples]
|
417
|
+
if block_state.mid_block_res_sample_zeros is None:
|
418
|
+
block_state.mid_block_res_sample_zeros = torch.zeros_like(mid_block_res_sample)
|
419
|
+
|
420
|
+
# Predict the noise
|
421
|
+
# store the noise_pred in guider_state_batch so we can apply guidance across all batches
|
422
|
+
guider_state_batch.noise_pred = components.unet(
|
423
|
+
block_state.scaled_latents,
|
424
|
+
t,
|
425
|
+
encoder_hidden_states=guider_state_batch.prompt_embeds,
|
426
|
+
timestep_cond=block_state.timestep_cond,
|
427
|
+
cross_attention_kwargs=block_state.cross_attention_kwargs,
|
428
|
+
added_cond_kwargs=added_cond_kwargs,
|
429
|
+
down_block_additional_residuals=down_block_res_samples,
|
430
|
+
mid_block_additional_residual=mid_block_res_sample,
|
431
|
+
return_dict=False,
|
432
|
+
)[0]
|
433
|
+
components.guider.cleanup_models(components.unet)
|
434
|
+
|
435
|
+
# Perform guidance
|
436
|
+
block_state.noise_pred, block_state.scheduler_step_kwargs = components.guider(guider_state)
|
437
|
+
|
438
|
+
return components, block_state
|
439
|
+
|
440
|
+
|
441
|
+
# loop step (3): scheduler step to update latents
|
442
|
+
class StableDiffusionXLLoopAfterDenoiser(ModularPipelineBlocks):
|
443
|
+
model_name = "stable-diffusion-xl"
|
444
|
+
|
445
|
+
@property
|
446
|
+
def expected_components(self) -> List[ComponentSpec]:
|
447
|
+
return [
|
448
|
+
ComponentSpec("scheduler", EulerDiscreteScheduler),
|
449
|
+
]
|
450
|
+
|
451
|
+
@property
|
452
|
+
def description(self) -> str:
|
453
|
+
return (
|
454
|
+
"step within the denoising loop that update the latents. "
|
455
|
+
"This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` "
|
456
|
+
"object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)"
|
457
|
+
)
|
458
|
+
|
459
|
+
@property
|
460
|
+
def inputs(self) -> List[Tuple[str, Any]]:
|
461
|
+
return [
|
462
|
+
InputParam("eta", default=0.0),
|
463
|
+
InputParam("generator"),
|
464
|
+
]
|
465
|
+
|
466
|
+
@property
|
467
|
+
def intermediate_outputs(self) -> List[OutputParam]:
|
468
|
+
return [OutputParam("latents", type_hint=torch.Tensor, description="The denoised latents")]
|
469
|
+
|
470
|
+
# YiYi TODO: move this out of here
|
471
|
+
@staticmethod
|
472
|
+
def prepare_extra_kwargs(func, exclude_kwargs=[], **kwargs):
|
473
|
+
accepted_kwargs = set(inspect.signature(func).parameters.keys())
|
474
|
+
extra_kwargs = {}
|
475
|
+
for key, value in kwargs.items():
|
476
|
+
if key in accepted_kwargs and key not in exclude_kwargs:
|
477
|
+
extra_kwargs[key] = value
|
478
|
+
|
479
|
+
return extra_kwargs
|
480
|
+
|
481
|
+
@torch.no_grad()
|
482
|
+
def __call__(self, components: StableDiffusionXLModularPipeline, block_state: BlockState, i: int, t: int):
|
483
|
+
# Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
484
|
+
block_state.extra_step_kwargs = self.prepare_extra_kwargs(
|
485
|
+
components.scheduler.step, generator=block_state.generator, eta=block_state.eta
|
486
|
+
)
|
487
|
+
|
488
|
+
# Perform scheduler step using the predicted output
|
489
|
+
block_state.latents_dtype = block_state.latents.dtype
|
490
|
+
block_state.latents = components.scheduler.step(
|
491
|
+
block_state.noise_pred,
|
492
|
+
t,
|
493
|
+
block_state.latents,
|
494
|
+
**block_state.extra_step_kwargs,
|
495
|
+
**block_state.scheduler_step_kwargs,
|
496
|
+
return_dict=False,
|
497
|
+
)[0]
|
498
|
+
|
499
|
+
if block_state.latents.dtype != block_state.latents_dtype:
|
500
|
+
if torch.backends.mps.is_available():
|
501
|
+
# some platforms (eg. apple mps) misbehave due to a pytorch bug: https://github.com/pytorch/pytorch/pull/99272
|
502
|
+
block_state.latents = block_state.latents.to(block_state.latents_dtype)
|
503
|
+
|
504
|
+
return components, block_state
|
505
|
+
|
506
|
+
|
507
|
+
# loop step (3): scheduler step to update latents (with inpainting)
|
508
|
+
class StableDiffusionXLInpaintLoopAfterDenoiser(ModularPipelineBlocks):
|
509
|
+
model_name = "stable-diffusion-xl"
|
510
|
+
|
511
|
+
@property
|
512
|
+
def expected_components(self) -> List[ComponentSpec]:
|
513
|
+
return [
|
514
|
+
ComponentSpec("scheduler", EulerDiscreteScheduler),
|
515
|
+
ComponentSpec("unet", UNet2DConditionModel),
|
516
|
+
]
|
517
|
+
|
518
|
+
@property
|
519
|
+
def description(self) -> str:
|
520
|
+
return (
|
521
|
+
"step within the denoising loop that update the latents (for inpainting workflow only). "
|
522
|
+
"This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` "
|
523
|
+
"object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)"
|
524
|
+
)
|
525
|
+
|
526
|
+
@property
|
527
|
+
def inputs(self) -> List[Tuple[str, Any]]:
|
528
|
+
return [
|
529
|
+
InputParam("eta", default=0.0),
|
530
|
+
InputParam("generator"),
|
531
|
+
InputParam(
|
532
|
+
"timesteps",
|
533
|
+
required=True,
|
534
|
+
type_hint=torch.Tensor,
|
535
|
+
description="The timesteps to use for the denoising process. Can be generated in set_timesteps step.",
|
536
|
+
),
|
537
|
+
InputParam(
|
538
|
+
"mask",
|
539
|
+
type_hint=Optional[torch.Tensor],
|
540
|
+
description="The mask to use for the denoising process, for inpainting task only. Can be generated in vae_encode or prepare_latent step.",
|
541
|
+
),
|
542
|
+
InputParam(
|
543
|
+
"noise",
|
544
|
+
type_hint=Optional[torch.Tensor],
|
545
|
+
description="The noise added to the image latents, for inpainting task only. Can be generated in prepare_latent step.",
|
546
|
+
),
|
547
|
+
InputParam(
|
548
|
+
"image_latents",
|
549
|
+
type_hint=Optional[torch.Tensor],
|
550
|
+
description="The image latents to use for the denoising process, for inpainting/image-to-image task only. Can be generated in vae_encode or prepare_latent step.",
|
551
|
+
),
|
552
|
+
]
|
553
|
+
|
554
|
+
@property
|
555
|
+
def intermediate_outputs(self) -> List[OutputParam]:
|
556
|
+
return [OutputParam("latents", type_hint=torch.Tensor, description="The denoised latents")]
|
557
|
+
|
558
|
+
@staticmethod
|
559
|
+
def prepare_extra_kwargs(func, exclude_kwargs=[], **kwargs):
|
560
|
+
accepted_kwargs = set(inspect.signature(func).parameters.keys())
|
561
|
+
extra_kwargs = {}
|
562
|
+
for key, value in kwargs.items():
|
563
|
+
if key in accepted_kwargs and key not in exclude_kwargs:
|
564
|
+
extra_kwargs[key] = value
|
565
|
+
|
566
|
+
return extra_kwargs
|
567
|
+
|
568
|
+
def check_inputs(self, components, block_state):
|
569
|
+
if components.num_channels_unet == 4:
|
570
|
+
if block_state.image_latents is None:
|
571
|
+
raise ValueError(f"image_latents is required for this step {self.__class__.__name__}")
|
572
|
+
if block_state.mask is None:
|
573
|
+
raise ValueError(f"mask is required for this step {self.__class__.__name__}")
|
574
|
+
if block_state.noise is None:
|
575
|
+
raise ValueError(f"noise is required for this step {self.__class__.__name__}")
|
576
|
+
|
577
|
+
@torch.no_grad()
|
578
|
+
def __call__(self, components: StableDiffusionXLModularPipeline, block_state: BlockState, i: int, t: int):
|
579
|
+
self.check_inputs(components, block_state)
|
580
|
+
|
581
|
+
# Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
582
|
+
block_state.extra_step_kwargs = self.prepare_extra_kwargs(
|
583
|
+
components.scheduler.step, generator=block_state.generator, eta=block_state.eta
|
584
|
+
)
|
585
|
+
|
586
|
+
# Perform scheduler step using the predicted output
|
587
|
+
block_state.latents_dtype = block_state.latents.dtype
|
588
|
+
block_state.latents = components.scheduler.step(
|
589
|
+
block_state.noise_pred,
|
590
|
+
t,
|
591
|
+
block_state.latents,
|
592
|
+
**block_state.extra_step_kwargs,
|
593
|
+
**block_state.scheduler_step_kwargs,
|
594
|
+
return_dict=False,
|
595
|
+
)[0]
|
596
|
+
|
597
|
+
if block_state.latents.dtype != block_state.latents_dtype:
|
598
|
+
if torch.backends.mps.is_available():
|
599
|
+
# some platforms (eg. apple mps) misbehave due to a pytorch bug: https://github.com/pytorch/pytorch/pull/99272
|
600
|
+
block_state.latents = block_state.latents.to(block_state.latents_dtype)
|
601
|
+
|
602
|
+
# adjust latent for inpainting
|
603
|
+
if components.num_channels_unet == 4:
|
604
|
+
block_state.init_latents_proper = block_state.image_latents
|
605
|
+
if i < len(block_state.timesteps) - 1:
|
606
|
+
block_state.noise_timestep = block_state.timesteps[i + 1]
|
607
|
+
block_state.init_latents_proper = components.scheduler.add_noise(
|
608
|
+
block_state.init_latents_proper, block_state.noise, torch.tensor([block_state.noise_timestep])
|
609
|
+
)
|
610
|
+
|
611
|
+
block_state.latents = (
|
612
|
+
1 - block_state.mask
|
613
|
+
) * block_state.init_latents_proper + block_state.mask * block_state.latents
|
614
|
+
|
615
|
+
return components, block_state
|
616
|
+
|
617
|
+
|
618
|
+
# the loop wrapper that iterates over the timesteps
|
619
|
+
class StableDiffusionXLDenoiseLoopWrapper(LoopSequentialPipelineBlocks):
|
620
|
+
model_name = "stable-diffusion-xl"
|
621
|
+
|
622
|
+
@property
|
623
|
+
def description(self) -> str:
|
624
|
+
return (
|
625
|
+
"Pipeline block that iteratively denoise the latents over `timesteps`. "
|
626
|
+
"The specific steps with each iteration can be customized with `sub_blocks` attributes"
|
627
|
+
)
|
628
|
+
|
629
|
+
@property
|
630
|
+
def loop_expected_components(self) -> List[ComponentSpec]:
|
631
|
+
return [
|
632
|
+
ComponentSpec(
|
633
|
+
"guider",
|
634
|
+
ClassifierFreeGuidance,
|
635
|
+
config=FrozenDict({"guidance_scale": 7.5}),
|
636
|
+
default_creation_method="from_config",
|
637
|
+
),
|
638
|
+
ComponentSpec("scheduler", EulerDiscreteScheduler),
|
639
|
+
ComponentSpec("unet", UNet2DConditionModel),
|
640
|
+
]
|
641
|
+
|
642
|
+
@property
|
643
|
+
def loop_inputs(self) -> List[InputParam]:
|
644
|
+
return [
|
645
|
+
InputParam(
|
646
|
+
"timesteps",
|
647
|
+
required=True,
|
648
|
+
type_hint=torch.Tensor,
|
649
|
+
description="The timesteps to use for the denoising process. Can be generated in set_timesteps step.",
|
650
|
+
),
|
651
|
+
InputParam(
|
652
|
+
"num_inference_steps",
|
653
|
+
required=True,
|
654
|
+
type_hint=int,
|
655
|
+
description="The number of inference steps to use for the denoising process. Can be generated in set_timesteps step.",
|
656
|
+
),
|
657
|
+
]
|
658
|
+
|
659
|
+
@torch.no_grad()
|
660
|
+
def __call__(self, components: StableDiffusionXLModularPipeline, state: PipelineState) -> PipelineState:
|
661
|
+
block_state = self.get_block_state(state)
|
662
|
+
|
663
|
+
block_state.disable_guidance = True if components.unet.config.time_cond_proj_dim is not None else False
|
664
|
+
if block_state.disable_guidance:
|
665
|
+
components.guider.disable()
|
666
|
+
else:
|
667
|
+
components.guider.enable()
|
668
|
+
|
669
|
+
block_state.num_warmup_steps = max(
|
670
|
+
len(block_state.timesteps) - block_state.num_inference_steps * components.scheduler.order, 0
|
671
|
+
)
|
672
|
+
|
673
|
+
with self.progress_bar(total=block_state.num_inference_steps) as progress_bar:
|
674
|
+
for i, t in enumerate(block_state.timesteps):
|
675
|
+
components, block_state = self.loop_step(components, block_state, i=i, t=t)
|
676
|
+
if i == len(block_state.timesteps) - 1 or (
|
677
|
+
(i + 1) > block_state.num_warmup_steps and (i + 1) % components.scheduler.order == 0
|
678
|
+
):
|
679
|
+
progress_bar.update()
|
680
|
+
|
681
|
+
self.set_block_state(state, block_state)
|
682
|
+
|
683
|
+
return components, state
|
684
|
+
|
685
|
+
|
686
|
+
# composing the denoising loops
|
687
|
+
class StableDiffusionXLDenoiseStep(StableDiffusionXLDenoiseLoopWrapper):
|
688
|
+
block_classes = [
|
689
|
+
StableDiffusionXLLoopBeforeDenoiser,
|
690
|
+
StableDiffusionXLLoopDenoiser,
|
691
|
+
StableDiffusionXLLoopAfterDenoiser,
|
692
|
+
]
|
693
|
+
block_names = ["before_denoiser", "denoiser", "after_denoiser"]
|
694
|
+
|
695
|
+
@property
|
696
|
+
def description(self) -> str:
|
697
|
+
return (
|
698
|
+
"Denoise step that iteratively denoise the latents. \n"
|
699
|
+
"Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method \n"
|
700
|
+
"At each iteration, it runs blocks defined in `sub_blocks` sequencially:\n"
|
701
|
+
" - `StableDiffusionXLLoopBeforeDenoiser`\n"
|
702
|
+
" - `StableDiffusionXLLoopDenoiser`\n"
|
703
|
+
" - `StableDiffusionXLLoopAfterDenoiser`\n"
|
704
|
+
"This block supports both text2img and img2img tasks."
|
705
|
+
)
|
706
|
+
|
707
|
+
|
708
|
+
# control_cond
|
709
|
+
class StableDiffusionXLControlNetDenoiseStep(StableDiffusionXLDenoiseLoopWrapper):
|
710
|
+
block_classes = [
|
711
|
+
StableDiffusionXLLoopBeforeDenoiser,
|
712
|
+
StableDiffusionXLControlNetLoopDenoiser,
|
713
|
+
StableDiffusionXLLoopAfterDenoiser,
|
714
|
+
]
|
715
|
+
block_names = ["before_denoiser", "denoiser", "after_denoiser"]
|
716
|
+
|
717
|
+
@property
|
718
|
+
def description(self) -> str:
|
719
|
+
return (
|
720
|
+
"Denoise step that iteratively denoise the latents with controlnet. \n"
|
721
|
+
"Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method \n"
|
722
|
+
"At each iteration, it runs blocks defined in `sub_blocks` sequencially:\n"
|
723
|
+
" - `StableDiffusionXLLoopBeforeDenoiser`\n"
|
724
|
+
" - `StableDiffusionXLControlNetLoopDenoiser`\n"
|
725
|
+
" - `StableDiffusionXLLoopAfterDenoiser`\n"
|
726
|
+
"This block supports using controlnet for both text2img and img2img tasks."
|
727
|
+
)
|
728
|
+
|
729
|
+
|
730
|
+
# mask
|
731
|
+
class StableDiffusionXLInpaintDenoiseStep(StableDiffusionXLDenoiseLoopWrapper):
|
732
|
+
block_classes = [
|
733
|
+
StableDiffusionXLInpaintLoopBeforeDenoiser,
|
734
|
+
StableDiffusionXLLoopDenoiser,
|
735
|
+
StableDiffusionXLInpaintLoopAfterDenoiser,
|
736
|
+
]
|
737
|
+
block_names = ["before_denoiser", "denoiser", "after_denoiser"]
|
738
|
+
|
739
|
+
@property
|
740
|
+
def description(self) -> str:
|
741
|
+
return (
|
742
|
+
"Denoise step that iteratively denoise the latents(for inpainting task only). \n"
|
743
|
+
"Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method \n"
|
744
|
+
"At each iteration, it runs blocks defined in `sub_blocks` sequencially:\n"
|
745
|
+
" - `StableDiffusionXLInpaintLoopBeforeDenoiser`\n"
|
746
|
+
" - `StableDiffusionXLLoopDenoiser`\n"
|
747
|
+
" - `StableDiffusionXLInpaintLoopAfterDenoiser`\n"
|
748
|
+
"This block onlysupports inpainting tasks."
|
749
|
+
)
|
750
|
+
|
751
|
+
|
752
|
+
# control_cond + mask
|
753
|
+
class StableDiffusionXLInpaintControlNetDenoiseStep(StableDiffusionXLDenoiseLoopWrapper):
|
754
|
+
block_classes = [
|
755
|
+
StableDiffusionXLInpaintLoopBeforeDenoiser,
|
756
|
+
StableDiffusionXLControlNetLoopDenoiser,
|
757
|
+
StableDiffusionXLInpaintLoopAfterDenoiser,
|
758
|
+
]
|
759
|
+
block_names = ["before_denoiser", "denoiser", "after_denoiser"]
|
760
|
+
|
761
|
+
@property
|
762
|
+
def description(self) -> str:
|
763
|
+
return (
|
764
|
+
"Denoise step that iteratively denoise the latents(for inpainting task only) with controlnet. \n"
|
765
|
+
"Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method \n"
|
766
|
+
"At each iteration, it runs blocks defined in `sub_blocks` sequencially:\n"
|
767
|
+
" - `StableDiffusionXLInpaintLoopBeforeDenoiser`\n"
|
768
|
+
" - `StableDiffusionXLControlNetLoopDenoiser`\n"
|
769
|
+
" - `StableDiffusionXLInpaintLoopAfterDenoiser`\n"
|
770
|
+
"This block only supports using controlnet for inpainting tasks."
|
771
|
+
)
|