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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. diffusers/__init__.py +16 -2
  2. diffusers/configuration_utils.py +1 -0
  3. diffusers/dependency_versions_check.py +0 -1
  4. diffusers/dependency_versions_table.py +4 -5
  5. diffusers/image_processor.py +186 -14
  6. diffusers/loaders/__init__.py +82 -0
  7. diffusers/loaders/ip_adapter.py +157 -0
  8. diffusers/loaders/lora.py +1415 -0
  9. diffusers/loaders/lora_conversion_utils.py +284 -0
  10. diffusers/loaders/single_file.py +631 -0
  11. diffusers/loaders/textual_inversion.py +459 -0
  12. diffusers/loaders/unet.py +735 -0
  13. diffusers/loaders/utils.py +59 -0
  14. diffusers/models/__init__.py +12 -1
  15. diffusers/models/attention.py +165 -14
  16. diffusers/models/attention_flax.py +9 -1
  17. diffusers/models/attention_processor.py +286 -1
  18. diffusers/models/autoencoder_asym_kl.py +14 -9
  19. diffusers/models/autoencoder_kl.py +3 -18
  20. diffusers/models/autoencoder_kl_temporal_decoder.py +402 -0
  21. diffusers/models/autoencoder_tiny.py +20 -24
  22. diffusers/models/consistency_decoder_vae.py +37 -30
  23. diffusers/models/controlnet.py +59 -39
  24. diffusers/models/controlnet_flax.py +19 -18
  25. diffusers/models/embeddings_flax.py +2 -0
  26. diffusers/models/lora.py +131 -1
  27. diffusers/models/modeling_flax_utils.py +2 -1
  28. diffusers/models/modeling_outputs.py +17 -0
  29. diffusers/models/modeling_utils.py +27 -19
  30. diffusers/models/normalization.py +2 -2
  31. diffusers/models/resnet.py +390 -59
  32. diffusers/models/transformer_2d.py +20 -3
  33. diffusers/models/transformer_temporal.py +183 -1
  34. diffusers/models/unet_2d_blocks_flax.py +5 -0
  35. diffusers/models/unet_2d_condition.py +9 -0
  36. diffusers/models/unet_2d_condition_flax.py +13 -13
  37. diffusers/models/unet_3d_blocks.py +957 -173
  38. diffusers/models/unet_3d_condition.py +16 -8
  39. diffusers/models/unet_kandi3.py +589 -0
  40. diffusers/models/unet_motion_model.py +48 -33
  41. diffusers/models/unet_spatio_temporal_condition.py +489 -0
  42. diffusers/models/vae.py +63 -13
  43. diffusers/models/vae_flax.py +7 -0
  44. diffusers/models/vq_model.py +3 -1
  45. diffusers/optimization.py +16 -9
  46. diffusers/pipelines/__init__.py +65 -12
  47. diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +93 -23
  48. diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +97 -25
  49. diffusers/pipelines/animatediff/pipeline_animatediff.py +34 -4
  50. diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
  51. diffusers/pipelines/auto_pipeline.py +6 -0
  52. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
  53. diffusers/pipelines/controlnet/pipeline_controlnet.py +217 -31
  54. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +101 -32
  55. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +136 -39
  56. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +119 -37
  57. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +196 -35
  58. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +102 -31
  59. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
  60. diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
  61. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
  62. diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
  63. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
  64. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
  65. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
  66. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
  67. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
  68. diffusers/pipelines/dit/pipeline_dit.py +1 -0
  69. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
  70. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
  71. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  72. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
  73. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
  74. diffusers/pipelines/kandinsky3/__init__.py +49 -0
  75. diffusers/pipelines/kandinsky3/kandinsky3_pipeline.py +452 -0
  76. diffusers/pipelines/kandinsky3/kandinsky3img2img_pipeline.py +460 -0
  77. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +65 -6
  78. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +55 -3
  79. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
  80. diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
  81. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
  82. diffusers/pipelines/pipeline_flax_utils.py +4 -2
  83. diffusers/pipelines/pipeline_utils.py +33 -13
  84. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +196 -36
  85. diffusers/pipelines/score_sde_ve/pipeline_score_sde_ve.py +1 -0
  86. diffusers/pipelines/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -0
  87. diffusers/pipelines/stable_diffusion/__init__.py +64 -21
  88. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +8 -3
  89. diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py +18 -2
  90. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
  91. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
  92. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
  93. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint_legacy.py +1 -0
  94. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +88 -9
  95. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_attend_and_excite.py +1 -0
  96. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
  97. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py +1 -0
  98. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen.py +1 -0
  99. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen_text_image.py +1 -0
  100. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
  101. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -9
  102. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +92 -9
  103. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py +1 -0
  104. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +17 -13
  105. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_k_diffusion.py +1 -0
  106. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +1 -0
  107. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_ldm3d.py +1 -0
  108. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py +1 -0
  109. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py +1 -0
  110. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_paradigms.py +1 -0
  111. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py +1 -0
  112. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py +1 -0
  113. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +1 -0
  114. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +103 -8
  115. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +113 -8
  116. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +115 -9
  117. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +16 -12
  118. diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
  119. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +649 -0
  120. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
  121. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +109 -14
  122. diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
  123. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +1 -0
  124. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +18 -3
  125. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +4 -2
  126. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +872 -0
  127. diffusers/pipelines/versatile_diffusion/modeling_text_unet.py +29 -40
  128. diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +1 -0
  129. diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +1 -0
  130. diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +1 -0
  131. diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
  132. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
  133. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
  134. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
  135. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +1 -1
  136. diffusers/schedulers/__init__.py +2 -4
  137. diffusers/schedulers/deprecated/__init__.py +50 -0
  138. diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
  139. diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
  140. diffusers/schedulers/scheduling_ddim.py +1 -3
  141. diffusers/schedulers/scheduling_ddim_inverse.py +1 -3
  142. diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
  143. diffusers/schedulers/scheduling_ddpm.py +1 -3
  144. diffusers/schedulers/scheduling_ddpm_parallel.py +1 -3
  145. diffusers/schedulers/scheduling_deis_multistep.py +15 -5
  146. diffusers/schedulers/scheduling_dpmsolver_multistep.py +15 -5
  147. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +15 -5
  148. diffusers/schedulers/scheduling_dpmsolver_sde.py +1 -3
  149. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +15 -5
  150. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +1 -3
  151. diffusers/schedulers/scheduling_euler_discrete.py +40 -13
  152. diffusers/schedulers/scheduling_heun_discrete.py +15 -5
  153. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +15 -5
  154. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +15 -5
  155. diffusers/schedulers/scheduling_lcm.py +123 -29
  156. diffusers/schedulers/scheduling_lms_discrete.py +1 -3
  157. diffusers/schedulers/scheduling_pndm.py +1 -3
  158. diffusers/schedulers/scheduling_repaint.py +1 -3
  159. diffusers/schedulers/scheduling_unipc_multistep.py +15 -5
  160. diffusers/utils/__init__.py +1 -0
  161. diffusers/utils/constants.py +8 -7
  162. diffusers/utils/dummy_pt_objects.py +45 -0
  163. diffusers/utils/dummy_torch_and_transformers_objects.py +60 -0
  164. diffusers/utils/dynamic_modules_utils.py +4 -4
  165. diffusers/utils/export_utils.py +8 -3
  166. diffusers/utils/logging.py +10 -10
  167. diffusers/utils/outputs.py +5 -5
  168. diffusers/utils/peft_utils.py +88 -44
  169. diffusers/utils/torch_utils.py +2 -2
  170. {diffusers-0.23.1.dist-info → diffusers-0.24.0.dist-info}/METADATA +38 -22
  171. {diffusers-0.23.1.dist-info → diffusers-0.24.0.dist-info}/RECORD +175 -157
  172. diffusers/loaders.py +0 -3336
  173. {diffusers-0.23.1.dist-info → diffusers-0.24.0.dist-info}/LICENSE +0 -0
  174. {diffusers-0.23.1.dist-info → diffusers-0.24.0.dist-info}/WHEEL +0 -0
  175. {diffusers-0.23.1.dist-info → diffusers-0.24.0.dist-info}/entry_points.txt +0 -0
  176. {diffusers-0.23.1.dist-info → diffusers-0.24.0.dist-info}/top_level.txt +0 -0
