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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. diffusers/__init__.py +26 -2
  2. diffusers/commands/fp16_safetensors.py +10 -11
  3. diffusers/configuration_utils.py +13 -8
  4. diffusers/dependency_versions_check.py +0 -1
  5. diffusers/dependency_versions_table.py +5 -5
  6. diffusers/experimental/rl/value_guided_sampling.py +1 -1
  7. diffusers/image_processor.py +463 -51
  8. diffusers/loaders/__init__.py +82 -0
  9. diffusers/loaders/ip_adapter.py +159 -0
  10. diffusers/loaders/lora.py +1553 -0
  11. diffusers/loaders/lora_conversion_utils.py +284 -0
  12. diffusers/loaders/single_file.py +637 -0
  13. diffusers/loaders/textual_inversion.py +455 -0
  14. diffusers/loaders/unet.py +828 -0
  15. diffusers/loaders/utils.py +59 -0
  16. diffusers/models/__init__.py +26 -9
  17. diffusers/models/activations.py +9 -6
  18. diffusers/models/attention.py +301 -29
  19. diffusers/models/attention_flax.py +9 -1
  20. diffusers/models/attention_processor.py +378 -6
  21. diffusers/models/autoencoders/__init__.py +5 -0
  22. diffusers/models/{autoencoder_asym_kl.py → autoencoders/autoencoder_asym_kl.py} +17 -12
  23. diffusers/models/{autoencoder_kl.py → autoencoders/autoencoder_kl.py} +47 -23
  24. diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +402 -0
  25. diffusers/models/{autoencoder_tiny.py → autoencoders/autoencoder_tiny.py} +24 -28
  26. diffusers/models/{consistency_decoder_vae.py → autoencoders/consistency_decoder_vae.py} +51 -44
  27. diffusers/models/{vae.py → autoencoders/vae.py} +71 -17
  28. diffusers/models/controlnet.py +59 -39
  29. diffusers/models/controlnet_flax.py +19 -18
  30. diffusers/models/downsampling.py +338 -0
  31. diffusers/models/embeddings.py +112 -29
  32. diffusers/models/embeddings_flax.py +2 -0
  33. diffusers/models/lora.py +131 -1
  34. diffusers/models/modeling_flax_utils.py +14 -8
  35. diffusers/models/modeling_outputs.py +17 -0
  36. diffusers/models/modeling_utils.py +37 -29
  37. diffusers/models/normalization.py +110 -4
  38. diffusers/models/resnet.py +299 -652
  39. diffusers/models/transformer_2d.py +22 -5
  40. diffusers/models/transformer_temporal.py +183 -1
  41. diffusers/models/unet_2d_blocks_flax.py +5 -0
  42. diffusers/models/unet_2d_condition.py +46 -0
  43. diffusers/models/unet_2d_condition_flax.py +13 -13
  44. diffusers/models/unet_3d_blocks.py +957 -173
  45. diffusers/models/unet_3d_condition.py +16 -8
  46. diffusers/models/unet_kandinsky3.py +535 -0
  47. diffusers/models/unet_motion_model.py +48 -33
  48. diffusers/models/unet_spatio_temporal_condition.py +489 -0
  49. diffusers/models/upsampling.py +454 -0
  50. diffusers/models/uvit_2d.py +471 -0
  51. diffusers/models/vae_flax.py +7 -0
  52. diffusers/models/vq_model.py +12 -3
  53. diffusers/optimization.py +16 -9
  54. diffusers/pipelines/__init__.py +137 -76
  55. diffusers/pipelines/amused/__init__.py +62 -0
  56. diffusers/pipelines/amused/pipeline_amused.py +328 -0
  57. diffusers/pipelines/amused/pipeline_amused_img2img.py +347 -0
  58. diffusers/pipelines/amused/pipeline_amused_inpaint.py +378 -0
  59. diffusers/pipelines/animatediff/pipeline_animatediff.py +66 -8
  60. diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
  61. diffusers/pipelines/auto_pipeline.py +23 -13
  62. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
  63. diffusers/pipelines/controlnet/pipeline_controlnet.py +238 -35
  64. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +148 -37
  65. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +155 -41
  66. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +123 -43
  67. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +216 -39
  68. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +106 -34
  69. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
  70. diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
  71. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
  72. diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
  73. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
  74. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
  75. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
  76. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
  77. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
  78. diffusers/pipelines/deprecated/__init__.py +153 -0
  79. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/__init__.py +3 -3
  80. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion.py +177 -34
  81. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py +182 -37
  82. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_output.py +1 -1
  83. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/__init__.py +1 -1
  84. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/mel.py +2 -2
  85. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py +4 -4
  86. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/__init__.py +1 -1
  87. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/pipeline_latent_diffusion_uncond.py +4 -4
  88. diffusers/pipelines/{pndm → deprecated/pndm}/__init__.py +1 -1
  89. diffusers/pipelines/{pndm → deprecated/pndm}/pipeline_pndm.py +4 -4
  90. diffusers/pipelines/{repaint → deprecated/repaint}/__init__.py +1 -1
  91. diffusers/pipelines/{repaint → deprecated/repaint}/pipeline_repaint.py +5 -5
  92. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/__init__.py +1 -1
  93. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/pipeline_score_sde_ve.py +5 -4
  94. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/__init__.py +6 -6
  95. diffusers/pipelines/{spectrogram_diffusion/continous_encoder.py → deprecated/spectrogram_diffusion/continuous_encoder.py} +2 -2
  96. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/midi_utils.py +1 -1
  97. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py +2 -2
  98. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/pipeline_spectrogram_diffusion.py +8 -7
  99. diffusers/pipelines/deprecated/stable_diffusion_variants/__init__.py +55 -0
  100. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_cycle_diffusion.py +34 -13
  101. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_onnx_stable_diffusion_inpaint_legacy.py +7 -6
  102. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_inpaint_legacy.py +12 -11
  103. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_model_editing.py +17 -11
  104. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_paradigms.py +11 -10
  105. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_pix2pix_zero.py +14 -13
  106. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/__init__.py +1 -1
  107. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/pipeline_stochastic_karras_ve.py +4 -4
  108. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/__init__.py +3 -3
  109. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/modeling_text_unet.py +83 -51
  110. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion.py +4 -4
  111. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_dual_guided.py +7 -6
  112. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_image_variation.py +7 -6
  113. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_text_to_image.py +7 -6
  114. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/__init__.py +3 -3
  115. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/pipeline_vq_diffusion.py +5 -5
  116. diffusers/pipelines/dit/pipeline_dit.py +1 -0
  117. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
  118. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
  119. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  120. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
  121. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
  122. diffusers/pipelines/kandinsky3/__init__.py +49 -0
  123. diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +98 -0
  124. diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +589 -0
  125. diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +654 -0
  126. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +111 -11
  127. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +102 -9
  128. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
  129. diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
  130. diffusers/pipelines/onnx_utils.py +8 -5
  131. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
  132. diffusers/pipelines/pipeline_flax_utils.py +11 -8
  133. diffusers/pipelines/pipeline_utils.py +63 -42
  134. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +247 -38
  135. diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +3 -3
  136. diffusers/pipelines/stable_diffusion/__init__.py +37 -65
  137. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +75 -78
  138. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
  139. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
  140. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
  141. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +174 -11
  142. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
  143. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
  144. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +178 -11
  145. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +224 -13
  146. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +74 -20
  147. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +4 -0
  148. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +7 -0
  149. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -0
  150. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -0
  151. diffusers/pipelines/stable_diffusion_attend_and_excite/__init__.py +48 -0
  152. diffusers/pipelines/{stable_diffusion → stable_diffusion_attend_and_excite}/pipeline_stable_diffusion_attend_and_excite.py +6 -2
  153. diffusers/pipelines/stable_diffusion_diffedit/__init__.py +48 -0
  154. diffusers/pipelines/{stable_diffusion → stable_diffusion_diffedit}/pipeline_stable_diffusion_diffedit.py +3 -3
  155. diffusers/pipelines/stable_diffusion_gligen/__init__.py +50 -0
  156. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py +3 -2
  157. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen_text_image.py +4 -3
  158. diffusers/pipelines/stable_diffusion_k_diffusion/__init__.py +60 -0
  159. diffusers/pipelines/{stable_diffusion → stable_diffusion_k_diffusion}/pipeline_stable_diffusion_k_diffusion.py +7 -1
  160. diffusers/pipelines/stable_diffusion_ldm3d/__init__.py +48 -0
  161. diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py +51 -7
  162. diffusers/pipelines/stable_diffusion_panorama/__init__.py +48 -0
  163. diffusers/pipelines/{stable_diffusion → stable_diffusion_panorama}/pipeline_stable_diffusion_panorama.py +57 -8
  164. diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +58 -6
  165. diffusers/pipelines/stable_diffusion_sag/__init__.py +48 -0
  166. diffusers/pipelines/{stable_diffusion → stable_diffusion_sag}/pipeline_stable_diffusion_sag.py +68 -10
  167. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +194 -17
  168. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +205 -16
  169. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +206 -17
  170. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +23 -17
  171. diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
  172. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +652 -0
  173. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
  174. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +115 -14
  175. diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
  176. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +6 -0
  177. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +23 -3
  178. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +334 -10
  179. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +1331 -0
  180. diffusers/pipelines/unclip/pipeline_unclip.py +2 -1
  181. diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -0
  182. diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
  183. diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
  184. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
  185. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
  186. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
  187. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +5 -1
  188. diffusers/schedulers/__init__.py +4 -4
  189. diffusers/schedulers/deprecated/__init__.py +50 -0
  190. diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
  191. diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
  192. diffusers/schedulers/scheduling_amused.py +162 -0
  193. diffusers/schedulers/scheduling_consistency_models.py +2 -0
  194. diffusers/schedulers/scheduling_ddim.py +1 -3
  195. diffusers/schedulers/scheduling_ddim_inverse.py +2 -7
  196. diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
  197. diffusers/schedulers/scheduling_ddpm.py +47 -3
  198. diffusers/schedulers/scheduling_ddpm_parallel.py +47 -3
  199. diffusers/schedulers/scheduling_deis_multistep.py +28 -6
  200. diffusers/schedulers/scheduling_dpmsolver_multistep.py +28 -6
  201. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +28 -6
  202. diffusers/schedulers/scheduling_dpmsolver_sde.py +3 -3
  203. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +28 -6
  204. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +59 -3
  205. diffusers/schedulers/scheduling_euler_discrete.py +102 -16
  206. diffusers/schedulers/scheduling_heun_discrete.py +17 -5
  207. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +17 -5
  208. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +17 -5
  209. diffusers/schedulers/scheduling_lcm.py +123 -29
  210. diffusers/schedulers/scheduling_lms_discrete.py +3 -3
  211. diffusers/schedulers/scheduling_pndm.py +1 -3
  212. diffusers/schedulers/scheduling_repaint.py +1 -3
  213. diffusers/schedulers/scheduling_unipc_multistep.py +28 -6
  214. diffusers/schedulers/scheduling_utils.py +3 -1
  215. diffusers/schedulers/scheduling_utils_flax.py +3 -1
  216. diffusers/training_utils.py +1 -1
  217. diffusers/utils/__init__.py +1 -2
  218. diffusers/utils/constants.py +10 -12
  219. diffusers/utils/dummy_pt_objects.py +75 -0
  220. diffusers/utils/dummy_torch_and_transformers_objects.py +105 -0
  221. diffusers/utils/dynamic_modules_utils.py +18 -22
  222. diffusers/utils/export_utils.py +8 -3
  223. diffusers/utils/hub_utils.py +24 -36
  224. diffusers/utils/logging.py +11 -11
  225. diffusers/utils/outputs.py +5 -5
  226. diffusers/utils/peft_utils.py +88 -44
  227. diffusers/utils/state_dict_utils.py +8 -0
  228. diffusers/utils/testing_utils.py +199 -1
  229. diffusers/utils/torch_utils.py +4 -4
  230. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/METADATA +86 -69
  231. diffusers-0.25.0.dist-info/RECORD +360 -0
  232. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/WHEEL +1 -1
  233. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/entry_points.txt +0 -1
  234. diffusers/loaders.py +0 -3336
  235. diffusers-0.23.1.dist-info/RECORD +0 -323
  236. /diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/modeling_roberta_series.py +0 -0
  237. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/LICENSE +0 -0
  238. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/top_level.txt +0 -0
