diffusers 0.26.2__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 +28 -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 +278 -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 +52 -21
  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.2.dist-info → diffusers-0.27.0.dist-info}/METADATA +5 -5
  294. diffusers-0.27.0.dist-info/RECORD +399 -0
  295. diffusers-0.26.2.dist-info/RECORD +0 -384
  296. {diffusers-0.26.2.dist-info → diffusers-0.27.0.dist-info}/LICENSE +0 -0
  297. {diffusers-0.26.2.dist-info → diffusers-0.27.0.dist-info}/WHEEL +0 -0
  298. {diffusers-0.26.2.dist-info → diffusers-0.27.0.dist-info}/entry_points.txt +0 -0
  299. {diffusers-0.26.2.dist-info → diffusers-0.27.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The InstructPix2Pix Authors and The HuggingFace Team. All rights reserved.
1
+ # Copyright 2024 The InstructPix2Pix Authors 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.
@@ -26,7 +26,7 @@ from ...models import AutoencoderKL, ImageProjection, UNet2DConditionModel
26
26
  from ...schedulers import KarrasDiffusionSchedulers
27
27
  from ...utils import PIL_INTERPOLATION, deprecate, logging
28
28
  from ...utils.torch_utils import randn_tensor
29
- from ..pipeline_utils import DiffusionPipeline
29
+ from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
30
30
  from . import StableDiffusionPipelineOutput
31
31
  from .safety_checker import StableDiffusionSafetyChecker
32
32
 
@@ -73,7 +73,7 @@ def retrieve_latents(
73
73
 
74
74
 
75
75
  class StableDiffusionInstructPix2PixPipeline(
76
- DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, IPAdapterMixin
76
+ DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin, IPAdapterMixin
77
77
  ):
78
78
  r"""
79
79
  Pipeline for pixel-level image editing by following text instructions (based on Stable Diffusion).
@@ -323,8 +323,6 @@ class StableDiffusionInstructPix2PixPipeline(
323
323
  batch_size = prompt_embeds.shape[0]
324
324
 
325
325
  device = self._execution_device
326
- # check if scheduler is in sigmas space
327
- scheduler_is_in_sigma_space = hasattr(self.scheduler, "sigmas")
328
326
 
329
327
  # 2. Encode input prompt
330
328
  prompt_embeds = self._encode_prompt(
@@ -411,15 +409,6 @@ class StableDiffusionInstructPix2PixPipeline(
411
409
  return_dict=False,
412
410
  )[0]
413
411
 
414
- # Hack:
415
- # For karras style schedulers the model does classifer free guidance using the
416
- # predicted_original_sample instead of the noise_pred. So we need to compute the
417
- # predicted_original_sample here if we are using a karras style scheduler.
418
- if scheduler_is_in_sigma_space:
419
- step_index = (self.scheduler.timesteps == t).nonzero()[0].item()
420
- sigma = self.scheduler.sigmas[step_index]
421
- noise_pred = latent_model_input - sigma * noise_pred
422
-
423
412
  # perform guidance
424
413
  if self.do_classifier_free_guidance:
425
414
  noise_pred_text, noise_pred_image, noise_pred_uncond = noise_pred.chunk(3)
@@ -429,15 +418,6 @@ class StableDiffusionInstructPix2PixPipeline(
429
418
  + self.image_guidance_scale * (noise_pred_image - noise_pred_uncond)
430
419
  )
431
420
 
432
- # Hack:
433
- # For karras style schedulers the model does classifer free guidance using the
434
- # predicted_original_sample instead of the noise_pred. But the scheduler.step function
435
- # expects the noise_pred and computes the predicted_original_sample internally. So we
436
- # need to overwrite the noise_pred here such that the value of the computed
437
- # predicted_original_sample is correct.
438
- if scheduler_is_in_sigma_space:
439
- noise_pred = (noise_pred - latents) / (-sigma)
440
-
441
421
  # compute the previous noisy sample x_t -> x_t-1
442
422
  latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
443
423
 
@@ -523,7 +503,7 @@ class StableDiffusionInstructPix2PixPipeline(
523
503
  batch_size = prompt_embeds.shape[0]
524
504
 
525
505
  if prompt_embeds is None:
526
- # textual inversion: procecss multi-vector tokens if necessary
506
+ # textual inversion: process multi-vector tokens if necessary
527
507
  if isinstance(self, TextualInversionLoaderMixin):
528
508
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
529
509
 
@@ -553,13 +533,15 @@ class StableDiffusionInstructPix2PixPipeline(
553
533
  else:
554
534
  attention_mask = None
555
535
 
556
- prompt_embeds = self.text_encoder(
557
- text_input_ids.to(device),
558
- attention_mask=attention_mask,
559
- )
536
+ prompt_embeds = self.text_encoder(text_input_ids.to(device), attention_mask=attention_mask)
560
537
  prompt_embeds = prompt_embeds[0]
561
538
 
562
- prompt_embeds = prompt_embeds.to(dtype=self.text_encoder.dtype, device=device)
539
+ if self.text_encoder is not None:
540
+ prompt_embeds_dtype = self.text_encoder.dtype
541
+ else:
542
+ prompt_embeds_dtype = self.unet.dtype
543
+
544
+ prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
563
545
 
564
546
  bs_embed, seq_len, _ = prompt_embeds.shape
565
547
  # duplicate text embeddings for each generation per prompt, using mps friendly method
@@ -587,7 +569,7 @@ class StableDiffusionInstructPix2PixPipeline(
587
569
  else:
588
570
  uncond_tokens = negative_prompt
589
571
 
590
- # textual inversion: procecss multi-vector tokens if necessary
572
+ # textual inversion: process multi-vector tokens if necessary
591
573
  if isinstance(self, TextualInversionLoaderMixin):
592
574
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
593
575
 
@@ -615,7 +597,7 @@ class StableDiffusionInstructPix2PixPipeline(
615
597
  # duplicate unconditional embeddings for each generation per prompt, using mps friendly method
616
598
  seq_len = negative_prompt_embeds.shape[1]
617
599
 
618
- negative_prompt_embeds = negative_prompt_embeds.to(dtype=self.text_encoder.dtype, device=device)
600
+ negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
619
601
 
620
602
  negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
621
603
  negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
@@ -805,34 +787,6 @@ class StableDiffusionInstructPix2PixPipeline(
805
787
 
806
788
  return image_latents
807
789
 
808
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
809
- def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
810
- r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
811
-
812
- The suffixes after the scaling factors represent the stages where they are being applied.
813
-
814
- Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
815
- that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
816
-
817
- Args:
818
- s1 (`float`):
819
- Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
820
- mitigate "oversmoothing effect" in the enhanced denoising process.
821
- s2 (`float`):
822
- Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
823
- mitigate "oversmoothing effect" in the enhanced denoising process.
824
- b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
825
- b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
826
- """
827
- if not hasattr(self, "unet"):
828
- raise ValueError("The pipeline must have `unet` for using FreeU.")
829
- self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
830
-
831
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
832
- def disable_freeu(self):
833
- """Disables the FreeU mechanism if enabled."""
834
- self.unet.disable_freeu()
835
-
836
790
  @property
837
791
  def guidance_scale(self):
838
792
  return self._guidance_scale
@@ -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.
@@ -27,7 +27,7 @@ from ...models import AutoencoderKL, UNet2DConditionModel
27
27
  from ...schedulers import EulerDiscreteScheduler
28
28
  from ...utils import deprecate, logging
29
29
  from ...utils.torch_utils import randn_tensor
30
- from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
30
+ from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput, StableDiffusionMixin
31
31
 
32
32
 
33
33
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -60,7 +60,7 @@ def preprocess(image):
60
60
  return image
61
61
 
62
62
 
63
- class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, FromSingleFileMixin):
63
+ class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, StableDiffusionMixin, FromSingleFileMixin):
64
64
  r"""
65
65
  Pipeline for upscaling Stable Diffusion output image resolution by a factor of 2.
66
66
 
@@ -258,34 +258,6 @@ class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, FromSingleFileMixi
258
258
  latents = latents * self.scheduler.init_noise_sigma
259
259
  return latents
260
260
 
261
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
262
- def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
263
- r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
264
-
265
- The suffixes after the scaling factors represent the stages where they are being applied.
266
-
267
- Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
268
- that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
269
-
270
- Args:
271
- s1 (`float`):
272
- Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
273
- mitigate "oversmoothing effect" in the enhanced denoising process.
274
- s2 (`float`):
275
- Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
276
- mitigate "oversmoothing effect" in the enhanced denoising process.
277
- b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
278
- b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
279
- """
280
- if not hasattr(self, "unet"):
281
- raise ValueError("The pipeline must have `unet` for using FreeU.")
282
- self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
283
-
284
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
285
- def disable_freeu(self):
286
- """Disables the FreeU mechanism if enabled."""
287
- self.unet.disable_freeu()
288
-
289
261
  @torch.no_grad()