@@ -242,6 +242,36 @@ class ImageTextPipelineOutput(metaclass=DummyObject):
242
242
  requires_backends(cls, ["torch", "transformers"])
243
243
 
244
244
 
245
+ class Kandinsky3Img2ImgPipeline(metaclass=DummyObject):
246
+ _backends = ["torch", "transformers"]
247
+
248
+ def __init__(self, *args, **kwargs):
249
+ requires_backends(self, ["torch", "transformers"])
250
+
251
+ @classmethod
252
+ def from_config(cls, *args, **kwargs):
253
+ requires_backends(cls, ["torch", "transformers"])
254
+
255
+ @classmethod
256
+ def from_pretrained(cls, *args, **kwargs):
257
+ requires_backends(cls, ["torch", "transformers"])
258
+
259
+
260
+ class Kandinsky3Pipeline(metaclass=DummyObject):
261
+ _backends = ["torch", "transformers"]
262
+
263
+ def __init__(self, *args, **kwargs):
264
+ requires_backends(self, ["torch", "transformers"])
265
+
266
+ @classmethod
267
+ def from_config(cls, *args, **kwargs):
268
+ requires_backends(cls, ["torch", "transformers"])
269
+
270
+ @classmethod
271
+ def from_pretrained(cls, *args, **kwargs):
272
+ requires_backends(cls, ["torch", "transformers"])
273
+
274
+
245
275
  class KandinskyCombinedPipeline(metaclass=DummyObject):