@@ -37,6 +37,7 @@ from ...models.lora import adjust_lora_scale_text_encoder
37
37
  from ...schedulers import KarrasDiffusionSchedulers
38
38
  from ...utils import (
39
39
  USE_PEFT_BACKEND,
40
+ deprecate,
40
41
  logging,
41
42
  replace_example_docstring,
42
43
  scale_lora_layers,
@@ -132,9 +133,13 @@ EXAMPLE_DOC_STRING = """
132
133
 
133
134
 
134
135
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.retrieve_latents
135
- def retrieve_latents(encoder_output, generator):
136
- if hasattr(encoder_output, "latent_dist"):
136
+ def retrieve_latents(
137
+ encoder_output: torch.Tensor, generator: Optional[torch.Generator] = None, sample_mode: str = "sample"
138
+ ):
139
+ if hasattr(encoder_output, "latent_dist") and sample_mode == "sample":
137
140
  return encoder_output.latent_dist.sample(generator)
141
+ elif hasattr(encoder_output, "latent_dist") and sample_mode == "argmax":
142
+ return encoder_output.latent_dist.mode()
138
143
  elif hasattr(encoder_output, "latents"):
139
144
  return encoder_output.latents
140
145
  else:
@@ -150,9 +155,10 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
150
155
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
151
156
  library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
152
157
 
153
- In addition the pipeline inherits the following loading methods:
154
- - *Textual-Inversion*: [`loaders.TextualInversionLoaderMixin.load_textual_inversion`]
155
- - *LoRA*: [`loaders.StableDiffusionXLLoraLoaderMixin.load_lora_weights`]
158
+ The pipeline also inherits the following loading methods:
159
+ - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
160
+ - [`~loaders.StableDiffusionXLLoraLoaderMixin.load_lora_weights`] for loading LoRA weights
161
+ - [`~loaders.StableDiffusionXLLoraLoaderMixin.save_lora_weights`] for saving LoRA weights
156
162
 
157
163
  Args:
158
164
  vae ([`AutoencoderKL`]):
@@ -192,8 +198,10 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
192
198
  watermark output images. If not defined, it will default to True if the package is installed, otherwise no
193
199
  watermarker will be used.
194
200
  """
201
+
195
202
  model_cpu_offload_seq = "text_encoder->text_encoder_2->unet->vae"
196
203
  _optional_components = ["tokenizer", "tokenizer_2", "text_encoder", "text_encoder_2"]
204
+ _callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
197
205
 
198
206
  def __init__(
199
207
  self,
@@ -542,6 +550,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
542
550
  controlnet_conditioning_scale=1.0,
543
551
  control_guidance_start=0.0,
544
552
  control_guidance_end=1.0,
553
+ callback_on_step_end_tensor_inputs=None,
545
554
  ):
546
555
  if strength < 0 or strength > 1:
547
556
  raise ValueError(f"The value of strength should in [0.0, 1.0] but is {strength}")
@@ -552,14 +561,20 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
552
561
  f"`num_inference_steps` has to be a positive integer but is {num_inference_steps} of type"
553
562
  f" {type(num_inference_steps)}."
554
563
  )
