diffusers 0.23.1__py3-none-any.whl → 0.25.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. diffusers/__init__.py +26 -2
  2. diffusers/commands/fp16_safetensors.py +10 -11
  3. diffusers/configuration_utils.py +13 -8
  4. diffusers/dependency_versions_check.py +0 -1
  5. diffusers/dependency_versions_table.py +5 -5
  6. diffusers/experimental/rl/value_guided_sampling.py +1 -1
  7. diffusers/image_processor.py +463 -51
  8. diffusers/loaders/__init__.py +82 -0
  9. diffusers/loaders/ip_adapter.py +159 -0
  10. diffusers/loaders/lora.py +1553 -0
  11. diffusers/loaders/lora_conversion_utils.py +284 -0
  12. diffusers/loaders/single_file.py +637 -0
  13. diffusers/loaders/textual_inversion.py +455 -0
  14. diffusers/loaders/unet.py +828 -0
  15. diffusers/loaders/utils.py +59 -0
  16. diffusers/models/__init__.py +26 -9
  17. diffusers/models/activations.py +9 -6
  18. diffusers/models/attention.py +301 -29
  19. diffusers/models/attention_flax.py +9 -1
  20. diffusers/models/attention_processor.py +378 -6
  21. diffusers/models/autoencoders/__init__.py +5 -0
  22. diffusers/models/{autoencoder_asym_kl.py → autoencoders/autoencoder_asym_kl.py} +17 -12
  23. diffusers/models/{autoencoder_kl.py → autoencoders/autoencoder_kl.py} +47 -23
  24. diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +402 -0
  25. diffusers/models/{autoencoder_tiny.py → autoencoders/autoencoder_tiny.py} +24 -28
  26. diffusers/models/{consistency_decoder_vae.py → autoencoders/consistency_decoder_vae.py} +51 -44
  27. diffusers/models/{vae.py → autoencoders/vae.py} +71 -17
  28. diffusers/models/controlnet.py +59 -39
  29. diffusers/models/controlnet_flax.py +19 -18
  30. diffusers/models/downsampling.py +338 -0
  31. diffusers/models/embeddings.py +112 -29
  32. diffusers/models/embeddings_flax.py +2 -0
  33. diffusers/models/lora.py +131 -1
  34. diffusers/models/modeling_flax_utils.py +14 -8
  35. diffusers/models/modeling_outputs.py +17 -0
  36. diffusers/models/modeling_utils.py +37 -29
  37. diffusers/models/normalization.py +110 -4
  38. diffusers/models/resnet.py +299 -652
  39. diffusers/models/transformer_2d.py +22 -5
  40. diffusers/models/transformer_temporal.py +183 -1
  41. diffusers/models/unet_2d_blocks_flax.py +5 -0
  42. diffusers/models/unet_2d_condition.py +46 -0
  43. diffusers/models/unet_2d_condition_flax.py +13 -13
  44. diffusers/models/unet_3d_blocks.py +957 -173
  45. diffusers/models/unet_3d_condition.py +16 -8
  46. diffusers/models/unet_kandinsky3.py +535 -0
  47. diffusers/models/unet_motion_model.py +48 -33
  48. diffusers/models/unet_spatio_temporal_condition.py +489 -0
  49. diffusers/models/upsampling.py +454 -0
  50. diffusers/models/uvit_2d.py +471 -0
  51. diffusers/models/vae_flax.py +7 -0
  52. diffusers/models/vq_model.py +12 -3
  53. diffusers/optimization.py +16 -9
  54. diffusers/pipelines/__init__.py +137 -76
  55. diffusers/pipelines/amused/__init__.py +62 -0
  56. diffusers/pipelines/amused/pipeline_amused.py +328 -0
  57. diffusers/pipelines/amused/pipeline_amused_img2img.py +347 -0
  58. diffusers/pipelines/amused/pipeline_amused_inpaint.py +378 -0
  59. diffusers/pipelines/animatediff/pipeline_animatediff.py +66 -8
  60. diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
  61. diffusers/pipelines/auto_pipeline.py +23 -13
  62. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
  63. diffusers/pipelines/controlnet/pipeline_controlnet.py +238 -35
  64. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +148 -37
  65. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +155 -41
  66. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +123 -43
  67. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +216 -39
  68. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +106 -34
  69. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
  70. diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
  71. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
  72. diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
  73. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
  74. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
  75. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
  76. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
  77. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
  78. diffusers/pipelines/deprecated/__init__.py +153 -0
  79. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/__init__.py +3 -3
  80. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion.py +177 -34
  81. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py +182 -37
  82. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_output.py +1 -1
  83. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/__init__.py +1 -1
  84. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/mel.py +2 -2
  85. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py +4 -4
  86. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/__init__.py +1 -1
  87. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/pipeline_latent_diffusion_uncond.py +4 -4
  88. diffusers/pipelines/{pndm → deprecated/pndm}/__init__.py +1 -1
  89. diffusers/pipelines/{pndm → deprecated/pndm}/pipeline_pndm.py +4 -4
  90. diffusers/pipelines/{repaint → deprecated/repaint}/__init__.py +1 -1
  91. diffusers/pipelines/{repaint → deprecated/repaint}/pipeline_repaint.py +5 -5
  92. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/__init__.py +1 -1
  93. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/pipeline_score_sde_ve.py +5 -4
  94. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/__init__.py +6 -6
  95. diffusers/pipelines/{spectrogram_diffusion/continous_encoder.py → deprecated/spectrogram_diffusion/continuous_encoder.py} +2 -2
  96. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/midi_utils.py +1 -1
  97. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py +2 -2
  98. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/pipeline_spectrogram_diffusion.py +8 -7
  99. diffusers/pipelines/deprecated/stable_diffusion_variants/__init__.py +55 -0
  100. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_cycle_diffusion.py +34 -13
  101. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_onnx_stable_diffusion_inpaint_legacy.py +7 -6
  102. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_inpaint_legacy.py +12 -11
  103. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_model_editing.py +17 -11
  104. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_paradigms.py +11 -10
  105. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_pix2pix_zero.py +14 -13
  106. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/__init__.py +1 -1
  107. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/pipeline_stochastic_karras_ve.py +4 -4
  108. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/__init__.py +3 -3
  109. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/modeling_text_unet.py +83 -51
  110. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion.py +4 -4
  111. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_dual_guided.py +7 -6
  112. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_image_variation.py +7 -6
  113. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_text_to_image.py +7 -6
  114. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/__init__.py +3 -3
  115. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/pipeline_vq_diffusion.py +5 -5
  116. diffusers/pipelines/dit/pipeline_dit.py +1 -0
  117. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
  118. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
  119. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  120. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
  121. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
  122. diffusers/pipelines/kandinsky3/__init__.py +49 -0
  123. diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +98 -0
  124. diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +589 -0
  125. diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +654 -0
  126. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +111 -11
  127. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +102 -9
  128. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
  129. diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
  130. diffusers/pipelines/onnx_utils.py +8 -5
  131. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
  132. diffusers/pipelines/pipeline_flax_utils.py +11 -8
  133. diffusers/pipelines/pipeline_utils.py +63 -42
  134. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +247 -38
  135. diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +3 -3
  136. diffusers/pipelines/stable_diffusion/__init__.py +37 -65
  137. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +75 -78
  138. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
  139. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
  140. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
  141. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +174 -11
  142. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
  143. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
  144. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +178 -11
  145. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +224 -13
  146. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +74 -20
  147. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +4 -0
  148. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +7 -0
  149. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -0
  150. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -0
  151. diffusers/pipelines/stable_diffusion_attend_and_excite/__init__.py +48 -0
  152. diffusers/pipelines/{stable_diffusion → stable_diffusion_attend_and_excite}/pipeline_stable_diffusion_attend_and_excite.py +6 -2
  153. diffusers/pipelines/stable_diffusion_diffedit/__init__.py +48 -0
  154. diffusers/pipelines/{stable_diffusion → stable_diffusion_diffedit}/pipeline_stable_diffusion_diffedit.py +3 -3
  155. diffusers/pipelines/stable_diffusion_gligen/__init__.py +50 -0
  156. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py +3 -2
  157. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen_text_image.py +4 -3
  158. diffusers/pipelines/stable_diffusion_k_diffusion/__init__.py +60 -0
  159. diffusers/pipelines/{stable_diffusion → stable_diffusion_k_diffusion}/pipeline_stable_diffusion_k_diffusion.py +7 -1
  160. diffusers/pipelines/stable_diffusion_ldm3d/__init__.py +48 -0
  161. diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py +51 -7
  162. diffusers/pipelines/stable_diffusion_panorama/__init__.py +48 -0
  163. diffusers/pipelines/{stable_diffusion → stable_diffusion_panorama}/pipeline_stable_diffusion_panorama.py +57 -8
  164. diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +58 -6
  165. diffusers/pipelines/stable_diffusion_sag/__init__.py +48 -0
  166. diffusers/pipelines/{stable_diffusion → stable_diffusion_sag}/pipeline_stable_diffusion_sag.py +68 -10
  167. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +194 -17
  168. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +205 -16
  169. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +206 -17
  170. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +23 -17
  171. diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
  172. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +652 -0
  173. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
  174. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +115 -14
  175. diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
  176. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +6 -0
  177. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +23 -3
  178. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +334 -10
  179. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +1331 -0
  180. diffusers/pipelines/unclip/pipeline_unclip.py +2 -1
  181. diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -0
  182. diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
  183. diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
  184. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
  185. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
  186. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
  187. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +5 -1
  188. diffusers/schedulers/__init__.py +4 -4
  189. diffusers/schedulers/deprecated/__init__.py +50 -0
  190. diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
  191. diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
  192. diffusers/schedulers/scheduling_amused.py +162 -0
  193. diffusers/schedulers/scheduling_consistency_models.py +2 -0
  194. diffusers/schedulers/scheduling_ddim.py +1 -3
  195. diffusers/schedulers/scheduling_ddim_inverse.py +2 -7
  196. diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
  197. diffusers/schedulers/scheduling_ddpm.py +47 -3
  198. diffusers/schedulers/scheduling_ddpm_parallel.py +47 -3
  199. diffusers/schedulers/scheduling_deis_multistep.py +28 -6
  200. diffusers/schedulers/scheduling_dpmsolver_multistep.py +28 -6
  201. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +28 -6
  202. diffusers/schedulers/scheduling_dpmsolver_sde.py +3 -3
  203. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +28 -6
  204. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +59 -3
  205. diffusers/schedulers/scheduling_euler_discrete.py +102 -16
  206. diffusers/schedulers/scheduling_heun_discrete.py +17 -5
  207. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +17 -5
  208. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +17 -5
  209. diffusers/schedulers/scheduling_lcm.py +123 -29
  210. diffusers/schedulers/scheduling_lms_discrete.py +3 -3
  211. diffusers/schedulers/scheduling_pndm.py +1 -3
  212. diffusers/schedulers/scheduling_repaint.py +1 -3
  213. diffusers/schedulers/scheduling_unipc_multistep.py +28 -6
  214. diffusers/schedulers/scheduling_utils.py +3 -1
  215. diffusers/schedulers/scheduling_utils_flax.py +3 -1
  216. diffusers/training_utils.py +1 -1
  217. diffusers/utils/__init__.py +1 -2
  218. diffusers/utils/constants.py +10 -12
  219. diffusers/utils/dummy_pt_objects.py +75 -0
  220. diffusers/utils/dummy_torch_and_transformers_objects.py +105 -0
  221. diffusers/utils/dynamic_modules_utils.py +18 -22
  222. diffusers/utils/export_utils.py +8 -3
  223. diffusers/utils/hub_utils.py +24 -36
  224. diffusers/utils/logging.py +11 -11
  225. diffusers/utils/outputs.py +5 -5
  226. diffusers/utils/peft_utils.py +88 -44
  227. diffusers/utils/state_dict_utils.py +8 -0
  228. diffusers/utils/testing_utils.py +199 -1
  229. diffusers/utils/torch_utils.py +4 -4
  230. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/METADATA +86 -69
  231. diffusers-0.25.0.dist-info/RECORD +360 -0
  232. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/WHEEL +1 -1
  233. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/entry_points.txt +0 -1
  234. diffusers/loaders.py +0 -3336
  235. diffusers-0.23.1.dist-info/RECORD +0 -323
  236. /diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/modeling_roberta_series.py +0 -0
  237. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/LICENSE +0 -0
  238. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/top_level.txt +0 -0