290
262
  def __call__(
291
263
  self,
@@ -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.
@@ -34,7 +34,7 @@ from ...models.lora import adjust_lora_scale_text_encoder
34
34
  from ...schedulers import DDPMScheduler, KarrasDiffusionSchedulers
35
35
  from ...utils import USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
36
36
  from ...utils.torch_utils import randn_tensor
37
- from ..pipeline_utils import DiffusionPipeline
37
+ from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
38
38
  from . import StableDiffusionPipelineOutput
39
39
 
40
40
 
@@ -68,7 +68,7 @@ def preprocess(image):
68
68
 
69
69
 
70
70
  class StableDiffusionUpscalePipeline(
71
- DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
71
+ DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
72
72
  ):
73
73
  r"""
74
74
  Pipeline for text-guided image super-resolution using Stable Diffusion 2.
@@ -262,7 +262,7 @@ class StableDiffusionUpscalePipeline(
262
262
  batch_size = prompt_embeds.shape[0]
263
263
 
264
264
  if prompt_embeds is None:
265
- # textual inversion: procecss multi-vector tokens if necessary
265
+ # textual inversion: process multi-vector tokens if necessary
266
266
  if isinstance(self, TextualInversionLoaderMixin):
267
267
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
268
268
 
@@ -344,7 +344,7 @@ class StableDiffusionUpscalePipeline(
344
344
  else:
345
345
  uncond_tokens = negative_prompt
346
346
 
347
- # textual inversion: procecss multi-vector tokens if necessary
347
+ # textual inversion: process multi-vector tokens if necessary
348
348
  if isinstance(self, TextualInversionLoaderMixin):
349
349
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
350
350
 
@@ -530,34 +530,6 @@ class StableDiffusionUpscalePipeline(
530
530
  self.vae.decoder.conv_in.to(dtype)
531
531
  self.vae.decoder.mid_block.to(dtype)
532
532
 
533
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_freeu
534
- def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
535
- r"""Enables the FreeU mechanism as in https://arxiv.org/abs/2309.11497.
536
-
537
- The suffixes after the scaling factors represent the stages where they are being applied.
538
-
539
- Please refer to the [official repository](https://github.com/ChenyangSi/FreeU) for combinations of the values
540
- that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL.
541
-
542
- Args:
543
- s1 (`float`):
544
- Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
545
- mitigate "oversmoothing effect" in the enhanced denoising process.
546
- s2 (`float`):
547
- Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
548
- mitigate "oversmoothing effect" in the enhanced denoising process.
549
- b1 (`float`): Scaling factor for stage 1 to amplify the contributions of backbone features.
550
- b2 (`float`): Scaling factor for stage 2 to amplify the contributions of backbone features.
551
- """
552
- if not hasattr(self, "unet"):
553
- raise ValueError("The pipeline must have `unet` for using FreeU.")
554
- self.unet.enable_freeu(s1=s1, s2=s2, b1=b1, b2=b2)
555
-
556
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_freeu
557
- def disable_freeu(self):
558
- """Disables the FreeU mechanism if enabled."""
559
- self.unet.disable_freeu()
560
-
561
533
  @torch.no_grad()
562
534
  def __call__(
563
535
  self,
@@ -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.
@@ -34,7 +34,7 @@ from ...utils import (
34
34
  unscale_lora_layers,
35
35
  )
36
36
  from ...utils.torch_utils import randn_tensor
37
- from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
37
+ from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput, StableDiffusionMixin
38
38
  from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
39
39
 
40
40
 
@@ -58,7 +58,7 @@ EXAMPLE_DOC_STRING = """
58
58
  """
59
59
 
60
60
 
61
- class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin):
61
+ class StableUnCLIPPipeline(DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin):
62
62
  """
63
63
  Pipeline for text-to-image generation using stable unCLIP.
64
64
 
@@ -155,22 +155,6 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
155
155
  self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
156
156
  self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
157
157
 
158
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
159
- def enable_vae_slicing(self):
160
- r"""
161
- Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
162
- compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
163
- """
164
- self.vae.enable_slicing()
165
-
166
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
167
- def disable_vae_slicing(self):
168
- r"""
169
- Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
170
- computing decoding in one step.
171
- """
172
- self.vae.disable_slicing()
173
-
174
158
  # Copied from diffusers.pipelines.unclip.pipeline_unclip.UnCLIPPipeline._encode_prompt with _encode_prompt->_encode_prior_prompt, tokenizer->prior_tokenizer, text_encoder->prior_text_encoder
175
159
  def _encode_prior_prompt(
176
160
  self,
@@ -359,7 +343,7 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
359
343
  batch_size = prompt_embeds.shape[0]
360
344
 
361
345
  if prompt_embeds is None:
362
- # textual inversion: procecss multi-vector tokens if necessary
346
+ # textual inversion: process multi-vector tokens if necessary
363
347
  if isinstance(self, TextualInversionLoaderMixin):
364
348
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
365
349
 
@@ -441,7 +425,7 @@ class StableUnCLIPPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
441
425
  else:
442
426
  uncond_tokens = negative_prompt
443
427
 
444
- # textual inversion: procecss multi-vector tokens if necessary
428
+ # textual inversion: process multi-vector tokens if necessary
445
429
  if isinstance(self, TextualInversionLoaderMixin):
446
430
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
447
431
 
@@ -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.
@@ -34,7 +34,7 @@ from ...utils import (
34
34
  unscale_lora_layers,
35
35
  )
36
36
  from ...utils.torch_utils import randn_tensor
37
- from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
37
+ from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput, StableDiffusionMixin
38
38
  from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
39
39
 
40
40
 
@@ -69,7 +69,9 @@ EXAMPLE_DOC_STRING = """
69
69
  """
70
70
 
71
71
 
72
- class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin):
72
+ class StableUnCLIPImg2ImgPipeline(
73
+ DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin
74
+ ):
73
75
  """
74
76
  Pipeline for text-guided image-to-image generation using stable unCLIP.
75
77
 
@@ -156,22 +158,6 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
156
158
  self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
157
159
  self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
158
160
 
159
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
160
- def enable_vae_slicing(self):
161
- r"""
162
- Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
163
- compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
164
- """
165
- self.vae.enable_slicing()
166
-
167
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
168
- def disable_vae_slicing(self):
169
- r"""
170
- Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
171
- computing decoding in one step.
172
- """
173
- self.vae.disable_slicing()
174
-
175
161
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
176
162
  def _encode_prompt(
177
163
  self,
@@ -321,7 +307,7 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
321
307
  batch_size = prompt_embeds.shape[0]
322
308
 
323
309
  if prompt_embeds is None:
324
- # textual inversion: procecss multi-vector tokens if necessary
310
+ # textual inversion: process multi-vector tokens if necessary
325
311
  if isinstance(self, TextualInversionLoaderMixin):
326
312
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
327
313
 
@@ -403,7 +389,7 @@ class StableUnCLIPImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
403
389
  else:
404
390
  uncond_tokens = negative_prompt
405
391
 
406
- # textual inversion: procecss multi-vector tokens if necessary
392
+ # textual inversion: process multi-vector tokens if necessary
407
393
  if isinstance(self, TextualInversionLoaderMixin):
408
394
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
409
395
 
@@ -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.
@@ -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
41
41
  from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
42
42
 
@@ -170,7 +170,7 @@ class AttendExciteAttnProcessor:
170
170
  return hidden_states
171
171
 
172
172
 
173
- class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversionLoaderMixin):
173
+ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin):
174
174
  r"""
175
175
  Pipeline for text-to-image generation using Stable Diffusion and Attend-and-Excite.
176
176
 
@@ -246,22 +246,6 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
246
246
  self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
247
247
  self.register_to_config(requires_safety_checker=requires_safety_checker)
248
248
 
249
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
250
- def enable_vae_slicing(self):
251
- r"""
252
- Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
253
- compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
254
- """
255
- self.vae.enable_slicing()
256
-
257
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
258
- def disable_vae_slicing(self):
259
- r"""
260
- Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
261
- computing decoding in one step.
262
- """
263
- self.vae.disable_slicing()
264
-
265
249
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
266
250
  def _encode_prompt(
267
251
  self,
@@ -356,7 +340,7 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
356
340
  batch_size = prompt_embeds.shape[0]
357
341
 
358
342
  if prompt_embeds is None:
359
- # textual inversion: procecss multi-vector tokens if necessary
343
+ # textual inversion: process multi-vector tokens if necessary
360
344
  if isinstance(self, TextualInversionLoaderMixin):
361
345
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
362
346
 
@@ -438,7 +422,7 @@ class StableDiffusionAttendAndExcitePipeline(DiffusionPipeline, TextualInversion
438
422
  else:
439
423
  uncond_tokens = negative_prompt
440
424
 
441
- # textual inversion: procecss multi-vector tokens if necessary
425
+ # textual inversion: process multi-vector tokens if necessary
442
426
  if isinstance(self, TextualInversionLoaderMixin):
443
427
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
444
428
 
@@ -1,4 +1,4 @@
1
- # Copyright 2023 DiffEdit Authors and Pix2Pix Zero Authors and The HuggingFace Team. All rights reserved.
1
+ # Copyright 2024 DiffEdit Authors and Pix2Pix Zero Authors 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.
@@ -39,7 +39,7 @@ from ...utils import (
39
39
  unscale_lora_layers,
40
40
  )
41
41
  from ...utils.torch_utils import randn_tensor
42
- from ..pipeline_utils import DiffusionPipeline
42
+ from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
43
43
  from ..stable_diffusion import StableDiffusionPipelineOutput
44
44
  from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
45
45
 
@@ -235,7 +235,9 @@ def preprocess_mask(mask, batch_size: int = 1):
235
235
  return mask
236
236
 
237
237
 
238
- class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin):
238
+ class StableDiffusionDiffEditPipeline(
239
+ DiffusionPipeline, StableDiffusionMixin, TextualInversionLoaderMixin, LoraLoaderMixin
240
+ ):
239
241
  r"""
240
242
  <Tip warning={true}>
241
243
 
@@ -371,39 +373,6 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
371
373
  self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
372
374
  self.register_to_config(requires_safety_checker=requires_safety_checker)
373
375
 
374
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
375
- def enable_vae_slicing(self):
376
- r"""
377
- Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
378
- compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
379
- """
380
- self.vae.enable_slicing()
381
-
382
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
383
- def disable_vae_slicing(self):
384
- r"""
385
- Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
386
- computing decoding in one step.
387
- """
388
- self.vae.disable_slicing()
389
-
390
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
391
- def enable_vae_tiling(self):
392
- r"""
393
- Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
394
- compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
395
- processing larger images.
396
- """
397
- self.vae.enable_tiling()
398
-
399
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
400
- def disable_vae_tiling(self):
401
- r"""
402
- Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
403
- computing decoding in one step.
404
- """
405
- self.vae.disable_tiling()
406
-
407
376
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
408
377
  def _encode_prompt(
409
378
  self,
@@ -498,7 +467,7 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
498
467
  batch_size = prompt_embeds.shape[0]
499
468
 
500
469
  if prompt_embeds is None:
501
- # textual inversion: procecss multi-vector tokens if necessary
470
+ # textual inversion: process multi-vector tokens if necessary
502
471
  if isinstance(self, TextualInversionLoaderMixin):
503
472
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
504
473
 
@@ -580,7 +549,7 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
580
549
  else:
581
550
  uncond_tokens = negative_prompt
582
551
 
583
- # textual inversion: procecss multi-vector tokens if necessary
552
+ # textual inversion: process multi-vector tokens if necessary
584
553
  if isinstance(self, TextualInversionLoaderMixin):
585
554
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
586
555
 
@@ -754,6 +723,8 @@ class StableDiffusionDiffEditPipeline(DiffusionPipeline, TextualInversionLoaderM
754
723
 
755
724
  t_start = max(num_inference_steps - init_timestep, 0)
756
725
  timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
726
+ if hasattr(self.scheduler, "set_begin_index"):
727
+ self.scheduler.set_begin_index(t_start * self.scheduler.order)
757
728
 
758
729
  return timesteps, num_inference_steps - t_start
759
730
 
@@ -1,4 +1,4 @@
1
- # Copyright 2023 The GLIGEN Authors and HuggingFace Team. All rights reserved.
1
+ # Copyright 2024 The GLIGEN Authors and 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.
@@ -35,7 +35,7 @@ from ...utils import (
35
35
  unscale_lora_layers,
36
36
  )
37
37
  from ...utils.torch_utils import randn_tensor
38
- from ..pipeline_utils import DiffusionPipeline
38
+ from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin
39
39
  from ..stable_diffusion import StableDiffusionPipelineOutput
40
40
  from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
41
41
 
@@ -99,7 +99,7 @@ EXAMPLE_DOC_STRING = """
99
99
  """
100
100
 
101
101
 
102
- class StableDiffusionGLIGENPipeline(DiffusionPipeline):
102
+ class StableDiffusionGLIGENPipeline(DiffusionPipeline, StableDiffusionMixin):
103
103
  r"""
104
104
  Pipeline for text-to-image generation using Stable Diffusion with Grounded-Language-to-Image Generation (GLIGEN).
105
105
 
@@ -172,35 +172,6 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
172
172
  self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor, do_convert_rgb=True)
173
173
  self.register_to_config(requires_safety_checker=requires_safety_checker)
174
174
 
175
- def enable_vae_slicing(self):
176
- r"""
177
- Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
178
- compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
179
- """
180
- self.vae.enable_slicing()
181
-
182
- def disable_vae_slicing(self):
183
- r"""
184
- Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
185
- computing decoding in one step.
186
- """
187
- self.vae.disable_slicing()
188
-
189
- def enable_vae_tiling(self):
190
- r"""
191
- Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
192
- compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
193
- processing larger images.
194
- """
195
- self.vae.enable_tiling()
196
-
197
- def disable_vae_tiling(self):
198
- r"""
199
- Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
200
- computing decoding in one step.
201
- """
202
- self.vae.disable_tiling()
203
-
204
175
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
205
176
  def _encode_prompt(
206
177
  self,
@@ -295,7 +266,7 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
295
266
  batch_size = prompt_embeds.shape[0]
296
267
 
297
268
  if prompt_embeds is None:
298
- # textual inversion: procecss multi-vector tokens if necessary
269
+ # textual inversion: process multi-vector tokens if necessary
299
270
  if isinstance(self, TextualInversionLoaderMixin):
300
271
  prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
301
272
 
@@ -377,7 +348,7 @@ class StableDiffusionGLIGENPipeline(DiffusionPipeline):
377
348
  else:
378
349
  uncond_tokens = negative_prompt
379
350
 
380
- # textual inversion: procecss multi-vector tokens if necessary
351
+ # textual inversion: process multi-vector tokens if necessary
381
352
  if isinstance(self, TextualInversionLoaderMixin):
382
353
  uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
383
354