555
- if (callback_steps is None) or (
556
- callback_steps is not None and (not isinstance(callback_steps, int) or callback_steps <= 0)
557
- ):
564
+
565
+ if callback_steps is not None and (not isinstance(callback_steps, int) or callback_steps <= 0):
558
566
  raise ValueError(
559
567
  f"`callback_steps` has to be a positive integer but is {callback_steps} of type"
560
568
  f" {type(callback_steps)}."
561
569
  )
562
570
 
571
+ if callback_on_step_end_tensor_inputs is not None and not all(
572
+ k in self._callback_tensor_inputs for k in callback_on_step_end_tensor_inputs
573
+ ):
574
+ raise ValueError(
575
+ f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found {[k for k in callback_on_step_end_tensor_inputs if k not in self._callback_tensor_inputs]}"
576
+ )
577
+
563
578
  if prompt is not None and prompt_embeds is not None:
564
579
  raise ValueError(
565
580
  f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to"
@@ -950,6 +965,29 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
950
965
  """Disables the FreeU mechanism if enabled."""
951
966
  self.unet.disable_freeu()
952
967
 
968
+ @property
969
+ def guidance_scale(self):
970
+ return self._guidance_scale
971
+
972
+ @property
973
+ def clip_skip(self):
974
+ return self._clip_skip
975
+
976
+ # here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
977
+ # of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
978
+ # corresponds to doing no classifier free guidance.
979
+ @property
980
+ def do_classifier_free_guidance(self):
981
+ return self._guidance_scale > 1
982
+
983
+ @property
984
+ def cross_attention_kwargs(self):
985
+ return self._cross_attention_kwargs
986
+
987
+ @property
988
+ def num_timesteps(self):
989
+ return self._num_timesteps
990
+
953
991
  @torch.no_grad()
954
992
  @replace_example_docstring(EXAMPLE_DOC_STRING)
955
993
  def __call__(
@@ -975,8 +1013,6 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
975
1013
  negative_pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
976
1014
  output_type: Optional[str] = "pil",
977
1015
  return_dict: bool = True,
978
- callback: Optional[Callable[[int, int, torch.FloatTensor], None]] = None,
979
- callback_steps: int = 1,
980
1016
  cross_attention_kwargs: Optional[Dict[str, Any]] = None,
981
1017
  controlnet_conditioning_scale: Union[float, List[float]] = 0.8,
982
1018
  guess_mode: bool = False,
@@ -991,6 +1027,9 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
991
1027
  aesthetic_score: float = 6.0,
992
1028
  negative_aesthetic_score: float = 2.5,
993
1029
  clip_skip: Optional[int] = None,
1030
+ callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
1031
+ callback_on_step_end_tensor_inputs: List[str] = ["latents"],
1032
+ **kwargs,
994
1033
  ):
995
1034
  r"""
996
1035
  Function invoked when calling the pipeline for generation.
@@ -1076,12 +1115,6 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1076
1115
  return_dict (`bool`, *optional*, defaults to `True`):
1077
1116
  Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] instead of a
1078
1117
  plain tuple.
1079
- callback (`Callable`, *optional*):
1080
- A function that will be called every `callback_steps` steps during inference. The function will be
1081
- called with the following arguments: `callback(step: int, timestep: int, latents: torch.FloatTensor)`.
1082
- callback_steps (`int`, *optional*, defaults to 1):
1083
- The frequency at which the `callback` function will be called. If not specified, the callback will be
1084
- called at every step.
1085
1118
  cross_attention_kwargs (`dict`, *optional*):
1086
1119
  A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
1087
1120
  `self.processor` in
@@ -1137,6 +1170,15 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1137
1170
  clip_skip (`int`, *optional*):
1138
1171
  Number of layers to be skipped from CLIP while computing the prompt embeddings. A value of 1 means that
1139
1172
  the output of the pre-final layer will be used for computing the prompt embeddings.
1173
+ callback_on_step_end (`Callable`, *optional*):
1174
+ A function that calls at the end of each denoising steps during the inference. The function is called
1175
+ with the following arguments: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int,
1176
+ callback_kwargs: Dict)`. `callback_kwargs` will include a list of all tensors as specified by
1177
+ `callback_on_step_end_tensor_inputs`.
1178
+ callback_on_step_end_tensor_inputs (`List`, *optional*):
1179
+ The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
1180
+ will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
1181
+ `._callback_tensor_inputs` attribute of your pipeine class.
1140
1182
 
1141
1183
  Examples:
1142
1184
 
@@ -1145,6 +1187,23 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1145
1187
  [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple`
1146
1188
  containing the output images.
1147
1189
  """
1190
+
1191
+ callback = kwargs.pop("callback", None)
1192
+ callback_steps = kwargs.pop("callback_steps", None)
1193
+
1194
+ if callback is not None:
1195
+ deprecate(
1196
+ "callback",
1197
+ "1.0.0",
1198
+ "Passing `callback` as an input argument to `__call__` is deprecated, consider using `callback_on_step_end`",
1199
+ )
1200
+ if callback_steps is not None:
1201
+ deprecate(
1202
+ "callback_steps",
1203
+ "1.0.0",
1204
+ "Passing `callback_steps` as an input argument to `__call__` is deprecated, consider using `callback_on_step_end`",
1205
+ )
1206
+
1148
1207
  controlnet = self.controlnet._orig_mod if is_compiled_module(self.controlnet) else self.controlnet
1149
1208
 
1150
1209
  # align format for control guidance
@@ -1154,9 +1213,10 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1154
1213
  control_guidance_end = len(control_guidance_start) * [control_guidance_end]
1155
1214
  elif not isinstance(control_guidance_start, list) and not isinstance(control_guidance_end, list):
1156
1215
  mult = len(controlnet.nets) if isinstance(controlnet, MultiControlNetModel) else 1
1157
- control_guidance_start, control_guidance_end = mult * [control_guidance_start], mult * [
1158
- control_guidance_end
1159
- ]
1216
+ control_guidance_start, control_guidance_end = (
1217
+ mult * [control_guidance_start],
1218
+ mult * [control_guidance_end],
1219
+ )
1160
1220
 
1161
1221
  # 1. Check inputs. Raise error if not correct
1162
1222
  self.check_inputs(
@@ -1175,8 +1235,13 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1175
1235
  controlnet_conditioning_scale,
1176
1236
  control_guidance_start,
1177
1237
  control_guidance_end,
1238
+ callback_on_step_end_tensor_inputs,
1178
1239
  )
1179
1240
 
1241
+ self._guidance_scale = guidance_scale
1242
+ self._clip_skip = clip_skip
1243
+ self._cross_attention_kwargs = cross_attention_kwargs
1244
+
1180
1245
  # 2. Define call parameters
1181
1246
  if prompt is not None and isinstance(prompt, str):
1182
1247
  batch_size = 1
@@ -1186,10 +1251,6 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1186
1251
  batch_size = prompt_embeds.shape[0]
1187
1252
 
1188
1253
  device = self._execution_device
1189
- # here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
1190
- # of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
1191
- # corresponds to doing no classifier free guidance.
1192
- do_classifier_free_guidance = guidance_scale > 1.0
1193
1254
 
1194
1255
  if isinstance(controlnet, MultiControlNetModel) and isinstance(controlnet_conditioning_scale, float):
1195
1256
  controlnet_conditioning_scale = [controlnet_conditioning_scale] * len(controlnet.nets)
@@ -1203,7 +1264,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1203
1264
 
1204
1265
  # 3. Encode input prompt
1205
1266
  text_encoder_lora_scale = (
1206
- cross_attention_kwargs.get("scale", None) if cross_attention_kwargs is not None else None
1267
+ self.cross_attention_kwargs.get("scale", None) if self.cross_attention_kwargs is not None else None
1207
1268
  )
1208
1269
  (
1209
1270
  prompt_embeds,
@@ -1215,7 +1276,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1215
1276
  prompt_2,
1216
1277
  device,
1217
1278
  num_images_per_prompt,
1218
- do_classifier_free_guidance,
1279
+ self.do_classifier_free_guidance,
1219
1280
  negative_prompt,
1220
1281
  negative_prompt_2,
1221
1282
  prompt_embeds=prompt_embeds,
@@ -1223,7 +1284,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1223
1284
  pooled_prompt_embeds=pooled_prompt_embeds,
1224
1285
  negative_pooled_prompt_embeds=negative_pooled_prompt_embeds,
1225
1286
  lora_scale=text_encoder_lora_scale,
1226
- clip_skip=clip_skip,
1287
+ clip_skip=self.clip_skip,
1227
1288
  )
1228
1289
 
1229
1290
  # 4. Prepare image and controlnet_conditioning_image
@@ -1238,7 +1299,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1238
1299
  num_images_per_prompt=num_images_per_prompt,
1239
1300
  device=device,
1240
1301
  dtype=controlnet.dtype,
1241
- do_classifier_free_guidance=do_classifier_free_guidance,
1302
+ do_classifier_free_guidance=self.do_classifier_free_guidance,
1242
1303
  guess_mode=guess_mode,
1243
1304
  )
