diffusers 0.33.0__py3-none-any.whl → 0.34.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (478) hide show
  1. diffusers/__init__.py +48 -1
  2. diffusers/commands/__init__.py +1 -1
  3. diffusers/commands/diffusers_cli.py +1 -1
  4. diffusers/commands/env.py +1 -1
  5. diffusers/commands/fp16_safetensors.py +1 -1
  6. diffusers/dependency_versions_check.py +1 -1
  7. diffusers/dependency_versions_table.py +1 -1
  8. diffusers/experimental/rl/value_guided_sampling.py +1 -1
  9. diffusers/hooks/faster_cache.py +2 -2
  10. diffusers/hooks/group_offloading.py +128 -29
  11. diffusers/hooks/hooks.py +2 -2
  12. diffusers/hooks/layerwise_casting.py +3 -3
  13. diffusers/hooks/pyramid_attention_broadcast.py +1 -1
  14. diffusers/image_processor.py +7 -2
  15. diffusers/loaders/__init__.py +4 -0
  16. diffusers/loaders/ip_adapter.py +5 -14
  17. diffusers/loaders/lora_base.py +212 -111
  18. diffusers/loaders/lora_conversion_utils.py +275 -34
  19. diffusers/loaders/lora_pipeline.py +1554 -819
  20. diffusers/loaders/peft.py +52 -109
  21. diffusers/loaders/single_file.py +2 -2
  22. diffusers/loaders/single_file_model.py +20 -4
  23. diffusers/loaders/single_file_utils.py +225 -5
  24. diffusers/loaders/textual_inversion.py +3 -2
  25. diffusers/loaders/transformer_flux.py +1 -1
  26. diffusers/loaders/transformer_sd3.py +2 -2
  27. diffusers/loaders/unet.py +2 -16
  28. diffusers/loaders/unet_loader_utils.py +1 -1
  29. diffusers/loaders/utils.py +1 -1
  30. diffusers/models/__init__.py +15 -1
  31. diffusers/models/activations.py +5 -5
  32. diffusers/models/adapter.py +2 -3
  33. diffusers/models/attention.py +4 -4
  34. diffusers/models/attention_flax.py +10 -10
  35. diffusers/models/attention_processor.py +14 -10
  36. diffusers/models/auto_model.py +47 -10
  37. diffusers/models/autoencoders/__init__.py +1 -0
  38. diffusers/models/autoencoders/autoencoder_asym_kl.py +4 -4
  39. diffusers/models/autoencoders/autoencoder_dc.py +3 -3
  40. diffusers/models/autoencoders/autoencoder_kl.py +4 -4
  41. diffusers/models/autoencoders/autoencoder_kl_allegro.py +4 -4
  42. diffusers/models/autoencoders/autoencoder_kl_cogvideox.py +6 -6
  43. diffusers/models/autoencoders/autoencoder_kl_cosmos.py +1108 -0
  44. diffusers/models/autoencoders/autoencoder_kl_hunyuan_video.py +2 -2
  45. diffusers/models/autoencoders/autoencoder_kl_ltx.py +3 -3
  46. diffusers/models/autoencoders/autoencoder_kl_magvit.py +4 -4
  47. diffusers/models/autoencoders/autoencoder_kl_mochi.py +3 -3
  48. diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +4 -4
  49. diffusers/models/autoencoders/autoencoder_kl_wan.py +256 -22
  50. diffusers/models/autoencoders/autoencoder_oobleck.py +1 -1
  51. diffusers/models/autoencoders/autoencoder_tiny.py +3 -3
  52. diffusers/models/autoencoders/consistency_decoder_vae.py +1 -1
  53. diffusers/models/autoencoders/vae.py +13 -2
  54. diffusers/models/autoencoders/vq_model.py +2 -2
  55. diffusers/models/cache_utils.py +1 -1
  56. diffusers/models/controlnet.py +1 -1
  57. diffusers/models/controlnet_flux.py +1 -1
  58. diffusers/models/controlnet_sd3.py +1 -1
  59. diffusers/models/controlnet_sparsectrl.py +1 -1
  60. diffusers/models/controlnets/__init__.py +1 -0
  61. diffusers/models/controlnets/controlnet.py +3 -3
  62. diffusers/models/controlnets/controlnet_flax.py +1 -1
  63. diffusers/models/controlnets/controlnet_flux.py +16 -15
  64. diffusers/models/controlnets/controlnet_hunyuan.py +2 -2
  65. diffusers/models/controlnets/controlnet_sana.py +290 -0
  66. diffusers/models/controlnets/controlnet_sd3.py +1 -1
  67. diffusers/models/controlnets/controlnet_sparsectrl.py +2 -2
  68. diffusers/models/controlnets/controlnet_union.py +1 -1
  69. diffusers/models/controlnets/controlnet_xs.py +7 -7
  70. diffusers/models/controlnets/multicontrolnet.py +4 -5
  71. diffusers/models/controlnets/multicontrolnet_union.py +5 -6
  72. diffusers/models/downsampling.py +2 -2
  73. diffusers/models/embeddings.py +10 -12
  74. diffusers/models/embeddings_flax.py +2 -2
  75. diffusers/models/lora.py +3 -3
  76. diffusers/models/modeling_utils.py +44 -14
  77. diffusers/models/normalization.py +4 -4
  78. diffusers/models/resnet.py +2 -2
  79. diffusers/models/resnet_flax.py +1 -1
  80. diffusers/models/transformers/__init__.py +5 -0
  81. diffusers/models/transformers/auraflow_transformer_2d.py +70 -24
  82. diffusers/models/transformers/cogvideox_transformer_3d.py +1 -1
  83. diffusers/models/transformers/consisid_transformer_3d.py +1 -1
  84. diffusers/models/transformers/dit_transformer_2d.py +2 -2
  85. diffusers/models/transformers/dual_transformer_2d.py +1 -1
  86. diffusers/models/transformers/hunyuan_transformer_2d.py +2 -2
  87. diffusers/models/transformers/latte_transformer_3d.py +4 -5
  88. diffusers/models/transformers/lumina_nextdit2d.py +2 -2
  89. diffusers/models/transformers/pixart_transformer_2d.py +3 -3
  90. diffusers/models/transformers/prior_transformer.py +1 -1
  91. diffusers/models/transformers/sana_transformer.py +8 -3
  92. diffusers/models/transformers/stable_audio_transformer.py +5 -9
  93. diffusers/models/transformers/t5_film_transformer.py +3 -3
  94. diffusers/models/transformers/transformer_2d.py +1 -1
  95. diffusers/models/transformers/transformer_allegro.py +1 -1
  96. diffusers/models/transformers/transformer_chroma.py +742 -0
  97. diffusers/models/transformers/transformer_cogview3plus.py +5 -10
  98. diffusers/models/transformers/transformer_cogview4.py +317 -25
  99. diffusers/models/transformers/transformer_cosmos.py +579 -0
  100. diffusers/models/transformers/transformer_flux.py +9 -11
  101. diffusers/models/transformers/transformer_hidream_image.py +942 -0
  102. diffusers/models/transformers/transformer_hunyuan_video.py +6 -8
  103. diffusers/models/transformers/transformer_hunyuan_video_framepack.py +416 -0
  104. diffusers/models/transformers/transformer_ltx.py +2 -2
  105. diffusers/models/transformers/transformer_lumina2.py +1 -1
  106. diffusers/models/transformers/transformer_mochi.py +1 -1
  107. diffusers/models/transformers/transformer_omnigen.py +2 -2
  108. diffusers/models/transformers/transformer_sd3.py +7 -7
  109. diffusers/models/transformers/transformer_temporal.py +1 -1
  110. diffusers/models/transformers/transformer_wan.py +24 -8
  111. diffusers/models/transformers/transformer_wan_vace.py +393 -0
  112. diffusers/models/unets/unet_1d.py +1 -1
  113. diffusers/models/unets/unet_1d_blocks.py +1 -1
  114. diffusers/models/unets/unet_2d.py +1 -1
  115. diffusers/models/unets/unet_2d_blocks.py +1 -1
  116. diffusers/models/unets/unet_2d_blocks_flax.py +8 -7
  117. diffusers/models/unets/unet_2d_condition.py +2 -2
  118. diffusers/models/unets/unet_2d_condition_flax.py +2 -2
  119. diffusers/models/unets/unet_3d_blocks.py +1 -1
  120. diffusers/models/unets/unet_3d_condition.py +3 -3
  121. diffusers/models/unets/unet_i2vgen_xl.py +3 -3
  122. diffusers/models/unets/unet_kandinsky3.py +1 -1
  123. diffusers/models/unets/unet_motion_model.py +2 -2
  124. diffusers/models/unets/unet_stable_cascade.py +1 -1
  125. diffusers/models/upsampling.py +2 -2
  126. diffusers/models/vae_flax.py +2 -2
  127. diffusers/models/vq_model.py +1 -1
  128. diffusers/pipelines/__init__.py +37 -6
  129. diffusers/pipelines/allegro/pipeline_allegro.py +11 -11
  130. diffusers/pipelines/amused/pipeline_amused.py +7 -6
  131. diffusers/pipelines/amused/pipeline_amused_img2img.py +6 -5
  132. diffusers/pipelines/amused/pipeline_amused_inpaint.py +6 -5
  133. diffusers/pipelines/animatediff/pipeline_animatediff.py +6 -6
  134. diffusers/pipelines/animatediff/pipeline_animatediff_controlnet.py +6 -6
  135. diffusers/pipelines/animatediff/pipeline_animatediff_sdxl.py +16 -15
  136. diffusers/pipelines/animatediff/pipeline_animatediff_sparsectrl.py +6 -6
  137. diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +5 -5
  138. diffusers/pipelines/animatediff/pipeline_animatediff_video2video_controlnet.py +5 -5
  139. diffusers/pipelines/audioldm/pipeline_audioldm.py +8 -7
  140. diffusers/pipelines/audioldm2/modeling_audioldm2.py +1 -1
  141. diffusers/pipelines/audioldm2/pipeline_audioldm2.py +23 -13
  142. diffusers/pipelines/aura_flow/pipeline_aura_flow.py +48 -11
  143. diffusers/pipelines/auto_pipeline.py +6 -7
  144. diffusers/pipelines/blip_diffusion/modeling_blip2.py +1 -1
  145. diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +2 -2
  146. diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +11 -10
  147. diffusers/pipelines/chroma/__init__.py +49 -0
  148. diffusers/pipelines/chroma/pipeline_chroma.py +949 -0
  149. diffusers/pipelines/chroma/pipeline_chroma_img2img.py +1034 -0
  150. diffusers/pipelines/chroma/pipeline_output.py +21 -0
  151. diffusers/pipelines/cogvideo/pipeline_cogvideox.py +8 -8
  152. diffusers/pipelines/cogvideo/pipeline_cogvideox_fun_control.py +8 -8
  153. diffusers/pipelines/cogvideo/pipeline_cogvideox_image2video.py +8 -8
  154. diffusers/pipelines/cogvideo/pipeline_cogvideox_video2video.py +8 -8
  155. diffusers/pipelines/cogview3/pipeline_cogview3plus.py +9 -9
  156. diffusers/pipelines/cogview4/pipeline_cogview4.py +7 -7
  157. diffusers/pipelines/cogview4/pipeline_cogview4_control.py +7 -7
  158. diffusers/pipelines/consisid/consisid_utils.py +2 -2
  159. diffusers/pipelines/consisid/pipeline_consisid.py +8 -8
  160. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -1
  161. diffusers/pipelines/controlnet/pipeline_controlnet.py +7 -7
  162. diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +8 -8
  163. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +7 -7
  164. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +7 -7
  165. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +14 -14
  166. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +10 -6
  167. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +13 -13
  168. diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py +14 -14
  169. diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py +5 -5
  170. diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl_img2img.py +13 -13
  171. diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +1 -1
  172. diffusers/pipelines/controlnet_hunyuandit/pipeline_hunyuandit_controlnet.py +8 -8
  173. diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet.py +7 -7
  174. diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet_inpainting.py +7 -7
  175. diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs.py +12 -10
  176. diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs_sd_xl.py +9 -7
  177. diffusers/pipelines/cosmos/__init__.py +54 -0
  178. diffusers/pipelines/cosmos/pipeline_cosmos2_text2image.py +673 -0
  179. diffusers/pipelines/cosmos/pipeline_cosmos2_video2world.py +792 -0
  180. diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py +664 -0
  181. diffusers/pipelines/cosmos/pipeline_cosmos_video2world.py +826 -0
  182. diffusers/pipelines/cosmos/pipeline_output.py +40 -0
  183. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +5 -4
  184. diffusers/pipelines/ddim/pipeline_ddim.py +4 -4
  185. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -1
  186. diffusers/pipelines/deepfloyd_if/pipeline_if.py +10 -10
  187. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +10 -10
  188. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +10 -10
  189. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +10 -10
  190. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +10 -10
  191. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +10 -10
  192. diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +8 -8
  193. diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +5 -5
  194. diffusers/pipelines/deprecated/audio_diffusion/mel.py +1 -1
  195. diffusers/pipelines/deprecated/audio_diffusion/pipeline_audio_diffusion.py +3 -3
  196. diffusers/pipelines/deprecated/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py +1 -1
  197. diffusers/pipelines/deprecated/pndm/pipeline_pndm.py +2 -2
  198. diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +4 -3
  199. diffusers/pipelines/deprecated/score_sde_ve/pipeline_score_sde_ve.py +1 -1
  200. diffusers/pipelines/deprecated/spectrogram_diffusion/continuous_encoder.py +1 -1
  201. diffusers/pipelines/deprecated/spectrogram_diffusion/midi_utils.py +1 -1
  202. diffusers/pipelines/deprecated/spectrogram_diffusion/notes_encoder.py +1 -1
  203. diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -1
  204. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +7 -7
  205. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_onnx_stable_diffusion_inpaint_legacy.py +9 -9
  206. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +10 -10
  207. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +10 -8
  208. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +5 -5
  209. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +18 -18
  210. diffusers/pipelines/deprecated/stochastic_karras_ve/pipeline_stochastic_karras_ve.py +1 -1
  211. diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +2 -2
  212. diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion.py +6 -6
  213. diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +5 -5
  214. diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +5 -5
  215. diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +5 -5
  216. diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +1 -1
  217. diffusers/pipelines/dit/pipeline_dit.py +1 -1
  218. diffusers/pipelines/easyanimate/pipeline_easyanimate.py +4 -4
  219. diffusers/pipelines/easyanimate/pipeline_easyanimate_control.py +4 -4
  220. diffusers/pipelines/easyanimate/pipeline_easyanimate_inpaint.py +7 -6
  221. diffusers/pipelines/flux/modeling_flux.py +1 -1
  222. diffusers/pipelines/flux/pipeline_flux.py +10 -17
  223. diffusers/pipelines/flux/pipeline_flux_control.py +6 -6
  224. diffusers/pipelines/flux/pipeline_flux_control_img2img.py +6 -6
  225. diffusers/pipelines/flux/pipeline_flux_control_inpaint.py +6 -6
  226. diffusers/pipelines/flux/pipeline_flux_controlnet.py +6 -6
  227. diffusers/pipelines/flux/pipeline_flux_controlnet_image_to_image.py +30 -22
  228. diffusers/pipelines/flux/pipeline_flux_controlnet_inpainting.py +2 -1
  229. diffusers/pipelines/flux/pipeline_flux_fill.py +6 -6
  230. diffusers/pipelines/flux/pipeline_flux_img2img.py +39 -6
  231. diffusers/pipelines/flux/pipeline_flux_inpaint.py +11 -6
  232. diffusers/pipelines/flux/pipeline_flux_prior_redux.py +1 -1
  233. diffusers/pipelines/free_init_utils.py +2 -2
  234. diffusers/pipelines/free_noise_utils.py +3 -3
  235. diffusers/pipelines/hidream_image/__init__.py +47 -0
  236. diffusers/pipelines/hidream_image/pipeline_hidream_image.py +1026 -0
  237. diffusers/pipelines/hidream_image/pipeline_output.py +35 -0
  238. diffusers/pipelines/hunyuan_video/__init__.py +2 -0
  239. diffusers/pipelines/hunyuan_video/pipeline_hunyuan_skyreels_image2video.py +8 -8
  240. diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video.py +8 -8
  241. diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video_framepack.py +1114 -0
  242. diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video_image2video.py +71 -15
  243. diffusers/pipelines/hunyuan_video/pipeline_output.py +19 -0
  244. diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py +8 -8
  245. diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +10 -8
  246. diffusers/pipelines/kandinsky/pipeline_kandinsky.py +6 -6
  247. diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +34 -34
  248. diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +19 -26
  249. diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +7 -7
  250. diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +11 -11
  251. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +6 -6
  252. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +35 -35
  253. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +6 -6
  254. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +17 -39
  255. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +17 -45
  256. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +7 -7
  257. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +10 -10
  258. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py +10 -10
  259. diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +7 -7
  260. diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +17 -38
  261. diffusers/pipelines/kolors/pipeline_kolors.py +10 -10
  262. diffusers/pipelines/kolors/pipeline_kolors_img2img.py +12 -12
  263. diffusers/pipelines/kolors/text_encoder.py +3 -3
  264. diffusers/pipelines/kolors/tokenizer.py +1 -1
  265. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +2 -2
  266. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +2 -2
  267. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -1
  268. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion_superresolution.py +3 -3
  269. diffusers/pipelines/latte/pipeline_latte.py +12 -12
  270. diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +13 -13
  271. diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +17 -16
  272. diffusers/pipelines/ltx/__init__.py +4 -0
  273. diffusers/pipelines/ltx/modeling_latent_upsampler.py +188 -0
  274. diffusers/pipelines/ltx/pipeline_ltx.py +51 -6
  275. diffusers/pipelines/ltx/pipeline_ltx_condition.py +107 -29
  276. diffusers/pipelines/ltx/pipeline_ltx_image2video.py +50 -6
  277. diffusers/pipelines/ltx/pipeline_ltx_latent_upsample.py +277 -0
  278. diffusers/pipelines/lumina/pipeline_lumina.py +13 -13
  279. diffusers/pipelines/lumina2/pipeline_lumina2.py +10 -10
  280. diffusers/pipelines/marigold/marigold_image_processing.py +2 -2
  281. diffusers/pipelines/mochi/pipeline_mochi.py +6 -6
  282. diffusers/pipelines/musicldm/pipeline_musicldm.py +16 -13
  283. diffusers/pipelines/omnigen/pipeline_omnigen.py +13 -11
  284. diffusers/pipelines/omnigen/processor_omnigen.py +8 -3
  285. diffusers/pipelines/onnx_utils.py +15 -2
  286. diffusers/pipelines/pag/pag_utils.py +2 -2
  287. diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py +12 -8
  288. diffusers/pipelines/pag/pipeline_pag_controlnet_sd_inpaint.py +7 -7
  289. diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py +10 -6
  290. diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl_img2img.py +14 -14
  291. diffusers/pipelines/pag/pipeline_pag_hunyuandit.py +8 -8
  292. diffusers/pipelines/pag/pipeline_pag_kolors.py +10 -10
  293. diffusers/pipelines/pag/pipeline_pag_pixart_sigma.py +11 -11
  294. diffusers/pipelines/pag/pipeline_pag_sana.py +18 -12
  295. diffusers/pipelines/pag/pipeline_pag_sd.py +8 -8
  296. diffusers/pipelines/pag/pipeline_pag_sd_3.py +7 -7
  297. diffusers/pipelines/pag/pipeline_pag_sd_3_img2img.py +7 -7
  298. diffusers/pipelines/pag/pipeline_pag_sd_animatediff.py +6 -6
  299. diffusers/pipelines/pag/pipeline_pag_sd_img2img.py +5 -5
  300. diffusers/pipelines/pag/pipeline_pag_sd_inpaint.py +8 -8
  301. diffusers/pipelines/pag/pipeline_pag_sd_xl.py +16 -15
  302. diffusers/pipelines/pag/pipeline_pag_sd_xl_img2img.py +18 -17
  303. diffusers/pipelines/pag/pipeline_pag_sd_xl_inpaint.py +12 -12
  304. diffusers/pipelines/paint_by_example/image_encoder.py +1 -1
  305. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +8 -7
  306. diffusers/pipelines/pia/pipeline_pia.py +8 -6
  307. diffusers/pipelines/pipeline_flax_utils.py +3 -4
  308. diffusers/pipelines/pipeline_loading_utils.py +89 -13
  309. diffusers/pipelines/pipeline_utils.py +105 -33
  310. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +11 -11
  311. diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py +11 -11
  312. diffusers/pipelines/sana/__init__.py +4 -0
  313. diffusers/pipelines/sana/pipeline_sana.py +23 -21
  314. diffusers/pipelines/sana/pipeline_sana_controlnet.py +1106 -0
  315. diffusers/pipelines/sana/pipeline_sana_sprint.py +23 -19
  316. diffusers/pipelines/sana/pipeline_sana_sprint_img2img.py +981 -0
  317. diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +7 -6
  318. diffusers/pipelines/shap_e/camera.py +1 -1
  319. diffusers/pipelines/shap_e/pipeline_shap_e.py +1 -1
  320. diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +1 -1
  321. diffusers/pipelines/shap_e/renderer.py +3 -3
  322. diffusers/pipelines/stable_audio/modeling_stable_audio.py +1 -1
  323. diffusers/pipelines/stable_audio/pipeline_stable_audio.py +5 -5
  324. diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +8 -8
  325. diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +13 -13
  326. diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +9 -9
  327. diffusers/pipelines/stable_diffusion/__init__.py +0 -7
  328. diffusers/pipelines/stable_diffusion/clip_image_project_model.py +1 -1
  329. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +11 -4
  330. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +1 -1
  331. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_img2img.py +1 -1
  332. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_inpaint.py +1 -1
  333. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +10 -10
  334. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +10 -10
  335. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +10 -10
  336. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +9 -9
  337. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +8 -8
  338. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +5 -5
  339. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +5 -5
  340. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +5 -5
  341. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +5 -5
  342. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +5 -5
  343. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +4 -4
  344. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +5 -5
  345. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +7 -7
  346. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -5
  347. diffusers/pipelines/stable_diffusion/safety_checker.py +1 -1
  348. diffusers/pipelines/stable_diffusion/safety_checker_flax.py +1 -1
  349. diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py +1 -1
  350. diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +7 -7
  351. diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +7 -7
  352. diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +7 -7
  353. diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +12 -8
  354. diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +15 -9
  355. diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +11 -9
  356. diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +11 -9
  357. diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +18 -12
  358. diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +11 -8
  359. diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +11 -8
  360. diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +15 -12
  361. diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +8 -6
  362. diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
  363. diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +15 -11
  364. diffusers/pipelines/stable_diffusion_xl/pipeline_flax_stable_diffusion_xl.py +1 -1
  365. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +16 -15
  366. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +18 -17
  367. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +12 -12
  368. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +16 -15
  369. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +3 -3
  370. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +12 -12
  371. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +18 -17
  372. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +12 -7
  373. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +12 -7
  374. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +15 -13
  375. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +24 -21
  376. diffusers/pipelines/unclip/pipeline_unclip.py +4 -3
  377. diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +4 -3
  378. diffusers/pipelines/unclip/text_proj.py +2 -2
  379. diffusers/pipelines/unidiffuser/modeling_text_decoder.py +2 -2
  380. diffusers/pipelines/unidiffuser/modeling_uvit.py +1 -1
  381. diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +8 -7
  382. diffusers/pipelines/visualcloze/__init__.py +52 -0
  383. diffusers/pipelines/visualcloze/pipeline_visualcloze_combined.py +444 -0
  384. diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py +952 -0
  385. diffusers/pipelines/visualcloze/visualcloze_utils.py +251 -0
  386. diffusers/pipelines/wan/__init__.py +2 -0
  387. diffusers/pipelines/wan/pipeline_wan.py +17 -12
  388. diffusers/pipelines/wan/pipeline_wan_i2v.py +42 -20
  389. diffusers/pipelines/wan/pipeline_wan_vace.py +976 -0
  390. diffusers/pipelines/wan/pipeline_wan_video2video.py +18 -18
  391. diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
  392. diffusers/pipelines/wuerstchen/modeling_wuerstchen_diffnext.py +1 -1
  393. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +1 -1
  394. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +8 -8
  395. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +16 -15
  396. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +6 -6
  397. diffusers/quantizers/__init__.py +179 -1
  398. diffusers/quantizers/base.py +6 -1
  399. diffusers/quantizers/bitsandbytes/bnb_quantizer.py +4 -0
  400. diffusers/quantizers/bitsandbytes/utils.py +10 -7
  401. diffusers/quantizers/gguf/gguf_quantizer.py +13 -4
  402. diffusers/quantizers/gguf/utils.py +16 -13
  403. diffusers/quantizers/quantization_config.py +18 -16
  404. diffusers/quantizers/quanto/quanto_quantizer.py +4 -0
  405. diffusers/quantizers/torchao/torchao_quantizer.py +5 -1
  406. diffusers/schedulers/__init__.py +3 -1
  407. diffusers/schedulers/deprecated/scheduling_karras_ve.py +4 -3
  408. diffusers/schedulers/deprecated/scheduling_sde_vp.py +1 -1
  409. diffusers/schedulers/scheduling_consistency_models.py +1 -1
  410. diffusers/schedulers/scheduling_cosine_dpmsolver_multistep.py +10 -5
  411. diffusers/schedulers/scheduling_ddim.py +8 -8
  412. diffusers/schedulers/scheduling_ddim_cogvideox.py +5 -5
  413. diffusers/schedulers/scheduling_ddim_flax.py +6 -6
  414. diffusers/schedulers/scheduling_ddim_inverse.py +6 -6
  415. diffusers/schedulers/scheduling_ddim_parallel.py +22 -22
  416. diffusers/schedulers/scheduling_ddpm.py +9 -9
  417. diffusers/schedulers/scheduling_ddpm_flax.py +7 -7
  418. diffusers/schedulers/scheduling_ddpm_parallel.py +18 -18
  419. diffusers/schedulers/scheduling_ddpm_wuerstchen.py +2 -2
  420. diffusers/schedulers/scheduling_deis_multistep.py +8 -8
  421. diffusers/schedulers/scheduling_dpm_cogvideox.py +5 -5
  422. diffusers/schedulers/scheduling_dpmsolver_multistep.py +12 -12
  423. diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +22 -20
  424. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +11 -11
  425. diffusers/schedulers/scheduling_dpmsolver_sde.py +2 -2
  426. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +13 -13
  427. diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +13 -8
  428. diffusers/schedulers/scheduling_edm_euler.py +20 -11
  429. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +3 -3
  430. diffusers/schedulers/scheduling_euler_discrete.py +3 -3
  431. diffusers/schedulers/scheduling_euler_discrete_flax.py +3 -3
  432. diffusers/schedulers/scheduling_flow_match_euler_discrete.py +20 -5
  433. diffusers/schedulers/scheduling_flow_match_heun_discrete.py +1 -1
  434. diffusers/schedulers/scheduling_flow_match_lcm.py +561 -0
  435. diffusers/schedulers/scheduling_heun_discrete.py +2 -2
  436. diffusers/schedulers/scheduling_ipndm.py +2 -2
  437. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +2 -2
  438. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +2 -2
  439. diffusers/schedulers/scheduling_karras_ve_flax.py +5 -5
  440. diffusers/schedulers/scheduling_lcm.py +3 -3
  441. diffusers/schedulers/scheduling_lms_discrete.py +2 -2
  442. diffusers/schedulers/scheduling_lms_discrete_flax.py +1 -1
  443. diffusers/schedulers/scheduling_pndm.py +4 -4
  444. diffusers/schedulers/scheduling_pndm_flax.py +4 -4
  445. diffusers/schedulers/scheduling_repaint.py +9 -9
  446. diffusers/schedulers/scheduling_sasolver.py +15 -15
  447. diffusers/schedulers/scheduling_scm.py +1 -1
  448. diffusers/schedulers/scheduling_sde_ve.py +1 -1
  449. diffusers/schedulers/scheduling_sde_ve_flax.py +2 -2
  450. diffusers/schedulers/scheduling_tcd.py +3 -3
  451. diffusers/schedulers/scheduling_unclip.py +5 -5
  452. diffusers/schedulers/scheduling_unipc_multistep.py +11 -11
  453. diffusers/schedulers/scheduling_utils.py +1 -1
  454. diffusers/schedulers/scheduling_utils_flax.py +1 -1
  455. diffusers/schedulers/scheduling_vq_diffusion.py +1 -1
  456. diffusers/training_utils.py +13 -5
  457. diffusers/utils/__init__.py +5 -0
  458. diffusers/utils/accelerate_utils.py +1 -1
  459. diffusers/utils/doc_utils.py +1 -1
  460. diffusers/utils/dummy_pt_objects.py +120 -0
  461. diffusers/utils/dummy_torch_and_transformers_objects.py +225 -0
  462. diffusers/utils/dynamic_modules_utils.py +21 -3
  463. diffusers/utils/export_utils.py +1 -1
  464. diffusers/utils/import_utils.py +81 -18
  465. diffusers/utils/logging.py +1 -1
  466. diffusers/utils/outputs.py +2 -1
  467. diffusers/utils/peft_utils.py +91 -8
  468. diffusers/utils/state_dict_utils.py +20 -3
  469. diffusers/utils/testing_utils.py +59 -7
  470. diffusers/utils/torch_utils.py +25 -5
  471. diffusers/video_processor.py +2 -2
  472. {diffusers-0.33.0.dist-info → diffusers-0.34.0.dist-info}/METADATA +3 -3
  473. diffusers-0.34.0.dist-info/RECORD +639 -0
  474. diffusers-0.33.0.dist-info/RECORD +0 -608
  475. {diffusers-0.33.0.dist-info → diffusers-0.34.0.dist-info}/LICENSE +0 -0
  476. {diffusers-0.33.0.dist-info → diffusers-0.34.0.dist-info}/WHEEL +0 -0
  477. {diffusers-0.33.0.dist-info → diffusers-0.34.0.dist-info}/entry_points.txt +0 -0
  478. {diffusers-0.33.0.dist-info → diffusers-0.34.0.dist-info}/top_level.txt +0 -0