246
276
  _backends = ["torch", "transformers"]
247
277
 
@@ -1142,6 +1172,21 @@ class StableUnCLIPPipeline(metaclass=DummyObject):
1142
1172
  requires_backends(cls, ["torch", "transformers"])
1143
1173
 
1144
1174
 
1175
+ class StableVideoDiffusionPipeline(metaclass=DummyObject):
1176
+ _backends = ["torch", "transformers"]
1177
+
1178
+ def __init__(self, *args, **kwargs):
1179
+ requires_backends(self, ["torch", "transformers"])
1180
+
1181
+ @classmethod
1182
+ def from_config(cls, *args, **kwargs):
1183
+ requires_backends(cls, ["torch", "transformers"])
1184
+
1185
+ @classmethod
1186
+ def from_pretrained(cls, *args, **kwargs):
1187
+ requires_backends(cls, ["torch", "transformers"])
1188
+
1189
+
1145
1190
  class TextToVideoSDPipeline(metaclass=DummyObject):
1146
1191
  _backends = ["torch", "transformers"]
1147
1192
 
@@ -1172,6 +1217,21 @@ class TextToVideoZeroPipeline(metaclass=DummyObject):
1172
1217
  requires_backends(cls, ["torch", "transformers"])
1173
1218
 
1174
1219
 
1220
+ class TextToVideoZeroSDXLPipeline(metaclass=DummyObject):
1221
+ _backends = ["torch", "transformers"]
1222
+
1223
+ def __init__(self, *args, **kwargs):
1224
+ requires_backends(self, ["torch", "transformers"])
1225
+
1226
+ @classmethod
1227
+ def from_config(cls, *args, **kwargs):
1228
+ requires_backends(cls, ["torch", "transformers"])
1229
+
1230
+ @classmethod
1231
+ def from_pretrained(cls, *args, **kwargs):
1232
+ requires_backends(cls, ["torch", "transformers"])
1233
+
1234
+
1175
1235
  class UnCLIPImageVariationPipeline(metaclass=DummyObject):
1176
1236
  _backends = ["torch", "transformers"]
1177
1237
 
@@ -87,9 +87,9 @@ def get_relative_imports(module_file):
87
87
  content = f.read()
88
88
 
89
89
  # Imports of the form `import .xxx`
90
- relative_imports = re.findall("^\s*import\s+\.(\S+)\s*$", content, flags=re.MULTILINE)
90
+ relative_imports = re.findall(r"^\s*import\s+\.(\S+)\s*$", content, flags=re.MULTILINE)
91
91
  # Imports of the form `from .xxx import yyy`
92
- relative_imports += re.findall("^\s*from\s+\.(\S+)\s+import", content, flags=re.MULTILINE)
92
+ relative_imports += re.findall(r"^\s*from\s+\.(\S+)\s+import", content, flags=re.MULTILINE)
93
93
  # Unique-ify
94
94
  return list(set(relative_imports))
95
95
 
@@ -131,9 +131,9 @@ def check_imports(filename):
131
131
  content = f.read()
132
132
 
133
133
  # Imports of the form `import xxx`
