diffusers 0.32.2__py3-none-any.whl → 0.33.1__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 +186 -3
- diffusers/configuration_utils.py +40 -12
- diffusers/dependency_versions_table.py +9 -2
- diffusers/hooks/__init__.py +9 -0
- diffusers/hooks/faster_cache.py +653 -0
- diffusers/hooks/group_offloading.py +793 -0
- diffusers/hooks/hooks.py +236 -0
- diffusers/hooks/layerwise_casting.py +245 -0
- diffusers/hooks/pyramid_attention_broadcast.py +311 -0
- diffusers/loaders/__init__.py +6 -0
- diffusers/loaders/ip_adapter.py +38 -30
- diffusers/loaders/lora_base.py +121 -86
- diffusers/loaders/lora_conversion_utils.py +504 -44
- diffusers/loaders/lora_pipeline.py +1769 -181
- diffusers/loaders/peft.py +167 -57
- diffusers/loaders/single_file.py +17 -2
- diffusers/loaders/single_file_model.py +53 -5
- diffusers/loaders/single_file_utils.py +646 -72
- diffusers/loaders/textual_inversion.py +9 -9
- diffusers/loaders/transformer_flux.py +8 -9
- diffusers/loaders/transformer_sd3.py +120 -39
- diffusers/loaders/unet.py +20 -7
- diffusers/models/__init__.py +22 -0
- diffusers/models/activations.py +9 -9
- diffusers/models/attention.py +0 -1
- diffusers/models/attention_processor.py +163 -25
- diffusers/models/auto_model.py +169 -0
- diffusers/models/autoencoders/__init__.py +2 -0
- diffusers/models/autoencoders/autoencoder_asym_kl.py +2 -0
- diffusers/models/autoencoders/autoencoder_dc.py +106 -4
- diffusers/models/autoencoders/autoencoder_kl.py +0 -4
- diffusers/models/autoencoders/autoencoder_kl_allegro.py +5 -23
- diffusers/models/autoencoders/autoencoder_kl_cogvideox.py +17 -55
- diffusers/models/autoencoders/autoencoder_kl_hunyuan_video.py +17 -97
- diffusers/models/autoencoders/autoencoder_kl_ltx.py +326 -107
- diffusers/models/autoencoders/autoencoder_kl_magvit.py +1094 -0
- diffusers/models/autoencoders/autoencoder_kl_mochi.py +21 -56
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +11 -42
- diffusers/models/autoencoders/autoencoder_kl_wan.py +855 -0
- diffusers/models/autoencoders/autoencoder_oobleck.py +1 -0
- diffusers/models/autoencoders/autoencoder_tiny.py +0 -4
- diffusers/models/autoencoders/consistency_decoder_vae.py +3 -1
- diffusers/models/autoencoders/vae.py +31 -141
- diffusers/models/autoencoders/vq_model.py +3 -0
- diffusers/models/cache_utils.py +108 -0
- diffusers/models/controlnets/__init__.py +1 -0
- diffusers/models/controlnets/controlnet.py +3 -8
- diffusers/models/controlnets/controlnet_flux.py +14 -42
- diffusers/models/controlnets/controlnet_sd3.py +58 -34
- diffusers/models/controlnets/controlnet_sparsectrl.py +4 -7
- diffusers/models/controlnets/controlnet_union.py +27 -18
- diffusers/models/controlnets/controlnet_xs.py +7 -46
- diffusers/models/controlnets/multicontrolnet_union.py +196 -0
- diffusers/models/embeddings.py +18 -7
- diffusers/models/model_loading_utils.py +122 -80
- diffusers/models/modeling_flax_pytorch_utils.py +1 -1
- diffusers/models/modeling_flax_utils.py +1 -1
- diffusers/models/modeling_pytorch_flax_utils.py +1 -1
- diffusers/models/modeling_utils.py +617 -272
- diffusers/models/normalization.py +67 -14
- diffusers/models/resnet.py +1 -1
- diffusers/models/transformers/__init__.py +6 -0
- diffusers/models/transformers/auraflow_transformer_2d.py +9 -35
- diffusers/models/transformers/cogvideox_transformer_3d.py +13 -24
- diffusers/models/transformers/consisid_transformer_3d.py +789 -0
- diffusers/models/transformers/dit_transformer_2d.py +5 -19
- diffusers/models/transformers/hunyuan_transformer_2d.py +4 -3
- diffusers/models/transformers/latte_transformer_3d.py +20 -15
- diffusers/models/transformers/lumina_nextdit2d.py +3 -1
- diffusers/models/transformers/pixart_transformer_2d.py +4 -19
- diffusers/models/transformers/prior_transformer.py +5 -1
- diffusers/models/transformers/sana_transformer.py +144 -40
- diffusers/models/transformers/stable_audio_transformer.py +5 -20
- diffusers/models/transformers/transformer_2d.py +7 -22
- diffusers/models/transformers/transformer_allegro.py +9 -17
- diffusers/models/transformers/transformer_cogview3plus.py +6 -17
- diffusers/models/transformers/transformer_cogview4.py +462 -0
- diffusers/models/transformers/transformer_easyanimate.py +527 -0
- diffusers/models/transformers/transformer_flux.py +68 -110
- diffusers/models/transformers/transformer_hunyuan_video.py +404 -46
- diffusers/models/transformers/transformer_ltx.py +53 -35
- diffusers/models/transformers/transformer_lumina2.py +548 -0
- diffusers/models/transformers/transformer_mochi.py +6 -17
- diffusers/models/transformers/transformer_omnigen.py +469 -0
- diffusers/models/transformers/transformer_sd3.py +56 -86
- diffusers/models/transformers/transformer_temporal.py +5 -11
- diffusers/models/transformers/transformer_wan.py +469 -0
- diffusers/models/unets/unet_1d.py +3 -1
- diffusers/models/unets/unet_2d.py +21 -20
- diffusers/models/unets/unet_2d_blocks.py +19 -243
- diffusers/models/unets/unet_2d_condition.py +4 -6
- diffusers/models/unets/unet_3d_blocks.py +14 -127
- diffusers/models/unets/unet_3d_condition.py +8 -12
- diffusers/models/unets/unet_i2vgen_xl.py +5 -13
- diffusers/models/unets/unet_kandinsky3.py +0 -4
- diffusers/models/unets/unet_motion_model.py +20 -114
- diffusers/models/unets/unet_spatio_temporal_condition.py +7 -8
- diffusers/models/unets/unet_stable_cascade.py +8 -35
- diffusers/models/unets/uvit_2d.py +1 -4
- diffusers/optimization.py +2 -2
- diffusers/pipelines/__init__.py +57 -8
- diffusers/pipelines/allegro/pipeline_allegro.py +22 -2
- diffusers/pipelines/amused/pipeline_amused.py +15 -2
- diffusers/pipelines/amused/pipeline_amused_img2img.py +15 -2
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +15 -2
- diffusers/pipelines/animatediff/pipeline_animatediff.py +15 -2
- diffusers/pipelines/animatediff/pipeline_animatediff_controlnet.py +15 -3
- diffusers/pipelines/animatediff/pipeline_animatediff_sdxl.py +24 -4
- diffusers/pipelines/animatediff/pipeline_animatediff_sparsectrl.py +15 -2
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +16 -4
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video_controlnet.py +16 -4
- diffusers/pipelines/audioldm/pipeline_audioldm.py +13 -2
- diffusers/pipelines/audioldm2/modeling_audioldm2.py +13 -68
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +39 -9
- diffusers/pipelines/aura_flow/pipeline_aura_flow.py +63 -7
- diffusers/pipelines/auto_pipeline.py +35 -14
- diffusers/pipelines/blip_diffusion/blip_image_processing.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_blip2.py +5 -8
- diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +12 -0
- diffusers/pipelines/cogvideo/pipeline_cogvideox.py +22 -6
- diffusers/pipelines/cogvideo/pipeline_cogvideox_fun_control.py +22 -6
- diffusers/pipelines/cogvideo/pipeline_cogvideox_image2video.py +22 -5
- diffusers/pipelines/cogvideo/pipeline_cogvideox_video2video.py +22 -6
- diffusers/pipelines/cogview3/pipeline_cogview3plus.py +12 -4
- diffusers/pipelines/cogview4/__init__.py +49 -0
- diffusers/pipelines/cogview4/pipeline_cogview4.py +684 -0
- diffusers/pipelines/cogview4/pipeline_cogview4_control.py +732 -0
- diffusers/pipelines/cogview4/pipeline_output.py +21 -0
- diffusers/pipelines/consisid/__init__.py +49 -0
- diffusers/pipelines/consisid/consisid_utils.py +357 -0
- diffusers/pipelines/consisid/pipeline_consisid.py +974 -0
- diffusers/pipelines/consisid/pipeline_output.py +20 -0
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +11 -0
- diffusers/pipelines/controlnet/pipeline_controlnet.py +6 -5
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +13 -0
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +17 -5
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +31 -12
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +26 -7
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +20 -3
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +22 -3
- diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py +26 -25
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py +224 -109
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl_img2img.py +25 -29
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +7 -4
- diffusers/pipelines/controlnet_hunyuandit/pipeline_hunyuandit_controlnet.py +3 -5
- diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet.py +121 -10
- diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet_inpainting.py +122 -11
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs.py +12 -1
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs_sd_xl.py +20 -3
- diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +14 -2
- diffusers/pipelines/ddim/pipeline_ddim.py +14 -1
- diffusers/pipelines/ddpm/pipeline_ddpm.py +15 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +12 -0
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +12 -0
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +14 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +12 -0
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +14 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +14 -1
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +11 -7
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +11 -7
- diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +1 -1
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +10 -6
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_onnx_stable_diffusion_inpaint_legacy.py +2 -2
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +11 -7
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +1 -1
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +1 -1
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +10 -105
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +1 -1
- diffusers/pipelines/dit/pipeline_dit.py +15 -2
- diffusers/pipelines/easyanimate/__init__.py +52 -0
- diffusers/pipelines/easyanimate/pipeline_easyanimate.py +770 -0
- diffusers/pipelines/easyanimate/pipeline_easyanimate_control.py +994 -0
- diffusers/pipelines/easyanimate/pipeline_easyanimate_inpaint.py +1234 -0
- diffusers/pipelines/easyanimate/pipeline_output.py +20 -0
- diffusers/pipelines/flux/pipeline_flux.py +53 -21
- diffusers/pipelines/flux/pipeline_flux_control.py +9 -12
- diffusers/pipelines/flux/pipeline_flux_control_img2img.py +6 -10
- diffusers/pipelines/flux/pipeline_flux_control_inpaint.py +8 -10
- diffusers/pipelines/flux/pipeline_flux_controlnet.py +185 -13
- diffusers/pipelines/flux/pipeline_flux_controlnet_image_to_image.py +8 -10
- diffusers/pipelines/flux/pipeline_flux_controlnet_inpainting.py +16 -16
- diffusers/pipelines/flux/pipeline_flux_fill.py +107 -39
- diffusers/pipelines/flux/pipeline_flux_img2img.py +193 -15
- diffusers/pipelines/flux/pipeline_flux_inpaint.py +199 -19
- diffusers/pipelines/free_noise_utils.py +3 -3
- diffusers/pipelines/hunyuan_video/__init__.py +4 -0
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_skyreels_image2video.py +804 -0
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video.py +90 -23
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video_image2video.py +924 -0
- diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py +3 -5
- diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +13 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +12 -0
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +12 -0
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +13 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +12 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +12 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +13 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +12 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +12 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +12 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +12 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py +12 -0
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +12 -0
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +12 -0
- diffusers/pipelines/kolors/pipeline_kolors.py +10 -8
- diffusers/pipelines/kolors/pipeline_kolors_img2img.py +6 -4
- diffusers/pipelines/kolors/text_encoder.py +7 -34
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +12 -1
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +13 -1
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +14 -13
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion_superresolution.py +12 -1
- diffusers/pipelines/latte/pipeline_latte.py +36 -7
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +67 -13
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +60 -15
- diffusers/pipelines/ltx/__init__.py +2 -0
- diffusers/pipelines/ltx/pipeline_ltx.py +25 -13
- diffusers/pipelines/ltx/pipeline_ltx_condition.py +1194 -0
- diffusers/pipelines/ltx/pipeline_ltx_image2video.py +31 -17
- diffusers/pipelines/lumina/__init__.py +2 -2
- diffusers/pipelines/lumina/pipeline_lumina.py +83 -20
- diffusers/pipelines/lumina2/__init__.py +48 -0
- diffusers/pipelines/lumina2/pipeline_lumina2.py +790 -0
- diffusers/pipelines/marigold/__init__.py +2 -0
- diffusers/pipelines/marigold/marigold_image_processing.py +127 -14
- diffusers/pipelines/marigold/pipeline_marigold_depth.py +31 -16
- diffusers/pipelines/marigold/pipeline_marigold_intrinsics.py +721 -0
- diffusers/pipelines/marigold/pipeline_marigold_normals.py +31 -16
- diffusers/pipelines/mochi/pipeline_mochi.py +14 -18
- diffusers/pipelines/musicldm/pipeline_musicldm.py +16 -1
- diffusers/pipelines/omnigen/__init__.py +50 -0
- diffusers/pipelines/omnigen/pipeline_omnigen.py +512 -0
- diffusers/pipelines/omnigen/processor_omnigen.py +327 -0
- diffusers/pipelines/onnx_utils.py +5 -3
- diffusers/pipelines/pag/pag_utils.py +1 -1
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py +12 -1
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_inpaint.py +15 -4
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py +20 -3
- diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl_img2img.py +20 -3
- diffusers/pipelines/pag/pipeline_pag_hunyuandit.py +1 -3
- diffusers/pipelines/pag/pipeline_pag_kolors.py +6 -4
- diffusers/pipelines/pag/pipeline_pag_pixart_sigma.py +16 -3
- diffusers/pipelines/pag/pipeline_pag_sana.py +65 -8
- diffusers/pipelines/pag/pipeline_pag_sd.py +23 -7
- diffusers/pipelines/pag/pipeline_pag_sd_3.py +3 -5
- diffusers/pipelines/pag/pipeline_pag_sd_3_img2img.py +3 -5
- diffusers/pipelines/pag/pipeline_pag_sd_animatediff.py +13 -1
- diffusers/pipelines/pag/pipeline_pag_sd_img2img.py +23 -7
- diffusers/pipelines/pag/pipeline_pag_sd_inpaint.py +26 -10
- diffusers/pipelines/pag/pipeline_pag_sd_xl.py +12 -4
- diffusers/pipelines/pag/pipeline_pag_sd_xl_img2img.py +7 -3
- diffusers/pipelines/pag/pipeline_pag_sd_xl_inpaint.py +10 -6
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +13 -3
- diffusers/pipelines/pia/pipeline_pia.py +13 -1
- diffusers/pipelines/pipeline_flax_utils.py +7 -7
- diffusers/pipelines/pipeline_loading_utils.py +193 -83
- diffusers/pipelines/pipeline_utils.py +221 -106
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +17 -5
- diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py +17 -4
- diffusers/pipelines/sana/__init__.py +2 -0
- diffusers/pipelines/sana/pipeline_sana.py +183 -58
- diffusers/pipelines/sana/pipeline_sana_sprint.py +889 -0
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +12 -2
- diffusers/pipelines/shap_e/pipeline_shap_e.py +12 -0
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +12 -0
- diffusers/pipelines/shap_e/renderer.py +6 -6
- diffusers/pipelines/stable_audio/pipeline_stable_audio.py +1 -1
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +15 -4
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +12 -8
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +12 -1
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +3 -2
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +14 -10
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_img2img.py +3 -3
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_inpaint.py +14 -10
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +4 -3
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +5 -4
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +18 -13
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +30 -8
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +24 -10
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +28 -12
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +39 -18
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +17 -6
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +13 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +20 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +14 -2
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +13 -1
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +16 -17
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +136 -18
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +150 -21
- diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +15 -3
- diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +26 -11
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +15 -3
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +22 -4
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +30 -13
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +12 -4
- diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +15 -3
- diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +15 -3
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +26 -12
- diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +16 -4
- diffusers/pipelines/stable_diffusion_xl/pipeline_flax_stable_diffusion_xl.py +1 -1
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +12 -4
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +7 -3
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +10 -6
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +11 -4
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +13 -2
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +18 -4
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +26 -5
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +13 -1
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +13 -1
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +28 -6
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +26 -4
- diffusers/pipelines/transformers_loading_utils.py +121 -0
- diffusers/pipelines/unclip/pipeline_unclip.py +11 -1
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +11 -1
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +19 -2
- diffusers/pipelines/wan/__init__.py +51 -0
- diffusers/pipelines/wan/pipeline_output.py +20 -0
- diffusers/pipelines/wan/pipeline_wan.py +595 -0
- diffusers/pipelines/wan/pipeline_wan_i2v.py +724 -0
- diffusers/pipelines/wan/pipeline_wan_video2video.py +727 -0
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +7 -31
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +12 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +12 -1
- diffusers/quantizers/auto.py +5 -1
- diffusers/quantizers/base.py +5 -9
- diffusers/quantizers/bitsandbytes/bnb_quantizer.py +41 -29
- diffusers/quantizers/bitsandbytes/utils.py +30 -20
- diffusers/quantizers/gguf/gguf_quantizer.py +1 -0
- diffusers/quantizers/gguf/utils.py +4 -2
- diffusers/quantizers/quantization_config.py +59 -4
- diffusers/quantizers/quanto/__init__.py +1 -0
- diffusers/quantizers/quanto/quanto_quantizer.py +177 -0
- diffusers/quantizers/quanto/utils.py +60 -0
- diffusers/quantizers/torchao/__init__.py +1 -1
- diffusers/quantizers/torchao/torchao_quantizer.py +47 -2
- diffusers/schedulers/__init__.py +2 -1
- diffusers/schedulers/scheduling_consistency_models.py +1 -2
- diffusers/schedulers/scheduling_ddim_inverse.py +1 -1
- diffusers/schedulers/scheduling_ddpm.py +2 -3
- diffusers/schedulers/scheduling_ddpm_parallel.py +1 -2
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +12 -4
- diffusers/schedulers/scheduling_edm_euler.py +45 -10
- diffusers/schedulers/scheduling_flow_match_euler_discrete.py +116 -28
- diffusers/schedulers/scheduling_flow_match_heun_discrete.py +7 -6
- diffusers/schedulers/scheduling_heun_discrete.py +1 -1
- diffusers/schedulers/scheduling_lcm.py +1 -2
- diffusers/schedulers/scheduling_lms_discrete.py +1 -1
- diffusers/schedulers/scheduling_repaint.py +5 -1
- diffusers/schedulers/scheduling_scm.py +265 -0
- diffusers/schedulers/scheduling_tcd.py +1 -2
- diffusers/schedulers/scheduling_utils.py +2 -1
- diffusers/training_utils.py +14 -7
- diffusers/utils/__init__.py +9 -1
- diffusers/utils/constants.py +13 -1
- diffusers/utils/deprecation_utils.py +1 -1
- diffusers/utils/dummy_bitsandbytes_objects.py +17 -0
- diffusers/utils/dummy_gguf_objects.py +17 -0
- diffusers/utils/dummy_optimum_quanto_objects.py +17 -0
- diffusers/utils/dummy_pt_objects.py +233 -0
- diffusers/utils/dummy_torch_and_transformers_and_opencv_objects.py +17 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +270 -0
- diffusers/utils/dummy_torchao_objects.py +17 -0
- diffusers/utils/dynamic_modules_utils.py +1 -1
- diffusers/utils/export_utils.py +28 -3
- diffusers/utils/hub_utils.py +52 -102
- diffusers/utils/import_utils.py +121 -221
- diffusers/utils/loading_utils.py +2 -1
- diffusers/utils/logging.py +1 -2
- diffusers/utils/peft_utils.py +6 -14
- diffusers/utils/remote_utils.py +425 -0
- diffusers/utils/source_code_parsing_utils.py +52 -0
- diffusers/utils/state_dict_utils.py +15 -1
- diffusers/utils/testing_utils.py +243 -13
- diffusers/utils/torch_utils.py +10 -0
- diffusers/utils/typing_utils.py +91 -0
- diffusers/video_processor.py +1 -1
- {diffusers-0.32.2.dist-info → diffusers-0.33.1.dist-info}/METADATA +21 -4
- diffusers-0.33.1.dist-info/RECORD +608 -0
- {diffusers-0.32.2.dist-info → diffusers-0.33.1.dist-info}/WHEEL +1 -1
- diffusers-0.32.2.dist-info/RECORD +0 -550
- {diffusers-0.32.2.dist-info → diffusers-0.33.1.dist-info}/LICENSE +0 -0
- {diffusers-0.32.2.dist-info → diffusers-0.33.1.dist-info}/entry_points.txt +0 -0
- {diffusers-0.32.2.dist-info → diffusers-0.33.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,732 @@
|
|
1
|
+
# Copyright 2024 The CogVideoX team, Tsinghua University & ZhipuAI and The HuggingFace Team.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
import inspect
|
17
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
18
|
+
|
19
|
+
import numpy as np
|
20
|
+
import torch
|
21
|
+
from transformers import AutoTokenizer, GlmModel
|
22
|
+
|
23
|
+
from ...callbacks import MultiPipelineCallbacks, PipelineCallback
|
24
|
+
from ...image_processor import PipelineImageInput, VaeImageProcessor
|
25
|
+
from ...models import AutoencoderKL, CogView4Transformer2DModel
|
26
|
+
from ...pipelines.pipeline_utils import DiffusionPipeline
|
27
|
+
from ...schedulers import FlowMatchEulerDiscreteScheduler
|
28
|
+
from ...utils import is_torch_xla_available, logging, replace_example_docstring
|
29
|
+
from ...utils.torch_utils import randn_tensor
|
30
|
+
from .pipeline_output import CogView4PipelineOutput
|
31
|
+
|
32
|
+
|
33
|
+
if is_torch_xla_available():
|
34
|
+
import torch_xla.core.xla_model as xm
|
35
|
+
|
36
|
+
XLA_AVAILABLE = True
|
37
|
+
else:
|
38
|
+
XLA_AVAILABLE = False
|
39
|
+
|
40
|
+
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
41
|
+
|
42
|
+
EXAMPLE_DOC_STRING = """
|
43
|
+
Examples:
|
44
|
+
```python
|
45
|
+
>>> import torch
|
46
|
+
>>> from diffusers import CogView4ControlPipeline
|
47
|
+
|
48
|
+
>>> pipe = CogView4ControlPipeline.from_pretrained("THUDM/CogView4-6B-Control", torch_dtype=torch.bfloat16)
|
49
|
+
>>> control_image = load_image(
|
50
|
+
... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png"
|
51
|
+
... )
|
52
|
+
>>> prompt = "A bird in space"
|
53
|
+
>>> image = pipe(prompt, control_image=control_image, height=1024, width=1024, guidance_scale=3.5).images[0]
|
54
|
+
>>> image.save("cogview4-control.png")
|
55
|
+
```
|
56
|
+
"""
|
57
|
+
|
58
|
+
|
59
|
+
# Copied from diffusers.pipelines.cogview4.pipeline_cogview4.calculate_shift
|
60
|
+
def calculate_shift(
|
61
|
+
image_seq_len,
|
62
|
+
base_seq_len: int = 256,
|
63
|
+
base_shift: float = 0.25,
|
64
|
+
max_shift: float = 0.75,
|
65
|
+
) -> float:
|
66
|
+
m = (image_seq_len / base_seq_len) ** 0.5
|
67
|
+
mu = m * max_shift + base_shift
|
68
|
+
return mu
|
69
|
+
|
70
|
+
|
71
|
+
# Copied from diffusers.pipelines.cogview4.pipeline_cogview4.retrieve_timesteps
|
72
|
+
def retrieve_timesteps(
|
73
|
+
scheduler,
|
74
|
+
num_inference_steps: Optional[int] = None,
|
75
|
+
device: Optional[Union[str, torch.device]] = None,
|
76
|
+
timesteps: Optional[List[int]] = None,
|
77
|
+
sigmas: Optional[List[float]] = None,
|
78
|
+
**kwargs,
|
79
|
+
):
|
80
|
+
r"""
|
81
|
+
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
|
82
|
+
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
|
83
|
+
|
84
|
+
Args:
|
85
|
+
scheduler (`SchedulerMixin`):
|
86
|
+
The scheduler to get timesteps from.
|
87
|
+
num_inference_steps (`int`):
|
88
|
+
The number of diffusion steps used when generating samples with a pre-trained model. If used, `timesteps`
|
89
|
+
must be `None`.
|
90
|
+
device (`str` or `torch.device`, *optional*):
|
91
|
+
The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
|
92
|
+
timesteps (`List[int]`, *optional*):
|
93
|
+
Custom timesteps used to override the timestep spacing strategy of the scheduler. If `timesteps` is passed,
|
94
|
+
`num_inference_steps` and `sigmas` must be `None`.
|
95
|
+
sigmas (`List[float]`, *optional*):
|
96
|
+
Custom sigmas used to override the timestep spacing strategy of the scheduler. If `sigmas` is passed,
|
97
|
+
`num_inference_steps` and `timesteps` must be `None`.
|
98
|
+
|
99
|
+
Returns:
|
100
|
+
`Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the
|
101
|
+
second element is the number of inference steps.
|
102
|
+
"""
|
103
|
+
accepts_timesteps = "timesteps" in set(inspect.signature(scheduler.set_timesteps).parameters.keys())
|
104
|
+
accepts_sigmas = "sigmas" in set(inspect.signature(scheduler.set_timesteps).parameters.keys())
|
105
|
+
|
106
|
+
if timesteps is not None and sigmas is not None:
|
107
|
+
if not accepts_timesteps and not accepts_sigmas:
|
108
|
+
raise ValueError(
|
109
|
+
f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom"
|
110
|
+
f" timestep or sigma schedules. Please check whether you are using the correct scheduler."
|
111
|
+
)
|
112
|
+
scheduler.set_timesteps(timesteps=timesteps, sigmas=sigmas, device=device, **kwargs)
|
113
|
+
timesteps = scheduler.timesteps
|
114
|
+
num_inference_steps = len(timesteps)
|
115
|
+
elif timesteps is not None and sigmas is None:
|
116
|
+
if not accepts_timesteps:
|
117
|
+
raise ValueError(
|
118
|
+
f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom"
|
119
|
+
f" timestep schedules. Please check whether you are using the correct scheduler."
|
120
|
+
)
|
121
|
+
scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs)
|
122
|
+
timesteps = scheduler.timesteps
|
123
|
+
num_inference_steps = len(timesteps)
|
124
|
+
elif timesteps is None and sigmas is not None:
|
125
|
+
if not accepts_sigmas:
|
126
|
+
raise ValueError(
|
127
|
+
f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom"
|
128
|
+
f" sigmas schedules. Please check whether you are using the correct scheduler."
|
129
|
+
)
|
130
|
+
scheduler.set_timesteps(sigmas=sigmas, device=device, **kwargs)
|
131
|
+
timesteps = scheduler.timesteps
|
132
|
+
num_inference_steps = len(timesteps)
|
133
|
+
else:
|
134
|
+
scheduler.set_timesteps(num_inference_steps, device=device, **kwargs)
|
135
|
+
timesteps = scheduler.timesteps
|
136
|
+
return timesteps, num_inference_steps
|
137
|
+
|
138
|
+
|
139
|
+
class CogView4ControlPipeline(DiffusionPipeline):
|
140
|
+
r"""
|
141
|
+
Pipeline for text-to-image generation using CogView4.
|
142
|
+
|
143
|
+
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
|
144
|
+
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
|
145
|
+
|
146
|
+
Args:
|
147
|
+
vae ([`AutoencoderKL`]):
|
148
|
+
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
|
149
|
+
text_encoder ([`GLMModel`]):
|
150
|
+
Frozen text-encoder. CogView4 uses [glm-4-9b-hf](https://huggingface.co/THUDM/glm-4-9b-hf).
|
151
|
+
tokenizer (`PreTrainedTokenizer`):
|
152
|
+
Tokenizer of class
|
153
|
+
[PreTrainedTokenizer](https://huggingface.co/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizer).
|
154
|
+
transformer ([`CogView4Transformer2DModel`]):
|
155
|
+
A text conditioned `CogView4Transformer2DModel` to denoise the encoded image latents.
|
156
|
+
scheduler ([`SchedulerMixin`]):
|
157
|
+
A scheduler to be used in combination with `transformer` to denoise the encoded image latents.
|
158
|
+
"""
|
159
|
+
|
160
|
+
_optional_components = []
|
161
|
+
model_cpu_offload_seq = "text_encoder->transformer->vae"
|
162
|
+
_callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
|
163
|
+
|
164
|
+
def __init__(
|
165
|
+
self,
|
166
|
+
tokenizer: AutoTokenizer,
|
167
|
+
text_encoder: GlmModel,
|
168
|
+
vae: AutoencoderKL,
|
169
|
+
transformer: CogView4Transformer2DModel,
|
170
|
+
scheduler: FlowMatchEulerDiscreteScheduler,
|
171
|
+
):
|
172
|
+
super().__init__()
|
173
|
+
|
174
|
+
self.register_modules(
|
175
|
+
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
|
176
|
+
)
|
177
|
+
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) if getattr(self, "vae", None) else 8
|
178
|
+
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
|
179
|
+
|
180
|
+
# Copied from diffusers.pipelines.cogview4.pipeline_cogview4.CogView4Pipeline._get_glm_embeds
|
181
|
+
def _get_glm_embeds(
|
182
|
+
self,
|
183
|
+
prompt: Union[str, List[str]] = None,
|
184
|
+
max_sequence_length: int = 1024,
|
185
|
+
device: Optional[torch.device] = None,
|
186
|
+
dtype: Optional[torch.dtype] = None,
|
187
|
+
):
|
188
|
+
device = device or self._execution_device
|
189
|
+
dtype = dtype or self.text_encoder.dtype
|
190
|
+
|
191
|
+
prompt = [prompt] if isinstance(prompt, str) else prompt
|
192
|
+
|
193
|
+
text_inputs = self.tokenizer(
|
194
|
+
prompt,
|
195
|
+
padding="longest", # not use max length
|
196
|
+
max_length=max_sequence_length,
|
197
|
+
truncation=True,
|
198
|
+
add_special_tokens=True,
|
199
|
+
return_tensors="pt",
|
200
|
+
)
|
201
|
+
text_input_ids = text_inputs.input_ids
|
202
|
+
untruncated_ids = self.tokenizer(prompt, padding="longest", return_tensors="pt").input_ids
|
203
|
+
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(text_input_ids, untruncated_ids):
|
204
|
+
removed_text = self.tokenizer.batch_decode(untruncated_ids[:, max_sequence_length - 1 : -1])
|
205
|
+
logger.warning(
|
206
|
+
"The following part of your input was truncated because `max_sequence_length` is set to "
|
207
|
+
f" {max_sequence_length} tokens: {removed_text}"
|
208
|
+
)
|
209
|
+
current_length = text_input_ids.shape[1]
|
210
|
+
pad_length = (16 - (current_length % 16)) % 16
|
211
|
+
if pad_length > 0:
|
212
|
+
pad_ids = torch.full(
|
213
|
+
(text_input_ids.shape[0], pad_length),
|
214
|
+
fill_value=self.tokenizer.pad_token_id,
|
215
|
+
dtype=text_input_ids.dtype,
|
216
|
+
device=text_input_ids.device,
|
217
|
+
)
|
218
|
+
text_input_ids = torch.cat([pad_ids, text_input_ids], dim=1)
|
219
|
+
prompt_embeds = self.text_encoder(text_input_ids.to(device), output_hidden_states=True).hidden_states[-2]
|
220
|
+
|
221
|
+
prompt_embeds = prompt_embeds.to(dtype=dtype, device=device)
|
222
|
+
return prompt_embeds
|
223
|
+
|
224
|
+
# Copied from diffusers.pipelines.cogview4.pipeline_cogview4.CogView4Pipeline.encode_prompt
|
225
|
+
def encode_prompt(
|
226
|
+
self,
|
227
|
+
prompt: Union[str, List[str]],
|
228
|
+
negative_prompt: Optional[Union[str, List[str]]] = None,
|
229
|
+
do_classifier_free_guidance: bool = True,
|
230
|
+
num_images_per_prompt: int = 1,
|
231
|
+
prompt_embeds: Optional[torch.Tensor] = None,
|
232
|
+
negative_prompt_embeds: Optional[torch.Tensor] = None,
|
233
|
+
device: Optional[torch.device] = None,
|
234
|
+
dtype: Optional[torch.dtype] = None,
|
235
|
+
max_sequence_length: int = 1024,
|
236
|
+
):
|
237
|
+
r"""
|
238
|
+
Encodes the prompt into text encoder hidden states.
|
239
|
+
|
240
|
+
Args:
|
241
|
+
prompt (`str` or `List[str]`, *optional*):
|
242
|
+
prompt to be encoded
|
243
|
+
negative_prompt (`str` or `List[str]`, *optional*):
|
244
|
+
The prompt or prompts not to guide the image generation. If not defined, one has to pass
|
245
|
+
`negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `guidance_scale` is
|
246
|
+
less than `1`).
|
247
|
+
do_classifier_free_guidance (`bool`, *optional*, defaults to `True`):
|
248
|
+
Whether to use classifier free guidance or not.
|
249
|
+
num_images_per_prompt (`int`, *optional*, defaults to 1):
|
250
|
+
Number of images that should be generated per prompt. torch device to place the resulting embeddings on
|
251
|
+
prompt_embeds (`torch.Tensor`, *optional*):
|
252
|
+
Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
|
253
|
+
provided, text embeddings will be generated from `prompt` input argument.
|
254
|
+
negative_prompt_embeds (`torch.Tensor`, *optional*):
|
255
|
+
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
|
256
|
+
weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
|
257
|
+
argument.
|
258
|
+
device: (`torch.device`, *optional*):
|
259
|
+
torch device
|
260
|
+
dtype: (`torch.dtype`, *optional*):
|
261
|
+
torch dtype
|
262
|
+
max_sequence_length (`int`, defaults to `1024`):
|
263
|
+
Maximum sequence length in encoded prompt. Can be set to other values but may lead to poorer results.
|
264
|
+
"""
|
265
|
+
device = device or self._execution_device
|
266
|
+
|
267
|
+
prompt = [prompt] if isinstance(prompt, str) else prompt
|
268
|
+
if prompt is not None:
|
269
|
+
batch_size = len(prompt)
|
270
|
+
else:
|
271
|
+
batch_size = prompt_embeds.shape[0]
|
272
|
+
|
273
|
+
if prompt_embeds is None:
|
274
|
+
prompt_embeds = self._get_glm_embeds(prompt, max_sequence_length, device, dtype)
|
275
|
+
|
276
|
+
seq_len = prompt_embeds.size(1)
|
277
|
+
prompt_embeds = prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
278
|
+
prompt_embeds = prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
279
|
+
|
280
|
+
if do_classifier_free_guidance and negative_prompt_embeds is None:
|
281
|
+
negative_prompt = negative_prompt or ""
|
282
|
+
negative_prompt = batch_size * [negative_prompt] if isinstance(negative_prompt, str) else negative_prompt
|
283
|
+
|
284
|
+
if prompt is not None and type(prompt) is not type(negative_prompt):
|
285
|
+
raise TypeError(
|
286
|
+
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
|
287
|
+
f" {type(prompt)}."
|
288
|
+
)
|
289
|
+
elif batch_size != len(negative_prompt):
|
290
|
+
raise ValueError(
|
291
|
+
f"`negative_prompt`: {negative_prompt} has batch size {len(negative_prompt)}, but `prompt`:"
|
292
|
+
f" {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches"
|
293
|
+
" the batch size of `prompt`."
|
294
|
+
)
|
295
|
+
|
296
|
+
negative_prompt_embeds = self._get_glm_embeds(negative_prompt, max_sequence_length, device, dtype)
|
297
|
+
|
298
|
+
seq_len = negative_prompt_embeds.size(1)
|
299
|
+
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
300
|
+
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
301
|
+
|
302
|
+
return prompt_embeds, negative_prompt_embeds
|
303
|
+
|
304
|
+
def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype, device, generator, latents=None):
|
305
|
+
if latents is not None:
|
306
|
+
return latents.to(device)
|
307
|
+
|
308
|
+
shape = (
|
309
|
+
batch_size,
|
310
|
+
num_channels_latents,
|
311
|
+
int(height) // self.vae_scale_factor,
|
312
|
+
int(width) // self.vae_scale_factor,
|
313
|
+
)
|
314
|
+
if isinstance(generator, list) and len(generator) != batch_size:
|
315
|
+
raise ValueError(
|
316
|
+
f"You have passed a list of generators of length {len(generator)}, but requested an effective batch"
|
317
|
+
f" size of {batch_size}. Make sure the batch size matches the length of the generators."
|
318
|
+
)
|
319
|
+
latents = randn_tensor(shape, generator=generator, device=device, dtype=dtype)
|
320
|
+
return latents
|
321
|
+
|
322
|
+
def prepare_image(
|
323
|
+
self,
|
324
|
+
image,
|
325
|
+
width,
|
326
|
+
height,
|
327
|
+
batch_size,
|
328
|
+
num_images_per_prompt,
|
329
|
+
device,
|
330
|
+
dtype,
|
331
|
+
do_classifier_free_guidance=False,
|
332
|
+
guess_mode=False,
|
333
|
+
):
|
334
|
+
if isinstance(image, torch.Tensor):
|
335
|
+
pass
|
336
|
+
else:
|
337
|
+
image = self.image_processor.preprocess(image, height=height, width=width)
|
338
|
+
|
339
|
+
image_batch_size = image.shape[0]
|
340
|
+
|
341
|
+
if image_batch_size == 1:
|
342
|
+
repeat_by = batch_size
|
343
|
+
else:
|
344
|
+
# image batch size is the same as prompt batch size
|
345
|
+
repeat_by = num_images_per_prompt
|
346
|
+
|
347
|
+
image = image.repeat_interleave(repeat_by, dim=0, output_size=image.shape[0] * repeat_by)
|
348
|
+
|
349
|
+
image = image.to(device=device, dtype=dtype)
|
350
|
+
|
351
|
+
if do_classifier_free_guidance and not guess_mode:
|
352
|
+
image = torch.cat([image] * 2)
|
353
|
+
|
354
|
+
return image
|
355
|
+
|
356
|
+
def check_inputs(
|
357
|
+
self,
|
358
|
+
prompt,
|
359
|
+
height,
|
360
|
+
width,
|
361
|
+
negative_prompt,
|
362
|
+
callback_on_step_end_tensor_inputs,
|
363
|
+
prompt_embeds=None,
|
364
|
+
negative_prompt_embeds=None,
|
365
|
+
):
|
366
|
+
if height % 16 != 0 or width % 16 != 0:
|
367
|
+
raise ValueError(f"`height` and `width` have to be divisible by 16 but are {height} and {width}.")
|
368
|
+
|
369
|
+
if callback_on_step_end_tensor_inputs is not None and not all(
|
370
|
+
k in self._callback_tensor_inputs for k in callback_on_step_end_tensor_inputs
|
371
|
+
):
|
372
|
+
raise ValueError(
|
373
|
+
f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found {[k for k in callback_on_step_end_tensor_inputs if k not in self._callback_tensor_inputs]}"
|
374
|
+
)
|
375
|
+
if prompt is not None and prompt_embeds is not None:
|
376
|
+
raise ValueError(
|
377
|
+
f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to"
|
378
|
+
" only forward one of the two."
|
379
|
+
)
|
380
|
+
elif prompt is None and prompt_embeds is None:
|
381
|
+
raise ValueError(
|
382
|
+
"Provide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined."
|
383
|
+
)
|
384
|
+
elif prompt is not None and (not isinstance(prompt, str) and not isinstance(prompt, list)):
|
385
|
+
raise ValueError(f"`prompt` has to be of type `str` or `list` but is {type(prompt)}")
|
386
|
+
|
387
|
+
if prompt is not None and negative_prompt_embeds is not None:
|
388
|
+
raise ValueError(
|
389
|
+
f"Cannot forward both `prompt`: {prompt} and `negative_prompt_embeds`:"
|
390
|
+
f" {negative_prompt_embeds}. Please make sure to only forward one of the two."
|
391
|
+
)
|
392
|
+
|
393
|
+
if negative_prompt is not None and negative_prompt_embeds is not None:
|
394
|
+
raise ValueError(
|
395
|
+
f"Cannot forward both `negative_prompt`: {negative_prompt} and `negative_prompt_embeds`:"
|
396
|
+
f" {negative_prompt_embeds}. Please make sure to only forward one of the two."
|
397
|
+
)
|
398
|
+
|
399
|
+
if prompt_embeds is not None and negative_prompt_embeds is not None:
|
400
|
+
if prompt_embeds.shape != negative_prompt_embeds.shape:
|
401
|
+
raise ValueError(
|
402
|
+
"`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but"
|
403
|
+
f" got: `prompt_embeds` {prompt_embeds.shape} != `negative_prompt_embeds`"
|
404
|
+
f" {negative_prompt_embeds.shape}."
|
405
|
+
)
|
406
|
+
|
407
|
+
@property
|
408
|
+
def guidance_scale(self):
|
409
|
+
return self._guidance_scale
|
410
|
+
|
411
|
+
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
|
412
|
+
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
|
413
|
+
# corresponds to doing no classifier free guidance.
|
414
|
+
@property
|
415
|
+
def do_classifier_free_guidance(self):
|
416
|
+
return self._guidance_scale > 1
|
417
|
+
|
418
|
+
@property
|
419
|
+
def num_timesteps(self):
|
420
|
+
return self._num_timesteps
|
421
|
+
|
422
|
+
@property
|
423
|
+
def attention_kwargs(self):
|
424
|
+
return self._attention_kwargs
|
425
|
+
|
426
|
+
@property
|
427
|
+
def current_timestep(self):
|
428
|
+
return self._current_timestep
|
429
|
+
|
430
|
+
@property
|
431
|
+
def interrupt(self):
|
432
|
+
return self._interrupt
|
433
|
+
|
434
|
+
@torch.no_grad()
|
435
|
+
@replace_example_docstring(EXAMPLE_DOC_STRING)
|
436
|
+
def __call__(
|
437
|
+
self,
|
438
|
+
prompt: Optional[Union[str, List[str]]] = None,
|
439
|
+
negative_prompt: Optional[Union[str, List[str]]] = None,
|
440
|
+
control_image: PipelineImageInput = None,
|
441
|
+
height: Optional[int] = None,
|
442
|
+
width: Optional[int] = None,
|
443
|
+
num_inference_steps: int = 50,
|
444
|
+
timesteps: Optional[List[int]] = None,
|
445
|
+
sigmas: Optional[List[float]] = None,
|
446
|
+
guidance_scale: float = 5.0,
|
447
|
+
num_images_per_prompt: int = 1,
|
448
|
+
generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
|
449
|
+
latents: Optional[torch.FloatTensor] = None,
|
450
|
+
prompt_embeds: Optional[torch.FloatTensor] = None,
|
451
|
+
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
452
|
+
original_size: Optional[Tuple[int, int]] = None,
|
453
|
+
crops_coords_top_left: Tuple[int, int] = (0, 0),
|
454
|
+
output_type: str = "pil",
|
455
|
+
return_dict: bool = True,
|
456
|
+
attention_kwargs: Optional[Dict[str, Any]] = None,
|
457
|
+
callback_on_step_end: Optional[
|
458
|
+
Union[Callable[[int, int, Dict], None], PipelineCallback, MultiPipelineCallbacks]
|
459
|
+
] = None,
|
460
|
+
callback_on_step_end_tensor_inputs: List[str] = ["latents"],
|
461
|
+
max_sequence_length: int = 1024,
|
462
|
+
) -> Union[CogView4PipelineOutput, Tuple]:
|
463
|
+
"""
|
464
|
+
Function invoked when calling the pipeline for generation.
|
465
|
+
|
466
|
+
Args:
|
467
|
+
prompt (`str` or `List[str]`, *optional*):
|
468
|
+
The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
|
469
|
+
negative_prompt (`str` or `List[str]`, *optional*):
|
470
|
+
The prompt or prompts not to guide the image generation. If not defined, one has to pass
|
471
|
+
`negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `guidance_scale` is
|
472
|
+
less than `1`).
|
473
|
+
height (`int`, *optional*, defaults to self.transformer.config.sample_size * self.vae_scale_factor):
|
474
|
+
The height in pixels of the generated image. If not provided, it is set to 1024.
|
475
|
+
width (`int`, *optional*, defaults to self.transformer.config.sample_size * self.vae_scale_factor):
|
476
|
+
The width in pixels of the generated image. If not provided it is set to 1024.
|
477
|
+
num_inference_steps (`int`, *optional*, defaults to `50`):
|
478
|
+
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
479
|
+
expense of slower inference.
|
480
|
+
timesteps (`List[int]`, *optional*):
|
481
|
+
Custom timesteps to use for the denoising process with schedulers which support a `timesteps` argument
|
482
|
+
in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is
|
483
|
+
passed will be used. Must be in descending order.
|
484
|
+
sigmas (`List[float]`, *optional*):
|
485
|
+
Custom sigmas to use for the denoising process with schedulers which support a `sigmas` argument in
|
486
|
+
their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed
|
487
|
+
will be used.
|
488
|
+
guidance_scale (`float`, *optional*, defaults to `5.0`):
|
489
|
+
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
|
490
|
+
`guidance_scale` is defined as `w` of equation 2. of [Imagen
|
491
|
+
Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
|
492
|
+
1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`,
|
493
|
+
usually at the expense of lower image quality.
|
494
|
+
num_images_per_prompt (`int`, *optional*, defaults to `1`):
|
495
|
+
The number of images to generate per prompt.
|
496
|
+
generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
|
497
|
+
One or a list of [torch generator(s)](https://pytorch.org/docs/stable/generated/torch.Generator.html)
|
498
|
+
to make generation deterministic.
|
499
|
+
latents (`torch.FloatTensor`, *optional*):
|
500
|
+
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
|
501
|
+
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
|
502
|
+
tensor will ge generated by sampling using the supplied random `generator`.
|
503
|
+
prompt_embeds (`torch.FloatTensor`, *optional*):
|
504
|
+
Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
|
505
|
+
provided, text embeddings will be generated from `prompt` input argument.
|
506
|
+
negative_prompt_embeds (`torch.FloatTensor`, *optional*):
|
507
|
+
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
|
508
|
+
weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
|
509
|
+
argument.
|
510
|
+
original_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
|
511
|
+
If `original_size` is not the same as `target_size` the image will appear to be down- or upsampled.
|
512
|
+
`original_size` defaults to `(height, width)` if not specified. Part of SDXL's micro-conditioning as
|
513
|
+
explained in section 2.2 of
|
514
|
+
[https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952).
|
515
|
+
crops_coords_top_left (`Tuple[int]`, *optional*, defaults to (0, 0)):
|
516
|
+
`crops_coords_top_left` can be used to generate an image that appears to be "cropped" from the position
|
517
|
+
`crops_coords_top_left` downwards. Favorable, well-centered images are usually achieved by setting
|
518
|
+
`crops_coords_top_left` to (0, 0). Part of SDXL's micro-conditioning as explained in section 2.2 of
|
519
|
+
[https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952).
|
520
|
+
output_type (`str`, *optional*, defaults to `"pil"`):
|
521
|
+
The output format of the generate image. Choose between
|
522
|
+
[PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`.
|
523
|
+
return_dict (`bool`, *optional*, defaults to `True`):
|
524
|
+
Whether or not to return a [`~pipelines.pipeline_CogView4.CogView4PipelineOutput`] instead of a plain
|
525
|
+
tuple.
|
526
|
+
attention_kwargs (`dict`, *optional*):
|
527
|
+
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
528
|
+
`self.processor` in
|
529
|
+
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
530
|
+
callback_on_step_end (`Callable`, *optional*):
|
531
|
+
A function that calls at the end of each denoising steps during the inference. The function is called
|
532
|
+
with the following arguments: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int,
|
533
|
+
callback_kwargs: Dict)`. `callback_kwargs` will include a list of all tensors as specified by
|
534
|
+
`callback_on_step_end_tensor_inputs`.
|
535
|
+
callback_on_step_end_tensor_inputs (`List`, *optional*):
|
536
|
+
The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
|
537
|
+
will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
|
538
|
+
`._callback_tensor_inputs` attribute of your pipeline class.
|
539
|
+
max_sequence_length (`int`, defaults to `224`):
|
540
|
+
Maximum sequence length in encoded prompt. Can be set to other values but may lead to poorer results.
|
541
|
+
Examples:
|
542
|
+
|
543
|
+
Returns:
|
544
|
+
[`~pipelines.cogview4.pipeline_CogView4.CogView4PipelineOutput`] or `tuple`:
|
545
|
+
[`~pipelines.cogview4.pipeline_CogView4.CogView4PipelineOutput`] if `return_dict` is True, otherwise a
|
546
|
+
`tuple`. When returning a tuple, the first element is a list with the generated images.
|
547
|
+
"""
|
548
|
+
|
549
|
+
if isinstance(callback_on_step_end, (PipelineCallback, MultiPipelineCallbacks)):
|
550
|
+
callback_on_step_end_tensor_inputs = callback_on_step_end.tensor_inputs
|
551
|
+
|
552
|
+
height = height or self.transformer.config.sample_size * self.vae_scale_factor
|
553
|
+
width = width or self.transformer.config.sample_size * self.vae_scale_factor
|
554
|
+
|
555
|
+
original_size = original_size or (height, width)
|
556
|
+
target_size = (height, width)
|
557
|
+
|
558
|
+
# Check inputs. Raise error if not correct
|
559
|
+
self.check_inputs(
|
560
|
+
prompt,
|
561
|
+
height,
|
562
|
+
width,
|
563
|
+
negative_prompt,
|
564
|
+
callback_on_step_end_tensor_inputs,
|
565
|
+
prompt_embeds,
|
566
|
+
negative_prompt_embeds,
|
567
|
+
)
|
568
|
+
self._guidance_scale = guidance_scale
|
569
|
+
self._attention_kwargs = attention_kwargs
|
570
|
+
self._current_timestep = None
|
571
|
+
self._interrupt = False
|
572
|
+
|
573
|
+
# Default call parameters
|
574
|
+
if prompt is not None and isinstance(prompt, str):
|
575
|
+
batch_size = 1
|
576
|
+
elif prompt is not None and isinstance(prompt, list):
|
577
|
+
batch_size = len(prompt)
|
578
|
+
else:
|
579
|
+
batch_size = prompt_embeds.shape[0]
|
580
|
+
|
581
|
+
device = self._execution_device
|
582
|
+
|
583
|
+
# Encode input prompt
|
584
|
+
prompt_embeds, negative_prompt_embeds = self.encode_prompt(
|
585
|
+
prompt,
|
586
|
+
negative_prompt,
|
587
|
+
self.do_classifier_free_guidance,
|
588
|
+
num_images_per_prompt=num_images_per_prompt,
|
589
|
+
prompt_embeds=prompt_embeds,
|
590
|
+
negative_prompt_embeds=negative_prompt_embeds,
|
591
|
+
max_sequence_length=max_sequence_length,
|
592
|
+
device=device,
|
593
|
+
)
|
594
|
+
|
595
|
+
# Prepare latents
|
596
|
+
latent_channels = self.transformer.config.in_channels // 2
|
597
|
+
|
598
|
+
control_image = self.prepare_image(
|
599
|
+
image=control_image,
|
600
|
+
width=width,
|
601
|
+
height=height,
|
602
|
+
batch_size=batch_size * num_images_per_prompt,
|
603
|
+
num_images_per_prompt=num_images_per_prompt,
|
604
|
+
device=device,
|
605
|
+
dtype=self.vae.dtype,
|
606
|
+
)
|
607
|
+
height, width = control_image.shape[-2:]
|
608
|
+
|
609
|
+
vae_shift_factor = 0
|
610
|
+
|
611
|
+
control_image = self.vae.encode(control_image).latent_dist.sample()
|
612
|
+
control_image = (control_image - vae_shift_factor) * self.vae.config.scaling_factor
|
613
|
+
|
614
|
+
latents = self.prepare_latents(
|
615
|
+
batch_size * num_images_per_prompt,
|
616
|
+
latent_channels,
|
617
|
+
height,
|
618
|
+
width,
|
619
|
+
torch.float32,
|
620
|
+
device,
|
621
|
+
generator,
|
622
|
+
latents,
|
623
|
+
)
|
624
|
+
|
625
|
+
# Prepare additional timestep conditions
|
626
|
+
original_size = torch.tensor([original_size], dtype=prompt_embeds.dtype, device=device)
|
627
|
+
target_size = torch.tensor([target_size], dtype=prompt_embeds.dtype, device=device)
|
628
|
+
crops_coords_top_left = torch.tensor([crops_coords_top_left], dtype=prompt_embeds.dtype, device=device)
|
629
|
+
|
630
|
+
original_size = original_size.repeat(batch_size * num_images_per_prompt, 1)
|
631
|
+
target_size = target_size.repeat(batch_size * num_images_per_prompt, 1)
|
632
|
+
crops_coords_top_left = crops_coords_top_left.repeat(batch_size * num_images_per_prompt, 1)
|
633
|
+
|
634
|
+
# Prepare timesteps
|
635
|
+
image_seq_len = ((height // self.vae_scale_factor) * (width // self.vae_scale_factor)) // (
|
636
|
+
self.transformer.config.patch_size**2
|
637
|
+
)
|
638
|
+
|
639
|
+
timesteps = (
|
640
|
+
np.linspace(self.scheduler.config.num_train_timesteps, 1.0, num_inference_steps)
|
641
|
+
if timesteps is None
|
642
|
+
else np.array(timesteps)
|
643
|
+
)
|
644
|
+
timesteps = timesteps.astype(np.int64).astype(np.float32)
|
645
|
+
sigmas = timesteps / self.scheduler.config.num_train_timesteps if sigmas is None else sigmas
|
646
|
+
mu = calculate_shift(
|
647
|
+
image_seq_len,
|
648
|
+
self.scheduler.config.get("base_image_seq_len", 256),
|
649
|
+
self.scheduler.config.get("base_shift", 0.25),
|
650
|
+
self.scheduler.config.get("max_shift", 0.75),
|
651
|
+
)
|
652
|
+
timesteps, num_inference_steps = retrieve_timesteps(
|
653
|
+
self.scheduler, num_inference_steps, device, timesteps, sigmas, mu=mu
|
654
|
+
)
|
655
|
+
self._num_timesteps = len(timesteps)
|
656
|
+
# Denoising loop
|
657
|
+
transformer_dtype = self.transformer.dtype
|
658
|
+
num_warmup_steps = max(len(timesteps) - num_inference_steps * self.scheduler.order, 0)
|
659
|
+
|
660
|
+
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
661
|
+
for i, t in enumerate(timesteps):
|
662
|
+
if self.interrupt:
|
663
|
+
continue
|
664
|
+
|
665
|
+
self._current_timestep = t
|
666
|
+
latent_model_input = torch.cat([latents, control_image], dim=1).to(transformer_dtype)
|
667
|
+
|
668
|
+
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
|
669
|
+
timestep = t.expand(latents.shape[0])
|
670
|
+
|
671
|
+
noise_pred_cond = self.transformer(
|
672
|
+
hidden_states=latent_model_input,
|
673
|
+
encoder_hidden_states=prompt_embeds,
|
674
|
+
timestep=timestep,
|
675
|
+
original_size=original_size,
|
676
|
+
target_size=target_size,
|
677
|
+
crop_coords=crops_coords_top_left,
|
678
|
+
attention_kwargs=attention_kwargs,
|
679
|
+
return_dict=False,
|
680
|
+
)[0]
|
681
|
+
|
682
|
+
# perform guidance
|
683
|
+
if self.do_classifier_free_guidance:
|
684
|
+
noise_pred_uncond = self.transformer(
|
685
|
+
hidden_states=latent_model_input,
|
686
|
+
encoder_hidden_states=negative_prompt_embeds,
|
687
|
+
timestep=timestep,
|
688
|
+
original_size=original_size,
|
689
|
+
target_size=target_size,
|
690
|
+
crop_coords=crops_coords_top_left,
|
691
|
+
attention_kwargs=attention_kwargs,
|
692
|
+
return_dict=False,
|
693
|
+
)[0]
|
694
|
+
|
695
|
+
noise_pred = noise_pred_uncond + self.guidance_scale * (noise_pred_cond - noise_pred_uncond)
|
696
|
+
else:
|
697
|
+
noise_pred = noise_pred_cond
|
698
|
+
latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
|
699
|
+
|
700
|
+
# call the callback, if provided
|
701
|
+
if callback_on_step_end is not None:
|
702
|
+
callback_kwargs = {}
|
703
|
+
for k in callback_on_step_end_tensor_inputs:
|
704
|
+
callback_kwargs[k] = locals()[k]
|
705
|
+
callback_outputs = callback_on_step_end(self, i, self.scheduler.sigmas[i], callback_kwargs)
|
706
|
+
latents = callback_outputs.pop("latents", latents)
|
707
|
+
prompt_embeds = callback_outputs.pop("prompt_embeds", prompt_embeds)
|
708
|
+
negative_prompt_embeds = callback_outputs.pop("negative_prompt_embeds", negative_prompt_embeds)
|
709
|
+
|
710
|
+
if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
|
711
|
+
progress_bar.update()
|
712
|
+
|
713
|
+
if XLA_AVAILABLE:
|
714
|
+
xm.mark_step()
|
715
|
+
|
716
|
+
self._current_timestep = None
|
717
|
+
|
718
|
+
if not output_type == "latent":
|
719
|
+
latents = latents.to(self.vae.dtype) / self.vae.config.scaling_factor
|
720
|
+
image = self.vae.decode(latents, return_dict=False, generator=generator)[0]
|
721
|
+
else:
|
722
|
+
image = latents
|
723
|
+
|
724
|
+
image = self.image_processor.postprocess(image, output_type=output_type)
|
725
|
+
|
726
|
+
# Offload all models
|
727
|
+
self.maybe_free_model_hooks()
|
728
|
+
|
729
|
+
if not return_dict:
|
730
|
+
return (image,)
|
731
|
+
|
732
|
+
return CogView4PipelineOutput(images=image)
|