diffusers/loaders/peft.py CHANGED
@@ -13,6 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  import inspect
16
+ import json
16
17
  import os
17
18
  from functools import partial
18
19
  from pathlib import Path
@@ -28,13 +29,13 @@ from ..utils import (
28
29
  convert_unet_state_dict_to_peft,
29
30
  delete_adapter_layers,
30
31
  get_adapter_name,
31
- get_peft_kwargs,
32
32
  is_peft_available,
33
33
  is_peft_version,
34
34
  logging,
35
35
  set_adapter_layers,
36
36
  set_weights_and_activate_adapters,
37
37
  )
38
+ from ..utils.peft_utils import _create_lora_config, _maybe_warn_for_unhandled_keys
38
39
  from .lora_base import _fetch_state_dict, _func_optionally_disable_offloading
39
40
  from .unet_loader_utils import _maybe_expand_lora_scales
40
41
 
@@ -52,32 +53,17 @@ _SET_ADAPTER_SCALE_FN_MAPPING = {
52
53
  "HunyuanVideoTransformer3DModel": lambda model_cls, weights: weights,
53
54
  "LTXVideoTransformer3DModel": lambda model_cls, weights: weights,
54
55
  "SanaTransformer2DModel": lambda model_cls, weights: weights,
56
+ "AuraFlowTransformer2DModel": lambda model_cls, weights: weights,
55
57
  "Lumina2Transformer2DModel": lambda model_cls, weights: weights,
56
58
  "WanTransformer3DModel": lambda model_cls, weights: weights,
57
59
  "CogView4Transformer2DModel": lambda model_cls, weights: weights,
60
+ "HiDreamImageTransformer2DModel": lambda model_cls, weights: weights,
61
+ "HunyuanVideoFramepackTransformer3DModel": lambda model_cls, weights: weights,
62
+ "WanVACETransformer3DModel": lambda model_cls, weights: weights,
63
+ "ChromaTransformer2DModel": lambda model_cls, weights: weights,
58
64
  }
