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
@@ -0,0 +1,311 @@
1
+ # Copyright 2024 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ from typing import Callable, Dict, List, Optional, Union
15
+
16
+ import PIL
17
+ import torch
18
+ from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
19
+
20
+ from ...models import StableCascadeUNet
21
+ from ...schedulers import DDPMWuerstchenScheduler
22
+ from ...utils import is_torch_version, replace_example_docstring
23
+ from ..pipeline_utils import DiffusionPipeline
24
+ from ..wuerstchen.modeling_paella_vq_model import PaellaVQModel
25
+ from .pipeline_stable_cascade import StableCascadeDecoderPipeline
26
+ from .pipeline_stable_cascade_prior import StableCascadePriorPipeline
27
+
28
+
29
+ TEXT2IMAGE_EXAMPLE_DOC_STRING = """
30
+ Examples:
31
+ ```py
32
+ >>> import torch
33
+ >>> from diffusers import StableCascadeCombinedPipeline
34
+ >>> pipe = StableCascadeCombinedPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.bfloat16)
35
+ >>> pipe.enable_model_cpu_offload()
36
+ >>> prompt = "an image of a shiba inu, donning a spacesuit and helmet"
37
+ >>> images = pipe(prompt=prompt)
38
+ ```
39
+ """
40
+
41
+
42
+ class StableCascadeCombinedPipeline(DiffusionPipeline):
43
+ """
44
+ Combined Pipeline for text-to-image generation using Stable Cascade.
45
+
46
+ This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
47
+ library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
48
+
49
+ Args:
50
+ tokenizer (`CLIPTokenizer`):
51
+ The decoder tokenizer to be used for text inputs.
52
+ text_encoder (`CLIPTextModel`):
53
+ The decoder text encoder to be used for text inputs.
54
+ decoder (`StableCascadeUNet`):
55
+ The decoder model to be used for decoder image generation pipeline.
56
+ scheduler (`DDPMWuerstchenScheduler`):
57
+ The scheduler to be used for decoder image generation pipeline.
58
+ vqgan (`PaellaVQModel`):
59
+ The VQGAN model to be used for decoder image generation pipeline.
60
+ feature_extractor ([`~transformers.CLIPImageProcessor`]):
61
+ Model that extracts features from generated images to be used as inputs for the `image_encoder`.
62
+ image_encoder ([`CLIPVisionModelWithProjection`]):
63
+ Frozen CLIP image-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)).
64
+ prior_prior (`StableCascadeUNet`):
65
+ The prior model to be used for prior pipeline.
66
+ prior_scheduler (`DDPMWuerstchenScheduler`):
67
+ The scheduler to be used for prior pipeline.
68
+ """
69
+
70
+ _load_connected_pipes = True
71
+
72
+ def __init__(
73
+ self,
74
+ tokenizer: CLIPTokenizer,
75
+ text_encoder: CLIPTextModel,
76
+ decoder: StableCascadeUNet,
77
+ scheduler: DDPMWuerstchenScheduler,
78
+ vqgan: PaellaVQModel,
79
+ prior_prior: StableCascadeUNet,
80
+ prior_text_encoder: CLIPTextModel,
81
+ prior_tokenizer: CLIPTokenizer,
82
+ prior_scheduler: DDPMWuerstchenScheduler,
83
+ prior_feature_extractor: Optional[CLIPImageProcessor] = None,
84
+ prior_image_encoder: Optional[CLIPVisionModelWithProjection] = None,
85
+ ):
86
+ super().__init__()
87
+
88
+ self.register_modules(
89
+ text_encoder=text_encoder,
90
+ tokenizer=tokenizer,
91
+ decoder=decoder,
92
+ scheduler=scheduler,
93
+ vqgan=vqgan,
94
+ prior_text_encoder=prior_text_encoder,
95
+ prior_tokenizer=prior_tokenizer,
96
+ prior_prior=prior_prior,
97
+ prior_scheduler=prior_scheduler,
98
+ prior_feature_extractor=prior_feature_extractor,
99
+ prior_image_encoder=prior_image_encoder,
100
+ )
101
+ self.prior_pipe = StableCascadePriorPipeline(
102
+ prior=prior_prior,
103
+ text_encoder=prior_text_encoder,
104
+ tokenizer=prior_tokenizer,
105
+ scheduler=prior_scheduler,
106
+ image_encoder=prior_image_encoder,
107
+ feature_extractor=prior_feature_extractor,
108
+ )
109
+ self.decoder_pipe = StableCascadeDecoderPipeline(
110
+ text_encoder=text_encoder,
111
+ tokenizer=tokenizer,
112
+ decoder=decoder,
113
+ scheduler=scheduler,
114
+ vqgan=vqgan,
115
+ )
116
+
117
+ def enable_xformers_memory_efficient_attention(self, attention_op: Optional[Callable] = None):
118
+ self.decoder_pipe.enable_xformers_memory_efficient_attention(attention_op)
119
+
120
+ def enable_model_cpu_offload(self, gpu_id=0):
121
+ r"""
122
+ Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
123
+ to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
124
+ method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
125
+ `enable_sequential_cpu_offload`, but performance is much better due to the iterative execution of the `unet`.
126
+ """
127
+ self.prior_pipe.enable_model_cpu_offload(gpu_id=gpu_id)
128
+ self.decoder_pipe.enable_model_cpu_offload(gpu_id=gpu_id)
129
+
130
+ def enable_sequential_cpu_offload(self, gpu_id=0):
131
+ r"""
132
+ Offloads all models (`unet`, `text_encoder`, `vae`, and `safety checker` state dicts) to CPU using 🤗
133
+ Accelerate, significantly reducing memory usage. Models are moved to a `torch.device('meta')` and loaded on a
134
+ GPU only when their specific submodule's `forward` method is called. Offloading happens on a submodule basis.
135
+ Memory savings are higher than using `enable_model_cpu_offload`, but performance is lower.
136
+ """
137
+ self.prior_pipe.enable_sequential_cpu_offload(gpu_id=gpu_id)
138
+ self.decoder_pipe.enable_sequential_cpu_offload(gpu_id=gpu_id)
139
+
140
+ def progress_bar(self, iterable=None, total=None):
141
+ self.prior_pipe.progress_bar(iterable=iterable, total=total)
142
+ self.decoder_pipe.progress_bar(iterable=iterable, total=total)
143
+
144
+ def set_progress_bar_config(self, **kwargs):
145
+ self.prior_pipe.set_progress_bar_config(**kwargs)
146
+ self.decoder_pipe.set_progress_bar_config(**kwargs)
147
+
148
+ @torch.no_grad()
149
+ @replace_example_docstring(TEXT2IMAGE_EXAMPLE_DOC_STRING)
150
+ def __call__(
151
+ self,
152
+ prompt: Optional[Union[str, List[str]]] = None,
153
+ images: Union[torch.Tensor, PIL.Image.Image, List[torch.Tensor], List[PIL.Image.Image]] = None,
154
+ height: int = 512,
155
+ width: int = 512,
156
+ prior_num_inference_steps: int = 60,
157
+ prior_guidance_scale: float = 4.0,
158
+ num_inference_steps: int = 12,
159
+ decoder_guidance_scale: float = 0.0,
160
+ negative_prompt: Optional[Union[str, List[str]]] = None,
161
+ prompt_embeds: Optional[torch.FloatTensor] = None,
162
+ prompt_embeds_pooled: Optional[torch.FloatTensor] = None,
163
+ negative_prompt_embeds: Optional[torch.FloatTensor] = None,
164
+ negative_prompt_embeds_pooled: Optional[torch.FloatTensor] = None,
165
+ num_images_per_prompt: int = 1,
166
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
167
+ latents: Optional[torch.FloatTensor] = None,
168
+ output_type: Optional[str] = "pil",
169
+ return_dict: bool = True,
170
+ prior_callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
171
+ prior_callback_on_step_end_tensor_inputs: List[str] = ["latents"],
172
+ callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
173
+ callback_on_step_end_tensor_inputs: List[str] = ["latents"],
174
+ ):
175
+ """
176
+ Function invoked when calling the pipeline for generation.
177
+
178
+ Args:
179
+ prompt (`str` or `List[str]`):
180
+ The prompt or prompts to guide the image generation for the prior and decoder.
181
+ images (`torch.Tensor`, `PIL.Image.Image`, `List[torch.Tensor]`, `List[PIL.Image.Image]`, *optional*):
182
+ The images to guide the image generation for the prior.
183
+ negative_prompt (`str` or `List[str]`, *optional*):
184
+ The prompt or prompts not to guide the image generation. Ignored when not using guidance (i.e., ignored
185
+ if `guidance_scale` is less than `1`).
186
+ prompt_embeds (`torch.FloatTensor`, *optional*):
187
+ Pre-generated text embeddings for the prior. Can be used to easily tweak text inputs, *e.g.* prompt
188
+ weighting. If not provided, text embeddings will be generated from `prompt` input argument.
189
+ prompt_embeds_pooled (`torch.FloatTensor`, *optional*):
190
+ Pre-generated text embeddings for the prior. Can be used to easily tweak text inputs, *e.g.* prompt
191
+ weighting. If not provided, text embeddings will be generated from `prompt` input argument.
192
+ negative_prompt_embeds (`torch.FloatTensor`, *optional*):
193
+ Pre-generated negative text embeddings for the prior. Can be used to easily tweak text inputs, *e.g.*
194
+ prompt weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt`
195
+ input argument.
196
+ negative_prompt_embeds_pooled (`torch.FloatTensor`, *optional*):
197
+ Pre-generated negative text embeddings for the prior. Can be used to easily tweak text inputs, *e.g.*
198
+ prompt weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt`
199
+ input argument.
200
+ num_images_per_prompt (`int`, *optional*, defaults to 1):
201
+ The number of images to generate per prompt.
202
+ height (`int`, *optional*, defaults to 512):
203
+ The height in pixels of the generated image.
204
+ width (`int`, *optional*, defaults to 512):
205
+ The width in pixels of the generated image.
206
+ prior_guidance_scale (`float`, *optional*, defaults to 4.0):
207
+ Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
208
+ `prior_guidance_scale` is defined as `w` of equation 2. of [Imagen
209
+ Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting
210
+ `prior_guidance_scale > 1`. Higher guidance scale encourages to generate images that are closely linked
211
+ to the text `prompt`, usually at the expense of lower image quality.
212
+ prior_num_inference_steps (`Union[int, Dict[float, int]]`, *optional*, defaults to 60):
213
+ The number of prior denoising steps. More denoising steps usually lead to a higher quality image at the
214
+ expense of slower inference. For more specific timestep spacing, you can pass customized
215
+ `prior_timesteps`
216
+ num_inference_steps (`int`, *optional*, defaults to 12):
217
+ The number of decoder denoising steps. More denoising steps usually lead to a higher quality image at
218
+ the expense of slower inference. For more specific timestep spacing, you can pass customized
219
+ `timesteps`
220
+ decoder_guidance_scale (`float`, *optional*, defaults to 0.0):
221
+ Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
222
+ `guidance_scale` is defined as `w` of equation 2. of [Imagen
223
+ Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
224
+ 1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`,
225
+ usually at the expense of lower image quality.
226
+ generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
227
+ One or a list of [torch generator(s)](https://pytorch.org/docs/stable/generated/torch.Generator.html)
228
+ to make generation deterministic.
229
+ latents (`torch.FloatTensor`, *optional*):
230
+ Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
231
+ generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
232
+ tensor will ge generated by sampling using the supplied random `generator`.
233
+ output_type (`str`, *optional*, defaults to `"pil"`):
234
+ The output format of the generate image. Choose between: `"pil"` (`PIL.Image.Image`), `"np"`
235
+ (`np.array`) or `"pt"` (`torch.Tensor`).
236
+ return_dict (`bool`, *optional*, defaults to `True`):
237
+ Whether or not to return a [`~pipelines.ImagePipelineOutput`] instead of a plain tuple.
238
+ prior_callback_on_step_end (`Callable`, *optional*):
239
+ A function that calls at the end of each denoising steps during the inference. The function is called
240
+ with the following arguments: `prior_callback_on_step_end(self: DiffusionPipeline, step: int, timestep:
241
+ int, callback_kwargs: Dict)`.
242
+ prior_callback_on_step_end_tensor_inputs (`List`, *optional*):
243
+ The list of tensor inputs for the `prior_callback_on_step_end` function. The tensors specified in the
244
+ list will be passed as `callback_kwargs` argument. You will only be able to include variables listed in
245
+ the `._callback_tensor_inputs` attribute of your pipeine class.
246
+ callback_on_step_end (`Callable`, *optional*):
247
+ A function that calls at the end of each denoising steps during the inference. The function is called
248
+ with the following arguments: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int,
249
+ callback_kwargs: Dict)`. `callback_kwargs` will include a list of all tensors as specified by
250
+ `callback_on_step_end_tensor_inputs`.
251
+ callback_on_step_end_tensor_inputs (`List`, *optional*):
252
+ The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
253
+ will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
254
+ `._callback_tensor_inputs` attribute of your pipeine class.
255
+
256
+ Examples:
257
+
258
+ Returns:
259
+ [`~pipelines.ImagePipelineOutput`] or `tuple` [`~pipelines.ImagePipelineOutput`] if `return_dict` is True,
260
+ otherwise a `tuple`. When returning a tuple, the first element is a list with the generated images.
261
+ """
262
+ dtype = self.decoder_pipe.decoder.dtype
263
+ if is_torch_version("<", "2.2.0") and dtype == torch.bfloat16:
264
+ raise ValueError(
265
+ "`StableCascadeCombinedPipeline` requires torch>=2.2.0 when using `torch.bfloat16` dtype."
266
+ )
267
+
268
+ prior_outputs = self.prior_pipe(
269
+ prompt=prompt if prompt_embeds is None else None,
270
+ images=images,
271
+ height=height,
272
+ width=width,
273
+ num_inference_steps=prior_num_inference_steps,
274
+ guidance_scale=prior_guidance_scale,
275
+ negative_prompt=negative_prompt if negative_prompt_embeds is None else None,
276
+ prompt_embeds=prompt_embeds,
277
+ prompt_embeds_pooled=prompt_embeds_pooled,
278
+ negative_prompt_embeds=negative_prompt_embeds,
279
+ negative_prompt_embeds_pooled=negative_prompt_embeds_pooled,
280
+ num_images_per_prompt=num_images_per_prompt,
281
+ generator=generator,
282
+ latents=latents,
283
+ output_type="pt",
284
+ return_dict=True,
285
+ callback_on_step_end=prior_callback_on_step_end,
286
+ callback_on_step_end_tensor_inputs=prior_callback_on_step_end_tensor_inputs,
287
+ )
288
+ image_embeddings = prior_outputs.image_embeddings
289
+ prompt_embeds = prior_outputs.get("prompt_embeds", None)
290
+ prompt_embeds_pooled = prior_outputs.get("prompt_embeds_pooled", None)
291
+ negative_prompt_embeds = prior_outputs.get("negative_prompt_embeds", None)
292
+ negative_prompt_embeds_pooled = prior_outputs.get("negative_prompt_embeds_pooled", None)
293
+
294
+ outputs = self.decoder_pipe(
295
+ image_embeddings=image_embeddings,
296
+ prompt=prompt if prompt_embeds is None else None,
297
+ num_inference_steps=num_inference_steps,
298
+ guidance_scale=decoder_guidance_scale,
299
+ negative_prompt=negative_prompt if negative_prompt_embeds is None else None,
300
+ prompt_embeds=prompt_embeds,
301
+ prompt_embeds_pooled=prompt_embeds_pooled,
302
+ negative_prompt_embeds=negative_prompt_embeds,
303
+ negative_prompt_embeds_pooled=negative_prompt_embeds_pooled,
304
+ generator=generator,
305
+ output_type=output_type,
306
+ return_dict=return_dict,
307
+ callback_on_step_end=callback_on_step_end,
308
+ callback_on_step_end_tensor_inputs=callback_on_step_end_tensor_inputs,
309
+ )
310
+
311
+ return outputs