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
@@ -19,15 +19,16 @@ import numpy as np
19
19
  import PIL.Image
20
20
  import torch
21
21
  from packaging import version
22
- from transformers import CLIPImageProcessor, XLMRobertaTokenizer
23
-
24
- from ...configuration_utils import FrozenDict
25
- from ...image_processor import PipelineImageInput, VaeImageProcessor
26
- from ...loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
27
- from ...models import AutoencoderKL, UNet2DConditionModel
28
- from ...models.lora import adjust_lora_scale_text_encoder
29
- from ...schedulers import KarrasDiffusionSchedulers
30
- from ...utils import (
22
+ from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection, XLMRobertaTokenizer
23
+
24
+ from ....configuration_utils import FrozenDict
25
+ from ....image_processor import PipelineImageInput, VaeImageProcessor
26
+ from ....loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
27
+ from ....models import AutoencoderKL, ImageProjection, UNet2DConditionModel
28
+ from ....models.attention_processor import FusedAttnProcessor2_0
29
+ from ....models.lora import adjust_lora_scale_text_encoder
30
+ from ....schedulers import KarrasDiffusionSchedulers
31
+ from ....utils import (
31
32
  PIL_INTERPOLATION,
32
33
  USE_PEFT_BACKEND,
33
34
  deprecate,
@@ -36,9 +37,9 @@ from ...utils import (
36
37
  scale_lora_layers,
37
38
  unscale_lora_layers,
38
39
  )
39
- from ...utils.torch_utils import randn_tensor
40
- from ..pipeline_utils import DiffusionPipeline
41
- from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
40
+ from ....utils.torch_utils import randn_tensor
41
+ from ...pipeline_utils import DiffusionPipeline
42
+ from ...stable_diffusion.safety_checker import StableDiffusionSafetyChecker
42
43
  from .modeling_roberta_series import RobertaSeriesModelWithTransformation
43
44
  from .pipeline_output import AltDiffusionPipelineOutput
44
45
 
@@ -76,9 +77,13 @@ EXAMPLE_DOC_STRING = """
76
77
 
77
78
 
78
79
  # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.retrieve_latents
79
- def retrieve_latents(encoder_output, generator):
80
- if hasattr(encoder_output, "latent_dist"):
80
+ def retrieve_latents(
81
+ encoder_output: torch.Tensor, generator: Optional[torch.Generator] = None, sample_mode: str = "sample"
82
+ ):
83
+ if hasattr(encoder_output, "latent_dist") and sample_mode == "sample":
81
84
  return encoder_output.latent_dist.sample(generator)
85
+ elif hasattr(encoder_output, "latent_dist") and sample_mode == "argmax":
86
+ return encoder_output.latent_dist.mode()
82
87
  elif hasattr(encoder_output, "latents"):
83
88
  return encoder_output.latents
84
89
  else:
@@ -109,9 +114,53 @@ def preprocess(image):
109
114
  return image
110
115
 
111
116
 
112
- # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline with Stable->Alt, CLIPTextModel->RobertaSeriesModelWithTransformation, CLIPTokenizer->XLMRobertaTokenizer, AltDiffusionSafetyChecker->StableDiffusionSafetyChecker
117
+ # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.retrieve_timesteps
118
+ def retrieve_timesteps(
119
+ scheduler,
120
+ num_inference_steps: Optional[int] = None,
121
+ device: Optional[Union[str, torch.device]] = None,
122
+ timesteps: Optional[List[int]] = None,
123
+ **kwargs,
124
+ ):
125
+ """
126
+ Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
127
+ custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
128
+
129
+ Args:
130
+ scheduler (`SchedulerMixin`):
131
+ The scheduler to get timesteps from.
132
+ num_inference_steps (`int`):
133
+ The number of diffusion steps used when generating samples with a pre-trained model. If used,
134
+ `timesteps` must be `None`.
135
+ device (`str` or `torch.device`, *optional*):
136
+ The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
137
+ timesteps (`List[int]`, *optional*):
138
+ Custom timesteps used to support arbitrary spacing between timesteps. If `None`, then the default
139
+ timestep spacing strategy of the scheduler is used. If `timesteps` is passed, `num_inference_steps`
140
+ must be `None`.
141
+
142
+ Returns:
143
+ `Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the
144
+ second element is the number of inference steps.
145
+ """
146
+ if timesteps is not None:
147
+ accepts_timesteps = "timesteps" in set(inspect.signature(scheduler.set_timesteps).parameters.keys())
148
+ if not accepts_timesteps:
149
+ raise ValueError(
150
+ f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom"
151
+ f" timestep schedules. Please check whether you are using the correct scheduler."
152
+ )
153
+ scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs)
154
+ timesteps = scheduler.timesteps
155
+ num_inference_steps = len(timesteps)
156
+ else:
157
+ scheduler.set_timesteps(num_inference_steps, device=device, **kwargs)
158
+ timesteps = scheduler.timesteps
159
+ return timesteps, num_inference_steps
160
+
161
+
113
162
  class AltDiffusionImg2ImgPipeline(
114
- DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
163
+ DiffusionPipeline, TextualInversionLoaderMixin, IPAdapterMixin, LoraLoaderMixin, FromSingleFileMixin
115
164
  ):
116
165
  r"""
117
166
  Pipeline for text-guided image-to-image generation using Alt Diffusion.
@@ -124,6 +173,7 @@ class AltDiffusionImg2ImgPipeline(
124
173
  - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
125
174
  - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
126
175
  - [`~loaders.FromSingleFileMixin.from_single_file`] for loading `.ckpt` files
176
+ - [`~loaders.IPAdapterMixin.load_ip_adapter`] for loading IP Adapters
127
177
 
128
178
  Args:
129
179
  vae ([`AutoencoderKL`]):
@@ -145,8 +195,8 @@ class AltDiffusionImg2ImgPipeline(
145
195
  A `CLIPImageProcessor` to extract features from generated images; used as inputs to the `safety_checker`.
146
196
  """
147
197
 
148
- model_cpu_offload_seq = "text_encoder->unet->vae"
149
- _optional_components = ["safety_checker", "feature_extractor"]
198
+ model_cpu_offload_seq = "text_encoder->image_encoder->unet->vae"
199
+ _optional_components = ["safety_checker", "feature_extractor", "image_encoder"]
150
200
  _exclude_from_cpu_offload = ["safety_checker"]
151
201
  _callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
152
202
 
@@ -159,6 +209,7 @@ class AltDiffusionImg2ImgPipeline(
159
209
  scheduler: KarrasDiffusionSchedulers,
160
210
  safety_checker: StableDiffusionSafetyChecker,
161
211
  feature_extractor: CLIPImageProcessor,
212
+ image_encoder: CLIPVisionModelWithProjection = None,
162
213
  requires_safety_checker: bool = True,
163
214
  ):
164
215
  super().__init__()
@@ -235,6 +286,7 @@ class AltDiffusionImg2ImgPipeline(
235
286
  scheduler=scheduler,
236
287
  safety_checker=safety_checker,
237
288
  feature_extractor=feature_extractor,
289
+ image_encoder=image_encoder,
238
290
  )
239
291
  self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
240
292
  self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
@@ -252,10 +304,7 @@ class AltDiffusionImg2ImgPipeline(
252
304
  lora_scale: Optional[float] = None,
253
305
  **kwargs,
254
306
  ):
255
- deprecation_message = (
256
- "`_encode_prompt()` is deprecated and it will be removed in a future version. Use `encode_prompt()`"
257
- " instead. Also, be aware that the output format changed from a concatenated tensor to a tuple."
258
- )
307
+ deprecation_message = "`_encode_prompt()` is deprecated and it will be removed in a future version. Use `encode_prompt()` instead. Also, be aware that the output format changed from a concatenated tensor to a tuple."
259
308
  deprecate("_encode_prompt()", "1.0.0", deprecation_message, standard_warn=False)
260
309
 
261
310
  prompt_embeds_tuple = self.encode_prompt(
@@ -456,6 +505,30 @@ class AltDiffusionImg2ImgPipeline(
456
505
 
457
506
  return prompt_embeds, negative_prompt_embeds
458
507
 
508
+ def encode_image(self, image, device, num_images_per_prompt, output_hidden_states=None):
509
+ dtype = next(self.image_encoder.parameters()).dtype
510
+
511
+ if not isinstance(image, torch.Tensor):
512
+ image = self.feature_extractor(image, return_tensors="pt").pixel_values
513
+
514
+ image = image.to(device=device, dtype=dtype)
515
+ if output_hidden_states:
516
+ image_enc_hidden_states = self.image_encoder(image, output_hidden_states=True).hidden_states[-2]
517
+ image_enc_hidden_states = image_enc_hidden_states.repeat_interleave(num_images_per_prompt, dim=0)
518
+ uncond_image_enc_hidden_states = self.image_encoder(
519
+ torch.zeros_like(image), output_hidden_states=True
520
+ ).hidden_states[-2]
521
+ uncond_image_enc_hidden_states = uncond_image_enc_hidden_states.repeat_interleave(
522
+ num_images_per_prompt, dim=0
523
+ )
524
+ return image_enc_hidden_states, uncond_image_enc_hidden_states
525
+ else:
526
+ image_embeds = self.image_encoder(image).image_embeds
527
+ image_embeds = image_embeds.repeat_interleave(num_images_per_prompt, dim=0)
528
+ uncond_image_embeds = torch.zeros_like(image_embeds)
529
+
530
+ return image_embeds, uncond_image_embeds
531
+
459
532
  def run_safety_checker(self, image, device, dtype):
460
533
  if self.safety_checker is None:
461
534
  has_nsfw_concept = None
@@ -471,10 +544,7 @@ class AltDiffusionImg2ImgPipeline(
471
544
  return image, has_nsfw_concept
472
545
 
473
546
  def decode_latents(self, latents):
474
- deprecation_message = (
475
- "The decode_latents method is deprecated and will be removed in 1.0.0. Please use"
476
- " VaeImageProcessor.postprocess(...) instead"
477
- )
547
+ deprecation_message = "The decode_latents method is deprecated and will be removed in 1.0.0. Please use VaeImageProcessor.postprocess(...) instead"
478
548
  deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)
479
549
 
480
550
  latents = 1 / self.vae.config.scaling_factor * latents
@@ -524,8 +594,7 @@ class AltDiffusionImg2ImgPipeline(
524
594
  k in self._callback_tensor_inputs for k in callback_on_step_end_tensor_inputs
525
595
  ):
526
596
  raise ValueError(
527
- f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found"
528
- f" {[k for k in callback_on_step_end_tensor_inputs if k not in self._callback_tensor_inputs]}"
597
+ 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]}"
529
598
  )
530
599
  if prompt is not None and prompt_embeds is not None:
531
600
  raise ValueError(
@@ -578,8 +647,8 @@ class AltDiffusionImg2ImgPipeline(
578
647
  else:
579
648
  if isinstance(generator, list) and len(generator) != batch_size:
580
649
  raise ValueError(
581
- f"You have passed a list of generators of length {len(generator)}, but requested an effective"
582
- f" batch size of {batch_size}. Make sure the batch size matches the length of the generators."
650
+ f"You have passed a list of generators of length {len(generator)}, but requested an effective batch"
651
+ f" size of {batch_size}. Make sure the batch size matches the length of the generators."
583
652
  )
584
653
 
585
654
  elif isinstance(generator, list):
@@ -646,6 +715,65 @@ class AltDiffusionImg2ImgPipeline(
646
715
  """Disables the FreeU mechanism if enabled."""
647
716
  self.unet.disable_freeu()
648
717
 
718
+ def fuse_qkv_projections(self, unet: bool = True, vae: bool = True):
719
+ """
720
+ Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query,
721
+ key, value) are fused. For cross-attention modules, key and value projection matrices are fused.
722
+
723
+ <Tip warning={true}>
724
+
725
+ This API is 🧪 experimental.
726
+
727
+ </Tip>
728
+
729
+ Args:
730
+ unet (`bool`, defaults to `True`): To apply fusion on the UNet.
731
+ vae (`bool`, defaults to `True`): To apply fusion on the VAE.
732
+ """
733
+ self.fusing_unet = False
734
+ self.fusing_vae = False
735
+
736
+ if unet:
737
+ self.fusing_unet = True
738
+ self.unet.fuse_qkv_projections()
739
+ self.unet.set_attn_processor(FusedAttnProcessor2_0())
740
+
741
+ if vae:
742
+ if not isinstance(self.vae, AutoencoderKL):
743
+ raise ValueError("`fuse_qkv_projections()` is only supported for the VAE of type `AutoencoderKL`.")
744
+
745
+ self.fusing_vae = True
746
+ self.vae.fuse_qkv_projections()
747
+ self.vae.set_attn_processor(FusedAttnProcessor2_0())
748
+
749
+ def unfuse_qkv_projections(self, unet: bool = True, vae: bool = True):
750
+ """Disable QKV projection fusion if enabled.
751
+
752
+ <Tip warning={true}>
753
+
754
+ This API is 🧪 experimental.
755
+
756
+ </Tip>
757
+
758
+ Args:
759
+ unet (`bool`, defaults to `True`): To apply fusion on the UNet.
760
+ vae (`bool`, defaults to `True`): To apply fusion on the VAE.
761
+
762
+ """
763
+ if unet:
764
+ if not self.fusing_unet:
765
+ logger.warning("The UNet was not initially fused for QKV projections. Doing nothing.")
766
+ else:
767
+ self.unet.unfuse_qkv_projections()
768
+ self.fusing_unet = False
769
+
770
+ if vae:
771
+ if not self.fusing_vae:
772
+ logger.warning("The VAE was not initially fused for QKV projections. Doing nothing.")
773
+ else:
774
+ self.vae.unfuse_qkv_projections()
775
+ self.fusing_vae = False
776
+
649
777
  def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
650
778
  """
651
779
  See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
@@ -705,6 +833,7 @@ class AltDiffusionImg2ImgPipeline(
705
833
  image: PipelineImageInput = None,
706
834
  strength: float = 0.8,
707
835
  num_inference_steps: Optional[int] = 50,
836
+ timesteps: List[int] = None,
708
837
  guidance_scale: Optional[float] = 7.5,
709
838
  negative_prompt: Optional[Union[str, List[str]]] = None,
710
839
  num_images_per_prompt: Optional[int] = 1,
@@ -712,6 +841,7 @@ class AltDiffusionImg2ImgPipeline(
712
841
  generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
713
842
  prompt_embeds: Optional[torch.FloatTensor] = None,
714
843
  negative_prompt_embeds: Optional[torch.FloatTensor] = None,
844
+ ip_adapter_image: Optional[PipelineImageInput] = None,
715
845
  output_type: Optional[str] = "pil",
716
846
  return_dict: bool = True,
717
847
  cross_attention_kwargs: Optional[Dict[str, Any]] = None,
@@ -741,6 +871,10 @@ class AltDiffusionImg2ImgPipeline(
741
871
  num_inference_steps (`int`, *optional*, defaults to 50):
742
872
  The number of denoising steps. More denoising steps usually lead to a higher quality image at the
743
873
  expense of slower inference. This parameter is modulated by `strength`.
874
+ timesteps (`List[int]`, *optional*):
875
+ Custom timesteps to use for the denoising process with schedulers which support a `timesteps` argument
876
+ in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is
877
+ passed will be used. Must be in descending order.
744
878
  guidance_scale (`float`, *optional*, defaults to 7.5):
745
879
  A higher guidance scale value encourages the model to generate images closely linked to the text
746
880
  `prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`.
@@ -761,6 +895,7 @@ class AltDiffusionImg2ImgPipeline(
761
895
  negative_prompt_embeds (`torch.FloatTensor`, *optional*):
762
896
  Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
763
897
  not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
898
+ ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
764
899
  output_type (`str`, *optional*, defaults to `"pil"`):
765
900
  The output format of the generated image. Choose between `PIL.Image` or `np.array`.
766
901
  return_dict (`bool`, *optional*, defaults to `True`):
@@ -780,7 +915,7 @@ class AltDiffusionImg2ImgPipeline(
780
915
  callback_on_step_end_tensor_inputs (`List`, *optional*):
781
916
  The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
782
917
  will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
783
- `._callback_tensor_inputs` attribute of your pipeine class.
918
+ `._callback_tensor_inputs` attribute of your pipeline class.
784
919
  Examples:
785
920
 
786
921
  Returns:
@@ -798,15 +933,13 @@ class AltDiffusionImg2ImgPipeline(
798
933
  deprecate(
799
934
  "callback",
800
935
  "1.0.0",
801
- "Passing `callback` as an input argument to `__call__` is deprecated, consider use"
802
- " `callback_on_step_end`",
936
+ "Passing `callback` as an input argument to `__call__` is deprecated, consider use `callback_on_step_end`",
803
937
  )
804
938
  if callback_steps is not None:
805
939
  deprecate(
806
940
  "callback_steps",
807
941
  "1.0.0",
808
- "Passing `callback_steps` as an input argument to `__call__` is deprecated, consider use"
809
- " `callback_on_step_end`",
942
+ "Passing `callback_steps` as an input argument to `__call__` is deprecated, consider use `callback_on_step_end`",
810
943
  )
811
944
 
812
945
  # 1. Check inputs. Raise error if not correct
@@ -855,11 +988,19 @@ class AltDiffusionImg2ImgPipeline(
855
988
  if self.do_classifier_free_guidance:
856
989
  prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
857
990
 
991
+ if ip_adapter_image is not None:
992
+ output_hidden_state = False if isinstance(self.unet.encoder_hid_proj, ImageProjection) else True
993
+ image_embeds, negative_image_embeds = self.encode_image(
994
+ ip_adapter_image, device, num_images_per_prompt, output_hidden_state
995
+ )
996
+ if self.do_classifier_free_guidance:
997
+ image_embeds = torch.cat([negative_image_embeds, image_embeds])
998
+
858
999
  # 4. Preprocess image
859
1000
  image = self.image_processor.preprocess(image)
860
1001
 
861
1002
  # 5. set timesteps
862
- self.scheduler.set_timesteps(num_inference_steps, device=device)
1003
+ timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, timesteps)
863
1004
  timesteps, num_inference_steps = self.get_timesteps(num_inference_steps, strength, device)
864
1005
  latent_timestep = timesteps[:1].repeat(batch_size * num_images_per_prompt)
865
1006
 
@@ -877,7 +1018,10 @@ class AltDiffusionImg2ImgPipeline(
877
1018
  # 7. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
878
1019
  extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
879
1020
 
880
- # 7.5 Optionally get Guidance Scale Embedding
1021
+ # 7.1 Add image embeds for IP-Adapter
1022
+ added_cond_kwargs = {"image_embeds": image_embeds} if ip_adapter_image is not None else None
1023
+
1024
+ # 7.2 Optionally get Guidance Scale Embedding
881
1025
  timestep_cond = None
882
1026
  if self.unet.config.time_cond_proj_dim is not None:
883
1027
  guidance_scale_tensor = torch.tensor(self.guidance_scale - 1).repeat(batch_size * num_images_per_prompt)
@@ -901,6 +1045,7 @@ class AltDiffusionImg2ImgPipeline(
901
1045
  encoder_hidden_states=prompt_embeds,
902
1046
  timestep_cond=timestep_cond,
903
1047
  cross_attention_kwargs=self.cross_attention_kwargs,
1048
+ added_cond_kwargs=added_cond_kwargs,
904
1049
  return_dict=False,
905
1050
  )[0]
906
1051
 
@@ -4,7 +4,7 @@ from typing import List, Optional, Union
4
4
  import numpy as np
5
5
  import PIL.Image
6
6
 
7
- from ...utils import (
7
+ from ....utils import (
8
8
  BaseOutput,
9
9
  )
10
10
 
@@ -1,6 +1,6 @@
1
1
  from typing import TYPE_CHECKING
2
2
 
3
- from ...utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
3
+ from ....utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
4
4
 
5
5
 
6
6
  _import_structure = {
@@ -15,8 +15,8 @@
15
15
 
16
16
  import numpy as np # noqa: E402
17
17
 
18
- from ...configuration_utils import ConfigMixin, register_to_config
19
- from ...schedulers.scheduling_utils import SchedulerMixin
18
+ from ....configuration_utils import ConfigMixin, register_to_config
19
+ from ....schedulers.scheduling_utils import SchedulerMixin
20
20
 
21
21
 
22
22
  try:
@@ -20,10 +20,10 @@ import numpy as np
20
20
  import torch
21
21
  from PIL import Image
22
22
 
23
- from ...models import AutoencoderKL, UNet2DConditionModel
24
- from ...schedulers import DDIMScheduler, DDPMScheduler
25
- from ...utils.torch_utils import randn_tensor
26
- from ..pipeline_utils import AudioPipelineOutput, BaseOutput, DiffusionPipeline, ImagePipelineOutput
23
+ from ....models import AutoencoderKL, UNet2DConditionModel
24
+ from ....schedulers import DDIMScheduler, DDPMScheduler
25
+ from ....utils.torch_utils import randn_tensor
26
+ from ...pipeline_utils import AudioPipelineOutput, BaseOutput, DiffusionPipeline, ImagePipelineOutput
27
27
  from .mel import Mel
28
28
 
29
29
 
@@ -1,6 +1,6 @@
1
1
  from typing import TYPE_CHECKING
2
2
 
3
- from ...utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
3
+ from ....utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
4
4
 
5
5
 
6
6
  _import_structure = {"pipeline_latent_diffusion_uncond": ["LDMPipeline"]}
@@ -17,10 +17,10 @@ from typing import List, Optional, Tuple, Union
17
17
 
18
18
  import torch
19
19
 
20
- from ...models import UNet2DModel, VQModel
21
- from ...schedulers import DDIMScheduler
22
- from ...utils.torch_utils import randn_tensor
23
- from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
20
+ from ....models import UNet2DModel, VQModel
21
+ from ....schedulers import DDIMScheduler
22
+ from ....utils.torch_utils import randn_tensor
23
+ from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
24
24
 
25
25
 
26
26
  class LDMPipeline(DiffusionPipeline):
@@ -1,6 +1,6 @@
1
1
  from typing import TYPE_CHECKING
2
2
 
3
- from ...utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
3
+ from ....utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
4
4
 
5
5
 
6
6
  _import_structure = {"pipeline_pndm": ["PNDMPipeline"]}
@@ -17,10 +17,10 @@ from typing import List, Optional, Tuple, Union
17
17
 
18
18
  import torch
19
19
 
20
- from ...models import UNet2DModel
21
- from ...schedulers import PNDMScheduler
22
- from ...utils.torch_utils import randn_tensor
23
- from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
20
+ from ....models import UNet2DModel
21
+ from ....schedulers import PNDMScheduler
22
+ from ....utils.torch_utils import randn_tensor
23
+ from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
24
24
 
25
25
 
26
26
  class PNDMPipeline(DiffusionPipeline):
@@ -1,6 +1,6 @@
1
1
  from typing import TYPE_CHECKING
2
2
 
3
- from ...utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
3
+ from ....utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
4
4
 
5
5
 
6
6
  _import_structure = {"pipeline_repaint": ["RePaintPipeline"]}
@@ -19,11 +19,11 @@ import numpy as np
19
19
  import PIL.Image
20
20
  import torch
21
21
 
22
- from ...models import UNet2DModel
23
- from ...schedulers import RePaintScheduler
24
- from ...utils import PIL_INTERPOLATION, deprecate, logging
25
- from ...utils.torch_utils import randn_tensor
26
- from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
22
+ from ....models import UNet2DModel
23
+ from ....schedulers import RePaintScheduler
24
+ from ....utils import PIL_INTERPOLATION, deprecate, logging
25
+ from ....utils.torch_utils import randn_tensor
26
+ from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
27
27
 
28
28
 
29
29
  logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -1,6 +1,6 @@
1
1
  from typing import TYPE_CHECKING
2
2
 
3
- from ...utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
3
+ from ....utils import DIFFUSERS_SLOW_IMPORT, _LazyModule
4
4
 
5
5
 
6
6
  _import_structure = {"pipeline_score_sde_ve": ["ScoreSdeVePipeline"]}
@@ -16,10 +16,10 @@ from typing import List, Optional, Tuple, Union
16
16
 
17
17
  import torch
18
18
 
19
- from ...models import UNet2DModel
20
- from ...schedulers import ScoreSdeVeScheduler
21
- from ...utils.torch_utils import randn_tensor
22
- from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
19
+ from ....models import UNet2DModel
20
+ from ....schedulers import ScoreSdeVeScheduler
21
+ from ....utils.torch_utils import randn_tensor
22
+ from ...pipeline_utils import DiffusionPipeline, ImagePipelineOutput
23
23
 
24
24
 
25
25
  class ScoreSdeVePipeline(DiffusionPipeline):
@@ -35,6 +35,7 @@ class ScoreSdeVePipeline(DiffusionPipeline):
35
35
  scheduler ([`ScoreSdeVeScheduler`]):
36
36
  A `ScoreSdeVeScheduler` to be used in combination with `unet` to denoise the encoded image.
37
37
  """
38
+
38
39
  unet: UNet2DModel
39
40
  scheduler: ScoreSdeVeScheduler
40
41
 
@@ -1,7 +1,7 @@
1
1
  # flake8: noqa
2
2
  from typing import TYPE_CHECKING
3
- from ...utils import DIFFUSERS_SLOW_IMPORT
4
- from ...utils import (
3
+ from ....utils import (
4
+ DIFFUSERS_SLOW_IMPORT,
5
5
  _LazyModule,
6
6
  is_note_seq_available,
7
7
  OptionalDependencyNotAvailable,
@@ -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 # noqa F403
20
+ from ....utils import dummy_torch_and_transformers_objects # noqa F403
21
21
 
22
22
  _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
23
23
  else:
@@ -32,7 +32,7 @@ try:
32
32
  if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
33
33
  raise OptionalDependencyNotAvailable()
34
34
  except OptionalDependencyNotAvailable:
35
- from ...utils import dummy_transformers_and_torch_and_note_seq_objects
35
+ from ....utils import dummy_transformers_and_torch_and_note_seq_objects
36
36
 
37
37
  _dummy_objects.update(get_objects_from_module(dummy_transformers_and_torch_and_note_seq_objects))
38
38
  else:
@@ -45,7 +45,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
45
45
  raise OptionalDependencyNotAvailable()
46
46
 
47
47
  except OptionalDependencyNotAvailable:
48
- from ...utils.dummy_torch_and_transformers_objects import *
48
+ from ....utils.dummy_torch_and_transformers_objects import *
49
49
  else:
50
50
  from .pipeline_spectrogram_diffusion import SpectrogramDiffusionPipeline
51
51
  from .pipeline_spectrogram_diffusion import SpectrogramContEncoder
@@ -56,7 +56,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
56
56
  if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
57
57
  raise OptionalDependencyNotAvailable()
58
58
  except OptionalDependencyNotAvailable:
59
- from ...utils.dummy_transformers_and_torch_and_note_seq_objects import *
59
+ from ....utils.dummy_transformers_and_torch_and_note_seq_objects import *
60
60
 
61
61
  else:
62
62
  from .midi_utils import MidiProcessor
@@ -22,8 +22,8 @@ from transformers.models.t5.modeling_t5 import (
22
22
  T5LayerNorm,
23
23
  )
24
24
 
25
- from ...configuration_utils import ConfigMixin, register_to_config
26
- from ...models import ModelMixin
25
+ from ....configuration_utils import ConfigMixin, register_to_config
26
+ from ....models import ModelMixin
27
27
 
28
28
 
29
29
  class SpectrogramContEncoder(ModelMixin, ConfigMixin, ModuleUtilsMixin):
@@ -22,7 +22,7 @@ import numpy as np
22
22
  import torch
23
23
  import torch.nn.functional as F
24
24
 
25
- from ...utils import is_note_seq_available
25
+ from ....utils import is_note_seq_available
26
26
  from .pipeline_spectrogram_diffusion import TARGET_FEATURE_LENGTH
27
27
 
28
28
 
@@ -18,8 +18,8 @@ import torch.nn as nn
18
18
  from transformers.modeling_utils import ModuleUtilsMixin
19
19
  from transformers.models.t5.modeling_t5 import T5Block, T5Config, T5LayerNorm
20
20
 
21
- from ...configuration_utils import ConfigMixin, register_to_config
22
- from ...models import ModelMixin
21
+ from ....configuration_utils import ConfigMixin, register_to_config
22
+ from ....models import ModelMixin
23
23
 
24
24
 
25
25
  class SpectrogramNotesEncoder(ModelMixin, ConfigMixin, ModuleUtilsMixin):
@@ -19,17 +19,17 @@ from typing import Any, Callable, List, Optional, Tuple, Union
19
19
  import numpy as np
20
20
  import torch
21
21
 
22
- from ...models import T5FilmDecoder
23
- from ...schedulers import DDPMScheduler
24
- from ...utils import is_onnx_available, logging
25
- from ...utils.torch_utils import randn_tensor
22
+ from ....models import T5FilmDecoder
23
+ from ....schedulers import DDPMScheduler
24
+ from ....utils import is_onnx_available, logging
25
+ from ....utils.torch_utils import randn_tensor
26
26
 
27
27
 
28
28
  if is_onnx_available():
29
- from ..onnx_utils import OnnxRuntimeModel
29
+ from ...onnx_utils import OnnxRuntimeModel
30
30
 
31
- from ..pipeline_utils import AudioPipelineOutput, DiffusionPipeline
32
- from .continous_encoder import SpectrogramContEncoder
31
+ from ...pipeline_utils import AudioPipelineOutput, DiffusionPipeline
32
+ from .continuous_encoder import SpectrogramContEncoder
33
33
  from .notes_encoder import SpectrogramNotesEncoder
34
34
 
35
35
 
@@ -54,6 +54,7 @@ class SpectrogramDiffusionPipeline(DiffusionPipeline):
54
54
  A scheduler to be used in combination with `decoder` to denoise the encoded audio latents.
55
55
  melgan ([`OnnxRuntimeModel`]):
56
56
  """
57
+
57
58
  _optional_components = ["melgan"]
58
59
 
59
60
  def __init__(