59
65
 
60
66
 
61
- def _maybe_raise_error_for_ambiguity(config):
62
- rank_pattern = config["rank_pattern"].copy()
63
- target_modules = config["target_modules"]
64
-
65
- for key in list(rank_pattern.keys()):
66
- # try to detect ambiguity
67
- # `target_modules` can also be a str, in which case this loop would loop
68
- # over the chars of the str. The technically correct way to match LoRA keys
69
- # in PEFT is to use LoraModel._check_target_module_exists (lora_config, key).
70
- # But this cuts it for now.
71
- exact_matches = [mod for mod in target_modules if mod == key]
72
- substring_matches = [mod for mod in target_modules if key in mod and mod != key]
73
-
74
- if exact_matches and substring_matches:
75
- if is_peft_version("<", "0.14.1"):
76
- raise ValueError(
77
- "There are ambiguous keys present in this LoRA. To load it, please update your `peft` installation - `pip install -U peft`."
78
- )
79
-
80
-
81
67
  class PeftAdapterMixin:
82
68
  """
83
69
  A class containing all functions for loading and using adapters weights that are supported in PEFT library. For
@@ -99,17 +85,6 @@ class PeftAdapterMixin:
99
85
  @classmethod
100
86
  # Copied from diffusers.loaders.lora_base.LoraBaseMixin._optionally_disable_offloading
101
87
  def _optionally_disable_offloading(cls, _pipeline):
102
- """
103
- Optionally removes offloading in case the pipeline has been already sequentially offloaded to CPU.
104
-
105
- Args:
106
- _pipeline (`DiffusionPipeline`):
107
- The pipeline to disable offloading for.
108
-
109
- Returns:
110
- tuple:
111
- A tuple indicating if `is_model_cpu_offload` or `is_sequential_cpu_offload` is True.
112
- """
113
88
  return _func_optionally_disable_offloading(_pipeline=_pipeline)
114
89
 
115
90
  def load_lora_adapter(
@@ -181,8 +156,11 @@ class PeftAdapterMixin:
181
156
  Note that hotswapping adapters of the text encoder is not yet supported. There are some further
182
157
  limitations to this technique, which are documented here:
183
158
  https://huggingface.co/docs/peft/main/en/package_reference/hotswap
159
+ metadata:
160
+ LoRA adapter metadata. When supplied, the metadata inferred through the state dict isn't used to
161
+ initialize `LoraConfig`.
184
162
  """
