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
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding=utf-8
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2025 The HuggingFace Inc. team.
|
3
3
|
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,7 +13,6 @@
|
|
13
13
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
|
-
import enum
|
17
16
|
import fnmatch
|
18
17
|
import importlib
|
19
18
|
import inspect
|
@@ -29,16 +28,19 @@ import PIL.Image
|
|
29
28
|
import requests
|
30
29
|
import torch
|
31
30
|
from huggingface_hub import (
|
31
|
+
DDUFEntry,
|
32
32
|
ModelCard,
|
33
33
|
create_repo,
|
34
34
|
hf_hub_download,
|
35
35
|
model_info,
|
36
|
+
read_dduf_file,
|
36
37
|
snapshot_download,
|
37
38
|
)
|
38
39
|
from huggingface_hub.utils import OfflineModeIsEnabled, validate_hf_hub_args
|
39
40
|
from packaging import version
|
40
41
|
from requests.exceptions import HTTPError
|
41
42
|
from tqdm.auto import tqdm
|
43
|
+
from typing_extensions import Self
|
42
44
|
|
43
45
|
from .. import __version__
|
44
46
|
from ..configuration_utils import ConfigMixin
|
@@ -52,6 +54,8 @@ from ..utils import (
|
|
52
54
|
DEPRECATED_REVISION_ARGS,
|
53
55
|
BaseOutput,
|
54
56
|
PushToHubMixin,
|
57
|
+
_get_detailed_type,
|
58
|
+
_is_valid_type,
|
55
59
|
is_accelerate_available,
|
56
60
|
is_accelerate_version,
|
57
61
|
is_torch_npu_available,
|
@@ -72,6 +76,7 @@ from .pipeline_loading_utils import (
|
|
72
76
|
CONNECTED_PIPES_KEYS,
|
73
77
|
CUSTOM_PIPELINE_FILE_NAME,
|
74
78
|
LOADABLE_CLASSES,
|
79
|
+
_download_dduf_file,
|
75
80
|
_fetch_class_library_tuple,
|
76
81
|
_get_custom_components_and_folders,
|
77
82
|
_get_custom_pipeline_class,
|
@@ -79,10 +84,12 @@ from .pipeline_loading_utils import (
|
|
79
84
|
_get_ignore_patterns,
|
80
85
|
_get_pipeline_class,
|
81
86
|
_identify_model_variants,
|
87
|
+
_maybe_raise_error_for_incorrect_transformers,
|
82
88
|
_maybe_raise_warning_for_inpainting,
|
83
89
|
_resolve_custom_pipeline_and_cls,
|
84
90
|
_unwrap_model,
|
85
91
|
_update_init_kwargs_with_connected_pipeline,
|
92
|
+
filter_model_files,
|
86
93
|
load_sub_model,
|
87
94
|
maybe_raise_or_warn,
|
88
95
|
variant_compatible_siblings,
|
@@ -218,6 +225,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
218
225
|
Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the
|
219
226
|
repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
|
220
227
|
namespace).
|
228
|
+
|
221
229
|
kwargs (`Dict[str, Any]`, *optional*):
|
222
230
|
Additional keyword arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
|
223
231
|
"""
|
@@ -318,7 +326,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
318
326
|
create_pr=create_pr,
|
319
327
|
)
|
320
328
|
|
321
|
-
def to(self, *args, **kwargs):
|
329
|
+
def to(self, *args, **kwargs) -> Self:
|
322
330
|
r"""
|
323
331
|
Performs Pipeline dtype and/or device conversion. A torch.dtype and torch.device are inferred from the
|
324
332
|
arguments of `self.to(*args, **kwargs).`
|
@@ -388,6 +396,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
388
396
|
)
|
389
397
|
|
390
398
|
device = device or device_arg
|
399
|
+
device_type = torch.device(device).type if device is not None else None
|
391
400
|
pipeline_has_bnb = any(any((_check_bnb_status(module))) for _, module in self.components.items())
|
392
401
|
|
393
402
|
# throw warning if pipeline is in "offloaded"-mode but user tries to manually set to GPU.
|
@@ -411,7 +420,14 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
411
420
|
pipeline_is_sequentially_offloaded = any(
|
412
421
|
module_is_sequentially_offloaded(module) for _, module in self.components.items()
|
413
422
|
)
|
414
|
-
|
423
|
+
|
424
|
+
is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1
|
425
|
+
if is_pipeline_device_mapped:
|
426
|
+
raise ValueError(
|
427
|
+
"It seems like you have activated a device mapping strategy on the pipeline which doesn't allow explicit device placement using `to()`. You can call `reset_device_map()` to remove the existing device map from the pipeline."
|
428
|
+
)
|
429
|
+
|
430
|
+
if device_type in ["cuda", "xpu"]:
|
415
431
|
if pipeline_is_sequentially_offloaded and not pipeline_has_bnb:
|
416
432
|
raise ValueError(
|
417
433
|
"It seems like you have activated sequential model offloading by calling `enable_sequential_cpu_offload`, but are now attempting to move the pipeline to GPU. This is not compatible with offloading. Please, move your pipeline `.to('cpu')` or consider removing the move altogether if you use sequential offloading."
|
@@ -422,15 +438,9 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
422
438
|
"You are trying to call `.to('cuda')` on a pipeline that has models quantized with `bitsandbytes`. Your current `accelerate` installation does not support it. Please upgrade the installation."
|
423
439
|
)
|
424
440
|
|
425
|
-
is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1
|
426
|
-
if is_pipeline_device_mapped:
|
427
|
-
raise ValueError(
|
428
|
-
"It seems like you have activated a device mapping strategy on the pipeline which doesn't allow explicit device placement using `to()`. You can call `reset_device_map()` first and then call `to()`."
|
429
|
-
)
|
430
|
-
|
431
441
|
# Display a warning in this case (the operation succeeds but the benefits are lost)
|
432
442
|
pipeline_is_offloaded = any(module_is_offloaded(module) for _, module in self.components.items())
|
433
|
-
if pipeline_is_offloaded and
|
443
|
+
if pipeline_is_offloaded and device_type in ["cuda", "xpu"]:
|
434
444
|
logger.warning(
|
435
445
|
f"It seems like you have activated model offloading by calling `enable_model_cpu_offload`, but are now manually moving the pipeline to GPU. It is strongly recommended against doing so as memory gains from offloading are likely to be lost. Offloading automatically takes care of moving the individual components {', '.join(self.components.keys())} to GPU when needed. To make sure offloading works as expected, you should consider moving the pipeline back to CPU: `pipeline.to('cpu')` or removing the move altogether if you use offloading."
|
436
446
|
)
|
@@ -442,6 +452,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
442
452
|
is_offloaded = pipeline_is_offloaded or pipeline_is_sequentially_offloaded
|
443
453
|
for module in modules:
|
444
454
|
_, is_loaded_in_4bit_bnb, is_loaded_in_8bit_bnb = _check_bnb_status(module)
|
455
|
+
is_group_offloaded = self._maybe_raise_error_if_group_offload_active(module=module)
|
445
456
|
|
446
457
|
if (is_loaded_in_4bit_bnb or is_loaded_in_8bit_bnb) and dtype is not None:
|
447
458
|
logger.warning(
|
@@ -453,11 +464,21 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
453
464
|
f"The module '{module.__class__.__name__}' has been loaded in `bitsandbytes` 8bit and moving it to {device} via `.to()` is not supported. Module is still on {module.device}."
|
454
465
|
)
|
455
466
|
|
467
|
+
# Note: we also handle this at the ModelMixin level. The reason for doing it here too is that modeling
|
468
|
+
# components can be from outside diffusers too, but still have group offloading enabled.
|
469
|
+
if (
|
470
|
+
self._maybe_raise_error_if_group_offload_active(raise_error=False, module=module)
|
471
|
+
and device is not None
|
472
|
+
):
|
473
|
+
logger.warning(
|
474
|
+
f"The module '{module.__class__.__name__}' is group offloaded and moving it to {device} via `.to()` is not supported."
|
475
|
+
)
|
476
|
+
|
456
477
|
# This can happen for `transformer` models. CPU placement was added in
|
457
478
|
# https://github.com/huggingface/transformers/pull/33122. So, we guard this accordingly.
|
458
479
|
if is_loaded_in_4bit_bnb and device is not None and is_transformers_version(">", "4.44.0"):
|
459
480
|
module.to(device=device)
|
460
|
-
elif not is_loaded_in_4bit_bnb and not is_loaded_in_8bit_bnb:
|
481
|
+
elif not is_loaded_in_4bit_bnb and not is_loaded_in_8bit_bnb and not is_group_offloaded:
|
461
482
|
module.to(device, dtype)
|
462
483
|
|
463
484
|
if (
|
@@ -507,7 +528,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
507
528
|
|
508
529
|
@classmethod
|
509
530
|
@validate_hf_hub_args
|
510
|
-
def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.PathLike]], **kwargs):
|
531
|
+
def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.PathLike]], **kwargs) -> Self:
|
511
532
|
r"""
|
512
533
|
Instantiate a PyTorch diffusion pipeline from pretrained pipeline weights.
|
513
534
|
|
@@ -516,7 +537,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
516
537
|
If you get the error message below, you need to finetune the weights for your downstream task:
|
517
538
|
|
518
539
|
```
|
519
|
-
Some weights of UNet2DConditionModel were not initialized from the model checkpoint at
|
540
|
+
Some weights of UNet2DConditionModel were not initialized from the model checkpoint at stable-diffusion-v1-5/stable-diffusion-v1-5 and are newly initialized because the shapes did not match:
|
520
541
|
- conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated
|
521
542
|
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
|
522
543
|
```
|
@@ -530,9 +551,13 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
530
551
|
- A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
|
531
552
|
saved using
|
532
553
|
[`~DiffusionPipeline.save_pretrained`].
|
533
|
-
|
554
|
+
- A path to a *directory* (for example `./my_pipeline_directory/`) containing a dduf file
|
555
|
+
torch_dtype (`str` or `torch.dtype` or `dict[str, Union[str, torch.dtype]]`, *optional*):
|
534
556
|
Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
|
535
|
-
dtype is automatically derived from the model's weights.
|
557
|
+
dtype is automatically derived from the model's weights. To load submodels with different dtype pass a
|
558
|
+
`dict` (for example `{'transformer': torch.bfloat16, 'vae': torch.float16}`). Set the default dtype for
|
559
|
+
unspecified components with `default` (for example `{'transformer': torch.bfloat16, 'default':
|
560
|
+
torch.float16}`). If a component is not specified and no default is set, `torch.float32` is used.
|
536
561
|
custom_pipeline (`str`, *optional*):
|
537
562
|
|
538
563
|
<Tip warning={true}>
|
@@ -624,6 +649,8 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
624
649
|
variant (`str`, *optional*):
|
625
650
|
Load weights from a specified variant filename such as `"fp16"` or `"ema"`. This is ignored when
|
626
651
|
loading `from_flax`.
|
652
|
+
dduf_file(`str`, *optional*):
|
653
|
+
Load weights from the specified dduf file.
|
627
654
|
|
628
655
|
<Tip>
|
629
656
|
|
@@ -643,7 +670,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
643
670
|
>>> # Download pipeline that requires an authorization token
|
644
671
|
>>> # For more information on access tokens, please refer to this section
|
645
672
|
>>> # of the documentation](https://huggingface.co/docs/hub/security-tokens)
|
646
|
-
>>> pipeline = DiffusionPipeline.from_pretrained("
|
673
|
+
>>> pipeline = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
|
647
674
|
|
648
675
|
>>> # Use a different scheduler
|
649
676
|
>>> from diffusers import LMSDiscreteScheduler
|
@@ -667,16 +694,24 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
667
694
|
custom_revision = kwargs.pop("custom_revision", None)
|
668
695
|
provider = kwargs.pop("provider", None)
|
669
696
|
sess_options = kwargs.pop("sess_options", None)
|
697
|
+
provider_options = kwargs.pop("provider_options", None)
|
670
698
|
device_map = kwargs.pop("device_map", None)
|
671
699
|
max_memory = kwargs.pop("max_memory", None)
|
672
700
|
offload_folder = kwargs.pop("offload_folder", None)
|
673
|
-
offload_state_dict = kwargs.pop("offload_state_dict",
|
701
|
+
offload_state_dict = kwargs.pop("offload_state_dict", None)
|
674
702
|
low_cpu_mem_usage = kwargs.pop("low_cpu_mem_usage", _LOW_CPU_MEM_USAGE_DEFAULT)
|
675
703
|
variant = kwargs.pop("variant", None)
|
704
|
+
dduf_file = kwargs.pop("dduf_file", None)
|
676
705
|
use_safetensors = kwargs.pop("use_safetensors", None)
|
677
706
|
use_onnx = kwargs.pop("use_onnx", None)
|
678
707
|
load_connected_pipeline = kwargs.pop("load_connected_pipeline", False)
|
679
708
|
|
709
|
+
if torch_dtype is not None and not isinstance(torch_dtype, dict) and not isinstance(torch_dtype, torch.dtype):
|
710
|
+
torch_dtype = torch.float32
|
711
|
+
logger.warning(
|
712
|
+
f"Passed `torch_dtype` {torch_dtype} is not a `torch.dtype`. Defaulting to `torch.float32`."
|
713
|
+
)
|
714
|
+
|
680
715
|
if low_cpu_mem_usage and not is_accelerate_available():
|
681
716
|
low_cpu_mem_usage = False
|
682
717
|
logger.warning(
|
@@ -721,6 +756,12 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
721
756
|
" dispatching. Please make sure to set `low_cpu_mem_usage=True`."
|
722
757
|
)
|
723
758
|
|
759
|
+
if dduf_file:
|
760
|
+
if custom_pipeline:
|
761
|
+
raise NotImplementedError("Custom pipelines are not supported with DDUF at the moment.")
|
762
|
+
if load_connected_pipeline:
|
763
|
+
raise NotImplementedError("Connected pipelines are not supported with DDUF at the moment.")
|
764
|
+
|
724
765
|
# 1. Download the checkpoints and configs
|
725
766
|
# use snapshot download here to get it working from from_pretrained
|
726
767
|
if not os.path.isdir(pretrained_model_name_or_path):
|
@@ -743,6 +784,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
743
784
|
custom_pipeline=custom_pipeline,
|
744
785
|
custom_revision=custom_revision,
|
745
786
|
variant=variant,
|
787
|
+
dduf_file=dduf_file,
|
746
788
|
load_connected_pipeline=load_connected_pipeline,
|
747
789
|
**kwargs,
|
748
790
|
)
|
@@ -764,7 +806,17 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
764
806
|
)
|
765
807
|
logger.warning(warn_msg)
|
766
808
|
|
767
|
-
|
809
|
+
dduf_entries = None
|
810
|
+
if dduf_file:
|
811
|
+
dduf_file_path = os.path.join(cached_folder, dduf_file)
|
812
|
+
dduf_entries = read_dduf_file(dduf_file_path)
|
813
|
+
# The reader contains already all the files needed, no need to check it again
|
814
|
+
cached_folder = ""
|
815
|
+
|
816
|
+
config_dict = cls.load_config(cached_folder, dduf_entries=dduf_entries)
|
817
|
+
|
818
|
+
if dduf_file:
|
819
|
+
_maybe_raise_error_for_incorrect_transformers(config_dict)
|
768
820
|
|
769
821
|
# pop out "_ignore_files" as it is only needed for download
|
770
822
|
config_dict.pop("_ignore_files", None)
|
@@ -835,26 +887,6 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
835
887
|
|
836
888
|
init_dict = {k: v for k, v in init_dict.items() if load_module(k, v)}
|
837
889
|
|
838
|
-
for key in init_dict.keys():
|
839
|
-
if key not in passed_class_obj:
|
840
|
-
continue
|
841
|
-
if "scheduler" in key:
|
842
|
-
continue
|
843
|
-
|
844
|
-
class_obj = passed_class_obj[key]
|
845
|
-
_expected_class_types = []
|
846
|
-
for expected_type in expected_types[key]:
|
847
|
-
if isinstance(expected_type, enum.EnumMeta):
|
848
|
-
_expected_class_types.extend(expected_type.__members__.keys())
|
849
|
-
else:
|
850
|
-
_expected_class_types.append(expected_type.__name__)
|
851
|
-
|
852
|
-
_is_valid_type = class_obj.__class__.__name__ in _expected_class_types
|
853
|
-
if not _is_valid_type:
|
854
|
-
logger.warning(
|
855
|
-
f"Expected types for {key}: {_expected_class_types}, got {class_obj.__class__.__name__}."
|
856
|
-
)
|
857
|
-
|
858
890
|
# Special case: safety_checker must be loaded separately when using `from_flax`
|
859
891
|
if from_flax and "safety_checker" in init_dict and "safety_checker" not in passed_class_obj:
|
860
892
|
raise NotImplementedError(
|
@@ -921,6 +953,11 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
921
953
|
loaded_sub_model = passed_class_obj[name]
|
922
954
|
else:
|
923
955
|
# load sub model
|
956
|
+
sub_model_dtype = (
|
957
|
+
torch_dtype.get(name, torch_dtype.get("default", torch.float32))
|
958
|
+
if isinstance(torch_dtype, dict)
|
959
|
+
else torch_dtype
|
960
|
+
)
|
924
961
|
loaded_sub_model = load_sub_model(
|
925
962
|
library_name=library_name,
|
926
963
|
class_name=class_name,
|
@@ -928,7 +965,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
928
965
|
pipelines=pipelines,
|
929
966
|
is_pipeline_module=is_pipeline_module,
|
930
967
|
pipeline_class=pipeline_class,
|
931
|
-
torch_dtype=
|
968
|
+
torch_dtype=sub_model_dtype,
|
932
969
|
provider=provider,
|
933
970
|
sess_options=sess_options,
|
934
971
|
device_map=current_device_map,
|
@@ -942,6 +979,8 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
942
979
|
low_cpu_mem_usage=low_cpu_mem_usage,
|
943
980
|
cached_folder=cached_folder,
|
944
981
|
use_safetensors=use_safetensors,
|
982
|
+
dduf_entries=dduf_entries,
|
983
|
+
provider_options=provider_options,
|
945
984
|
)
|
946
985
|
logger.info(
|
947
986
|
f"Loaded {name} as {class_name} from `{name}` subfolder of {pretrained_model_name_or_path}."
|
@@ -967,15 +1006,31 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
967
1006
|
for module in missing_modules:
|
968
1007
|
init_kwargs[module] = passed_class_obj.get(module, None)
|
969
1008
|
elif len(missing_modules) > 0:
|
970
|
-
passed_modules = set(list(init_kwargs.keys()) + list(passed_class_obj.keys())) - optional_kwargs
|
1009
|
+
passed_modules = set(list(init_kwargs.keys()) + list(passed_class_obj.keys())) - set(optional_kwargs)
|
971
1010
|
raise ValueError(
|
972
1011
|
f"Pipeline {pipeline_class} expected {expected_modules}, but only {passed_modules} were passed."
|
973
1012
|
)
|
974
1013
|
|
975
|
-
# 10.
|
1014
|
+
# 10. Type checking init arguments
|
1015
|
+
for kw, arg in init_kwargs.items():
|
1016
|
+
# Too complex to validate with type annotation alone
|
1017
|
+
if "scheduler" in kw:
|
1018
|
+
continue
|
1019
|
+
# Many tokenizer annotations don't include its "Fast" variant, so skip this
|
1020
|
+
# e.g T5Tokenizer but not T5TokenizerFast
|
1021
|
+
elif "tokenizer" in kw:
|
1022
|
+
continue
|
1023
|
+
elif (
|
1024
|
+
arg is not None # Skip if None
|
1025
|
+
and not expected_types[kw] == (inspect.Signature.empty,) # Skip if no type annotations
|
1026
|
+
and not _is_valid_type(arg, expected_types[kw]) # Check type
|
1027
|
+
):
|
1028
|
+
logger.warning(f"Expected types for {kw}: {expected_types[kw]}, got {_get_detailed_type(arg)}.")
|
1029
|
+
|
1030
|
+
# 11. Instantiate the pipeline
|
976
1031
|
model = pipeline_class(**init_kwargs)
|
977
1032
|
|
978
|
-
#
|
1033
|
+
# 12. Save where the model was instantiated from
|
979
1034
|
model.register_to_config(_name_or_path=pretrained_model_name_or_path)
|
980
1035
|
if device_map is not None:
|
981
1036
|
setattr(model, "hf_device_map", final_device_map)
|
@@ -992,6 +1047,19 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
992
1047
|
[`~DiffusionPipeline.enable_sequential_cpu_offload`] the execution device can only be inferred from
|
993
1048
|
Accelerate's module hooks.
|
994
1049
|
"""
|
1050
|
+
from ..hooks.group_offloading import _get_group_onload_device
|
1051
|
+
|
1052
|
+
# When apply group offloading at the leaf_level, we're in the same situation as accelerate's sequential
|
1053
|
+
# offloading. We need to return the onload device of the group offloading hooks so that the intermediates
|
1054
|
+
# required for computation (latents, prompt embeddings, etc.) can be created on the correct device.
|
1055
|
+
for name, model in self.components.items():
|
1056
|
+
if not isinstance(model, torch.nn.Module):
|
1057
|
+
continue
|
1058
|
+
try:
|
1059
|
+
return _get_group_onload_device(model)
|
1060
|
+
except ValueError:
|
1061
|
+
pass
|
1062
|
+
|
995
1063
|
for name, model in self.components.items():
|
996
1064
|
if not isinstance(model, torch.nn.Module) or name in self._exclude_from_cpu_offload:
|
997
1065
|
continue
|
@@ -1030,6 +1098,8 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1030
1098
|
The PyTorch device type of the accelerator that shall be used in inference. If not specified, it will
|
1031
1099
|
default to "cuda".
|
1032
1100
|
"""
|
1101
|
+
self._maybe_raise_error_if_group_offload_active(raise_error=True)
|
1102
|
+
|
1033
1103
|
is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1
|
1034
1104
|
if is_pipeline_device_mapped:
|
1035
1105
|
raise ValueError(
|
@@ -1105,11 +1175,20 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1105
1175
|
|
1106
1176
|
def maybe_free_model_hooks(self):
|
1107
1177
|
r"""
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1178
|
+
Method that performs the following:
|
1179
|
+
- Offloads all components.
|
1180
|
+
- Removes all model hooks that were added when using `enable_model_cpu_offload`, and then applies them again.
|
1181
|
+
In case the model has not been offloaded, this function is a no-op.
|
1182
|
+
- Resets stateful diffusers hooks of denoiser components if they were added with
|
1183
|
+
[`~hooks.HookRegistry.register_hook`].
|
1184
|
+
|
1185
|
+
Make sure to add this function to the end of the `__call__` function of your pipeline so that it functions
|
1186
|
+
correctly when applying `enable_model_cpu_offload`.
|
1112
1187
|
"""
|
1188
|
+
for component in self.components.values():
|
1189
|
+
if hasattr(component, "_reset_stateful_cache"):
|
1190
|
+
component._reset_stateful_cache()
|
1191
|
+
|
1113
1192
|
if not hasattr(self, "_all_hooks") or len(self._all_hooks) == 0:
|
1114
1193
|
# `enable_model_cpu_offload` has not be called, so silently do nothing
|
1115
1194
|
return
|
@@ -1132,6 +1211,8 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1132
1211
|
The PyTorch device type of the accelerator that shall be used in inference. If not specified, it will
|
1133
1212
|
default to "cuda".
|
1134
1213
|
"""
|
1214
|
+
self._maybe_raise_error_if_group_offload_active(raise_error=True)
|
1215
|
+
|
1135
1216
|
if is_accelerate_available() and is_accelerate_version(">=", "0.14.0"):
|
1136
1217
|
from accelerate import cpu_offload
|
1137
1218
|
else:
|
@@ -1255,6 +1336,8 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1255
1336
|
variant (`str`, *optional*):
|
1256
1337
|
Load weights from a specified variant filename such as `"fp16"` or `"ema"`. This is ignored when
|
1257
1338
|
loading `from_flax`.
|
1339
|
+
dduf_file(`str`, *optional*):
|
1340
|
+
Load weights from the specified DDUF file.
|
1258
1341
|
use_safetensors (`bool`, *optional*, defaults to `None`):
|
1259
1342
|
If set to `None`, the safetensors weights are downloaded if they're available **and** if the
|
1260
1343
|
safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
|
@@ -1295,11 +1378,26 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1295
1378
|
use_onnx = kwargs.pop("use_onnx", None)
|
1296
1379
|
load_connected_pipeline = kwargs.pop("load_connected_pipeline", False)
|
1297
1380
|
trust_remote_code = kwargs.pop("trust_remote_code", False)
|
1381
|
+
dduf_file: Optional[Dict[str, DDUFEntry]] = kwargs.pop("dduf_file", None)
|
1382
|
+
|
1383
|
+
if dduf_file:
|
1384
|
+
if custom_pipeline:
|
1385
|
+
raise NotImplementedError("Custom pipelines are not supported with DDUF at the moment.")
|
1386
|
+
if load_connected_pipeline:
|
1387
|
+
raise NotImplementedError("Connected pipelines are not supported with DDUF at the moment.")
|
1388
|
+
return _download_dduf_file(
|
1389
|
+
pretrained_model_name=pretrained_model_name,
|
1390
|
+
dduf_file=dduf_file,
|
1391
|
+
pipeline_class_name=cls.__name__,
|
1392
|
+
cache_dir=cache_dir,
|
1393
|
+
proxies=proxies,
|
1394
|
+
local_files_only=local_files_only,
|
1395
|
+
token=token,
|
1396
|
+
revision=revision,
|
1397
|
+
)
|
1298
1398
|
|
1299
|
-
allow_pickle = False
|
1300
|
-
if use_safetensors is None
|
1301
|
-
use_safetensors = True
|
1302
|
-
allow_pickle = True
|
1399
|
+
allow_pickle = True if (use_safetensors is None or use_safetensors is False) else False
|
1400
|
+
use_safetensors = use_safetensors if use_safetensors is not None else True
|
1303
1401
|
|
1304
1402
|
allow_patterns = None
|
1305
1403
|
ignore_patterns = None
|
@@ -1314,6 +1412,18 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1314
1412
|
model_info_call_error = e # save error to reraise it if model is not cached locally
|
1315
1413
|
|
1316
1414
|
if not local_files_only:
|
1415
|
+
config_file = hf_hub_download(
|
1416
|
+
pretrained_model_name,
|
1417
|
+
cls.config_name,
|
1418
|
+
cache_dir=cache_dir,
|
1419
|
+
revision=revision,
|
1420
|
+
proxies=proxies,
|
1421
|
+
force_download=force_download,
|
1422
|
+
token=token,
|
1423
|
+
)
|
1424
|
+
config_dict = cls._dict_from_json_file(config_file)
|
1425
|
+
ignore_filenames = config_dict.pop("_ignore_files", [])
|
1426
|
+
|
1317
1427
|
filenames = {sibling.rfilename for sibling in info.siblings}
|
1318
1428
|
if variant is not None and _check_legacy_sharding_variant_format(filenames=filenames, variant=variant):
|
1319
1429
|
warn_msg = (
|
@@ -1328,60 +1438,20 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1328
1438
|
)
|
1329
1439
|
logger.warning(warn_msg)
|
1330
1440
|
|
1331
|
-
|
1332
|
-
|
1333
|
-
config_file = hf_hub_download(
|
1334
|
-
pretrained_model_name,
|
1335
|
-
cls.config_name,
|
1336
|
-
cache_dir=cache_dir,
|
1337
|
-
revision=revision,
|
1338
|
-
proxies=proxies,
|
1339
|
-
force_download=force_download,
|
1340
|
-
token=token,
|
1341
|
-
)
|
1342
|
-
|
1343
|
-
config_dict = cls._dict_from_json_file(config_file)
|
1344
|
-
ignore_filenames = config_dict.pop("_ignore_files", [])
|
1345
|
-
|
1346
|
-
# remove ignored filenames
|
1347
|
-
model_filenames = set(model_filenames) - set(ignore_filenames)
|
1348
|
-
variant_filenames = set(variant_filenames) - set(ignore_filenames)
|
1349
|
-
|
1441
|
+
filenames = set(filenames) - set(ignore_filenames)
|
1350
1442
|
if revision in DEPRECATED_REVISION_ARGS and version.parse(
|
1351
1443
|
version.parse(__version__).base_version
|
1352
1444
|
) >= version.parse("0.22.0"):
|
1353
|
-
warn_deprecated_model_variant(pretrained_model_name, token, variant, revision,
|
1445
|
+
warn_deprecated_model_variant(pretrained_model_name, token, variant, revision, filenames)
|
1354
1446
|
|
1355
1447
|
custom_components, folder_names = _get_custom_components_and_folders(
|
1356
|
-
pretrained_model_name, config_dict, filenames,
|
1448
|
+
pretrained_model_name, config_dict, filenames, variant
|
1357
1449
|
)
|
1358
|
-
model_folder_names = {os.path.split(f)[0] for f in model_filenames if os.path.split(f)[0] in folder_names}
|
1359
|
-
|
1360
1450
|
custom_class_name = None
|
1361
1451
|
if custom_pipeline is None and isinstance(config_dict["_class_name"], (list, tuple)):
|
1362
1452
|
custom_pipeline = config_dict["_class_name"][0]
|
1363
1453
|
custom_class_name = config_dict["_class_name"][1]
|
1364
1454
|
|
1365
|
-
# all filenames compatible with variant will be added
|
1366
|
-
allow_patterns = list(model_filenames)
|
1367
|
-
|
1368
|
-
# allow all patterns from non-model folders
|
1369
|
-
# this enables downloading schedulers, tokenizers, ...
|
1370
|
-
allow_patterns += [f"{k}/*" for k in folder_names if k not in model_folder_names]
|
1371
|
-
# add custom component files
|
1372
|
-
allow_patterns += [f"{k}/{f}.py" for k, f in custom_components.items()]
|
1373
|
-
# add custom pipeline file
|
1374
|
-
allow_patterns += [f"{custom_pipeline}.py"] if f"{custom_pipeline}.py" in filenames else []
|
1375
|
-
# also allow downloading config.json files with the model
|
1376
|
-
allow_patterns += [os.path.join(k, "config.json") for k in model_folder_names]
|
1377
|
-
|
1378
|
-
allow_patterns += [
|
1379
|
-
SCHEDULER_CONFIG_NAME,
|
1380
|
-
CONFIG_NAME,
|
1381
|
-
cls.config_name,
|
1382
|
-
CUSTOM_PIPELINE_FILE_NAME,
|
1383
|
-
]
|
1384
|
-
|
1385
1455
|
load_pipe_from_hub = custom_pipeline is not None and f"{custom_pipeline}.py" in filenames
|
1386
1456
|
load_components_from_hub = len(custom_components) > 0
|
1387
1457
|
|
@@ -1394,8 +1464,8 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1394
1464
|
|
1395
1465
|
if load_components_from_hub and not trust_remote_code:
|
1396
1466
|
raise ValueError(
|
1397
|
-
f"The repository for {pretrained_model_name} contains custom code in {'.py, '.join([os.path.join(k, v) for k,v in custom_components.items()])} which must be executed to correctly "
|
1398
|
-
f"load the model. You can inspect the repository content at {', '.join([f'https://hf.co/{pretrained_model_name}/{k}/{v}.py' for k,v in custom_components.items()])}.\n"
|
1467
|
+
f"The repository for {pretrained_model_name} contains custom code in {'.py, '.join([os.path.join(k, v) for k, v in custom_components.items()])} which must be executed to correctly "
|
1468
|
+
f"load the model. You can inspect the repository content at {', '.join([f'https://hf.co/{pretrained_model_name}/{k}/{v}.py' for k, v in custom_components.items()])}.\n"
|
1399
1469
|
f"Please pass the argument `trust_remote_code=True` to allow custom code to be run."
|
1400
1470
|
)
|
1401
1471
|
|
@@ -1414,12 +1484,15 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1414
1484
|
expected_components, _ = cls._get_signature_keys(pipeline_class)
|
1415
1485
|
passed_components = [k for k in expected_components if k in kwargs]
|
1416
1486
|
|
1487
|
+
# retrieve the names of the folders containing model weights
|
1488
|
+
model_folder_names = {
|
1489
|
+
os.path.split(f)[0] for f in filter_model_files(filenames) if os.path.split(f)[0] in folder_names
|
1490
|
+
}
|
1417
1491
|
# retrieve all patterns that should not be downloaded and error out when needed
|
1418
1492
|
ignore_patterns = _get_ignore_patterns(
|
1419
1493
|
passed_components,
|
1420
1494
|
model_folder_names,
|
1421
|
-
|
1422
|
-
variant_filenames,
|
1495
|
+
filenames,
|
1423
1496
|
use_safetensors,
|
1424
1497
|
from_flax,
|
1425
1498
|
allow_pickle,
|
@@ -1428,6 +1501,29 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1428
1501
|
variant,
|
1429
1502
|
)
|
1430
1503
|
|
1504
|
+
model_filenames, variant_filenames = variant_compatible_siblings(
|
1505
|
+
filenames, variant=variant, ignore_patterns=ignore_patterns
|
1506
|
+
)
|
1507
|
+
|
1508
|
+
# all filenames compatible with variant will be added
|
1509
|
+
allow_patterns = list(model_filenames)
|
1510
|
+
|
1511
|
+
# allow all patterns from non-model folders
|
1512
|
+
# this enables downloading schedulers, tokenizers, ...
|
1513
|
+
allow_patterns += [f"{k}/*" for k in folder_names if k not in model_folder_names]
|
1514
|
+
# add custom component files
|
1515
|
+
allow_patterns += [f"{k}/{f}.py" for k, f in custom_components.items()]
|
1516
|
+
# add custom pipeline file
|
1517
|
+
allow_patterns += [f"{custom_pipeline}.py"] if f"{custom_pipeline}.py" in filenames else []
|
1518
|
+
# also allow downloading config.json files with the model
|
1519
|
+
allow_patterns += [os.path.join(k, "config.json") for k in model_folder_names]
|
1520
|
+
allow_patterns += [
|
1521
|
+
SCHEDULER_CONFIG_NAME,
|
1522
|
+
CONFIG_NAME,
|
1523
|
+
cls.config_name,
|
1524
|
+
CUSTOM_PIPELINE_FILE_NAME,
|
1525
|
+
]
|
1526
|
+
|
1431
1527
|
# Don't download any objects that are passed
|
1432
1528
|
allow_patterns = [
|
1433
1529
|
p for p in allow_patterns if not (len(p.split("/")) == 2 and p.split("/")[0] in passed_components)
|
@@ -1470,7 +1566,6 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1470
1566
|
user_agent=user_agent,
|
1471
1567
|
)
|
1472
1568
|
|
1473
|
-
# retrieve pipeline class from local file
|
1474
1569
|
cls_name = cls.load_config(os.path.join(cached_folder, "model_index.json")).get("_class_name", None)
|
1475
1570
|
cls_name = cls_name[4:] if isinstance(cls_name, str) and cls_name.startswith("Flax") else cls_name
|
1476
1571
|
|
@@ -1523,7 +1618,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1523
1618
|
expected_modules.add(name)
|
1524
1619
|
optional_parameters.remove(name)
|
1525
1620
|
|
1526
|
-
return expected_modules, optional_parameters
|
1621
|
+
return sorted(expected_modules), sorted(optional_parameters)
|
1527
1622
|
|
1528
1623
|
@classmethod
|
1529
1624
|
def _get_signature_types(cls):
|
@@ -1555,7 +1650,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1555
1650
|
... StableDiffusionInpaintPipeline,
|
1556
1651
|
... )
|
1557
1652
|
|
1558
|
-
>>> text2img = StableDiffusionPipeline.from_pretrained("
|
1653
|
+
>>> text2img = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
|
1559
1654
|
>>> img2img = StableDiffusionImg2ImgPipeline(**text2img.components)
|
1560
1655
|
>>> inpaint = StableDiffusionInpaintPipeline(**text2img.components)
|
1561
1656
|
```
|
@@ -1565,10 +1660,12 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1565
1660
|
k: getattr(self, k) for k in self.config.keys() if not k.startswith("_") and k not in optional_parameters
|
1566
1661
|
}
|
1567
1662
|
|
1568
|
-
|
1663
|
+
actual = sorted(set(components.keys()))
|
1664
|
+
expected = sorted(expected_modules)
|
1665
|
+
if actual != expected:
|
1569
1666
|
raise ValueError(
|
1570
1667
|
f"{self} has been incorrectly initialized or {self.__class__} is incorrectly implemented. Expected"
|
1571
|
-
f" {
|
1668
|
+
f" {expected} to be defined, but {actual} are defined."
|
1572
1669
|
)
|
1573
1670
|
|
1574
1671
|
return components
|
@@ -1688,7 +1785,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1688
1785
|
>>> from diffusers import StableDiffusionPipeline
|
1689
1786
|
|
1690
1787
|
>>> pipe = StableDiffusionPipeline.from_pretrained(
|
1691
|
-
... "
|
1788
|
+
... "stable-diffusion-v1-5/stable-diffusion-v1-5",
|
1692
1789
|
... torch_dtype=torch.float16,
|
1693
1790
|
... use_safetensors=True,
|
1694
1791
|
... )
|
@@ -1735,13 +1832,13 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1735
1832
|
```py
|
1736
1833
|
>>> from diffusers import StableDiffusionPipeline, StableDiffusionSAGPipeline
|
1737
1834
|
|
1738
|
-
>>> pipe = StableDiffusionPipeline.from_pretrained("
|
1835
|
+
>>> pipe = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
|
1739
1836
|
>>> new_pipe = StableDiffusionSAGPipeline.from_pipe(pipe)
|
1740
1837
|
```
|
1741
1838
|
"""
|
1742
1839
|
|
1743
1840
|
original_config = dict(pipeline.config)
|
1744
|
-
torch_dtype = kwargs.pop("torch_dtype",
|
1841
|
+
torch_dtype = kwargs.pop("torch_dtype", torch.float32)
|
1745
1842
|
|
1746
1843
|
# derive the pipeline class to instantiate
|
1747
1844
|
custom_pipeline = kwargs.pop("custom_pipeline", None)
|
@@ -1839,6 +1936,24 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
|
|
1839
1936
|
|
1840
1937
|
return new_pipeline
|
1841
1938
|
|
1939
|
+
def _maybe_raise_error_if_group_offload_active(
|
1940
|
+
self, raise_error: bool = False, module: Optional[torch.nn.Module] = None
|
1941
|
+
) -> bool:
|
1942
|
+
from ..hooks.group_offloading import _is_group_offload_enabled
|
1943
|
+
|
1944
|
+
components = self.components.values() if module is None else [module]
|
1945
|
+
components = [component for component in components if isinstance(component, torch.nn.Module)]
|
1946
|
+
for component in components:
|
1947
|
+
if _is_group_offload_enabled(component):
|
1948
|
+
if raise_error:
|
1949
|
+
raise ValueError(
|
1950
|
+
"You are trying to apply model/sequential CPU offloading to a pipeline that contains components "
|
1951
|
+
"with group offloading enabled. This is not supported. Please disable group offloading for "
|
1952
|
+
"components of the pipeline to use other offloading methods."
|
1953
|
+
)
|
1954
|
+
return True
|
1955
|
+
return False
|
1956
|
+
|
1842
1957
|
|
1843
1958
|
class StableDiffusionMixin:
|
1844
1959
|
r"""
|