134
- imports = re.findall("^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
134
+ imports = re.findall(r"^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
135
135
  # Imports of the form `from xxx import yyy`
136
- imports += re.findall("^\s*from\s+(\S+)\s+import", content, flags=re.MULTILINE)
136
+ imports += re.findall(r"^\s*from\s+(\S+)\s+import", content, flags=re.MULTILINE)
137
137
  # Only keep the top-level module
138
138
  imports = [imp.split(".")[0] for imp in imports if not imp.startswith(".")]
139
139
 
@@ -3,7 +3,7 @@ import random
3
3
  import struct
4
4
  import tempfile
5
5
  from contextlib import contextmanager
6
- from typing import List
6
+ from typing import List, Union
7
7
 
8
8
  import numpy as np
9
9
  import PIL.Image
@@ -115,7 +115,9 @@ def export_to_obj(mesh, output_obj_path: str = None):
115
115
  f.writelines("\n".join(combined_data))
116
116
 
117
117
 
118
- def export_to_video(video_frames: List[np.ndarray], output_video_path: str = None) -> str:
118
+ def export_to_video(
119
+ video_frames: Union[List[np.ndarray], List[PIL.Image.Image]], output_video_path: str = None, fps: int = 8
120
+ ) -> str:
119
121
  if is_opencv_available():
120
122
  import cv2
121
123
  else:
@@ -123,9 +125,12 @@ def export_to_video(video_frames: List[np.ndarray], output_video_path: str = Non
123
125
  if output_video_path is None:
124
126
  output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").name
125
127
 
128
+ if isinstance(video_frames[0], PIL.Image.Image):
129
+ video_frames = [np.array(frame) for frame in video_frames]
130
+
126
131
  fourcc = cv2.VideoWriter_fourcc(*"mp4v")
127
132
  h, w, c = video_frames[0].shape
128
- video_writer = cv2.VideoWriter(output_video_path, fourcc, fps=8, frameSize=(w, h))
133
+ video_writer = cv2.VideoWriter(output_video_path, fourcc, fps=fps, frameSize=(w, h))
129
134
  for i in range(len(video_frames)):
130
135
  img = cv2.cvtColor(video_frames[i], cv2.COLOR_RGB2BGR)
131
136
  video_writer.write(img)
@@ -28,7 +28,7 @@ from logging import (
28
28
  WARN, # NOQA
29
29
  WARNING, # NOQA
30
30
  )
31
- from typing import Optional
31
+ from typing import Dict, Optional
32
32
 
33
33
  from tqdm import auto as tqdm_lib
34
34
 
@@ -49,7 +49,7 @@ _default_log_level = logging.WARNING
49
49
  _tqdm_active = True
50
50
 
51
51
 
52
- def _get_default_logging_level():
52
+ def _get_default_logging_level() -> int:
53
53
  """
54
54
  If DIFFUSERS_VERBOSITY env var is set to one of the valid choices return that as the new default level. If it is
55
55
  not - fall back to `_default_log_level`
@@ -104,7 +104,7 @@ def _reset_library_root_logger() -> None:
104
104
  _default_handler = None
105
105
 
106
106
 
107
- def get_log_levels_dict():
107
+ def get_log_levels_dict() -> Dict[str, int]:
108
108
  return log_levels
109
109
 
110
110
 
@@ -161,22 +161,22 @@ def set_verbosity(verbosity: int) -> None:
161
161
  _get_library_root_logger().setLevel(verbosity)
162
162
 
163
163
 
164
- def set_verbosity_info():
164
+ def set_verbosity_info() -> None:
165
165
  """Set the verbosity to the `INFO` level."""
166
166
  return set_verbosity(INFO)
167
167
 
168
168
 
169
- def set_verbosity_warning():
169
+ def set_verbosity_warning() -> None:
170
170
  """Set the verbosity to the `WARNING` level."""
171
171
  return set_verbosity(WARNING)
172
172
 
173
173
 
174
- def set_verbosity_debug():
174
+ def set_verbosity_debug() -> None:
175
175
  """Set the verbosity to the `DEBUG` level."""
176
176
  return set_verbosity(DEBUG)
177
177
 
178
178
 
179
- def set_verbosity_error():
179
+ def set_verbosity_error() -> None:
180
180
  """Set the verbosity to the `ERROR` level."""
181
181
  return set_verbosity(ERROR)
182
182
 
@@ -263,7 +263,7 @@ def reset_format() -> None:
263
263
  handler.setFormatter(None)
264
264
 
265
265
 
266
- def warning_advice(self, *args, **kwargs):
266
+ def warning_advice(self, *args, **kwargs) -> None:
267
267
  """
268
268
  This method is identical to `logger.warning()`, but if env var DIFFUSERS_NO_ADVISORY_WARNINGS=1 is set, this
269
269
  warning will not be printed
@@ -327,13 +327,13 @@ def is_progress_bar_enabled() -> bool:
327
327
  return bool(_tqdm_active)
328
328
 
329
329
 
330
- def enable_progress_bar():
330
+ def enable_progress_bar() -> None:
331
331
  """Enable tqdm progress bar."""
332
332
  global _tqdm_active
333
333
  _tqdm_active = True
334
334
 
335
335
 
336
- def disable_progress_bar():
336
+ def disable_progress_bar() -> None:
337
337
  """Disable tqdm progress bar."""
338
338
  global _tqdm_active
339
339
  _tqdm_active = False
@@ -24,7 +24,7 @@ import numpy as np
24
24
  from .import_utils import is_torch_available
25
25
 
26
26
 
27
- def is_tensor(x):
27
+ def is_tensor(x) -> bool:
28
28
  """
29
29
  Tests if `x` is a `torch.Tensor` or `np.ndarray`.
30
30
  """
@@ -66,7 +66,7 @@ class BaseOutput(OrderedDict):
66
66
  lambda values, context: cls(**torch.utils._pytree._dict_unflatten(values, context)),
67
67
  )
68
68
 
69
- def __post_init__(self):
69
+ def __post_init__(self) -> None:
70
70
  class_fields = fields(self)
71
71
 
72
72
  # Safety and consistency checks
@@ -97,14 +97,14 @@ class BaseOutput(OrderedDict):
97
97
  def update(self, *args, **kwargs):
98
98
  raise Exception(f"You cannot use ``update`` on a {self.__class__.__name__} instance.")
99
99
 
100
- def __getitem__(self, k):
100
+ def __getitem__(self, k: Any) -> Any:
101
101
  if isinstance(k, str):
102
102
  inner_dict = dict(self.items())
103
103
  return inner_dict[k]
104
104
  else:
105
105
  return self.to_tuple()[k]
106
106
 
107
- def __setattr__(self, name, value):
107
+ def __setattr__(self, name: Any, value: Any) -> None:
108
108
  if name in self.keys() and value is not None:
109
109
  # Don't call self.__setitem__ to avoid recursion errors
110
110
  super().__setitem__(name, value)
@@ -123,7 +123,7 @@ class BaseOutput(OrderedDict):
123
123
  args = tuple(getattr(self, field.name) for field in fields(self))
124
124
  return callable, args, *remaining
125
125
 
126
- def to_tuple(self) -> Tuple[Any]:
126
+ def to_tuple(self) -> Tuple[Any, ...]:
127
127
  """
128
128
  Convert self to a tuple containing all the attributes/keys that are not `None`.
129
129
  """
@@ -23,55 +23,77 @@ from packaging import version
23
23
  from .import_utils import is_peft_available, is_torch_available
24
24
 
25
25
 
26
- def recurse_remove_peft_layers(model):
27
- if is_torch_available():
28
- import torch
26
+ if is_torch_available():
27
+ import torch
28
+
29
29
 
30
+ def recurse_remove_peft_layers(model):
30
31
  r"""
31
32
  Recursively replace all instances of `LoraLayer` with corresponding new layers in `model`.
32
33
  """
33
- from peft.tuners.lora import LoraLayer
34
-
35
- for name, module in model.named_children():
36
- if len(list(module.children())) > 0:
37
- ## compound module, go inside it
38
- recurse_remove_peft_layers(module)
39
-
40
- module_replaced = False
41
-
42
- if isinstance(module, LoraLayer) and isinstance(module, torch.nn.Linear):
43
- new_module = torch.nn.Linear(module.in_features, module.out_features, bias=module.bias is not None).to(
44
- module.weight.device
45
- )
46
- new_module.weight = module.weight
47
- if module.bias is not None:
48
- new_module.bias = module.bias
49
-
50
- module_replaced = True
51
- elif isinstance(module, LoraLayer) and isinstance(module, torch.nn.Conv2d):
52
- new_module = torch.nn.Conv2d(
53
- module.in_channels,
54
- module.out_channels,
55
- module.kernel_size,
56
- module.stride,
57
- module.padding,
58
- module.dilation,
59
- module.groups,
60
- ).to(module.weight.device)
61
-
62
- new_module.weight = module.weight
63
- if module.bias is not None:
64
- new_module.bias = module.bias
65
-
66
- module_replaced = True
67
-
68
- if module_replaced:
69
- setattr(model, name, new_module)
70
- del module
71
-
72
- if torch.cuda.is_available():
73
- torch.cuda.empty_cache()
34
+ from peft.tuners.tuners_utils import BaseTunerLayer
74
35
 
36
+ has_base_layer_pattern = False
37
+ for module in model.modules():
38
+ if isinstance(module, BaseTunerLayer):
39
+ has_base_layer_pattern = hasattr(module, "base_layer")
40
+ break
41
+
42
+ if has_base_layer_pattern:
43
+ from peft.utils import _get_submodules
44
+
45
+ key_list = [key for key, _ in model.named_modules() if "lora" not in key]
46
+ for key in key_list:
47
+ try:
48
+ parent, target, target_name = _get_submodules(model, key)
49
+ except AttributeError:
50
+ continue
51
+ if hasattr(target, "base_layer"):
52
+ setattr(parent, target_name, target.get_base_layer())
53
+ else:
54
+ # This is for backwards compatibility with PEFT <= 0.6.2.
55
+ # TODO can be removed once that PEFT version is no longer supported.
56
+ from peft.tuners.lora import LoraLayer
57
+
58
+ for name, module in model.named_children():
59
+ if len(list(module.children())) > 0:
60
+ ## compound module, go inside it
61
+ recurse_remove_peft_layers(module)
62
+
63
+ module_replaced = False
64
+
65
+ if isinstance(module, LoraLayer) and isinstance(module, torch.nn.Linear):
66
+ new_module = torch.nn.Linear(module.in_features, module.out_features, bias=module.bias is not None).to(
67
+ module.weight.device
68
+ )
69
+ new_module.weight = module.weight
70
+ if module.bias is not None:
71
+ new_module.bias = module.bias
72
+
73
+ module_replaced = True
74
+ elif isinstance(module, LoraLayer) and isinstance(module, torch.nn.Conv2d):
75
+ new_module = torch.nn.Conv2d(
76
+ module.in_channels,
77
+ module.out_channels,
78
+ module.kernel_size,
79
+ module.stride,
80
+ module.padding,
81
+ module.dilation,
82
+ module.groups,
83
+ ).to(module.weight.device)
84
+
85
+ new_module.weight = module.weight
86
+ if module.bias is not None:
87
+ new_module.bias = module.bias
88
+
89
+ module_replaced = True
90
+
91
+ if module_replaced:
92
+ setattr(model, name, new_module)
93
+ del module
94
+
95
+ if torch.cuda.is_available():
96
+ torch.cuda.empty_cache()
75
97
  return model
76
98
 
77
99
 
@@ -180,6 +202,28 @@ def set_adapter_layers(model, enabled=True):
180
202
  module.disable_adapters = not enabled
181
203
 
182
204
 
205
+ def delete_adapter_layers(model, adapter_name):
206
+ from peft.tuners.tuners_utils import BaseTunerLayer
207
+
208
+ for module in model.modules():
209
+ if isinstance(module, BaseTunerLayer):
210
+ if hasattr(module, "delete_adapter"):
211
+ module.delete_adapter(adapter_name)
212
+ else:
213
+ raise ValueError(
214
+ "The version of PEFT you are using is not compatible, please use a version that is greater than 0.6.1"
215
+ )
216
+
217
+ # For transformers integration - we need to pop the adapter from the config
218
+ if getattr(model, "_hf_peft_config_loaded", False) and hasattr(model, "peft_config"):
219
+ model.peft_config.pop(adapter_name, None)
220
+ # In case all adapters are deleted, we need to delete the config
221
+ # and make sure to set the flag to False
222
+ if len(model.peft_config) == 0:
223
+ del model.peft_config
224
+ model._hf_peft_config_loaded = None
225
+
226
+
183
227
  def set_weights_and_activate_adapters(model, adapter_names, weights):
184
228
  from peft.tuners.tuners_utils import BaseTunerLayer
185
229
 
@@ -82,14 +82,14 @@ def randn_tensor(
82
82
  return latents
83
83
 
84
84
 
85
- def is_compiled_module(module):
85
+ def is_compiled_module(module) -> bool:
86
86
  """Check whether the module was compiled with torch.compile()"""
87
87
  if is_torch_version("<", "2.0.0") or not hasattr(torch, "_dynamo"):
88
88
  return False
89
89
  return isinstance(module, torch._dynamo.eval_frame.OptimizedModule)
90
90
 
91
91
 
92
- def fourier_filter(x_in, threshold, scale):
92
+ def fourier_filter(x_in: torch.Tensor, threshold: int, scale: int) -> torch.Tensor:
93
93
  """Fourier filter as introduced in FreeU (https://arxiv.org/abs/2309.11497).
94
94
 
95
95
  This version of the method comes from here:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: diffusers
3
- Version: 0.23.1
3
+ Version: 0.24.0
4
4
  Summary: State-of-the-art diffusion in PyTorch and JAX.
5
5
  Home-page: https://github.com/huggingface/diffusers
6
6
  Author: The HuggingFace team
@@ -14,16 +14,17 @@ Classifier: Intended Audience :: Education
14
14
  Classifier: Intended Audience :: Science/Research
15
15
  Classifier: License :: OSI Approved :: Apache Software License
16
16
  Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
18
  Classifier: Programming Language :: Python :: 3
18
19
  Classifier: Programming Language :: Python :: 3.8
19
20
  Classifier: Programming Language :: Python :: 3.9
20
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Programming Language :: Python :: 3.10
21
22
  Requires-Python: >=3.8.0
22
23
  Description-Content-Type: text/markdown
23
24
  License-File: LICENSE
24
25
  Requires-Dist: Pillow
25
26
  Requires-Dist: filelock
26
- Requires-Dist: huggingface-hub (>=0.13.2)
27
+ Requires-Dist: huggingface-hub (>=0.19.4)
27
28
  Requires-Dist: importlib-metadata
28
29
  Requires-Dist: numpy
29
30
  Requires-Dist: regex (!=2019.12.17)
@@ -32,7 +33,6 @@ Requires-Dist: safetensors (>=0.3.1)
32
33
  Provides-Extra: dev
33
34
  Requires-Dist: Jinja2 ; extra == 'dev'
34
35
  Requires-Dist: accelerate (>=0.11.0) ; extra == 'dev'
35
- Requires-Dist: black (~=23.1) ; extra == 'dev'
36
36
  Requires-Dist: compel (==0.1.8) ; extra == 'dev'
37
37
  Requires-Dist: datasets ; extra == 'dev'
38
38
  Requires-Dist: flax (>=0.4.1) ; extra == 'dev'
@@ -50,7 +50,7 @@ Requires-Dist: pytest ; extra == 'dev'
50
50
  Requires-Dist: pytest-timeout ; extra == 'dev'
51
51
  Requires-Dist: pytest-xdist ; extra == 'dev'
52
52
  Requires-Dist: requests-mock (==1.10.0) ; extra == 'dev'
53
- Requires-Dist: ruff (==0.0.280) ; extra == 'dev'
53
+ Requires-Dist: ruff (<=0.2,>=0.1.5) ; extra == 'dev'
54
54
  Requires-Dist: safetensors (>=0.3.1) ; extra == 'dev'
55
55
  Requires-Dist: scipy ; extra == 'dev'
56
56
  Requires-Dist: sentencepiece (!=0.1.92,>=0.1.91) ; extra == 'dev'
@@ -66,10 +66,9 @@ Requires-Dist: flax (>=0.4.1) ; extra == 'flax'
66
66
  Requires-Dist: jax (>=0.4.1) ; extra == 'flax'
67
67
  Requires-Dist: jaxlib (>=0.4.1) ; extra == 'flax'
68
68
  Provides-Extra: quality
69
- Requires-Dist: black (~=23.1) ; extra == 'quality'
70
69
  Requires-Dist: hf-doc-builder (>=0.3.0) ; extra == 'quality'
71
70
  Requires-Dist: isort (>=5.5.4) ; extra == 'quality'
72
- Requires-Dist: ruff (==0.0.280) ; extra == 'quality'
71
+ Requires-Dist: ruff (<=0.2,>=0.1.5) ; extra == 'quality'
73
72
  Requires-Dist: urllib3 (<=2.0.0) ; extra == 'quality'
74
73
  Provides-Extra: test
75
74
  Requires-Dist: Jinja2 ; extra == 'test'
@@ -99,6 +98,22 @@ Requires-Dist: datasets ; extra == 'training'
99
98
  Requires-Dist: protobuf (<4,>=3.20.3) ; extra == 'training'
100
99
  Requires-Dist: tensorboard ; extra == 'training'
101
100
 
101
+ <!---
102
+ Copyright 2022 - The HuggingFace Team. All rights reserved.
103
+
104
+ Licensed under the Apache License, Version 2.0 (the "License");
105
+ you may not use this file except in compliance with the License.
106
+ You may obtain a copy of the License at
107
+
108
+ http://www.apache.org/licenses/LICENSE-2.0
109
+
110
+ Unless required by applicable law or agreed to in writing, software
111
+ distributed under the License is distributed on an "AS IS" BASIS,
112
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113
+ See the License for the specific language governing permissions and
114
+ limitations under the License.
115
+ -->
116
+
102
117
  <p align="center">
103
118
  <br>
104
119
  <img src="https://raw.githubusercontent.com/huggingface/diffusers/main/docs/source/en/imgs/diffusers_library.jpg" width="400"/>
@@ -115,7 +130,10 @@ Requires-Dist: tensorboard ; extra == 'training'
115
130
  <img alt="GitHub release" src="https://static.pepy.tech/badge/diffusers/month">
116
131
  </a>
117
132
  <a href="CODE_OF_CONDUCT.md">
118
- <img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg">
133
+ <img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg">
134
+ </a>
135
+ <a href="https://twitter.com/diffuserslib">
136
+ <img alt="X account" src="https://img.shields.io/twitter/url/https/twitter.com/diffuserslib.svg?style=social&label=Follow%20%40diffuserslib">
119
137
  </a>
120
138
  </p>
121
139
 
@@ -125,11 +143,11 @@ Requires-Dist: tensorboard ; extra == 'training'
125
143
 
126
144
  - State-of-the-art [diffusion pipelines](https://huggingface.co/docs/diffusers/api/pipelines/overview) that can be run in inference with just a few lines of code.
127
145
  - Interchangeable noise [schedulers](https://huggingface.co/docs/diffusers/api/schedulers/overview) for different diffusion speeds and output quality.
128
- - Pretrained [models](https://huggingface.co/docs/diffusers/api/models) that can be used as building blocks, and combined with schedulers, for creating your own end-to-end diffusion systems.
146
+ - Pretrained [models](https://huggingface.co/docs/diffusers/api/models/overview) that can be used as building blocks, and combined with schedulers, for creating your own end-to-end diffusion systems.
129
147
 
130
148
  ## Installation
131
149
 
132
- We recommend installing 🤗 Diffusers in a virtual environment from PyPi or Conda. For more details about installing [PyTorch](https://pytorch.org/get-started/locally/) and [Flax](https://flax.readthedocs.io/en/latest/#installation), please refer to their official documentation.
150
+ We recommend installing 🤗 Diffusers in a virtual environment from PyPI or Conda. For more details about installing [PyTorch](https://pytorch.org/get-started/locally/) and [Flax](https://flax.readthedocs.io/en/latest/#installation), please refer to their official documentation.
133
151
 
134
152
  ### PyTorch
135
153
 
@@ -159,7 +177,7 @@ Please refer to the [How to use Stable Diffusion in Apple Silicon](https://huggi
159
177
 
160
178
  ## Quickstart
161
179
 
162
- Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 4000+ checkpoints):
180
+ Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 15000+ checkpoints):
163
181
 
164
182
  ```python
165
183
  from diffusers import DiffusionPipeline
@@ -176,14 +194,13 @@ You can also dig into the models and schedulers toolbox to build your own diffus
176
194
  from diffusers import DDPMScheduler, UNet2DModel
177
195
  from PIL import Image
178
196
  import torch
179
- import numpy as np
180
197
 
181
198
  scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
182
199
  model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
183
200
  scheduler.set_timesteps(50)
184
201
 
185
202
  sample_size = model.config.sample_size
186
- noise = torch.randn((1, 3, sample_size, sample_size)).to("cuda")
203
+ noise = torch.randn((1, 3, sample_size, sample_size), device="cuda")
187
204
  input = noise
188
205
 
189
206
  for t in scheduler.timesteps:
@@ -218,8 +235,7 @@ You can look out for [issues](https://github.com/huggingface/diffusers/issues) y
218
235
  - See [New model/pipeline](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22) to contribute exciting new diffusion models / diffusion pipelines
219
236
  - See [New scheduler](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22)
220
237
 
221
- Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a>. We discuss the hottest trends about diffusion models, help each other with contributions, personal projects or
222
- just hang out ☕.
238
+ Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a>. We discuss the hottest trends about diffusion models, help each other with contributions, personal projects or just hang out ☕.
223
239
 
224
240
 
225
241
  ## Popular Tasks & Pipelines
@@ -242,12 +258,12 @@ just hang out ☕.
242
258
  </tr>
243
259
  <tr>
244
260
  <td>Text-to-Image</td>
245
- <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/unclip">unclip</a></td>
261
+ <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/unclip">unCLIP</a></td>
246
262
  <td><a href="https://huggingface.co/kakaobrain/karlo-v1-alpha"> kakaobrain/karlo-v1-alpha </a></td>
247
263
  </tr>
248
264
  <tr>
249
265
  <td>Text-to-Image</td>
250
- <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/if">DeepFloyd IF</a></td>
266
+ <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/deepfloyd_if">DeepFloyd IF</a></td>
251
267
  <td><a href="https://huggingface.co/DeepFloyd/IF-I-XL-v1.0"> DeepFloyd/IF-I-XL-v1.0 </a></td>
252
268
  </tr>
253
269
  <tr>
@@ -257,12 +273,12 @@ just hang out ☕.
257
273
  </tr>
258
274
  <tr style="border-top: 2px solid black">
259
275
  <td>Text-guided Image-to-Image</td>
260
- <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/controlnet">Controlnet</a></td>
276
+ <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/controlnet">ControlNet</a></td>
261
277
  <td><a href="https://huggingface.co/lllyasviel/sd-controlnet-canny"> lllyasviel/sd-controlnet-canny </a></td>
262
278
  </tr>
263
279
  <tr>
264
280
  <td>Text-guided Image-to-Image</td>
265
- <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/pix2pix">Instruct Pix2Pix</a></td>
281
+ <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/pix2pix">InstructPix2Pix</a></td>
266
282
  <td><a href="https://huggingface.co/timbrooks/instruct-pix2pix"> timbrooks/instruct-pix2pix </a></td>
267
283
  </tr>
268
284
  <tr>
@@ -272,7 +288,7 @@ just hang out ☕.
272
288
  </tr>
273
289
  <tr style="border-top: 2px solid black">
274
290
  <td>Text-guided Image Inpainting</td>
275
- <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpaint">Stable Diffusion Inpaint</a></td>
291
+ <td><a href="https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpaint">Stable Diffusion Inpainting</a></td>
276
292
  <td><a href="https://huggingface.co/runwayml/stable-diffusion-inpainting"> runwayml/stable-diffusion-inpainting </a></td>
277
293
  </tr>
278
294
  <tr style="border-top: 2px solid black">
@@ -303,9 +319,9 @@ just hang out ☕.
303
319
  - https://github.com/deep-floyd/IF
304
320
  - https://github.com/bentoml/BentoML
305
321
  - https://github.com/bmaltais/kohya_ss
306
- - +3000 other amazing GitHub repositories 💪
322
+ - +6000 other amazing GitHub repositories 💪
307
323
 
308
- Thank you for using us ❤️
324
+ Thank you for using us ❤️.
309
325
 
310
326
  ## Credits
311
327