185
- from peft import LoraConfig, inject_adapter_in_model, set_peft_model_state_dict
163
+ from peft import inject_adapter_in_model, set_peft_model_state_dict
186
164
  from peft.tuners.tuners_utils import BaseTunerLayer
187
165
 
188
166
  cache_dir = kwargs.pop("cache_dir", None)
@@ -198,6 +176,7 @@ class PeftAdapterMixin:
198
176
  network_alphas = kwargs.pop("network_alphas", None)
199
177
  _pipeline = kwargs.pop("_pipeline", None)
200
178
  low_cpu_mem_usage = kwargs.pop("low_cpu_mem_usage", False)
179
+ metadata = kwargs.pop("metadata", None)
201
180
  allow_pickle = False
202
181
 
203
182
  if low_cpu_mem_usage and is_peft_version("<=", "0.13.0"):
@@ -205,12 +184,8 @@ class PeftAdapterMixin:
205
184
  "`low_cpu_mem_usage=True` is not compatible with this `peft` version. Please update it with `pip install -U peft`."
206
185
  )
207
186
 
208
- user_agent = {
209
- "file_type": "attn_procs_weights",
210
- "framework": "pytorch",
211
- }
212
-
213
- state_dict = _fetch_state_dict(
187
+ user_agent = {"file_type": "attn_procs_weights", "framework": "pytorch"}
188
+ state_dict, metadata = _fetch_state_dict(
214
189
  pretrained_model_name_or_path_or_dict=pretrained_model_name_or_path_or_dict,
215
190
  weight_name=weight_name,
216
191
  use_safetensors=use_safetensors,
@@ -223,12 +198,17 @@ class PeftAdapterMixin:
223
198
  subfolder=subfolder,
224
199
  user_agent=user_agent,
225
200
  allow_pickle=allow_pickle,
201
+ metadata=metadata,
226
202
  )
227
203
  if network_alphas is not None and prefix is None:
228
204
  raise ValueError("`network_alphas` cannot be None when `prefix` is None.")
205
+ if network_alphas and metadata:
206
+ raise ValueError("Both `network_alphas` and `metadata` cannot be specified.")
229
207
 
230
208
  if prefix is not None:
231
- state_dict = {k[len(f"{prefix}.") :]: v for k, v in state_dict.items() if k.startswith(f"{prefix}.")}
209
+ state_dict = {k.removeprefix(f"{prefix}."): v for k, v in state_dict.items() if k.startswith(f"{prefix}.")}
210
+ if metadata is not None:
211
+ metadata = {k.removeprefix(f"{prefix}."): v for k, v in metadata.items() if k.startswith(f"{prefix}.")}
232
212
 
233
213
  if len(state_dict) > 0:
234
214
  if adapter_name in getattr(self, "peft_config", {}) and not hotswap:
@@ -248,7 +228,7 @@ class PeftAdapterMixin:
248
228
 
249
229
  rank = {}
250
230
  for key, val in state_dict.items():
251
- # Cannot figure out rank from lora layers that don't have atleast 2 dimensions.
231
+ # Cannot figure out rank from lora layers that don't have at least 2 dimensions.
252
232
  # Bias layers in LoRA only have a single dimension
253
233
  if "lora_B" in key and val.ndim > 1:
254
234
  # Check out https://github.com/huggingface/peft/pull/2419 for the `^` symbol.
@@ -259,32 +239,13 @@ class PeftAdapterMixin:
259
239
 
260
240
  if network_alphas is not None and len(network_alphas) >= 1:
261
241
  alpha_keys = [k for k in network_alphas.keys() if k.startswith(f"{prefix}.")]
262
- network_alphas = {k.replace(f"{prefix}.", ""): v for k, v in network_alphas.items() if k in alpha_keys}
242
+ network_alphas = {
243
+ k.removeprefix(f"{prefix}."): v for k, v in network_alphas.items() if k in alpha_keys
244
+ }
263
245
 
264
- lora_config_kwargs = get_peft_kwargs(rank, network_alpha_dict=network_alphas, peft_state_dict=state_dict)
265
- _maybe_raise_error_for_ambiguity(lora_config_kwargs)
246
+ # create LoraConfig
247
+ lora_config = _create_lora_config(state_dict, network_alphas, metadata, rank)
266
248
 
267
- if "use_dora" in lora_config_kwargs:
268
- if lora_config_kwargs["use_dora"]:
269
- if is_peft_version("<", "0.9.0"):
270
- raise ValueError(
271
- "You need `peft` 0.9.0 at least to use DoRA-enabled LoRAs. Please upgrade your installation of `peft`."
272
- )
273
- else:
274
- if is_peft_version("<", "0.9.0"):
275
- lora_config_kwargs.pop("use_dora")
276
-
277
- if "lora_bias" in lora_config_kwargs:
278
- if lora_config_kwargs["lora_bias"]:
279
- if is_peft_version("<=", "0.13.2"):
280
- raise ValueError(
281
- "You need `peft` 0.14.0 at least to use `lora_bias` in LoRAs. Please upgrade your installation of `peft`."
282
- )
283
- else:
284
- if is_peft_version("<=", "0.13.2"):
285
- lora_config_kwargs.pop("lora_bias")
286
-
287
- lora_config = LoraConfig(**lora_config_kwargs)
288
249
  # adapter_name
289
250
  if adapter_name is None:
290
251
  adapter_name = get_adapter_name(self)
@@ -294,9 +255,8 @@ class PeftAdapterMixin:
294
255
  # Now we remove any existing hooks to `_pipeline`.
295
256
 
296
257
  # In case the pipeline has been already offloaded to CPU - temporarily remove the hooks
297
- # otherwise loading LoRA weights will lead to an error
258
+ # otherwise loading LoRA weights will lead to an error.
298
259
  is_model_cpu_offload, is_sequential_cpu_offload = self._optionally_disable_offloading(_pipeline)
299
-
300
260
  peft_kwargs = {}
301
261
  if is_peft_version(">=", "0.13.1"):
302
262
  peft_kwargs["low_cpu_mem_usage"] = low_cpu_mem_usage
@@ -328,7 +288,7 @@ class PeftAdapterMixin:
328
288
  new_sd[k] = v
329
289
  return new_sd
330
290
 
331
- # To handle scenarios where we cannot successfully set state dict. If it's unsucessful,
291
+ # To handle scenarios where we cannot successfully set state dict. If it's unsuccessful,
332
292
  # we should also delete the `peft_config` associated to the `adapter_name`.
333
293
  try:
334
294
  if hotswap:
@@ -342,7 +302,7 @@ class PeftAdapterMixin:
342
302
  config=lora_config,
343
303
  )