1244
1305
  height, width = control_image.shape[-2:]
@@ -1254,7 +1315,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1254
1315
  num_images_per_prompt=num_images_per_prompt,
1255
1316
  device=device,
1256
1317
  dtype=controlnet.dtype,
1257
- do_classifier_free_guidance=do_classifier_free_guidance,
1318
+ do_classifier_free_guidance=self.do_classifier_free_guidance,
1258
1319
  guess_mode=guess_mode,
1259
1320
  )
1260
1321
 
@@ -1269,6 +1330,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1269
1330
  self.scheduler.set_timesteps(num_inference_steps, device=device)
1270
1331
  timesteps, num_inference_steps = self.get_timesteps(num_inference_steps, strength, device)
1271
1332
  latent_timestep = timesteps[:1].repeat(batch_size * num_images_per_prompt)
1333
+ self._num_timesteps = len(timesteps)
1272
1334
 
1273
1335
  # 6. Prepare latent variables
1274
1336
  latents = self.prepare_latents(
@@ -1326,7 +1388,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1326
1388
  )
1327
1389
  add_time_ids = add_time_ids.repeat(batch_size * num_images_per_prompt, 1)
1328
1390
 
1329
- if do_classifier_free_guidance:
1391
+ if self.do_classifier_free_guidance:
1330
1392
  prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds], dim=0)
