diffusers 0.26.3__py3-none-any.whl → 0.27.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diffusers/__init__.py +20 -1
- diffusers/commands/__init__.py +1 -1
- diffusers/commands/diffusers_cli.py +1 -1
- diffusers/commands/env.py +1 -1
- diffusers/commands/fp16_safetensors.py +1 -1
- diffusers/configuration_utils.py +7 -3
- diffusers/dependency_versions_check.py +1 -1
- diffusers/dependency_versions_table.py +2 -2
- diffusers/experimental/rl/value_guided_sampling.py +1 -1
- diffusers/image_processor.py +110 -4
- diffusers/loaders/autoencoder.py +7 -8
- diffusers/loaders/controlnet.py +17 -8
- diffusers/loaders/ip_adapter.py +86 -23
- diffusers/loaders/lora.py +105 -310
- diffusers/loaders/lora_conversion_utils.py +1 -1
- diffusers/loaders/peft.py +1 -1
- diffusers/loaders/single_file.py +51 -12
- diffusers/loaders/single_file_utils.py +274 -49
- diffusers/loaders/textual_inversion.py +23 -4
- diffusers/loaders/unet.py +195 -41
- diffusers/loaders/utils.py +1 -1
- diffusers/models/__init__.py +3 -1
- diffusers/models/activations.py +9 -9
- diffusers/models/attention.py +26 -36
- diffusers/models/attention_flax.py +1 -1
- diffusers/models/attention_processor.py +171 -114
- diffusers/models/autoencoders/autoencoder_asym_kl.py +1 -1
- diffusers/models/autoencoders/autoencoder_kl.py +3 -1
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +1 -1
- diffusers/models/autoencoders/autoencoder_tiny.py +4 -2
- diffusers/models/autoencoders/consistency_decoder_vae.py +1 -1
- diffusers/models/autoencoders/vae.py +1 -1
- diffusers/models/controlnet.py +1 -1
- diffusers/models/controlnet_flax.py +1 -1
- diffusers/models/downsampling.py +8 -12
- diffusers/models/dual_transformer_2d.py +1 -1
- diffusers/models/embeddings.py +3 -4
- diffusers/models/embeddings_flax.py +1 -1
- diffusers/models/lora.py +33 -10
- 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 +4 -6
- diffusers/models/normalization.py +1 -1
- diffusers/models/resnet.py +31 -58
- diffusers/models/resnet_flax.py +1 -1
- diffusers/models/t5_film_transformer.py +1 -1
- diffusers/models/transformer_2d.py +1 -1
- diffusers/models/transformer_temporal.py +1 -1
- diffusers/models/transformers/dual_transformer_2d.py +1 -1
- diffusers/models/transformers/t5_film_transformer.py +1 -1
- diffusers/models/transformers/transformer_2d.py +29 -31
- diffusers/models/transformers/transformer_temporal.py +1 -1
- diffusers/models/unet_1d.py +1 -1
- diffusers/models/unet_1d_blocks.py +1 -1
- diffusers/models/unet_2d.py +1 -1
- diffusers/models/unet_2d_blocks.py +1 -1
- diffusers/models/unet_2d_condition.py +1 -1
- diffusers/models/unets/__init__.py +1 -0
- diffusers/models/unets/unet_1d.py +1 -1
- diffusers/models/unets/unet_1d_blocks.py +1 -1
- diffusers/models/unets/unet_2d.py +4 -4
- diffusers/models/unets/unet_2d_blocks.py +238 -98
- diffusers/models/unets/unet_2d_blocks_flax.py +1 -1
- diffusers/models/unets/unet_2d_condition.py +420 -323
- diffusers/models/unets/unet_2d_condition_flax.py +21 -12
- diffusers/models/unets/unet_3d_blocks.py +50 -40
- diffusers/models/unets/unet_3d_condition.py +47 -8
- diffusers/models/unets/unet_i2vgen_xl.py +75 -30
- diffusers/models/unets/unet_kandinsky3.py +1 -1
- diffusers/models/unets/unet_motion_model.py +48 -8
- diffusers/models/unets/unet_spatio_temporal_condition.py +1 -1
- diffusers/models/unets/unet_stable_cascade.py +610 -0
- diffusers/models/unets/uvit_2d.py +1 -1
- diffusers/models/upsampling.py +10 -16
- diffusers/models/vae_flax.py +1 -1
- diffusers/models/vq_model.py +1 -1
- diffusers/optimization.py +1 -1
- diffusers/pipelines/__init__.py +26 -0
- diffusers/pipelines/amused/pipeline_amused.py +1 -1
- diffusers/pipelines/amused/pipeline_amused_img2img.py +1 -1
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +1 -1
- diffusers/pipelines/animatediff/pipeline_animatediff.py +162 -417
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +165 -137
- diffusers/pipelines/animatediff/pipeline_output.py +7 -6
- diffusers/pipelines/audioldm/pipeline_audioldm.py +3 -19
- diffusers/pipelines/audioldm2/modeling_audioldm2.py +1 -1
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +3 -3
- diffusers/pipelines/auto_pipeline.py +7 -16
- diffusers/pipelines/blip_diffusion/blip_image_processing.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_blip2.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +2 -2
- diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +2 -2
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -1
- diffusers/pipelines/controlnet/pipeline_controlnet.py +90 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +2 -2
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +98 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +92 -90
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +145 -70
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +126 -89
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +108 -96
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +2 -2
- diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -1
- diffusers/pipelines/ddim/pipeline_ddim.py +1 -1
- diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +5 -5
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +4 -4
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +5 -5
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +5 -5
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +10 -120
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +10 -91
- diffusers/pipelines/deprecated/audio_diffusion/mel.py +1 -1
- diffusers/pipelines/deprecated/audio_diffusion/pipeline_audio_diffusion.py +1 -1
- diffusers/pipelines/deprecated/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py +1 -1
- diffusers/pipelines/deprecated/pndm/pipeline_pndm.py +1 -1
- diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +1 -1
- diffusers/pipelines/deprecated/score_sde_ve/pipeline_score_sde_ve.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/continuous_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/midi_utils.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/notes_encoder.py +1 -1
- diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -1
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +5 -4
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +5 -4
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +7 -22
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +5 -39
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +5 -5
- diffusers/pipelines/deprecated/stochastic_karras_ve/pipeline_stochastic_karras_ve.py +1 -1
- diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +31 -22
- 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 -2
- diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +1 -1
- diffusers/pipelines/dit/pipeline_dit.py +1 -1
- diffusers/pipelines/free_init_utils.py +184 -0
- diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +22 -104
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +2 -2
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +2 -2
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +104 -93
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +112 -74
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -1
- diffusers/pipelines/ledits_pp/__init__.py +55 -0
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +1505 -0
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +1797 -0
- diffusers/pipelines/ledits_pp/pipeline_output.py +43 -0
- diffusers/pipelines/musicldm/pipeline_musicldm.py +3 -19
- diffusers/pipelines/onnx_utils.py +1 -1
- diffusers/pipelines/paint_by_example/image_encoder.py +1 -1
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +3 -3
- diffusers/pipelines/pia/pipeline_pia.py +168 -327
- diffusers/pipelines/pipeline_flax_utils.py +1 -1
- diffusers/pipelines/pipeline_loading_utils.py +508 -0
- diffusers/pipelines/pipeline_utils.py +188 -534
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +56 -10
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +3 -3
- diffusers/pipelines/shap_e/camera.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e.py +1 -1
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +1 -1
- diffusers/pipelines/shap_e/renderer.py +1 -1
- diffusers/pipelines/stable_cascade/__init__.py +50 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +482 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +311 -0
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +638 -0
- diffusers/pipelines/stable_diffusion/clip_image_project_model.py +1 -1
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +4 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_img2img.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +90 -146
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +5 -4
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +4 -32
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -119
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +92 -119
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +13 -59
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +3 -31
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +5 -33
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -21
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +7 -21
- diffusers/pipelines/stable_diffusion/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion/safety_checker_flax.py +1 -1
- diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py +1 -1
- diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +5 -21
- diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +9 -38
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +5 -34
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +6 -35
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +7 -6
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +4 -124
- diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +282 -80
- diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +94 -46
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +3 -3
- diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +6 -22
- diffusers/pipelines/stable_diffusion_xl/pipeline_flax_stable_diffusion_xl.py +1 -1
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +96 -148
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +98 -154
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +98 -153
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +25 -87
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +89 -80
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +5 -49
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +80 -88
- diffusers/pipelines/text_to_video_synthesis/pipeline_output.py +8 -6
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +15 -86
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +20 -93
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +5 -5
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +3 -19
- diffusers/pipelines/unclip/pipeline_unclip.py +1 -1
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -1
- diffusers/pipelines/unclip/text_proj.py +1 -1
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +35 -35
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +4 -21
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_diffnext.py +2 -2
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +4 -5
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +8 -8
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +1 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +2 -2
- diffusers/schedulers/__init__.py +7 -1
- diffusers/schedulers/deprecated/scheduling_karras_ve.py +1 -1
- diffusers/schedulers/deprecated/scheduling_sde_vp.py +1 -1
- diffusers/schedulers/scheduling_consistency_models.py +42 -19
- diffusers/schedulers/scheduling_ddim.py +2 -4
- diffusers/schedulers/scheduling_ddim_flax.py +13 -5
- diffusers/schedulers/scheduling_ddim_inverse.py +2 -4
- diffusers/schedulers/scheduling_ddim_parallel.py +2 -4
- diffusers/schedulers/scheduling_ddpm.py +2 -4
- diffusers/schedulers/scheduling_ddpm_flax.py +1 -1
- diffusers/schedulers/scheduling_ddpm_parallel.py +2 -4
- diffusers/schedulers/scheduling_ddpm_wuerstchen.py +1 -1
- diffusers/schedulers/scheduling_deis_multistep.py +46 -19
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +107 -21
- diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +1 -1
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +9 -7
- diffusers/schedulers/scheduling_dpmsolver_sde.py +35 -35
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +49 -18
- diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +683 -0
- diffusers/schedulers/scheduling_edm_euler.py +381 -0
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +43 -15
- diffusers/schedulers/scheduling_euler_discrete.py +42 -17
- diffusers/schedulers/scheduling_euler_discrete_flax.py +1 -1
- diffusers/schedulers/scheduling_heun_discrete.py +35 -35
- diffusers/schedulers/scheduling_ipndm.py +37 -11
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +44 -44
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +44 -44
- diffusers/schedulers/scheduling_karras_ve_flax.py +1 -1
- diffusers/schedulers/scheduling_lcm.py +38 -14
- diffusers/schedulers/scheduling_lms_discrete.py +43 -15
- diffusers/schedulers/scheduling_lms_discrete_flax.py +1 -1
- diffusers/schedulers/scheduling_pndm.py +2 -4
- diffusers/schedulers/scheduling_pndm_flax.py +2 -4
- diffusers/schedulers/scheduling_repaint.py +1 -1
- diffusers/schedulers/scheduling_sasolver.py +41 -9
- diffusers/schedulers/scheduling_sde_ve.py +1 -1
- diffusers/schedulers/scheduling_sde_ve_flax.py +1 -1
- diffusers/schedulers/scheduling_tcd.py +686 -0
- diffusers/schedulers/scheduling_unclip.py +1 -1
- diffusers/schedulers/scheduling_unipc_multistep.py +46 -19
- diffusers/schedulers/scheduling_utils.py +2 -1
- diffusers/schedulers/scheduling_utils_flax.py +1 -1
- diffusers/schedulers/scheduling_vq_diffusion.py +1 -1
- diffusers/training_utils.py +9 -2
- diffusers/utils/__init__.py +2 -1
- diffusers/utils/accelerate_utils.py +1 -1
- diffusers/utils/constants.py +1 -1
- diffusers/utils/doc_utils.py +1 -1
- diffusers/utils/dummy_pt_objects.py +60 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +75 -0
- diffusers/utils/dynamic_modules_utils.py +1 -1
- diffusers/utils/export_utils.py +3 -3
- diffusers/utils/hub_utils.py +60 -16
- diffusers/utils/import_utils.py +15 -1
- diffusers/utils/loading_utils.py +2 -0
- diffusers/utils/logging.py +1 -1
- diffusers/utils/model_card_template.md +24 -0
- diffusers/utils/outputs.py +14 -7
- diffusers/utils/peft_utils.py +1 -1
- diffusers/utils/state_dict_utils.py +1 -1
- diffusers/utils/testing_utils.py +2 -0
- diffusers/utils/torch_utils.py +1 -1
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/METADATA +46 -46
- diffusers-0.27.0.dist-info/RECORD +399 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/WHEEL +1 -1
- diffusers-0.26.3.dist-info/RECORD +0 -384
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/LICENSE +0 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/entry_points.txt +0 -0
- {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding=utf-8
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 The HuggingFace Inc. team.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -28,6 +28,7 @@ from ..schedulers import (
|
|
28
28
|
DDIMScheduler,
|
29
29
|
DDPMScheduler,
|
30
30
|
DPMSolverMultistepScheduler,
|
31
|
+
EDMDPMSolverMultistepScheduler,
|
31
32
|
EulerAncestralDiscreteScheduler,
|
32
33
|
EulerDiscreteScheduler,
|
33
34
|
HeunDiscreteScheduler,
|
@@ -48,7 +49,6 @@ if is_transformers_available():
|
|
48
49
|
|
49
50
|
if is_accelerate_available():
|
50
51
|
from accelerate import init_empty_weights
|
51
|
-
from accelerate.utils import set_module_tensor_to_device
|
52
52
|
|
53
53
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
54
54
|
|
@@ -81,6 +81,87 @@ SCHEDULER_DEFAULT_CONFIG = {
|
|
81
81
|
"timestep_spacing": "leading",
|
82
82
|
}
|
83
83
|
|
84
|
+
|
85
|
+
STABLE_CASCADE_DEFAULT_CONFIGS = {
|
86
|
+
"stage_c": {"pretrained_model_name_or_path": "diffusers/stable-cascade-configs", "subfolder": "prior"},
|
87
|
+
"stage_c_lite": {"pretrained_model_name_or_path": "diffusers/stable-cascade-configs", "subfolder": "prior_lite"},
|
88
|
+
"stage_b": {"pretrained_model_name_or_path": "diffusers/stable-cascade-configs", "subfolder": "decoder"},
|
89
|
+
"stage_b_lite": {"pretrained_model_name_or_path": "diffusers/stable-cascade-configs", "subfolder": "decoder_lite"},
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
def convert_stable_cascade_unet_single_file_to_diffusers(original_state_dict):
|
94
|
+
is_stage_c = "clip_txt_mapper.weight" in original_state_dict
|
95
|
+
|
96
|
+
if is_stage_c:
|
97
|
+
state_dict = {}
|
98
|
+
for key in original_state_dict.keys():
|
99
|
+
if key.endswith("in_proj_weight"):
|
100
|
+
weights = original_state_dict[key].chunk(3, 0)
|
101
|
+
state_dict[key.replace("attn.in_proj_weight", "to_q.weight")] = weights[0]
|
102
|
+
state_dict[key.replace("attn.in_proj_weight", "to_k.weight")] = weights[1]
|
103
|
+
state_dict[key.replace("attn.in_proj_weight", "to_v.weight")] = weights[2]
|
104
|
+
elif key.endswith("in_proj_bias"):
|
105
|
+
weights = original_state_dict[key].chunk(3, 0)
|
106
|
+
state_dict[key.replace("attn.in_proj_bias", "to_q.bias")] = weights[0]
|
107
|
+
state_dict[key.replace("attn.in_proj_bias", "to_k.bias")] = weights[1]
|
108
|
+
state_dict[key.replace("attn.in_proj_bias", "to_v.bias")] = weights[2]
|
109
|
+
elif key.endswith("out_proj.weight"):
|
110
|
+
weights = original_state_dict[key]
|
111
|
+
state_dict[key.replace("attn.out_proj.weight", "to_out.0.weight")] = weights
|
112
|
+
elif key.endswith("out_proj.bias"):
|
113
|
+
weights = original_state_dict[key]
|
114
|
+
state_dict[key.replace("attn.out_proj.bias", "to_out.0.bias")] = weights
|
115
|
+
else:
|
116
|
+
state_dict[key] = original_state_dict[key]
|
117
|
+
else:
|
118
|
+
state_dict = {}
|
119
|
+
for key in original_state_dict.keys():
|
120
|
+
if key.endswith("in_proj_weight"):
|
121
|
+
weights = original_state_dict[key].chunk(3, 0)
|
122
|
+
state_dict[key.replace("attn.in_proj_weight", "to_q.weight")] = weights[0]
|
123
|
+
state_dict[key.replace("attn.in_proj_weight", "to_k.weight")] = weights[1]
|
124
|
+
state_dict[key.replace("attn.in_proj_weight", "to_v.weight")] = weights[2]
|
125
|
+
elif key.endswith("in_proj_bias"):
|
126
|
+
weights = original_state_dict[key].chunk(3, 0)
|
127
|
+
state_dict[key.replace("attn.in_proj_bias", "to_q.bias")] = weights[0]
|
128
|
+
state_dict[key.replace("attn.in_proj_bias", "to_k.bias")] = weights[1]
|
129
|
+
state_dict[key.replace("attn.in_proj_bias", "to_v.bias")] = weights[2]
|
130
|
+
elif key.endswith("out_proj.weight"):
|
131
|
+
weights = original_state_dict[key]
|
132
|
+
state_dict[key.replace("attn.out_proj.weight", "to_out.0.weight")] = weights
|
133
|
+
elif key.endswith("out_proj.bias"):
|
134
|
+
weights = original_state_dict[key]
|
135
|
+
state_dict[key.replace("attn.out_proj.bias", "to_out.0.bias")] = weights
|
136
|
+
# rename clip_mapper to clip_txt_pooled_mapper
|
137
|
+
elif key.endswith("clip_mapper.weight"):
|
138
|
+
weights = original_state_dict[key]
|
139
|
+
state_dict[key.replace("clip_mapper.weight", "clip_txt_pooled_mapper.weight")] = weights
|
140
|
+
elif key.endswith("clip_mapper.bias"):
|
141
|
+
weights = original_state_dict[key]
|
142
|
+
state_dict[key.replace("clip_mapper.bias", "clip_txt_pooled_mapper.bias")] = weights
|
143
|
+
else:
|
144
|
+
state_dict[key] = original_state_dict[key]
|
145
|
+
|
146
|
+
return state_dict
|
147
|
+
|
148
|
+
|
149
|
+
def infer_stable_cascade_single_file_config(checkpoint):
|
150
|
+
is_stage_c = "clip_txt_mapper.weight" in checkpoint
|
151
|
+
is_stage_b = "down_blocks.1.0.channelwise.0.weight" in checkpoint
|
152
|
+
|
153
|
+
if is_stage_c and (checkpoint["clip_txt_mapper.weight"].shape[0] == 1536):
|
154
|
+
config_type = "stage_c_lite"
|
155
|
+
elif is_stage_c and (checkpoint["clip_txt_mapper.weight"].shape[0] == 2048):
|
156
|
+
config_type = "stage_c"
|
157
|
+
elif is_stage_b and checkpoint["down_blocks.1.0.channelwise.0.weight"].shape[-1] == 576:
|
158
|
+
config_type = "stage_b_lite"
|
159
|
+
elif is_stage_b and checkpoint["down_blocks.1.0.channelwise.0.weight"].shape[-1] == 640:
|
160
|
+
config_type = "stage_b"
|
161
|
+
|
162
|
+
return STABLE_CASCADE_DEFAULT_CONFIGS[config_type]
|
163
|
+
|
164
|
+
|
84
165
|
DIFFUSERS_TO_LDM_MAPPING = {
|
85
166
|
"unet": {
|
86
167
|
"layers": {
|
@@ -176,6 +257,7 @@ DIFFUSERS_TO_LDM_MAPPING = {
|
|
176
257
|
|
177
258
|
LDM_VAE_KEY = "first_stage_model."
|
178
259
|
LDM_VAE_DEFAULT_SCALING_FACTOR = 0.18215
|
260
|
+
PLAYGROUND_VAE_SCALING_FACTOR = 0.5
|
179
261
|
LDM_UNET_KEY = "model.diffusion_model."
|
180
262
|
LDM_CONTROLNET_KEY = "control_model."
|
181
263
|
LDM_CLIP_PREFIX_TO_REMOVE = ["cond_stage_model.transformer.", "conditioner.embedders.0.transformer."]
|
@@ -228,17 +310,34 @@ def fetch_ldm_config_and_checkpoint(
|
|
228
310
|
cache_dir=None,
|
229
311
|
local_files_only=None,
|
230
312
|
revision=None,
|
231
|
-
use_safetensors=True,
|
232
313
|
):
|
233
|
-
|
234
|
-
|
314
|
+
checkpoint = load_single_file_model_checkpoint(
|
315
|
+
pretrained_model_link_or_path,
|
316
|
+
resume_download=resume_download,
|
317
|
+
force_download=force_download,
|
318
|
+
proxies=proxies,
|
319
|
+
token=token,
|
320
|
+
cache_dir=cache_dir,
|
321
|
+
local_files_only=local_files_only,
|
322
|
+
revision=revision,
|
323
|
+
)
|
324
|
+
original_config = fetch_original_config(class_name, checkpoint, original_config_file)
|
325
|
+
|
326
|
+
return original_config, checkpoint
|
235
327
|
|
236
|
-
if from_safetensors and use_safetensors is False:
|
237
|
-
raise ValueError("Make sure to install `safetensors` with `pip install safetensors`.")
|
238
328
|
|
329
|
+
def load_single_file_model_checkpoint(
|
330
|
+
pretrained_model_link_or_path,
|
331
|
+
resume_download=False,
|
332
|
+
force_download=False,
|
333
|
+
proxies=None,
|
334
|
+
token=None,
|
335
|
+
cache_dir=None,
|
336
|
+
local_files_only=None,
|
337
|
+
revision=None,
|
338
|
+
):
|
239
339
|
if os.path.isfile(pretrained_model_link_or_path):
|
240
340
|
checkpoint = load_state_dict(pretrained_model_link_or_path)
|
241
|
-
|
242
341
|
else:
|
243
342
|
repo_id, weights_name = _extract_repo_id_and_weights_name(pretrained_model_link_or_path)
|
244
343
|
checkpoint_path = _get_model_file(
|
@@ -258,9 +357,7 @@ def fetch_ldm_config_and_checkpoint(
|
|
258
357
|
while "state_dict" in checkpoint:
|
259
358
|
checkpoint = checkpoint["state_dict"]
|
260
359
|
|
261
|
-
|
262
|
-
|
263
|
-
return original_config, checkpoint
|
360
|
+
return checkpoint
|
264
361
|
|
265
362
|
|
266
363
|
def infer_original_config_file(class_name, checkpoint):
|
@@ -313,7 +410,7 @@ def fetch_original_config(pipeline_class_name, checkpoint, original_config_file=
|
|
313
410
|
return original_config
|
314
411
|
|
315
412
|
|
316
|
-
def infer_model_type(original_config, model_type=None):
|
413
|
+
def infer_model_type(original_config, checkpoint, model_type=None):
|
317
414
|
if model_type is not None:
|
318
415
|
return model_type
|
319
416
|
|
@@ -331,7 +428,9 @@ def infer_model_type(original_config, model_type=None):
|
|
331
428
|
|
332
429
|
elif has_network_config:
|
333
430
|
context_dim = original_config["model"]["params"]["network_config"]["params"]["context_dim"]
|
334
|
-
if
|
431
|
+
if "edm_mean" in checkpoint and "edm_std" in checkpoint:
|
432
|
+
model_type = "Playground"
|
433
|
+
elif context_dim == 2048:
|
335
434
|
model_type = "SDXL"
|
336
435
|
else:
|
337
436
|
model_type = "SDXL-Refiner"
|
@@ -352,13 +451,13 @@ def set_image_size(pipeline_class_name, original_config, checkpoint, image_size=
|
|
352
451
|
return image_size
|
353
452
|
|
354
453
|
global_step = checkpoint["global_step"] if "global_step" in checkpoint else None
|
355
|
-
model_type = infer_model_type(original_config, model_type)
|
454
|
+
model_type = infer_model_type(original_config, checkpoint, model_type)
|
356
455
|
|
357
456
|
if pipeline_class_name == "StableDiffusionUpscalePipeline":
|
358
457
|
image_size = original_config["model"]["params"]["unet_config"]["params"]["image_size"]
|
359
458
|
return image_size
|
360
459
|
|
361
|
-
elif model_type in ["SDXL", "SDXL-Refiner"]:
|
460
|
+
elif model_type in ["SDXL", "SDXL-Refiner", "Playground"]:
|
362
461
|
image_size = 1024
|
363
462
|
return image_size
|
364
463
|
|
@@ -466,8 +565,8 @@ def create_unet_diffusers_config(original_config, image_size: int):
|
|
466
565
|
config = {
|
467
566
|
"sample_size": image_size // vae_scale_factor,
|
468
567
|
"in_channels": unet_params["in_channels"],
|
469
|
-
"down_block_types":
|
470
|
-
"block_out_channels":
|
568
|
+
"down_block_types": down_block_types,
|
569
|
+
"block_out_channels": block_out_channels,
|
471
570
|
"layers_per_block": unet_params["num_res_blocks"],
|
472
571
|
"cross_attention_dim": context_dim,
|
473
572
|
"attention_head_dim": head_dim,
|
@@ -486,7 +585,7 @@ def create_unet_diffusers_config(original_config, image_size: int):
|
|
486
585
|
config["num_class_embeds"] = unet_params["num_classes"]
|
487
586
|
|
488
587
|
config["out_channels"] = unet_params["out_channels"]
|
489
|
-
config["up_block_types"] =
|
588
|
+
config["up_block_types"] = up_block_types
|
490
589
|
|
491
590
|
return config
|
492
591
|
|
@@ -514,12 +613,14 @@ def create_controlnet_diffusers_config(original_config, image_size: int):
|
|
514
613
|
return controlnet_config
|
515
614
|
|
516
615
|
|
517
|
-
def create_vae_diffusers_config(original_config, image_size, scaling_factor=None):
|
616
|
+
def create_vae_diffusers_config(original_config, image_size, scaling_factor=None, latents_mean=None, latents_std=None):
|
518
617
|
"""
|
519
618
|
Creates a config for the diffusers based on the config of the LDM model.
|
520
619
|
"""
|
521
620
|
vae_params = original_config["model"]["params"]["first_stage_config"]["params"]["ddconfig"]
|
522
|
-
if scaling_factor is None and
|
621
|
+
if (scaling_factor is None) and (latents_mean is not None) and (latents_std is not None):
|
622
|
+
scaling_factor = PLAYGROUND_VAE_SCALING_FACTOR
|
623
|
+
elif (scaling_factor is None) and ("scale_factor" in original_config["model"]["params"]):
|
523
624
|
scaling_factor = original_config["model"]["params"]["scale_factor"]
|
524
625
|
elif scaling_factor is None:
|
525
626
|
scaling_factor = LDM_VAE_DEFAULT_SCALING_FACTOR
|
@@ -532,13 +633,15 @@ def create_vae_diffusers_config(original_config, image_size, scaling_factor=None
|
|
532
633
|
"sample_size": image_size,
|
533
634
|
"in_channels": vae_params["in_channels"],
|
534
635
|
"out_channels": vae_params["out_ch"],
|
535
|
-
"down_block_types":
|
536
|
-
"up_block_types":
|
537
|
-
"block_out_channels":
|
636
|
+
"down_block_types": down_block_types,
|
637
|
+
"up_block_types": up_block_types,
|
638
|
+
"block_out_channels": block_out_channels,
|
538
639
|
"latent_channels": vae_params["z_channels"],
|
539
640
|
"layers_per_block": vae_params["num_res_blocks"],
|
540
641
|
"scaling_factor": scaling_factor,
|
541
642
|
}
|
643
|
+
if latents_mean is not None and latents_std is not None:
|
644
|
+
config.update({"latents_mean": latents_mean, "latents_std": latents_std})
|
542
645
|
|
543
646
|
return config
|
544
647
|
|
@@ -857,7 +960,7 @@ def convert_controlnet_checkpoint(
|
|
857
960
|
|
858
961
|
|
859
962
|
def create_diffusers_controlnet_model_from_ldm(
|
860
|
-
pipeline_class_name, original_config, checkpoint, upcast_attention=False, image_size=None
|
963
|
+
pipeline_class_name, original_config, checkpoint, upcast_attention=False, image_size=None, torch_dtype=None
|
861
964
|
):
|
862
965
|
# import here to avoid circular imports
|
863
966
|
from ..models import ControlNetModel
|
@@ -874,11 +977,25 @@ def create_diffusers_controlnet_model_from_ldm(
|
|
874
977
|
controlnet = ControlNetModel(**diffusers_config)
|
875
978
|
|
876
979
|
if is_accelerate_available():
|
877
|
-
|
878
|
-
|
980
|
+
from ..models.modeling_utils import load_model_dict_into_meta
|
981
|
+
|
982
|
+
unexpected_keys = load_model_dict_into_meta(
|
983
|
+
controlnet, diffusers_format_controlnet_checkpoint, dtype=torch_dtype
|
984
|
+
)
|
985
|
+
if controlnet._keys_to_ignore_on_load_unexpected is not None:
|
986
|
+
for pat in controlnet._keys_to_ignore_on_load_unexpected:
|
987
|
+
unexpected_keys = [k for k in unexpected_keys if re.search(pat, k) is None]
|
988
|
+
|
989
|
+
if len(unexpected_keys) > 0:
|
990
|
+
logger.warning(
|
991
|
+
f"Some weights of the model checkpoint were not used when initializing {controlnet.__name__}: \n {[', '.join(unexpected_keys)]}"
|
992
|
+
)
|
879
993
|
else:
|
880
994
|
controlnet.load_state_dict(diffusers_format_controlnet_checkpoint)
|
881
995
|
|
996
|
+
if torch_dtype is not None:
|
997
|
+
controlnet = controlnet.to(torch_dtype)
|
998
|
+
|
882
999
|
return {"controlnet": controlnet}
|
883
1000
|
|
884
1001
|
|
@@ -1014,7 +1131,7 @@ def convert_ldm_vae_checkpoint(checkpoint, config):
|
|
1014
1131
|
return new_checkpoint
|
1015
1132
|
|
1016
1133
|
|
1017
|
-
def create_text_encoder_from_ldm_clip_checkpoint(config_name, checkpoint, local_files_only=False):
|
1134
|
+
def create_text_encoder_from_ldm_clip_checkpoint(config_name, checkpoint, local_files_only=False, torch_dtype=None):
|
1018
1135
|
try:
|
1019
1136
|
config = CLIPTextConfig.from_pretrained(config_name, local_files_only=local_files_only)
|
1020
1137
|
except Exception:
|
@@ -1038,14 +1155,26 @@ def create_text_encoder_from_ldm_clip_checkpoint(config_name, checkpoint, local_
|
|
1038
1155
|
text_model_dict[diffusers_key] = checkpoint[key]
|
1039
1156
|
|
1040
1157
|
if is_accelerate_available():
|
1041
|
-
|
1042
|
-
|
1158
|
+
from ..models.modeling_utils import load_model_dict_into_meta
|
1159
|
+
|
1160
|
+
unexpected_keys = load_model_dict_into_meta(text_model, text_model_dict, dtype=torch_dtype)
|
1161
|
+
if text_model._keys_to_ignore_on_load_unexpected is not None:
|
1162
|
+
for pat in text_model._keys_to_ignore_on_load_unexpected:
|
1163
|
+
unexpected_keys = [k for k in unexpected_keys if re.search(pat, k) is None]
|
1164
|
+
|
1165
|
+
if len(unexpected_keys) > 0:
|
1166
|
+
logger.warning(
|
1167
|
+
f"Some weights of the model checkpoint were not used when initializing {text_model.__class__.__name__}: \n {[', '.join(unexpected_keys)]}"
|
1168
|
+
)
|
1043
1169
|
else:
|
1044
1170
|
if not (hasattr(text_model, "embeddings") and hasattr(text_model.embeddings.position_ids)):
|
1045
1171
|
text_model_dict.pop("text_model.embeddings.position_ids", None)
|
1046
1172
|
|
1047
1173
|
text_model.load_state_dict(text_model_dict)
|
1048
1174
|
|
1175
|
+
if torch_dtype is not None:
|
1176
|
+
text_model = text_model.to(torch_dtype)
|
1177
|
+
|
1049
1178
|
return text_model
|
1050
1179
|
|
1051
1180
|
|
@@ -1055,6 +1184,7 @@ def create_text_encoder_from_open_clip_checkpoint(
|
|
1055
1184
|
prefix="cond_stage_model.model.",
|
1056
1185
|
has_projection=False,
|
1057
1186
|
local_files_only=False,
|
1187
|
+
torch_dtype=None,
|
1058
1188
|
**config_kwargs,
|
1059
1189
|
):
|
1060
1190
|
try:
|
@@ -1116,13 +1246,21 @@ def create_text_encoder_from_open_clip_checkpoint(
|
|
1116
1246
|
text_model_dict[diffusers_key + ".q_proj.bias"] = weight_value[:text_proj_dim]
|
1117
1247
|
text_model_dict[diffusers_key + ".k_proj.bias"] = weight_value[text_proj_dim : text_proj_dim * 2]
|
1118
1248
|
text_model_dict[diffusers_key + ".v_proj.bias"] = weight_value[text_proj_dim * 2 :]
|
1119
|
-
|
1120
1249
|
else:
|
1121
1250
|
text_model_dict[diffusers_key] = checkpoint[key]
|
1122
1251
|
|
1123
1252
|
if is_accelerate_available():
|
1124
|
-
|
1125
|
-
|
1253
|
+
from ..models.modeling_utils import load_model_dict_into_meta
|
1254
|
+
|
1255
|
+
unexpected_keys = load_model_dict_into_meta(text_model, text_model_dict, dtype=torch_dtype)
|
1256
|
+
if text_model._keys_to_ignore_on_load_unexpected is not None:
|
1257
|
+
for pat in text_model._keys_to_ignore_on_load_unexpected:
|
1258
|
+
unexpected_keys = [k for k in unexpected_keys if re.search(pat, k) is None]
|
1259
|
+
|
1260
|
+
if len(unexpected_keys) > 0:
|
1261
|
+
logger.warning(
|
1262
|
+
f"Some weights of the model checkpoint were not used when initializing {text_model.__class__.__name__}: \n {[', '.join(unexpected_keys)]}"
|
1263
|
+
)
|
1126
1264
|
|
1127
1265
|
else:
|
1128
1266
|
if not (hasattr(text_model, "embeddings") and hasattr(text_model.embeddings.position_ids)):
|
@@ -1130,6 +1268,9 @@ def create_text_encoder_from_open_clip_checkpoint(
|
|
1130
1268
|
|
1131
1269
|
text_model.load_state_dict(text_model_dict)
|
1132
1270
|
|
1271
|
+
if torch_dtype is not None:
|
1272
|
+
text_model = text_model.to(torch_dtype)
|
1273
|
+
|
1133
1274
|
return text_model
|
1134
1275
|
|
1135
1276
|
|
@@ -1138,15 +1279,18 @@ def create_diffusers_unet_model_from_ldm(
|
|
1138
1279
|
original_config,
|
1139
1280
|
checkpoint,
|
1140
1281
|
num_in_channels=None,
|
1141
|
-
upcast_attention=
|
1282
|
+
upcast_attention=None,
|
1142
1283
|
extract_ema=False,
|
1143
1284
|
image_size=None,
|
1285
|
+
torch_dtype=None,
|
1286
|
+
model_type=None,
|
1144
1287
|
):
|
1145
1288
|
from ..models import UNet2DConditionModel
|
1146
1289
|
|
1147
1290
|
if num_in_channels is None:
|
1148
1291
|
if pipeline_class_name in [
|
1149
1292
|
"StableDiffusionInpaintPipeline",
|
1293
|
+
"StableDiffusionControlNetInpaintPipeline",
|
1150
1294
|
"StableDiffusionXLInpaintPipeline",
|
1151
1295
|
"StableDiffusionXLControlNetInpaintPipeline",
|
1152
1296
|
]:
|
@@ -1158,34 +1302,76 @@ def create_diffusers_unet_model_from_ldm(
|
|
1158
1302
|
else:
|
1159
1303
|
num_in_channels = 4
|
1160
1304
|
|
1161
|
-
image_size = set_image_size(
|
1305
|
+
image_size = set_image_size(
|
1306
|
+
pipeline_class_name, original_config, checkpoint, image_size=image_size, model_type=model_type
|
1307
|
+
)
|
1162
1308
|
unet_config = create_unet_diffusers_config(original_config, image_size=image_size)
|
1163
1309
|
unet_config["in_channels"] = num_in_channels
|
1164
|
-
|
1310
|
+
if upcast_attention is not None:
|
1311
|
+
unet_config["upcast_attention"] = upcast_attention
|
1165
1312
|
|
1166
1313
|
diffusers_format_unet_checkpoint = convert_ldm_unet_checkpoint(checkpoint, unet_config, extract_ema=extract_ema)
|
1167
1314
|
ctx = init_empty_weights if is_accelerate_available() else nullcontext
|
1315
|
+
|
1168
1316
|
with ctx():
|
1169
1317
|
unet = UNet2DConditionModel(**unet_config)
|
1170
1318
|
|
1171
1319
|
if is_accelerate_available():
|
1172
|
-
|
1173
|
-
|
1320
|
+
from ..models.modeling_utils import load_model_dict_into_meta
|
1321
|
+
|
1322
|
+
unexpected_keys = load_model_dict_into_meta(unet, diffusers_format_unet_checkpoint, dtype=torch_dtype)
|
1323
|
+
if unet._keys_to_ignore_on_load_unexpected is not None:
|
1324
|
+
for pat in unet._keys_to_ignore_on_load_unexpected:
|
1325
|
+
unexpected_keys = [k for k in unexpected_keys if re.search(pat, k) is None]
|
1326
|
+
|
1327
|
+
if len(unexpected_keys) > 0:
|
1328
|
+
logger.warning(
|
1329
|
+
f"Some weights of the model checkpoint were not used when initializing {unet.__name__}: \n {[', '.join(unexpected_keys)]}"
|
1330
|
+
)
|
1174
1331
|
else:
|
1175
1332
|
unet.load_state_dict(diffusers_format_unet_checkpoint)
|
1176
1333
|
|
1334
|
+
if torch_dtype is not None:
|
1335
|
+
unet = unet.to(torch_dtype)
|
1336
|
+
|
1177
1337
|
return {"unet": unet}
|
1178
1338
|
|
1179
1339
|
|
1180
1340
|
def create_diffusers_vae_model_from_ldm(
|
1181
|
-
pipeline_class_name,
|
1341
|
+
pipeline_class_name,
|
1342
|
+
original_config,
|
1343
|
+
checkpoint,
|
1344
|
+
image_size=None,
|
1345
|
+
scaling_factor=None,
|
1346
|
+
torch_dtype=None,
|
1347
|
+
model_type=None,
|
1182
1348
|
):
|
1183
1349
|
# import here to avoid circular imports
|
1184
1350
|
from ..models import AutoencoderKL
|
1185
1351
|
|
1186
|
-
image_size = set_image_size(
|
1352
|
+
image_size = set_image_size(
|
1353
|
+
pipeline_class_name, original_config, checkpoint, image_size=image_size, model_type=model_type
|
1354
|
+
)
|
1355
|
+
model_type = infer_model_type(original_config, checkpoint, model_type)
|
1187
1356
|
|
1188
|
-
|
1357
|
+
if model_type == "Playground":
|
1358
|
+
edm_mean = (
|
1359
|
+
checkpoint["edm_mean"].to(dtype=torch_dtype).tolist() if torch_dtype else checkpoint["edm_mean"].tolist()
|
1360
|
+
)
|
1361
|
+
edm_std = (
|
1362
|
+
checkpoint["edm_std"].to(dtype=torch_dtype).tolist() if torch_dtype else checkpoint["edm_std"].tolist()
|
1363
|
+
)
|
1364
|
+
else:
|
1365
|
+
edm_mean = None
|
1366
|
+
edm_std = None
|
1367
|
+
|
1368
|
+
vae_config = create_vae_diffusers_config(
|
1369
|
+
original_config,
|
1370
|
+
image_size=image_size,
|
1371
|
+
scaling_factor=scaling_factor,
|
1372
|
+
latents_mean=edm_mean,
|
1373
|
+
latents_std=edm_std,
|
1374
|
+
)
|
1189
1375
|
diffusers_format_vae_checkpoint = convert_ldm_vae_checkpoint(checkpoint, vae_config)
|
1190
1376
|
ctx = init_empty_weights if is_accelerate_available() else nullcontext
|
1191
1377
|
|
@@ -1193,11 +1379,23 @@ def create_diffusers_vae_model_from_ldm(
|
|
1193
1379
|
vae = AutoencoderKL(**vae_config)
|
1194
1380
|
|
1195
1381
|
if is_accelerate_available():
|
1196
|
-
|
1197
|
-
|
1382
|
+
from ..models.modeling_utils import load_model_dict_into_meta
|
1383
|
+
|
1384
|
+
unexpected_keys = load_model_dict_into_meta(vae, diffusers_format_vae_checkpoint, dtype=torch_dtype)
|
1385
|
+
if vae._keys_to_ignore_on_load_unexpected is not None:
|
1386
|
+
for pat in vae._keys_to_ignore_on_load_unexpected:
|
1387
|
+
unexpected_keys = [k for k in unexpected_keys if re.search(pat, k) is None]
|
1388
|
+
|
1389
|
+
if len(unexpected_keys) > 0:
|
1390
|
+
logger.warning(
|
1391
|
+
f"Some weights of the model checkpoint were not used when initializing {vae.__name__}: \n {[', '.join(unexpected_keys)]}"
|
1392
|
+
)
|
1198
1393
|
else:
|
1199
1394
|
vae.load_state_dict(diffusers_format_vae_checkpoint)
|
1200
1395
|
|
1396
|
+
if torch_dtype is not None:
|
1397
|
+
vae = vae.to(torch_dtype)
|
1398
|
+
|
1201
1399
|
return {"vae": vae}
|
1202
1400
|
|
1203
1401
|
|
@@ -1206,8 +1404,9 @@ def create_text_encoders_and_tokenizers_from_ldm(
|
|
1206
1404
|
checkpoint,
|
1207
1405
|
model_type=None,
|
1208
1406
|
local_files_only=False,
|
1407
|
+
torch_dtype=None,
|
1209
1408
|
):
|
1210
|
-
model_type = infer_model_type(original_config, model_type=model_type)
|
1409
|
+
model_type = infer_model_type(original_config, checkpoint=checkpoint, model_type=model_type)
|
1211
1410
|
|
1212
1411
|
if model_type == "FrozenOpenCLIPEmbedder":
|
1213
1412
|
config_name = "stabilityai/stable-diffusion-2"
|
@@ -1215,7 +1414,7 @@ def create_text_encoders_and_tokenizers_from_ldm(
|
|
1215
1414
|
|
1216
1415
|
try:
|
1217
1416
|
text_encoder = create_text_encoder_from_open_clip_checkpoint(
|
1218
|
-
config_name, checkpoint, local_files_only=local_files_only, **config_kwargs
|
1417
|
+
config_name, checkpoint, local_files_only=local_files_only, torch_dtype=torch_dtype, **config_kwargs
|
1219
1418
|
)
|
1220
1419
|
tokenizer = CLIPTokenizer.from_pretrained(
|
1221
1420
|
config_name, subfolder="tokenizer", local_files_only=local_files_only
|
@@ -1231,7 +1430,10 @@ def create_text_encoders_and_tokenizers_from_ldm(
|
|
1231
1430
|
try:
|
1232
1431
|
config_name = "openai/clip-vit-large-patch14"
|
1233
1432
|
text_encoder = create_text_encoder_from_ldm_clip_checkpoint(
|
1234
|
-
config_name,
|
1433
|
+
config_name,
|
1434
|
+
checkpoint,
|
1435
|
+
local_files_only=local_files_only,
|
1436
|
+
torch_dtype=torch_dtype,
|
1235
1437
|
)
|
1236
1438
|
tokenizer = CLIPTokenizer.from_pretrained(config_name, local_files_only=local_files_only)
|
1237
1439
|
|
@@ -1255,6 +1457,7 @@ def create_text_encoders_and_tokenizers_from_ldm(
|
|
1255
1457
|
prefix=prefix,
|
1256
1458
|
has_projection=True,
|
1257
1459
|
local_files_only=local_files_only,
|
1460
|
+
torch_dtype=torch_dtype,
|
1258
1461
|
**config_kwargs,
|
1259
1462
|
)
|
1260
1463
|
except Exception:
|
@@ -1270,12 +1473,12 @@ def create_text_encoders_and_tokenizers_from_ldm(
|
|
1270
1473
|
"text_encoder_2": text_encoder_2,
|
1271
1474
|
}
|
1272
1475
|
|
1273
|
-
elif model_type
|
1476
|
+
elif model_type in ["SDXL", "Playground"]:
|
1274
1477
|
try:
|
1275
1478
|
config_name = "openai/clip-vit-large-patch14"
|
1276
1479
|
tokenizer = CLIPTokenizer.from_pretrained(config_name, local_files_only=local_files_only)
|
1277
1480
|
text_encoder = create_text_encoder_from_ldm_clip_checkpoint(
|
1278
|
-
config_name, checkpoint, local_files_only=local_files_only
|
1481
|
+
config_name, checkpoint, local_files_only=local_files_only, torch_dtype=torch_dtype
|
1279
1482
|
)
|
1280
1483
|
|
1281
1484
|
except Exception:
|
@@ -1294,6 +1497,7 @@ def create_text_encoders_and_tokenizers_from_ldm(
|
|
1294
1497
|
prefix=prefix,
|
1295
1498
|
has_projection=True,
|
1296
1499
|
local_files_only=local_files_only,
|
1500
|
+
torch_dtype=torch_dtype,
|
1297
1501
|
**config_kwargs,
|
1298
1502
|
)
|
1299
1503
|
except Exception:
|
@@ -1320,7 +1524,7 @@ def create_scheduler_from_ldm(
|
|
1320
1524
|
model_type=None,
|
1321
1525
|
):
|
1322
1526
|
scheduler_config = get_default_scheduler_config()
|
1323
|
-
model_type = infer_model_type(original_config, model_type=model_type)
|
1527
|
+
model_type = infer_model_type(original_config, checkpoint=checkpoint, model_type=model_type)
|
1324
1528
|
|
1325
1529
|
global_step = checkpoint["global_step"] if "global_step" in checkpoint else None
|
1326
1530
|
|
@@ -1343,7 +1547,8 @@ def create_scheduler_from_ldm(
|
|
1343
1547
|
|
1344
1548
|
if model_type in ["SDXL", "SDXL-Refiner"]:
|
1345
1549
|
scheduler_type = "euler"
|
1346
|
-
|
1550
|
+
elif model_type == "Playground":
|
1551
|
+
scheduler_type = "edm_dpm_solver_multistep"
|
1347
1552
|
else:
|
1348
1553
|
beta_start = original_config["model"]["params"].get("linear_start", 0.02)
|
1349
1554
|
beta_end = original_config["model"]["params"].get("linear_end", 0.085)
|
@@ -1375,6 +1580,26 @@ def create_scheduler_from_ldm(
|
|
1375
1580
|
elif scheduler_type == "ddim":
|
1376
1581
|
scheduler = DDIMScheduler.from_config(scheduler_config)
|
1377
1582
|
|
1583
|
+
elif scheduler_type == "edm_dpm_solver_multistep":
|
1584
|
+
scheduler_config = {
|
1585
|
+
"algorithm_type": "dpmsolver++",
|
1586
|
+
"dynamic_thresholding_ratio": 0.995,
|
1587
|
+
"euler_at_final": False,
|
1588
|
+
"final_sigmas_type": "zero",
|
1589
|
+
"lower_order_final": True,
|
1590
|
+
"num_train_timesteps": 1000,
|
1591
|
+
"prediction_type": "epsilon",
|
1592
|
+
"rho": 7.0,
|
1593
|
+
"sample_max_value": 1.0,
|
1594
|
+
"sigma_data": 0.5,
|
1595
|
+
"sigma_max": 80.0,
|
1596
|
+
"sigma_min": 0.002,
|
1597
|
+
"solver_order": 2,
|
1598
|
+
"solver_type": "midpoint",
|
1599
|
+
"thresholding": False,
|
1600
|
+
}
|
1601
|
+
scheduler = EDMDPMSolverMultistepScheduler(**scheduler_config)
|
1602
|
+
|
1378
1603
|
else:
|
1379
1604
|
raise ValueError(f"Scheduler of type {scheduler_type} doesn't exist!")
|
1380
1605
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -215,7 +215,7 @@ class TextualInversionLoaderMixin:
|
|
215
215
|
embedding = state_dict["string_to_param"]["*"]
|
216
216
|
else:
|
217
217
|
raise ValueError(
|
218
|
-
f"Loaded state
|
218
|
+
f"Loaded state dictionary is incorrect: {state_dict}. \n\n"
|
219
219
|
"Please verify that the loaded state dictionary of the textual embedding either only has a single key or includes the `string_to_param`"
|
220
220
|
" input key."
|
221
221
|
)
|
@@ -457,6 +457,8 @@ class TextualInversionLoaderMixin:
|
|
457
457
|
def unload_textual_inversion(
|
458
458
|
self,
|
459
459
|
tokens: Optional[Union[str, List[str]]] = None,
|
460
|
+
tokenizer: Optional["PreTrainedTokenizer"] = None,
|
461
|
+
text_encoder: Optional["PreTrainedModel"] = None,
|
460
462
|
):
|
461
463
|
r"""
|
462
464
|
Unload Textual Inversion embeddings from the text encoder of [`StableDiffusionPipeline`]
|
@@ -481,11 +483,28 @@ class TextualInversionLoaderMixin:
|
|
481
483
|
|
482
484
|
# Remove just one token
|
483
485
|
pipeline.unload_textual_inversion("<moe-bius>")
|
486
|
+
|
487
|
+
# Example 3: unload from SDXL
|
488
|
+
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
|
489
|
+
embedding_path = hf_hub_download(repo_id="linoyts/web_y2k", filename="web_y2k_emb.safetensors", repo_type="model")
|
490
|
+
|
491
|
+
# load embeddings to the text encoders
|
492
|
+
state_dict = load_file(embedding_path)
|
493
|
+
|
494
|
+
# load embeddings of text_encoder 1 (CLIP ViT-L/14)
|
495
|
+
pipeline.load_textual_inversion(state_dict["clip_l"], token=["<s0>", "<s1>"], text_encoder=pipeline.text_encoder, tokenizer=pipeline.tokenizer)
|
496
|
+
# load embeddings of text_encoder 2 (CLIP ViT-G/14)
|
497
|
+
pipeline.load_textual_inversion(state_dict["clip_g"], token=["<s0>", "<s1>"], text_encoder=pipeline.text_encoder_2, tokenizer=pipeline.tokenizer_2)
|
498
|
+
|
499
|
+
# Unload explicitly from both text encoders abd tokenizers
|
500
|
+
pipeline.unload_textual_inversion(tokens=["<s0>", "<s1>"], text_encoder=pipeline.text_encoder, tokenizer=pipeline.tokenizer)
|
501
|
+
pipeline.unload_textual_inversion(tokens=["<s0>", "<s1>"], text_encoder=pipeline.text_encoder_2, tokenizer=pipeline.tokenizer_2)
|
502
|
+
|
484
503
|
```
|
485
504
|
"""
|
486
505
|
|
487
|
-
tokenizer = getattr(self, "tokenizer", None)
|
488
|
-
text_encoder = getattr(self, "text_encoder", None)
|
506
|
+
tokenizer = tokenizer or getattr(self, "tokenizer", None)
|
507
|
+
text_encoder = text_encoder or getattr(self, "text_encoder", None)
|
489
508
|
|
490
509
|
# Get textual inversion tokens and ids
|
491
510
|
token_ids = []
|