344
304
  except Exception as e:
345
- logger.error(f"Hotswapping {adapter_name} was unsucessful with the following error: \n{e}")
305
+ logger.error(f"Hotswapping {adapter_name} was unsuccessful with the following error: \n{e}")
346
306
  raise
347
307
  # the hotswap function raises if there are incompatible keys, so if we reach this point we can set
348
308
  # it to None
@@ -377,33 +337,10 @@ class PeftAdapterMixin:
377
337
  module.delete_adapter(adapter_name)
378
338
 
379
339
  self.peft_config.pop(adapter_name)
380
- logger.error(f"Loading {adapter_name} was unsucessful with the following error: \n{e}")
340
+ logger.error(f"Loading {adapter_name} was unsuccessful with the following error: \n{e}")
381
341
  raise
382
342
 
383
- warn_msg = ""
384
- if incompatible_keys is not None:
385
- # Check only for unexpected keys.
386
- unexpected_keys = getattr(incompatible_keys, "unexpected_keys", None)
387
- if unexpected_keys:
388
- lora_unexpected_keys = [k for k in unexpected_keys if "lora_" in k and adapter_name in k]
389
- if lora_unexpected_keys:
390
- warn_msg = (
391
- f"Loading adapter weights from state_dict led to unexpected keys found in the model:"
392
- f" {', '.join(lora_unexpected_keys)}. "
393
- )
394
-
395
- # Filter missing keys specific to the current adapter.
396
- missing_keys = getattr(incompatible_keys, "missing_keys", None)
397
- if missing_keys:
398
- lora_missing_keys = [k for k in missing_keys if "lora_" in k and adapter_name in k]
399
- if lora_missing_keys:
400
- warn_msg += (
401
- f"Loading adapter weights from state_dict led to missing keys in the model:"
402
- f" {', '.join(lora_missing_keys)}."
403
- )
404
-
405
- if warn_msg:
406
- logger.warning(warn_msg)
343
+ _maybe_warn_for_unhandled_keys(incompatible_keys, adapter_name)
407
344
 
