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.
Files changed (299) hide show
  1. diffusers/__init__.py +20 -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/configuration_utils.py +7 -3
  7. diffusers/dependency_versions_check.py +1 -1
  8. diffusers/dependency_versions_table.py +2 -2
  9. diffusers/experimental/rl/value_guided_sampling.py +1 -1
  10. diffusers/image_processor.py +110 -4
  11. diffusers/loaders/autoencoder.py +7 -8
  12. diffusers/loaders/controlnet.py +17 -8
  13. diffusers/loaders/ip_adapter.py +86 -23
  14. diffusers/loaders/lora.py +105 -310
  15. diffusers/loaders/lora_conversion_utils.py +1 -1
  16. diffusers/loaders/peft.py +1 -1
  17. diffusers/loaders/single_file.py +51 -12
  18. diffusers/loaders/single_file_utils.py +274 -49
  19. diffusers/loaders/textual_inversion.py +23 -4
  20. diffusers/loaders/unet.py +195 -41
  21. diffusers/loaders/utils.py +1 -1
  22. diffusers/models/__init__.py +3 -1
  23. diffusers/models/activations.py +9 -9
  24. diffusers/models/attention.py +26 -36
  25. diffusers/models/attention_flax.py +1 -1
  26. diffusers/models/attention_processor.py +171 -114
  27. diffusers/models/autoencoders/autoencoder_asym_kl.py +1 -1
  28. diffusers/models/autoencoders/autoencoder_kl.py +3 -1
  29. diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +1 -1
  30. diffusers/models/autoencoders/autoencoder_tiny.py +4 -2
  31. diffusers/models/autoencoders/consistency_decoder_vae.py +1 -1
  32. diffusers/models/autoencoders/vae.py +1 -1
  33. diffusers/models/controlnet.py +1 -1
  34. diffusers/models/controlnet_flax.py +1 -1
  35. diffusers/models/downsampling.py +8 -12
  36. diffusers/models/dual_transformer_2d.py +1 -1
  37. diffusers/models/embeddings.py +3 -4
  38. diffusers/models/embeddings_flax.py +1 -1
  39. diffusers/models/lora.py +33 -10
  40. diffusers/models/modeling_flax_pytorch_utils.py +1 -1
  41. diffusers/models/modeling_flax_utils.py +1 -1
  42. diffusers/models/modeling_pytorch_flax_utils.py +1 -1
  43. diffusers/models/modeling_utils.py +4 -6
  44. diffusers/models/normalization.py +1 -1
  45. diffusers/models/resnet.py +31 -58
  46. diffusers/models/resnet_flax.py +1 -1
  47. diffusers/models/t5_film_transformer.py +1 -1
  48. diffusers/models/transformer_2d.py +1 -1
  49. diffusers/models/transformer_temporal.py +1 -1
  50. diffusers/models/transformers/dual_transformer_2d.py +1 -1
  51. diffusers/models/transformers/t5_film_transformer.py +1 -1
  52. diffusers/models/transformers/transformer_2d.py +29 -31
  53. diffusers/models/transformers/transformer_temporal.py +1 -1
  54. diffusers/models/unet_1d.py +1 -1
  55. diffusers/models/unet_1d_blocks.py +1 -1
  56. diffusers/models/unet_2d.py +1 -1
  57. diffusers/models/unet_2d_blocks.py +1 -1
  58. diffusers/models/unet_2d_condition.py +1 -1
  59. diffusers/models/unets/__init__.py +1 -0
  60. diffusers/models/unets/unet_1d.py +1 -1
  61. diffusers/models/unets/unet_1d_blocks.py +1 -1
  62. diffusers/models/unets/unet_2d.py +4 -4
  63. diffusers/models/unets/unet_2d_blocks.py +238 -98
  64. diffusers/models/unets/unet_2d_blocks_flax.py +1 -1
  65. diffusers/models/unets/unet_2d_condition.py +420 -323
  66. diffusers/models/unets/unet_2d_condition_flax.py +21 -12
  67. diffusers/models/unets/unet_3d_blocks.py +50 -40
  68. diffusers/models/unets/unet_3d_condition.py +47 -8
  69. diffusers/models/unets/unet_i2vgen_xl.py +75 -30
  70. diffusers/models/unets/unet_kandinsky3.py +1 -1
  71. diffusers/models/unets/unet_motion_model.py +48 -8
  72. diffusers/models/unets/unet_spatio_temporal_condition.py +1 -1
  73. diffusers/models/unets/unet_stable_cascade.py +610 -0
  74. diffusers/models/unets/uvit_2d.py +1 -1
  75. diffusers/models/upsampling.py +10 -16
  76. diffusers/models/vae_flax.py +1 -1
  77. diffusers/models/vq_model.py +1 -1
  78. diffusers/optimization.py +1 -1
  79. diffusers/pipelines/__init__.py +26 -0
  80. diffusers/pipelines/amused/pipeline_amused.py +1 -1
  81. diffusers/pipelines/amused/pipeline_amused_img2img.py +1 -1
  82. diffusers/pipelines/amused/pipeline_amused_inpaint.py +1 -1
  83. diffusers/pipelines/animatediff/pipeline_animatediff.py +162 -417
  84. diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +165 -137
  85. diffusers/pipelines/animatediff/pipeline_output.py +7 -6
  86. diffusers/pipelines/audioldm/pipeline_audioldm.py +3 -19
  87. diffusers/pipelines/audioldm2/modeling_audioldm2.py +1 -1
  88. diffusers/pipelines/audioldm2/pipeline_audioldm2.py +3 -3
  89. diffusers/pipelines/auto_pipeline.py +7 -16
  90. diffusers/pipelines/blip_diffusion/blip_image_processing.py +1 -1
  91. diffusers/pipelines/blip_diffusion/modeling_blip2.py +1 -1
  92. diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +2 -2
  93. diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +2 -2
  94. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -1
  95. diffusers/pipelines/controlnet/pipeline_controlnet.py +90 -90
  96. diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +2 -2
  97. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +98 -90
  98. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +92 -90
  99. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +145 -70
  100. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +126 -89
  101. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +108 -96
  102. diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +2 -2
  103. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -1
  104. diffusers/pipelines/ddim/pipeline_ddim.py +1 -1
  105. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -1
  106. diffusers/pipelines/deepfloyd_if/pipeline_if.py +4 -4
  107. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +4 -4
  108. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +5 -5
  109. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +4 -4
  110. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +5 -5
  111. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +5 -5
  112. diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +10 -120
  113. diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +10 -91
  114. diffusers/pipelines/deprecated/audio_diffusion/mel.py +1 -1
  115. diffusers/pipelines/deprecated/audio_diffusion/pipeline_audio_diffusion.py +1 -1
  116. diffusers/pipelines/deprecated/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py +1 -1
  117. diffusers/pipelines/deprecated/pndm/pipeline_pndm.py +1 -1
  118. diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +1 -1
  119. diffusers/pipelines/deprecated/score_sde_ve/pipeline_score_sde_ve.py +1 -1
  120. diffusers/pipelines/deprecated/spectrogram_diffusion/continuous_encoder.py +1 -1
  121. diffusers/pipelines/deprecated/spectrogram_diffusion/midi_utils.py +1 -1
  122. diffusers/pipelines/deprecated/spectrogram_diffusion/notes_encoder.py +1 -1
  123. diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -1
  124. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +5 -4
  125. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +5 -4
  126. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +7 -22
  127. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +5 -39
  128. diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +5 -5
  129. diffusers/pipelines/deprecated/stochastic_karras_ve/pipeline_stochastic_karras_ve.py +1 -1
  130. diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +31 -22
  131. diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +1 -1
  132. diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +1 -1
  133. diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +1 -2
  134. diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +1 -1
  135. diffusers/pipelines/dit/pipeline_dit.py +1 -1
  136. diffusers/pipelines/free_init_utils.py +184 -0
  137. diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +22 -104
  138. diffusers/pipelines/kandinsky/pipeline_kandinsky.py +1 -1
  139. diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +1 -1
  140. diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +1 -1
  141. diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +2 -2
  142. diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +1 -1
  143. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
  144. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +1 -1
  145. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +1 -1
  146. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +1 -1
  147. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  148. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +2 -2
  149. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +104 -93
  150. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +112 -74
  151. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -1
  152. diffusers/pipelines/ledits_pp/__init__.py +55 -0
  153. diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +1505 -0
  154. diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +1797 -0
  155. diffusers/pipelines/ledits_pp/pipeline_output.py +43 -0
  156. diffusers/pipelines/musicldm/pipeline_musicldm.py +3 -19
  157. diffusers/pipelines/onnx_utils.py +1 -1
  158. diffusers/pipelines/paint_by_example/image_encoder.py +1 -1
  159. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +3 -3
  160. diffusers/pipelines/pia/pipeline_pia.py +168 -327
  161. diffusers/pipelines/pipeline_flax_utils.py +1 -1
  162. diffusers/pipelines/pipeline_loading_utils.py +508 -0
  163. diffusers/pipelines/pipeline_utils.py +188 -534
  164. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +56 -10
  165. diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +3 -3
  166. diffusers/pipelines/shap_e/camera.py +1 -1
  167. diffusers/pipelines/shap_e/pipeline_shap_e.py +1 -1
  168. diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +1 -1
  169. diffusers/pipelines/shap_e/renderer.py +1 -1
  170. diffusers/pipelines/stable_cascade/__init__.py +50 -0
  171. diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +482 -0
  172. diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +311 -0
  173. diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +638 -0
  174. diffusers/pipelines/stable_diffusion/clip_image_project_model.py +1 -1
  175. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +4 -1
  176. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +1 -1
  177. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_img2img.py +2 -2
  178. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion_inpaint.py +1 -1
  179. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +1 -1
  180. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +1 -1
  181. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -1
  182. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +1 -1
  183. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +90 -146
  184. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +5 -4
  185. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +4 -32
  186. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -119
  187. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +92 -119
  188. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +13 -59
  189. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +3 -31
  190. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +5 -33
  191. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -21
  192. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +7 -21
  193. diffusers/pipelines/stable_diffusion/safety_checker.py +1 -1
  194. diffusers/pipelines/stable_diffusion/safety_checker_flax.py +1 -1
  195. diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py +1 -1
  196. diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +5 -21
  197. diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +9 -38
  198. diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +5 -34
  199. diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +6 -35
  200. diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +7 -6
  201. diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +4 -124
  202. diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +282 -80
  203. diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +94 -46
  204. diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +3 -3
  205. diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
  206. diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +6 -22
  207. diffusers/pipelines/stable_diffusion_xl/pipeline_flax_stable_diffusion_xl.py +1 -1
  208. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +96 -148
  209. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +98 -154
  210. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +98 -153
  211. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +25 -87
  212. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +89 -80
  213. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +5 -49
  214. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +80 -88
  215. diffusers/pipelines/text_to_video_synthesis/pipeline_output.py +8 -6
  216. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +15 -86
  217. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +20 -93
  218. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +5 -5
  219. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +3 -19
  220. diffusers/pipelines/unclip/pipeline_unclip.py +1 -1
  221. diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -1
  222. diffusers/pipelines/unclip/text_proj.py +1 -1
  223. diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +35 -35
  224. diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
  225. diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +4 -21
  226. diffusers/pipelines/wuerstchen/modeling_wuerstchen_diffnext.py +2 -2
  227. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +4 -5
  228. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +8 -8
  229. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +1 -1
  230. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +2 -2
  231. diffusers/schedulers/__init__.py +7 -1
  232. diffusers/schedulers/deprecated/scheduling_karras_ve.py +1 -1
  233. diffusers/schedulers/deprecated/scheduling_sde_vp.py +1 -1
  234. diffusers/schedulers/scheduling_consistency_models.py +42 -19
  235. diffusers/schedulers/scheduling_ddim.py +2 -4
  236. diffusers/schedulers/scheduling_ddim_flax.py +13 -5
  237. diffusers/schedulers/scheduling_ddim_inverse.py +2 -4
  238. diffusers/schedulers/scheduling_ddim_parallel.py +2 -4
  239. diffusers/schedulers/scheduling_ddpm.py +2 -4
  240. diffusers/schedulers/scheduling_ddpm_flax.py +1 -1
  241. diffusers/schedulers/scheduling_ddpm_parallel.py +2 -4
  242. diffusers/schedulers/scheduling_ddpm_wuerstchen.py +1 -1
  243. diffusers/schedulers/scheduling_deis_multistep.py +46 -19
  244. diffusers/schedulers/scheduling_dpmsolver_multistep.py +107 -21
  245. diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +1 -1
  246. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +9 -7
  247. diffusers/schedulers/scheduling_dpmsolver_sde.py +35 -35
  248. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +49 -18
  249. diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +683 -0
  250. diffusers/schedulers/scheduling_edm_euler.py +381 -0
  251. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +43 -15
  252. diffusers/schedulers/scheduling_euler_discrete.py +42 -17
  253. diffusers/schedulers/scheduling_euler_discrete_flax.py +1 -1
  254. diffusers/schedulers/scheduling_heun_discrete.py +35 -35
  255. diffusers/schedulers/scheduling_ipndm.py +37 -11
  256. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +44 -44
  257. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +44 -44
  258. diffusers/schedulers/scheduling_karras_ve_flax.py +1 -1
  259. diffusers/schedulers/scheduling_lcm.py +38 -14
  260. diffusers/schedulers/scheduling_lms_discrete.py +43 -15
  261. diffusers/schedulers/scheduling_lms_discrete_flax.py +1 -1
  262. diffusers/schedulers/scheduling_pndm.py +2 -4
  263. diffusers/schedulers/scheduling_pndm_flax.py +2 -4
  264. diffusers/schedulers/scheduling_repaint.py +1 -1
  265. diffusers/schedulers/scheduling_sasolver.py +41 -9
  266. diffusers/schedulers/scheduling_sde_ve.py +1 -1
  267. diffusers/schedulers/scheduling_sde_ve_flax.py +1 -1
  268. diffusers/schedulers/scheduling_tcd.py +686 -0
  269. diffusers/schedulers/scheduling_unclip.py +1 -1
  270. diffusers/schedulers/scheduling_unipc_multistep.py +46 -19
  271. diffusers/schedulers/scheduling_utils.py +2 -1
  272. diffusers/schedulers/scheduling_utils_flax.py +1 -1
  273. diffusers/schedulers/scheduling_vq_diffusion.py +1 -1
  274. diffusers/training_utils.py +9 -2
  275. diffusers/utils/__init__.py +2 -1
  276. diffusers/utils/accelerate_utils.py +1 -1
  277. diffusers/utils/constants.py +1 -1
  278. diffusers/utils/doc_utils.py +1 -1
  279. diffusers/utils/dummy_pt_objects.py +60 -0
  280. diffusers/utils/dummy_torch_and_transformers_objects.py +75 -0
  281. diffusers/utils/dynamic_modules_utils.py +1 -1
  282. diffusers/utils/export_utils.py +3 -3
  283. diffusers/utils/hub_utils.py +60 -16
  284. diffusers/utils/import_utils.py +15 -1
  285. diffusers/utils/loading_utils.py +2 -0
  286. diffusers/utils/logging.py +1 -1
  287. diffusers/utils/model_card_template.md +24 -0
  288. diffusers/utils/outputs.py +14 -7
  289. diffusers/utils/peft_utils.py +1 -1
  290. diffusers/utils/state_dict_utils.py +1 -1
  291. diffusers/utils/testing_utils.py +2 -0
  292. diffusers/utils/torch_utils.py +1 -1
  293. {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/METADATA +46 -46
  294. diffusers-0.27.0.dist-info/RECORD +399 -0
  295. {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/WHEEL +1 -1
  296. diffusers-0.26.3.dist-info/RECORD +0 -384
  297. {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/LICENSE +0 -0
  298. {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/entry_points.txt +0 -0
  299. {diffusers-0.26.3.dist-info → diffusers-0.27.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright 2023 Alibaba DAMO-VILAB and The HuggingFace Team. All rights reserved.
1
+ # Copyright 2024 Alibaba DAMO-VILAB and 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.
@@ -22,21 +22,16 @@ import torch
22
22
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
23
23
 
24
24
  from ...image_processor import PipelineImageInput, VaeImageProcessor
25
- from ...loaders import LoraLoaderMixin
26
25
  from ...models import AutoencoderKL
27
- from ...models.lora import adjust_lora_scale_text_encoder
28
26
  from ...models.unets.unet_i2vgen_xl import I2VGenXLUNet
29
27
  from ...schedulers import DDIMScheduler
30
28
  from ...utils import (
31
- USE_PEFT_BACKEND,
32
29
  BaseOutput,
33
30
  logging,
34
31
  replace_example_docstring,
35
- scale_lora_layers,
36
- unscale_lora_layers,
37
32
  )
38
33
  from ...utils.torch_utils import randn_tensor
39
- from ..pipeline_utils import DiffusionPipeline
34
+ from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
40
35
 
41
36
 
42
37
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -46,11 +41,12 @@ EXAMPLE_DOC_STRING = """
46
41
  ```py
47
42
  >>> import torch
48
43
  >>> from diffusers import I2VGenXLPipeline
44
+ >>> from diffusers.utils import export_to_gif, load_image
49
45
 
50
46
  >>> pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
51
47
  >>> pipeline.enable_model_cpu_offload()
52
48
 
53
- >>> image_url = "https://github.com/ali-vilab/i2vgen-xl/blob/main/data/test_images/img_0009.png?raw=true"
49
+ >>> image_url = "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/i2vgen_xl_images/img_0009.png"
54
50
  >>> image = load_image(image_url).convert("RGB")
55
51
 
56
52
  >>> prompt = "Papers were floating in the air on a table in the library"
@@ -87,7 +83,7 @@ def tensor2vid(video: torch.Tensor, processor: "VaeImageProcessor", output_type:
87
83
  outputs = torch.stack(outputs)
88
84
 
89
85
  elif not output_type == "pil":
90
- raise ValueError(f"{output_type} does not exist. Please choose one of ['np', 'pt', 'pil]")
86
+ raise ValueError(f"{output_type} does not exist. Please choose one of ['np', 'pt', 'pil']")
91
87
 
92
88
  return outputs
93
89
 
@@ -95,18 +91,22 @@ def tensor2vid(video: torch.Tensor, processor: "VaeImageProcessor", output_type:
95
91
  @dataclass
96
92
  class I2VGenXLPipelineOutput(BaseOutput):
97
93
  r"""
98
- Output class for image-to-video pipeline.
94
+ Output class for image-to-video pipeline.
99
95
 
100
- Args:
101
- frames (`List[np.ndarray]` or `torch.FloatTensor`)
102
- List of denoised frames (essentially images) as NumPy arrays of shape `(height, width, num_channels)` or as
103
- a `torch` tensor. The length of the list denotes the video length (the number of frames).
96
+ Args:
97
+ frames (`torch.Tensor`, `np.ndarray`, or List[List[PIL.Image.Image]]):
98
+ List of video outputs - It can be a nested list of length `batch_size,` with each sub-list containing denoised
99
+ PIL image sequences of length `num_frames.` It can also be a NumPy array or Torch tensor of shape
100
+ `(batch_size, num_frames, channels, height, width)`
104
101
  """
105
102
 
106
- frames: Union[List[np.ndarray], torch.FloatTensor]
103
+ frames: Union[torch.Tensor, np.ndarray, List[List[PIL.Image.Image]]]
107
104
 
108
105
 
109
- class I2VGenXLPipeline(DiffusionPipeline):
106
+ class I2VGenXLPipeline(
107
+ DiffusionPipeline,
108
+ StableDiffusionMixin,
109
+ ):
110
110
  r"""
111
111
  Pipeline for image-to-video generation as proposed in [I2VGenXL](https://i2vgen-xl.github.io/).
112
112
 
@@ -164,39 +164,6 @@ class I2VGenXLPipeline(DiffusionPipeline):
164
164
  def do_classifier_free_guidance(self):
165
165
  return self._guidance_scale > 1
166
166
 
167
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
168
- def enable_vae_slicing(self):
169
- r"""
170
- Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
171
- compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
172
- """
173
- self.vae.enable_slicing()
174
-
175
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
176
- def disable_vae_slicing(self):
177
- r"""
178
- Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
179
- computing decoding in one step.
180
- """
181
- self.vae.disable_slicing()
182
-
183
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
184
- def enable_vae_tiling(self):
185
- r"""
186
- Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
187
- compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
188
- processing larger images.
189
- """
190
- self.vae.enable_tiling()
191
-
192
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
193
- def disable_vae_tiling(self):
194
- r"""
195
- Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
196
- computing decoding in one step.
197
- """
198
- self.vae.disable_tiling()
199
-
200
167
  def encode_prompt(
201
168
  self,
202
169
  prompt,
@@ -205,7 +172,6 @@ class I2VGenXLPipeline(DiffusionPipeline):
205
172
  negative_prompt=None,
206
173
  prompt_embeds: Optional[torch.FloatTensor] = None,
207
174
  negative_prompt_embeds: Optional[torch.FloatTensor] = None,
208
- lora_scale: Optional[float] = None,
209
175
  clip_skip: Optional[int] = None,
210
176
  ):
211
177
  r"""
@@ -231,23 +197,10 @@ class I2VGenXLPipeline(DiffusionPipeline):
231
197
  Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
232
198
  weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
233
199
  argument.
234
- lora_scale (`float`, *optional*):
235
- A LoRA scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded.
236
200
  clip_skip (`int`, *optional*):
237
201
  Number of layers to be skipped from CLIP while computing the prompt embeddings. A value of 1 means that
238
202
  the output of the pre-final layer will be used for computing the prompt embeddings.
239
203
  """
240
- # set lora scale so that monkey patched LoRA
241
- # function of text encoder can correctly access it
242
- if lora_scale is not None and isinstance(self, LoraLoaderMixin):
243
- self._lora_scale = lora_scale
244
-
245
- # dynamically adjust the LoRA scale
246
- if not USE_PEFT_BACKEND:
247
- adjust_lora_scale_text_encoder(self.text_encoder, lora_scale)
248
- else:
249
- scale_lora_layers(self.text_encoder, lora_scale)
250
-
251
204
  if prompt is not None and isinstance(prompt, str):
252
205
  batch_size = 1
253
206
  elif prompt is not None and isinstance(prompt, list):
@@ -378,10 +331,6 @@ class I2VGenXLPipeline(DiffusionPipeline):
378
331
  negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_videos_per_prompt, 1)
379
332
  negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_videos_per_prompt, seq_len, -1)
380
333
 
381
- if isinstance(self, LoraLoaderMixin) and USE_PEFT_BACKEND:
382
- # Retrieve the original scale by scaling back the LoRA layers
383
- unscale_lora_layers(self.text_encoder, lora_scale)
384
-
385
334
  return prompt_embeds, negative_prompt_embeds
386
335
 
387
336
  def _encode_image(self, image, device, num_videos_per_prompt):
@@ -563,34 +512,6 @@ class I2VGenXLPipeline(DiffusionPipeline):
563
512
  latents = latents * self.scheduler.init_noise_sigma
564
513
  return latents
565
514
 
566
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
567
- def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
568
- r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
569
-
570
- The suffixes after the scaling factors represent the stages where they are being applied.
571
-
572
- Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
573
- that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
574
-
575
- Args:
576
- s1 (`float`):
577
- Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
578
- mitigate "oversmoothing effect" in the enhanced denoising process.
579
- s2 (`float`):
580
- Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
581
- mitigate "oversmoothing effect" in the enhanced denoising process.
582
- b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
583
- b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
584
- """
585
- if not hasattr(self, "unet"):
586
- raise ValueError("The pipeline must have `unet` for using FreeU.")
587
- self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
588
-
589
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
590
- def disable_freeu(self):
591
- """Disables the FreeU mechanism if enabled."""
592
- self.unet.disable_freeu()
593
-
594
515
  @torch.no_grad()
595
516
  @replace_example_docstring(EXAMPLE_DOC_STRING)
596
517
  def __call__(
@@ -704,9 +625,6 @@ class I2VGenXLPipeline(DiffusionPipeline):
704
625
  self._guidance_scale = guidance_scale
705
626
 
706
627
  # 3.1 Encode input text prompt
707
- text_encoder_lora_scale = (
708
- cross_attention_kwargs.get("scale", None) if cross_attention_kwargs is not None else None
709
- )
710
628
  prompt_embeds, negative_prompt_embeds = self.encode_prompt(
711
629
  prompt,
712
630
  device,
@@ -714,7 +632,6 @@ class I2VGenXLPipeline(DiffusionPipeline):
714
632
  negative_prompt,
715
633
  prompt_embeds=prompt_embeds,
716
634
  negative_prompt_embeds=negative_prompt_embeds,
717
- lora_scale=text_encoder_lora_scale,
718
635
  clip_skip=clip_skip,
719
636
  )
720
637
  # For classifier free guidance, we need to do two forward passes.
@@ -809,13 +726,14 @@ class I2VGenXLPipeline(DiffusionPipeline):
809
726
  if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
810
727
  progress_bar.update()
811
728
 
729
+ # 8. Post processing
812
730
  if output_type == "latent":
813
- return I2VGenXLPipelineOutput(frames=latents)
814
-
815
- video_tensor = self.decode_latents(latents, decode_chunk_size=decode_chunk_size)
816
- video = tensor2vid(video_tensor, self.image_processor, output_type=output_type)
731
+ video = latents
732
+ else:
733
+ video_tensor = self.decode_latents(latents, decode_chunk_size=decode_chunk_size)
734
+ video = tensor2vid(video_tensor, self.image_processor, output_type=output_type)
817
735
 
818
- # Offload all models
736
+ # 9. Offload all models
819
737
  self.maybe_free_model_hooks()
820
738
 
821
739
  if not return_dict:
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -481,7 +481,7 @@ class KandinskyInpaintPipeline(DiffusionPipeline):
481
481
  if not self._warn_has_been_called and version.parse(version.parse(__version__).base_version) < version.parse(
482
482
  "0.23.0.dev0"
483
483
  ):
484
- logger.warn(
484
+ logger.warning(
485
485
  "Please note that the expected format of `mask_image` has recently been changed. "
486
486
  "Before diffusers == 0.19.0, Kandinsky Inpainting pipelines repainted black pixels and preserved black pixels. "
487
487
  "As of diffusers==0.19.0 this behavior has been inverted. Now white pixels are repainted and black pixels are preserved. "
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The HuggingFace Team. All rights reserved.
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.
@@ -372,7 +372,7 @@ class KandinskyV22InpaintPipeline(DiffusionPipeline):
372
372
  if not self._warn_has_been_called and version.parse(version.parse(__version__).base_version) < version.parse(
373
373
  "0.23.0.dev0"
374
374
  ):
375
- logger.warn(
375
+ logger.warning(
376
376
  "Please note that the expected format of `mask_image` has recently been changed. "
377
377
  "Before diffusers == 0.19.0, Kandinsky Inpainting pipelines repainted black pixels and preserved black pixels. "
378
378
  "As of diffusers==0.19.0 this behavior has been inverted. Now white pixels are repainted and black pixels are preserved. "
@@ -1,4 +1,4 @@
1
- # Copyright 2023 Stanford University Team and The HuggingFace Team. All rights reserved.
1
+ # Copyright 2024 Stanford University Team and 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.
@@ -36,7 +36,7 @@ from ...utils import (
36
36
  unscale_lora_layers,
37
37
  )
38
38
  from ...utils.torch_utils import randn_tensor
39
- from ..pipeline_utils import DiffusionPipeline
39
+ from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
40
40
  from ..stable_diffusion import StableDiffusionPipelineOutput, StableDiffusionSafetyChecker
41
41
 
42
42
 
@@ -129,7 +129,12 @@ EXAMPLE_DOC_STRING = """
129
129
 
130
130
 
131
131
  class LatentConsistencyModelImg2ImgPipeline(
132
- DiffusionPipeline, TextualInversionLoaderMixin, IPAdapterMixin, LoraLoaderMixin, FromSingleFileMixin
132
+ DiffusionPipeline,
133
+ StableDiffusionMixin,
134
+ TextualInversionLoaderMixin,
135
+ IPAdapterMixin,
136
+ LoraLoaderMixin,
137
+ FromSingleFileMixin,
133
138
  ):
134
139
  r"""
135
140
  Pipeline for image-to-image generation using a latent consistency model.
@@ -209,67 +214,6 @@ class LatentConsistencyModelImg2ImgPipeline(
209
214
  self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
210
215
  self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
211
216
 
212
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
213
- def enable_vae_slicing(self):
214
- r"""
215
- Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
216
- compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
217
- """
218
- self.vae.enable_slicing()
219
-
220
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
221
- def disable_vae_slicing(self):
222
- r"""
223
- Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
224
- computing decoding in one step.
225
- """
226
- self.vae.disable_slicing()
227
-
228
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
229
- def enable_vae_tiling(self):
230
- r"""
231
- Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
232
- compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
233
- processing larger images.
234
- """
235
- self.vae.enable_tiling()
236
-
237
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
238
- def disable_vae_tiling(self):
239
- r"""
240
- Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
241
- computing decoding in one step.
242
- """
243
- self.vae.disable_tiling()
244
-
245
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
246
- def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
247
- r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
248
-
249
- The suffixes after the scaling factors represent the stages where they are being applied.
250
-
251
- Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
252
- that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
253
-
254
- Args:
255
- s1 (`float`):
256
- Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
257
- mitigate "oversmoothing effect" in the enhanced denoising process.
258
- s2 (`float`):
259
- Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
260
- mitigate "oversmoothing effect" in the enhanced denoising process.
261
- b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
262
- b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
263
- """
264
- if not hasattr(self, "unet"):
265
- raise ValueError("The pipeline must have `unet` for using FreeU.")
266
- self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
267
-
268
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
269
- def disable_freeu(self):
270
- """Disables the FreeU mechanism if enabled."""
271
- self.unet.disable_freeu()
272
-
273
217
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.encode_prompt
274
218
  def encode_prompt(
275
219
  self,
@@ -331,7 +275,7 @@ class LatentConsistencyModelImg2ImgPipeline(
331
275
  batch_size = prompt_embeds.shape[0]
332
276
 
333
277
  if prompt_embeds is None:
334
- # textual inversion: procecss multi-vector tokens if necessary
278
+ # textual inversion: process multi-vector tokens if necessary
335
279
  if isinstance(self, TextualInversionLoaderMixin):
336
280
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
337
281
 
@@ -413,7 +357,7 @@ class LatentConsistencyModelImg2ImgPipeline(
413
357
  else:
414
358
  uncond_tokens = negative_prompt
415
359
 
416
- # textual inversion: procecss multi-vector tokens if necessary
360
+ # textual inversion: process multi-vector tokens if necessary
417
361
  if isinstance(self, TextualInversionLoaderMixin):
418
362
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
419
363
 
@@ -478,31 +422,54 @@ class LatentConsistencyModelImg2ImgPipeline(
478
422
  return image_embeds, uncond_image_embeds
479
423
 
480
424
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
481
- def prepare_ip_adapter_image_embeds(self, ip_adapter_image, device, num_images_per_prompt):
482
- if not isinstance(ip_adapter_image, list):
483
- ip_adapter_image = [ip_adapter_image]
425
+ def prepare_ip_adapter_image_embeds(
426
+ self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
427
+ ):
428
+ if ip_adapter_image_embeds is None:
429
+ if not isinstance(ip_adapter_image, list):
430
+ ip_adapter_image = [ip_adapter_image]
484
431
 
485
- if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
486
- raise ValueError(
487
- f"`ip_adapter_image` must have same length as the number of IP Adapters. Got {len(ip_adapter_image)} images and {len(self.unet.encoder_hid_proj.image_projection_layers)} IP Adapters."
488
- )
432
+ if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
433
+ raise ValueError(
434
+ f"`ip_adapter_image` must have same length as the number of IP Adapters. Got {len(ip_adapter_image)} images and {len(self.unet.encoder_hid_proj.image_projection_layers)} IP Adapters."
435
+ )
489
436
 
490
- image_embeds = []
491
- for single_ip_adapter_image, image_proj_layer in zip(
492
- ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
493
- ):
494
- output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
495
- single_image_embeds, single_negative_image_embeds = self.encode_image(
496
- single_ip_adapter_image, device, 1, output_hidden_state
497
- )
498
- single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
499
- single_negative_image_embeds = torch.stack([single_negative_image_embeds] * num_images_per_prompt, dim=0)
437
+ image_embeds = []
438
+ for single_ip_adapter_image, image_proj_layer in zip(
439
+ ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
440
+ ):
441
+ output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
442
+ single_image_embeds, single_negative_image_embeds = self.encode_image(
443
+ single_ip_adapter_image, device, 1, output_hidden_state
444
+ )
445
+ single_image_embeds = torch.stack([single_image_embeds] * num_images_per_prompt, dim=0)
446
+ single_negative_image_embeds = torch.stack(
447
+ [single_negative_image_embeds] * num_images_per_prompt, dim=0
448
+ )
500
449
 
501
- if self.do_classifier_free_guidance:
502
- single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
503
- single_image_embeds = single_image_embeds.to(device)
450
+ if do_classifier_free_guidance:
451
+ single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
452
+ single_image_embeds = single_image_embeds.to(device)
504
453
 
505
- image_embeds.append(single_image_embeds)
454
+ image_embeds.append(single_image_embeds)
455
+ else:
456
+ repeat_dims = [1]
457
+ image_embeds = []
458
+ for single_image_embeds in ip_adapter_image_embeds:
459
+ if do_classifier_free_guidance:
460
+ single_negative_image_embeds, single_image_embeds = single_image_embeds.chunk(2)
461
+ single_image_embeds = single_image_embeds.repeat(
462
+ num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
463
+ )
464
+ single_negative_image_embeds = single_negative_image_embeds.repeat(
465
+ num_images_per_prompt, *(repeat_dims * len(single_negative_image_embeds.shape[1:]))
466
+ )
467
+ single_image_embeds = torch.cat([single_negative_image_embeds, single_image_embeds])
468
+ else:
469
+ single_image_embeds = single_image_embeds.repeat(
470
+ num_images_per_prompt, *(repeat_dims * len(single_image_embeds.shape[1:]))
471
+ )
472
+ image_embeds.append(single_image_embeds)
506
473
 
507
474
  return image_embeds
508
475
 
@@ -634,6 +601,8 @@ class LatentConsistencyModelImg2ImgPipeline(
634
601
 
635
602
  t_start = max(num_inference_steps - init_timestep, 0)
636
603
  timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
604
+ if hasattr(self.scheduler, "set_begin_index"):
605
+ self.scheduler.set_begin_index(t_start * self.scheduler.order)
637
606
 
638
607
  return timesteps, num_inference_steps - t_start
639
608
 
@@ -643,6 +612,8 @@ class LatentConsistencyModelImg2ImgPipeline(
643
612
  strength: float,
644
613
  callback_steps: int,
645
614
  prompt_embeds: Optional[torch.FloatTensor] = None,
615
+ ip_adapter_image=None,
616
+ ip_adapter_image_embeds=None,
646
617
  callback_on_step_end_tensor_inputs=None,
647
618
  ):
648
619
  if strength < 0 or strength > 1:
@@ -673,6 +644,21 @@ class LatentConsistencyModelImg2ImgPipeline(
673
644
  elif prompt is not None and (not isinstance(prompt, str) and not isinstance(prompt, list)):
674
645
  raise ValueError(f"`prompt` has to be of type `str` or `list` but is {type(prompt)}")
675
646
 
647
+ if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
648
+ raise ValueError(
649
+ "Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
650
+ )
651
+
652
+ if ip_adapter_image_embeds is not None:
653
+ if not isinstance(ip_adapter_image_embeds, list):
654
+ raise ValueError(
655
+ f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
656
+ )
657
+ elif ip_adapter_image_embeds[0].ndim not in [3, 4]:
658
+ raise ValueError(
659
+ f"`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is {ip_adapter_image_embeds[0].ndim}D"
660
+ )
661
+
676
662
  @property
677
663
  def guidance_scale(self):
678
664
  return self._guidance_scale
@@ -685,6 +671,10 @@ class LatentConsistencyModelImg2ImgPipeline(
685
671
  def clip_skip(self):
686
672
  return self._clip_skip
687
673
 
674
+ @property
675
+ def do_classifier_free_guidance(self):
676
+ return False
677
+
688
678
  @property
689
679
  def num_timesteps(self):
690
680
  return self._num_timesteps
@@ -705,6 +695,7 @@ class LatentConsistencyModelImg2ImgPipeline(
705
695
  latents: Optional[torch.FloatTensor] = None,
706
696
  prompt_embeds: Optional[torch.FloatTensor] = None,
707
697
  ip_adapter_image: Optional[PipelineImageInput] = None,
698
+ ip_adapter_image_embeds: Optional[List[torch.FloatTensor]] = None,
708
699
  output_type: Optional[str] = "pil",
709
700
  return_dict: bool = True,
710
701
  cross_attention_kwargs: Optional[Dict[str, Any]] = None,
@@ -755,6 +746,11 @@ class LatentConsistencyModelImg2ImgPipeline(
755
746
  provided, text embeddings are generated from the `prompt` input argument.
756
747
  ip_adapter_image: (`PipelineImageInput`, *optional*):
757
748
  Optional image input to work with IP Adapters.
749
+ ip_adapter_image_embeds (`List[torch.FloatTensor]`, *optional*):
750
+ Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of IP-adapters.
751
+ Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should contain the negative image embedding
752
+ if `do_classifier_free_guidance` is set to `True`.
753
+ If not provided, embeddings are computed from the `ip_adapter_image` input argument.
758
754
  output_type (`str`, *optional*, defaults to `"pil"`):
759
755
  The output format of the generated image. Choose between `PIL.Image` or `np.array`.
760
756
  return_dict (`bool`, *optional*, defaults to `True`):
@@ -802,7 +798,15 @@ class LatentConsistencyModelImg2ImgPipeline(
802
798
  )
803
799
 
804
800
  # 1. Check inputs. Raise error if not correct
805
- self.check_inputs(prompt, strength, callback_steps, prompt_embeds, callback_on_step_end_tensor_inputs)
801
+ self.check_inputs(
802
+ prompt,
803
+ strength,
804
+ callback_steps,
805
+ prompt_embeds,
806
+ ip_adapter_image,
807
+ ip_adapter_image_embeds,
808
+ callback_on_step_end_tensor_inputs,
809
+ )
806
810
  self._guidance_scale = guidance_scale
807
811
  self._clip_skip = clip_skip
808
812
  self._cross_attention_kwargs = cross_attention_kwargs
@@ -816,11 +820,14 @@ class LatentConsistencyModelImg2ImgPipeline(
816
820
  batch_size = prompt_embeds.shape[0]
817
821
 
818
822
  device = self._execution_device
819
- # do_classifier_free_guidance = guidance_scale > 1.0
820
823
 
821
- if ip_adapter_image is not None:
824
+ if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
822
825
  image_embeds = self.prepare_ip_adapter_image_embeds(
823
- ip_adapter_image, device, batch_size * num_images_per_prompt
826
+ ip_adapter_image,
827
+ ip_adapter_image_embeds,
828
+ device,
829
+ batch_size * num_images_per_prompt,
830
+ self.do_classifier_free_guidance,
824
831
  )
825
832
 
826
833
  # 3. Encode input prompt
@@ -835,7 +842,7 @@ class LatentConsistencyModelImg2ImgPipeline(
835
842
  prompt,
836
843
  device,
837
844
  num_images_per_prompt,
838
- False,
845
+ self.do_classifier_free_guidance,
839
846
  negative_prompt=None,
840
847
  prompt_embeds=prompt_embeds,
841
848
  negative_prompt_embeds=None,
@@ -881,7 +888,11 @@ class LatentConsistencyModelImg2ImgPipeline(
881
888
  extra_step_kwargs = self.prepare_extra_step_kwargs(generator, None)
882
889
 
883
890
  # 7.1 Add image embeds for IP-Adapter
884
- added_cond_kwargs = {"image_embeds": image_embeds} if ip_adapter_image is not None else None
891
+ added_cond_kwargs = (
892
+ {"image_embeds": image_embeds}
893
+ if ip_adapter_image is not None or ip_adapter_image_embeds is not None
894
+ else None
895
+ )
885
896
 
886
897
  # 8. LCM Multistep Sampling Loop
887
898
  num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order