1331
1393
  add_text_embeds = torch.cat([negative_pooled_prompt_embeds, add_text_embeds], dim=0)
1332
1394
  add_neg_time_ids = add_neg_time_ids.repeat(batch_size * num_images_per_prompt, 1)
@@ -1341,13 +1403,13 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1341
1403
  with self.progress_bar(total=num_inference_steps) as progress_bar:
1342
1404
  for i, t in enumerate(timesteps):
1343
1405
  # expand the latents if we are doing classifier free guidance
1344
- latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents
1406
+ latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents
1345
1407
  latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
1346
1408
 
1347
1409
  added_cond_kwargs = {"text_embeds": add_text_embeds, "time_ids": add_time_ids}
1348
1410
 
1349
1411
  # controlnet(s) inference
1350
- if guess_mode and do_classifier_free_guidance:
1412
+ if guess_mode and self.do_classifier_free_guidance:
1351
1413
  # Infer ControlNet only for the conditional batch.
1352
1414
  control_model_input = latents
1353
1415
  control_model_input = self.scheduler.scale_model_input(control_model_input, t)
@@ -1380,7 +1442,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1380
1442
  return_dict=False,
1381
1443
  )
1382
1444
 
1383
- if guess_mode and do_classifier_free_guidance:
1445
+ if guess_mode and self.do_classifier_free_guidance:
1384
1446
  # Infered ControlNet only for the conditional batch.
1385
1447
  # To apply the output of ControlNet to both the unconditional and conditional batches,
1386
1448
  # add 0 to the unconditional batch to keep it unchanged.
@@ -1392,7 +1454,7 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1392
1454
  latent_model_input,
1393
1455
  t,