408
345
  # Offload back.
409
346
  if is_model_cpu_offload:
@@ -413,10 +350,11 @@ class PeftAdapterMixin:
413
350
  # Unsafe code />
414
351
 
415
352
  if prefix is not None and not state_dict:
353
+ model_class_name = self.__class__.__name__
416
354
  logger.warning(
417
- f"No LoRA keys associated to {self.__class__.__name__} found with the {prefix=}. "
355
+ f"No LoRA keys associated to {model_class_name} found with the {prefix=}. "
418
356
  "This is safe to ignore if LoRA state dict didn't originally have any "
419
- f"{self.__class__.__name__} related params. You can also try specifying `prefix=None` "
357
+ f"{model_class_name} related params. You can also try specifying `prefix=None` "
420
358
  "to resolve the warning. Otherwise, open an issue if you think it's unexpected: "
421
359
  "https://github.com/huggingface/diffusers/issues/new"
422
360
  )
@@ -439,17 +377,13 @@ class PeftAdapterMixin:
439
377
  underlying model has multiple adapters loaded.
440
378
  upcast_before_saving (`bool`, defaults to `False`):
441
379
  Whether to cast the underlying model to `torch.float32` before serialization.
442
- save_function (`Callable`):
443
- The function to use to save the state dictionary. Useful during distributed training when you need to
444
- replace `torch.save` with another method. Can be configured with the environment variable
445
- `DIFFUSERS_SAVE_MODE`.
446
380
  safe_serialization (`bool`, *optional*, defaults to `True`):