@@ -28,7 +28,14 @@ from typing import Any, Callable, Dict, List, Optional, Union
28
28
  import numpy as np
29
29
  import PIL.Image
30
30
  import torch
31
- from huggingface_hub import ModelCard, create_repo, hf_hub_download, model_info, snapshot_download
31
+ from huggingface_hub import (
32
+ ModelCard,
33
+ create_repo,
34
+ hf_hub_download,
35
+ model_info,
36
+ snapshot_download,
37
+ )
38
+ from huggingface_hub.utils import validate_hf_hub_args
32
39
  from packaging import version
33
40
  from requests.exceptions import HTTPError
34
41
  from tqdm.auto import tqdm
@@ -40,8 +47,6 @@ from ..schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
40
47
  from ..utils import (
41
48
  CONFIG_NAME,
42
49
  DEPRECATED_REVISION_ARGS,
43
- DIFFUSERS_CACHE,
44
- HF_HUB_OFFLINE,
45
50
  SAFETENSORS_WEIGHTS_NAME,
46
51
  WEIGHTS_NAME,
47
52
  BaseOutput,
@@ -49,6 +54,7 @@ from ..utils import (
49
54
  get_class_from_dynamic_module,
50
55
  is_accelerate_available,
51
56
  is_accelerate_version,
57
+ is_peft_available,
52
58
  is_torch_version,
53
59
  is_transformers_available,
54
60
  logging,
@@ -248,17 +254,18 @@ def variant_compatible_siblings(filenames, variant=None) -> Union[List[os.PathLi
248
254
  return usable_filenames, variant_filenames
249
255
 
250
256
 
251
- def warn_deprecated_model_variant(pretrained_model_name_or_path, use_auth_token, variant, revision, model_filenames):
257
+ @validate_hf_hub_args
258
+ def warn_deprecated_model_variant(pretrained_model_name_or_path, token, variant, revision, model_filenames):
252
259
  info = model_info(
253
260
  pretrained_model_name_or_path,
254
- use_auth_token=use_auth_token,
261
+ token=token,
255
262
  revision=None,
256
263
  )
257
264
  filenames = {sibling.rfilename for sibling in info.siblings}
258
265
  comp_model_filenames, _ = variant_compatible_siblings(filenames, variant=revision)
259
266
  comp_model_filenames = [".".join(f.split(".")[:1] + f.split(".")[2:]) for f in comp_model_filenames]
260
267
 
261
- if set(comp_model_filenames) == set(model_filenames):
268
+ if set(model_filenames).issubset(set(comp_model_filenames)):
262
269
  warnings.warn(
263
270
  f"You are loading the variant {revision} from {pretrained_model_name_or_path} via `revision='{revision}'` even though you can load it via `variant=`{revision}`. Loading model variants via `revision='{revision}'` is deprecated and will be removed in diffusers v1. Please use `variant='{revision}'` instead.",
264
271
  FutureWarning,
@@ -270,6 +277,20 @@ def warn_deprecated_model_variant(pretrained_model_name_or_path, use_auth_token,
270
277
  )
271
278
 
272
279
 
280
+ def _unwrap_model(model):
281
+ """Unwraps a model."""
282
+ if is_compiled_module(model):
283
+ model = model._orig_mod
284
+
285
+ if is_peft_available():
286
+ from peft import PeftModel
287
+
288
+ if isinstance(model, PeftModel):
289
+ model = model.base_model.model
290
+
291
+ return model
292
+
293
+
273
294
  def maybe_raise_or_warn(
274
295
  library_name, library, class_name, importable_classes, passed_class_obj, name, is_pipeline_module
275
296
  ):
@@ -287,9 +308,8 @@ def maybe_raise_or_warn(
287
308
  # Dynamo wraps the original model in a private class.
288
309
  # I didn't find a public API to get the original class.
289
310
  sub_model = passed_class_obj[name]
290
- model_cls = sub_model.__class__
291
- if is_compiled_module(sub_model):
292
- model_cls = sub_model._orig_mod.__class__
311
+ unwrapped_sub_model = _unwrap_model(sub_model)
312
+ model_cls = unwrapped_sub_model.__class__
293
313
 
294
314
  if not issubclass(model_cls, expected_class_obj):
295
315
  raise ValueError(
@@ -361,7 +381,6 @@ def _get_pipeline_class(
361
381
  custom_pipeline,
362
382
  module_file=file_name,
363
383
  class_name=class_name,
364
- repo_id=repo_id,
365
384
  cache_dir=cache_dir,
366
385
  revision=revision,
367
386
  )
@@ -528,6 +547,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
528
547
  - **_optional_components** (`List[str]`) -- List of all optional components that don't have to be passed to the
529
548
  pipeline to function (should be overridden by subclasses).
530
549
  """
550
+
531
551
  config_name = "model_index.json"
532
552
  model_cpu_offload_seq = None
533
553
  _optional_components = []
@@ -542,14 +562,11 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
542
562
 
543
563
  for name, module in kwargs.items():
544
564
  # retrieve library
545
- if module is None:
565
+ if module is None or isinstance(module, (tuple, list)) and module[0] is None:
546
566
  register_dict = {name: (None, None)}
547
567
  else:
548
568
  # register the config from the original module, not the dynamo compiled one
549
- if is_compiled_module(module):
550
- not_compiled_module = module._orig_mod
551
- else:
552
- not_compiled_module = module
569
+ not_compiled_module = _unwrap_model(module)
553
570
 
554
571
  library = not_compiled_module.__module__.split(".")[0]
555
572
 
@@ -652,7 +669,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
652
669
  # Dynamo wraps the original model in a private class.
653
670
  # I didn't find a public API to get the original class.
654
671
  if is_compiled_module(sub_model):
655
- sub_model = sub_model._orig_mod
672
+ sub_model = _unwrap_model(sub_model)
656
673
  model_cls = sub_model.__class__
657
674
 
658
675
  save_method_name = None
@@ -746,10 +763,10 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
746
763
 
747
764
  torch_dtype = kwargs.pop("torch_dtype", None)
748
765
  if torch_dtype is not None:
749
- deprecate("torch_dtype", "0.25.0", "")
766
+ deprecate("torch_dtype", "0.27.0", "")
750
767
  torch_device = kwargs.pop("torch_device", None)
751
768
  if torch_device is not None:
752
- deprecate("torch_device", "0.25.0", "")
769
+ deprecate("torch_device", "0.27.0", "")
753
770
 
754
771
  dtype_kwarg = kwargs.pop("dtype", None)
755
772
  device_kwarg = kwargs.pop("device", None)
@@ -897,6 +914,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
897
914
  return torch.float32
898
915
 
899
916
  @classmethod
917
+ @validate_hf_hub_args
900
918
  def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.PathLike]], **kwargs):
901
919
  r"""
902
920
  Instantiate a PyTorch diffusion pipeline from pretrained pipeline weights.
@@ -964,7 +982,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
964
982
  local_files_only (`bool`, *optional*, defaults to `False`):
965
983
  Whether to only load local model weights and configuration files or not. If set to `True`, the model
966
984
  won't be downloaded from the Hub.
967
- use_auth_token (`str` or *bool*, *optional*):
985
+ token (`str` or *bool*, *optional*):
968
986
  The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
969
987
  `diffusers-cli login` (stored in `~/.huggingface`) is used.
970
988
  revision (`str`, *optional*, defaults to `"main"`):
@@ -1044,12 +1062,12 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1044
1062
  >>> pipeline.scheduler = scheduler
1045
1063
  ```
1046
1064
  """
1047
- cache_dir = kwargs.pop("cache_dir", DIFFUSERS_CACHE)
1065
+ cache_dir = kwargs.pop("cache_dir", None)
1048
1066
  resume_download = kwargs.pop("resume_download", False)
1049
1067
  force_download = kwargs.pop("force_download", False)
1050
1068
  proxies = kwargs.pop("proxies", None)
1051
- local_files_only = kwargs.pop("local_files_only", HF_HUB_OFFLINE)
1052
- use_auth_token = kwargs.pop("use_auth_token", None)
1069
+ local_files_only = kwargs.pop("local_files_only", None)
1070
+ token = kwargs.pop("token", None)
1053
1071
  revision = kwargs.pop("revision", None)
1054
1072
  from_flax = kwargs.pop("from_flax", False)
1055
1073
  torch_dtype = kwargs.pop("torch_dtype", None)
@@ -1082,7 +1100,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1082
1100
  force_download=force_download,
1083
1101
  proxies=proxies,
1084
1102
  local_files_only=local_files_only,
1085
- use_auth_token=use_auth_token,
1103
+ token=token,
1086
1104
  revision=revision,
1087
1105
  from_flax=from_flax,
1088
1106
  use_safetensors=use_safetensors,
@@ -1287,7 +1305,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1287
1305
  "force_download": force_download,
1288
1306
  "proxies": proxies,
1289
1307
  "local_files_only": local_files_only,
1290
- "use_auth_token": use_auth_token,
1308
+ "token": token,
1291
1309
  "revision": revision,
1292
1310
  "torch_dtype": torch_dtype,
1293
1311
  "custom_pipeline": custom_pipeline,
@@ -1517,6 +1535,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1517
1535
  cpu_offload(model, device, offload_buffers=offload_buffers)
1518
1536
 
1519
1537
  @classmethod
1538
+ @validate_hf_hub_args
1520
1539
  def download(cls, pretrained_model_name, **kwargs) -> Union[str, os.PathLike]:
1521
1540
  r"""
1522
1541
  Download and cache a PyTorch diffusion pipeline from pretrained pipeline weights.
@@ -1564,7 +1583,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1564
1583
  local_files_only (`bool`, *optional*, defaults to `False`):
1565
1584
  Whether to only load local model weights and configuration files or not. If set to `True`, the model
1566
1585
  won't be downloaded from the Hub.
1567
- use_auth_token (`str` or *bool*, *optional*):
1586
+ token (`str` or *bool*, *optional*):
1568
1587
  The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
1569
1588
  `diffusers-cli login` (stored in `~/.huggingface`) is used.
1570
1589
  revision (`str`, *optional*, defaults to `"main"`):
@@ -1607,12 +1626,12 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1607
1626
  </Tip>
1608
1627
 
1609
1628
  """
1610
- cache_dir = kwargs.pop("cache_dir", DIFFUSERS_CACHE)
1629
+ cache_dir = kwargs.pop("cache_dir", None)
1611
1630
  resume_download = kwargs.pop("resume_download", False)
1612
1631
  force_download = kwargs.pop("force_download", False)
1613
1632
  proxies = kwargs.pop("proxies", None)
1614
- local_files_only = kwargs.pop("local_files_only", HF_HUB_OFFLINE)
1615
- use_auth_token = kwargs.pop("use_auth_token", None)
1633
+ local_files_only = kwargs.pop("local_files_only", None)
1634
+ token = kwargs.pop("token", None)
1616
1635
  revision = kwargs.pop("revision", None)
1617
1636
  from_flax = kwargs.pop("from_flax", False)
1618
1637
  custom_pipeline = kwargs.pop("custom_pipeline", None)
@@ -1634,11 +1653,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1634
1653
  model_info_call_error: Optional[Exception] = None
1635
1654
  if not local_files_only:
1636
1655
  try:
1637
- info = model_info(
1638
- pretrained_model_name,
1639
- use_auth_token=use_auth_token,
1640
- revision=revision,
1641
- )
1656
+ info = model_info(pretrained_model_name, token=token, revision=revision)
1642
1657
  except HTTPError as e:
1643
1658
  logger.warn(f"Couldn't connect to the Hub: {e}.\nWill try to load from local cache.")
1644
1659
  local_files_only = True
@@ -1653,7 +1668,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1653
1668
  proxies=proxies,
1654
1669
  force_download=force_download,
1655
1670
  resume_download=resume_download,
1656
- use_auth_token=use_auth_token,
1671
+ token=token,
1657
1672
  )
1658
1673
 
1659
1674
  config_dict = cls._dict_from_json_file(config_file)
@@ -1676,7 +1691,8 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1676
1691
  if module_candidate is None or not isinstance(module_candidate, str):
1677
1692
  continue
1678
1693
 
1679
- candidate_file = os.path.join(component, module_candidate + ".py")
1694
+ # We compute candidate file path on the Hub. Do not use `os.path.join`.
1695
+ candidate_file = f"{component}/{module_candidate}.py"
1680
1696
 
1681
1697
  if candidate_file in filenames:
1682
1698
  custom_components[component] = module_candidate
@@ -1702,9 +1718,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1702
1718
  if revision in DEPRECATED_REVISION_ARGS and version.parse(
1703
1719
  version.parse(__version__).base_version
1704
1720
  ) >= version.parse("0.22.0"):
1705
- warn_deprecated_model_variant(
1706
- pretrained_model_name, use_auth_token, variant, revision, model_filenames
1707
- )
1721
+ warn_deprecated_model_variant(pretrained_model_name, token, variant, revision, model_filenames)
1708
1722
 
1709
1723
  model_folder_names = {os.path.split(f)[0] for f in model_filenames if os.path.split(f)[0] in folder_names}
1710
1724
 
@@ -1846,7 +1860,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1846
1860
  resume_download=resume_download,
1847
1861
  proxies=proxies,
1848
1862
  local_files_only=local_files_only,
1849
- use_auth_token=use_auth_token,
1863
+ token=token,
1850
1864
  revision=revision,
1851
1865
  allow_patterns=allow_patterns,
1852
1866
  ignore_patterns=ignore_patterns,
@@ -1870,7 +1884,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1870
1884
  "force_download": force_download,
1871
1885
  "proxies": proxies,
1872
1886
  "local_files_only": local_files_only,
1873
- "use_auth_token": use_auth_token,
1887
+ "token": token,
1874
1888
  "variant": variant,
1875
1889
  "use_safetensors": use_safetensors,
1876
1890
  }
@@ -1894,12 +1908,19 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
1894
1908
  " above."
1895
1909
  ) from model_info_call_error
1896
1910
 
1897
- @staticmethod
1898
- def _get_signature_keys(obj):
1911
+ @classmethod
1912
+ def _get_signature_keys(cls, obj):
1899
1913
  parameters = inspect.signature(obj.__init__).parameters
1900
1914
  required_parameters = {k: v for k, v in parameters.items() if v.default == inspect._empty}
1901
1915
  optional_parameters = set({k for k, v in parameters.items() if v.default != inspect._empty})
1902
1916
  expected_modules = set(required_parameters.keys()) - {"self"}
1917
+
1918
+ optional_names = list(optional_parameters)
1919
+ for name in optional_names:
1920
+ if name in cls._optional_components:
1921
+ expected_modules.add(name)
1922
+ optional_parameters.remove(name)
1923
+
1903
1924
  return expected_modules, optional_parameters
1904
1925
 
1905
1926
  @property