1394
1456
  encoder_hidden_states=prompt_embeds,
1395
- cross_attention_kwargs=cross_attention_kwargs,
1457
+ cross_attention_kwargs=self.cross_attention_kwargs,
1396
1458
  down_block_additional_residuals=down_block_res_samples,
1397
1459
  mid_block_additional_residual=mid_block_res_sample,
1398
1460
  added_cond_kwargs=added_cond_kwargs,
@@ -1400,13 +1462,23 @@ class StableDiffusionXLControlNetImg2ImgPipeline(
1400
1462
  )[0]
1401
1463
 
1402
1464
  # perform guidance
1403
- if do_classifier_free_guidance:
1465
+ if self.do_classifier_free_guidance:
1404
1466
  noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)
1405
1467
  noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
1406
1468
 
1407
1469
  # compute the previous noisy sample x_t -> x_t-1
1408
1470
  latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
1409
1471
 
1472
+ if callback_on_step_end is not None:
1473
+ callback_kwargs = {}
1474
+ for k in callback_on_step_end_tensor_inputs:
1475
+ callback_kwargs[k] = locals()[k]
1476
+ callback_outputs = callback_on_step_end(self, i, t, callback_kwargs)
1477
+
1478
+ latents = callback_outputs.pop("latents", latents)
1479
+ prompt_embeds = callback_outputs.pop("prompt_embeds", prompt_embeds)
1480
+ negative_prompt_embeds = callback_outputs.pop("negative_prompt_embeds", negative_prompt_embeds)
1481
+
1410
1482
  # call the callback, if provided
1411
1483
  if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
1412
1484
  progress_bar.update()
@@ -39,6 +39,7 @@ class DanceDiffusionPipeline(DiffusionPipeline):
39
39
  A scheduler to be used in combination with `unet` to denoise the encoded audio latents. Can be one of
40
40
  [`IPNDMScheduler`].
41
41
  """
42
+
42
43
  model_cpu_offload_seq = "unet"
43
44
 
44
45
  def __init__(self, unet, scheduler):
@@ -35,6 +35,7 @@ class DDIMPipeline(DiffusionPipeline):
35
35
  A scheduler to be used in combination with `unet` to denoise the encoded image. Can be one of
36
36
  [`DDPMScheduler`], or [`DDIMScheduler`].
37
37
  """
38
+
38
39
  model_cpu_offload_seq = "unet"
39
40
 
40
41
  def __init__(self, unet, scheduler):
@@ -35,6 +35,7 @@ class DDPMPipeline(DiffusionPipeline):
35
35
  A scheduler to be used in combination with `unet` to denoise the encoded image. Can be one of
36
36
  [`DDPMScheduler`], or [`DDIMScheduler`].