447
381
  Whether to save the model using `safetensors` or the traditional PyTorch way with `pickle`.
448
382
  weight_name: (`str`, *optional*, defaults to `None`): Name of the file to serialize the state dict with.
449
383
  """
450
384
  from peft.utils import get_peft_model_state_dict
451
385
 
452
- from .lora_base import LORA_WEIGHT_NAME, LORA_WEIGHT_NAME_SAFE
386
+ from .lora_base import LORA_ADAPTER_METADATA_KEY, LORA_WEIGHT_NAME, LORA_WEIGHT_NAME_SAFE
453
387
 
454
388
  if adapter_name is None:
455
389
  adapter_name = get_adapter_name(self)
@@ -457,6 +391,8 @@ class PeftAdapterMixin:
457
391
  if adapter_name not in getattr(self, "peft_config", {}):
458
392
  raise ValueError(f"Adapter name {adapter_name} not found in the model.")
459
393
 
394
+ lora_adapter_metadata = self.peft_config[adapter_name].to_dict()
395
+
460
396
  lora_layers_to_save = get_peft_model_state_dict(
461
397
  self.to(dtype=torch.float32 if upcast_before_saving else None), adapter_name=adapter_name
462
398
  )
@@ -466,7 +402,15 @@ class PeftAdapterMixin:
466
402
  if safe_serialization:
467
403
 
468
404
  def save_function(weights, filename):
469
- return safetensors.torch.save_file(weights, filename, metadata={"format": "pt"})
405
+ # Inject framework format.
406
+ metadata = {"format": "pt"}
407
+ if lora_adapter_metadata is not None:
408
+ for key, value in lora_adapter_metadata.items():
409
+ if isinstance(value, set):
410
+ lora_adapter_metadata[key] = list(value)
411
+ metadata[LORA_ADAPTER_METADATA_KEY] = json.dumps(lora_adapter_metadata, indent=2, sort_keys=True)
412
+
413
+ return safetensors.torch.save_file(weights, filename, metadata=metadata)
470
414
 
471
415
  else:
472
416
  save_function = torch.save
@@ -479,7 +423,6 @@ class PeftAdapterMixin:
479
423
  else:
480
424
  weight_name = LORA_WEIGHT_NAME
481
425
 
482
- # TODO: we could consider saving the `peft_config` as well.
483
426
  save_path = Path(save_directory, weight_name).as_posix()
484
427
  save_function(lora_layers_to_save, save_path)
485
428
  logger.info(f"Model weights saved in {save_path}")
@@ -490,7 +433,7 @@ class PeftAdapterMixin:
490
433
  weights: Optional[Union[float, Dict, List[float], List[Dict], List[None]]] = None,
491
434
  ):
492
435
  """
493
- Set the currently active adapters for use in the UNet.
436
+ Set the currently active adapters for use in the diffusion network (e.g. unet, transformer, etc.).
494
437
 
495
438
  Args:
496
439
  adapter_names (`List[str]` or `str`):
@@ -512,7 +455,7 @@ class PeftAdapterMixin:
512
455
  "jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
513
456
  )
514
457
  pipeline.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
515
- pipeline.set_adapters(["cinematic", "pixel"], adapter_weights=[0.5, 0.5])
458
+ pipeline.unet.set_adapters(["cinematic", "pixel"], adapter_weights=[0.5, 0.5])
516
459
  ```
517
460
  """
518
461
  if not USE_PEFT_BACKEND:
@@ -710,7 +653,7 @@ class PeftAdapterMixin:
710
653
  if self.lora_scale != 1.0:
711
654
  module.scale_layer(self.lora_scale)
712
655
 
713
- # For BC with prevous PEFT versions, we need to check the signature
656
+ # For BC with previous PEFT versions, we need to check the signature
714
657
  # of the `merge` method to see if it supports the `adapter_names` argument.
715
658
  supported_merge_kwargs = list(inspect.signature(module.merge).parameters)
716
659
  if "adapter_names" in supported_merge_kwargs:
@@ -760,7 +703,7 @@ class PeftAdapterMixin:
760
703
  pipeline.load_lora_weights(
761
704
  "jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
762
705
  )
763
- pipeline.disable_lora()
706
+ pipeline.unet.disable_lora()
764
707
  ```
765
708
  """
766
709
  if not USE_PEFT_BACKEND:
@@ -783,7 +726,7 @@ class PeftAdapterMixin:
783
726
  pipeline.load_lora_weights(
784
727
  "jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
785
728
  )
786
- pipeline.enable_lora()
729
+ pipeline.unet.enable_lora()
787
730
  ```
788
731
  """
789
732
  if not USE_PEFT_BACKEND:
@@ -810,7 +753,7 @@ class PeftAdapterMixin:
810
753
  pipeline.load_lora_weights(
811
754
  "jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_names="cinematic"
812
755
  )
813
- pipeline.delete_adapters("cinematic")
756
+ pipeline.unet.delete_adapters("cinematic")
814
757
  ```
815
758
  """
816
759
  if not USE_PEFT_BACKEND:
@@ -1,4 +1,4 @@
1
- # Copyright 2024 The HuggingFace Team. All rights reserved.
1
+ # Copyright 2025 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.
@@ -453,7 +453,7 @@ class FromSingleFileMixin:
453
453
  logger.warning(
454
454
  "Detected legacy `from_single_file` loading behavior. Attempting to create the pipeline based on inferred components.\n"
455
455
  "This may lead to errors if the model components are not correctly inferred. \n"
456
- "To avoid this warning, please explicity pass the `config` argument to `from_single_file` with a path to a local diffusers model repo \n"
456
+ "To avoid this warning, please explicitly pass the `config` argument to `from_single_file` with a path to a local diffusers model repo \n"
457
457
  "e.g. `from_single_file(<my model checkpoint path>, config=<path to local diffusers model repo>) \n"
458
458
  "or run `from_single_file` with `local_files_only=False` first to update the local cache directory with "
459
459
  "the necessary config files.\n"
@@ -1,4 +1,4 @@
1
- # Copyright 2024 The HuggingFace Team. All rights reserved.
1
+ # Copyright 2025 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.
@@ -21,6 +21,7 @@ import torch
21
21
  from huggingface_hub.utils import validate_hf_hub_args
22
22
  from typing_extensions import Self
23
23
 
24
+ from .. import __version__
24
25
  from ..quantizers import DiffusersAutoQuantizer
25
26
  from ..utils import deprecate, is_accelerate_available, logging
26
27
  from .single_file_utils import (
@@ -28,8 +29,10 @@ from .single_file_utils import (
28
29
  convert_animatediff_checkpoint_to_diffusers,
29
30
  convert_auraflow_transformer_checkpoint_to_diffusers,
30
31
  convert_autoencoder_dc_checkpoint_to_diffusers,
32
+ convert_chroma_transformer_checkpoint_to_diffusers,
31
33
  convert_controlnet_checkpoint,
32
34
  convert_flux_transformer_checkpoint_to_diffusers,
35
+ convert_hidream_transformer_to_diffusers,
33
36
  convert_hunyuan_video_transformer_to_diffusers,
34
37
  convert_ldm_unet_checkpoint,
35
38
  convert_ldm_vae_checkpoint,
@@ -95,6 +98,10 @@ SINGLE_FILE_LOADABLE_CLASSES = {
95
98
  "checkpoint_mapping_fn": convert_flux_transformer_checkpoint_to_diffusers,
96
99
  "default_subfolder": "transformer",
97
100
  },
101
+ "ChromaTransformer2DModel": {
102
+ "checkpoint_mapping_fn": convert_chroma_transformer_checkpoint_to_diffusers,
103
+ "default_subfolder": "transformer",
104
+ },
98
105
  "LTXVideoTransformer3DModel": {
99
106
  "checkpoint_mapping_fn": convert_ltx_transformer_checkpoint_to_diffusers,
100
107
  "default_subfolder": "transformer",
@@ -132,6 +139,10 @@ SINGLE_FILE_LOADABLE_CLASSES = {
132
139
  "checkpoint_mapping_fn": convert_wan_vae_to_diffusers,
133
140
  "default_subfolder": "vae",
134
141
  },
142
+ "HiDreamImageTransformer2DModel": {
143
+ "checkpoint_mapping_fn": convert_hidream_transformer_to_diffusers,
144
+ "default_subfolder": "transformer",
145
+ },
135
146
  }
136
147
 
137
148
 
@@ -186,9 +197,8 @@ class FromOriginalModelMixin:
186
197
  original_config (`str`, *optional*):
187
198
  Dict or path to a yaml file containing the configuration for the model in its original format.
188
199
  If a dict is provided, it will be used to initialize the model configuration.
189
- torch_dtype (`str` or `torch.dtype`, *optional*):
190
- Override the default `torch.dtype` and load the model with another dtype. If `"auto"` is passed, the
191
- dtype is automatically derived from the model's weights.
200
+ torch_dtype (`torch.dtype`, *optional*):
201
+ Override the default `torch.dtype` and load the model with another dtype.
192
202
  force_download (`bool`, *optional*, defaults to `False`):
193
203
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
194
204
  cached versions if they exist.
@@ -260,6 +270,11 @@ class FromOriginalModelMixin:
260
270
  device = kwargs.pop("device", None)
261
271
  disable_mmap = kwargs.pop("disable_mmap", False)
262
272
 
273
+ user_agent = {"diffusers": __version__, "file_type": "single_file", "framework": "pytorch"}
274
+ # In order to ensure popular quantization methods are supported. Can be disable with `disable_telemetry`
275
+ if quantization_config is not None:
276
+ user_agent["quant"] = quantization_config.quant_method.value
277
+
263
278
  if torch_dtype is not None and not isinstance(torch_dtype, torch.dtype):
264
279
  torch_dtype = torch.float32
265
280
  logger.warning(
@@ -278,6 +293,7 @@ class FromOriginalModelMixin:
278
293
  local_files_only=local_files_only,
279
294
  revision=revision,
280
295
  disable_mmap=disable_mmap,
296
+ user_agent=user_agent,
281
297
  )
282
298
  if quantization_config is not None:
283
299
  hf_quantizer = DiffusersAutoQuantizer.from_config(quantization_config)