37
37
  """
38
+
38
39
  model_cpu_offload_seq = "unet"
39
40
 
40
41
  def __init__(self, unet, scheduler):
@@ -98,7 +98,19 @@ class IFPipeline(DiffusionPipeline, LoraLoaderMixin):
98
98
  watermarker: Optional[IFWatermarker]
99
99
 
100
100
  bad_punct_regex = re.compile(
101
- r"[" + "#®•©™&@·º½¾¿¡§~" + "\)" + "\(" + "\]" + "\[" + "\}" + "\{" + "\|" + "\\" + "\/" + "\*" + r"]{1,}"
101
+ r"["
102
+ + "#®•©™&@·º½¾¿¡§~"
103
+ + r"\)"
104
+ + r"\("
105
+ + r"\]"
106
+ + r"\["
107
+ + r"\}"
108
+ + r"\{"
109
+ + r"\|"
110
+ + "\\"
111
+ + r"\/"
112
+ + r"\*"
113
+ + r"]{1,}"
102
114
  ) # noqa
103
115
 
104
116
  _optional_components = ["tokenizer", "text_encoder", "safety_checker", "feature_extractor", "watermarker"]
@@ -122,7 +122,19 @@ class IFImg2ImgPipeline(DiffusionPipeline, LoraLoaderMixin):
122
122
  watermarker: Optional[IFWatermarker]
123
123
 
124
124
  bad_punct_regex = re.compile(
125
- r"[" + "#®•©™&@·º½¾¿¡§~" + "\)" + "\(" + "\]" + "\[" + "\}" + "\{" + "\|" + "\\" + "\/" + "\*" + r"]{1,}"
125
+ r"["
126
+ + "#®•©™&@·º½¾¿¡§~"
127
+ + r"\)"
128
+ + r"\("
129
+ + r"\]"
130
+ + r"\["
131
+ + r"\}"
132
+ + r"\{"
133
+ + r"\|"
134
+ + "\\"
135
+ + r"\/"
136
+ + r"\*"
137
+ + r"]{1,}"
126
138
  ) # noqa
127
139
 
128
140
  _optional_components = ["tokenizer", "text_encoder", "safety_checker", "feature_extractor", "watermarker"]
@@ -126,7 +126,19 @@ class IFImg2ImgSuperResolutionPipeline(DiffusionPipeline, LoraLoaderMixin):
126
126
  watermarker: Optional[IFWatermarker]
127
127
 
128
128
  bad_punct_regex = re.compile(
129
- r"[" + "#®•©™&@·º½¾¿¡§~" + "\)" + "\(" + "\]" + "\[" + "\}" + "\{" + "\|" + "\\" + "\/" + "\*" + r"]{1,}"
129
+ r"["
130
+ + "#®•©™&@·º½¾¿¡§~"
131
+ + r"\)"
132
+ + r"\("
133
+ + r"\]"
134
+ + r"\["
135
+ + r"\}"
136
+ + r"\{"
137
+ + r"\|"
138
+ + "\\"
139
+ + r"\/"
140
+ + r"\*"
141
+ + r"]{1,}"
130
142
  ) # noqa
131
143
 
132
144
  _optional_components = ["tokenizer", "text_encoder", "safety_checker", "feature_extractor"]
@@ -125,7 +125,19 @@ class IFInpaintingPipeline(DiffusionPipeline, LoraLoaderMixin):
125
125
  watermarker: Optional[IFWatermarker]
126
126
 
127
127
  bad_punct_regex = re.compile(
128
- r"[" + "#®•©™&@·º½¾¿¡§~" + "\)" + "\(" + "\]" + "\[" + "\}" + "\{" + "\|" + "\\" + "\/" + "\*" + r"]{1,}"
128
+ r"["
129
+ + "#®•©™&@·º½¾¿¡§~"
130
+ + r"\)"
131
+ + r"\("
132
+ + r"\]"
133
+ + r"\["
134
+ + r"\}"
135
+ + r"\{"
136
+ + r"\|"
137
+ + "\\"
138
+ + r"\/"
139
+ + r"\*"
140
+ + r"]{1,}"
129
141
  ) # noqa
130
142
 
131
143
  _optional_components = ["tokenizer", "text_encoder", "safety_checker", "feature_extractor", "watermarker"]
@@ -128,7 +128,19 @@ class IFInpaintingSuperResolutionPipeline(DiffusionPipeline, LoraLoaderMixin):
128
128
  watermarker: Optional[IFWatermarker]
129
129
 
130
130
  bad_punct_regex = re.compile(
131
- r"[" + "#®•©™&@·º½¾¿¡§~" + "\)" + "\(" + "\]" + "\[" + "\}" + "\{" + "\|" + "\\" + "\/" + "\*" + r"]{1,}"
131
+ r"["
132
+ + "#®•©™&@·º½¾¿¡§~"
133
+ + r"\)"
134
+ + r"\("
135
+ + r"\]"
136
+ + r"\["
137
+ + r"\}"
138
+ + r"\{"
139
+ + r"\|"
140
+ + "\\"
141
+ + r"\/"
142
+ + r"\*"
143
+ + r"]{1,}"
132
144
  ) # noqa
133
145
 
134
146
  model_cpu_offload_seq = "text_encoder->unet"
@@ -84,7 +84,19 @@ class IFSuperResolutionPipeline(DiffusionPipeline, LoraLoaderMixin):
84
84
  watermarker: Optional[IFWatermarker]
85
85
 
86
86
  bad_punct_regex = re.compile(
87
- r"[" + "#®•©™&@·º½¾¿¡§~" + "\)" + "\(" + "\]" + "\[" + "\}" + "\{" + "\|" + "\\" + "\/" + "\*" + r"]{1,}"
87
+ r"["
88
+ + "#®•©™&@·º½¾¿¡§~"
89
+ + r"\)"
90
+ + r"\("
91
+ + r"\]"
92
+ + r"\["
93
+ + r"\}"
94
+ + r"\{"
95
+ + r"\|"
96
+ + "\\"
97
+ + r"\/"
98
+ + r"\*"
99
+ + r"]{1,}"
88
100
  ) # noqa
89
101
 
90
102
  _optional_components = ["tokenizer", "text_encoder", "safety_checker", "feature_extractor", "watermarker"]
@@ -0,0 +1,153 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ...utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
+ OptionalDependencyNotAvailable,
6
+ _LazyModule,
7
+ get_objects_from_module,
8
+ is_librosa_available,
9
+ is_note_seq_available,
10
+ is_torch_available,
11
+ is_transformers_available,
12
+ )
13
+
14
+
15
+ _dummy_objects = {}
16
+ _import_structure = {}
17
+
18
+ try:
19
+ if not is_torch_available():
20
+ raise OptionalDependencyNotAvailable()
21
+ except OptionalDependencyNotAvailable:
22
+ from ...utils import dummy_pt_objects
23
+
24
+ _dummy_objects.update(get_objects_from_module(dummy_pt_objects))
25
+ else:
26
+ _import_structure["latent_diffusion_uncond"] = ["LDMPipeline"]
27
+ _import_structure["pndm"] = ["PNDMPipeline"]
28
+ _import_structure["repaint"] = ["RePaintPipeline"]
29
+ _import_structure["score_sde_ve"] = ["ScoreSdeVePipeline"]
30
+ _import_structure["stochastic_karras_ve"] = ["KarrasVePipeline"]
31
+
32
+ try:
33
+ if not (is_transformers_available() and is_torch_available()):
34
+ raise OptionalDependencyNotAvailable()
35
+ except OptionalDependencyNotAvailable:
36
+ from ...utils import dummy_torch_and_transformers_objects
37
+
38
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
39
+ else:
40
+ _import_structure["alt_diffusion"] = [
41
+ "AltDiffusionImg2ImgPipeline",
42
+ "AltDiffusionPipeline",
43
+ "AltDiffusionPipelineOutput",
44
+ ]
45
+ _import_structure["versatile_diffusion"] = [
46
+ "VersatileDiffusionDualGuidedPipeline",
47
+ "VersatileDiffusionImageVariationPipeline",
48
+ "VersatileDiffusionPipeline",
49
+ "VersatileDiffusionTextToImagePipeline",
50
+ ]
51
+ _import_structure["vq_diffusion"] = ["VQDiffusionPipeline"]
52
+ _import_structure["stable_diffusion_variants"] = [
53
+ "CycleDiffusionPipeline",
54
+ "StableDiffusionInpaintPipelineLegacy",
55
+ "StableDiffusionPix2PixZeroPipeline",
56
+ "StableDiffusionParadigmsPipeline",
57
+ "StableDiffusionModelEditingPipeline",
58
+ ]
59
+
60
+ try:
61
+ if not (is_torch_available() and is_librosa_available()):
62
+ raise OptionalDependencyNotAvailable()
63
+ except OptionalDependencyNotAvailable:
64
+ from ...utils import dummy_torch_and_librosa_objects # noqa F403
65
+
66
+ _dummy_objects.update(get_objects_from_module(dummy_torch_and_librosa_objects))
67
+
68
+ else:
69
+ _import_structure["audio_diffusion"] = ["AudioDiffusionPipeline", "Mel"]
70
+
71
+ try:
72
+ if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
73
+ raise OptionalDependencyNotAvailable()
74
+ except OptionalDependencyNotAvailable:
75
+ from ...utils import dummy_transformers_and_torch_and_note_seq_objects # noqa F403
76
+
77
+ _dummy_objects.update(get_objects_from_module(dummy_transformers_and_torch_and_note_seq_objects))
78
+
79
+ else:
80
+ _import_structure["spectrogram_diffusion"] = ["MidiProcessor", "SpectrogramDiffusionPipeline"]
81
+
82
+
83
+ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
84
+ try:
85
+ if not is_torch_available():
86
+ raise OptionalDependencyNotAvailable()
87
+ except OptionalDependencyNotAvailable:
88
+ from ...utils.dummy_pt_objects import *
89
+
90
+ else:
91
+ from .latent_diffusion_uncond import LDMPipeline
92
+ from .pndm import PNDMPipeline
93
+ from .repaint import RePaintPipeline
94
+ from .score_sde_ve import ScoreSdeVePipeline
95
+ from .stochastic_karras_ve import KarrasVePipeline
96
+
97
+ try:
98
+ if not (is_transformers_available() and is_torch_available()):
99
+ raise OptionalDependencyNotAvailable()
100
+ except OptionalDependencyNotAvailable:
101
+ from ...utils.dummy_torch_and_transformers_objects import *
102
+
103
+ else:
104
+ from .alt_diffusion import AltDiffusionImg2ImgPipeline, AltDiffusionPipeline, AltDiffusionPipelineOutput
105
+ from .audio_diffusion import AudioDiffusionPipeline, Mel
106
+ from .spectrogram_diffusion import SpectrogramDiffusionPipeline
107
+ from .stable_diffusion_variants import (
108
+ CycleDiffusionPipeline,
109
+ StableDiffusionInpaintPipelineLegacy,
110
+ StableDiffusionModelEditingPipeline,
111
+ StableDiffusionParadigmsPipeline,
112
+ StableDiffusionPix2PixZeroPipeline,
113
+ )
114
+ from .stochastic_karras_ve import KarrasVePipeline
115
+ from .versatile_diffusion import (
116
+ VersatileDiffusionDualGuidedPipeline,
117
+ VersatileDiffusionImageVariationPipeline,
118
+ VersatileDiffusionPipeline,
119
+ VersatileDiffusionTextToImagePipeline,
120
+ )
121
+ from .vq_diffusion import VQDiffusionPipeline
122
+
123
+ try:
124
+ if not (is_torch_available() and is_librosa_available()):
125
+ raise OptionalDependencyNotAvailable()
126
+ except OptionalDependencyNotAvailable:
127
+ from ...utils.dummy_torch_and_librosa_objects import *
128
+ else:
129
+ from .audio_diffusion import AudioDiffusionPipeline, Mel
130
+
131
+ try:
132
+ if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
133
+ raise OptionalDependencyNotAvailable()
134
+ except OptionalDependencyNotAvailable:
135
+ from ...utils.dummy_transformers_and_torch_and_note_seq_objects import * # noqa F403
136
+ else:
137
+ from .spectrogram_diffusion import (
138
+ MidiProcessor,
139
+ SpectrogramDiffusionPipeline,
140
+ )
141
+
142
+
143
+ else:
144
+ import sys
145
+
146
+ sys.modules[__name__] = _LazyModule(
147
+ __name__,
148
+ globals()["__file__"],
149
+ _import_structure,
150
+ module_spec=__spec__,
151
+ )
152
+ for name, value in _dummy_objects.items():
153
+ setattr(sys.modules[__name__], name, value)
@@ -1,6 +1,6 @@
1
1
  from typing import TYPE_CHECKING
2
2
 
3
- from ...utils import (
3
+ from ....utils import (
4
4
  DIFFUSERS_SLOW_IMPORT,
5
5
  OptionalDependencyNotAvailable,
6
6
  _LazyModule,
@@ -17,7 +17,7 @@ try:
17
17
  if not (is_transformers_available() and is_torch_available()):
18
18
  raise OptionalDependencyNotAvailable()
19
19
  except OptionalDependencyNotAvailable:
20
- from ...utils import dummy_torch_and_transformers_objects
20
+ from ....utils import dummy_torch_and_transformers_objects
21
21
 
22
22
  _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
23
23
  else:
@@ -32,7 +32,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
32
32
  if not (is_transformers_available() and is_torch_available()):
33
33
  raise OptionalDependencyNotAvailable()
34
34
  except OptionalDependencyNotAvailable:
35
- from ...utils.dummy_torch_and_transformers_objects import *
35
+ from ....utils.dummy_torch_and_transformers_objects import *
36
36
 
37
37
  else:
38
38
  from .modeling_roberta_series import RobertaSeriesModelWithTransformation