diffusers 0.19.3__py3-none-any.whl → 0.20.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. diffusers/__init__.py +3 -1
  2. diffusers/commands/fp16_safetensors.py +2 -7
  3. diffusers/configuration_utils.py +23 -1
  4. diffusers/dependency_versions_table.py +1 -1
  5. diffusers/loaders.py +62 -64
  6. diffusers/models/__init__.py +1 -0
  7. diffusers/models/activations.py +2 -0
  8. diffusers/models/attention.py +45 -1
  9. diffusers/models/autoencoder_tiny.py +193 -0
  10. diffusers/models/controlnet.py +1 -1
  11. diffusers/models/embeddings.py +56 -0
  12. diffusers/models/lora.py +0 -6
  13. diffusers/models/modeling_flax_utils.py +28 -2
  14. diffusers/models/modeling_utils.py +33 -16
  15. diffusers/models/transformer_2d.py +26 -9
  16. diffusers/models/unet_1d.py +2 -2
  17. diffusers/models/unet_2d_blocks.py +106 -56
  18. diffusers/models/unet_2d_condition.py +20 -5
  19. diffusers/models/vae.py +106 -1
  20. diffusers/pipelines/__init__.py +1 -0
  21. diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +10 -3
  22. diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +10 -3
  23. diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -1
  24. diffusers/pipelines/auto_pipeline.py +33 -43
  25. diffusers/pipelines/controlnet/multicontrolnet.py +4 -2
  26. diffusers/pipelines/controlnet/pipeline_controlnet.py +20 -4
  27. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +15 -7
  28. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +14 -4
  29. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +157 -10
  30. diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +2 -10
  31. diffusers/pipelines/deepfloyd_if/pipeline_if.py +1 -1
  32. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +1 -1
  33. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +1 -1
  34. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +1 -1
  35. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +1 -1
  36. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +1 -1
  37. diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +43 -2
  38. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +44 -2
  39. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +1 -1
  40. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  41. diffusers/pipelines/pipeline_flax_utils.py +41 -4
  42. diffusers/pipelines/pipeline_utils.py +60 -16
  43. diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +2 -2
  44. diffusers/pipelines/stable_diffusion/__init__.py +1 -0
  45. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +81 -37
  46. diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py +10 -3
  47. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +10 -3
  48. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_attend_and_excite.py +10 -3
  49. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +10 -3
  50. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py +12 -5
  51. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen.py +832 -0
  52. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +10 -3
  53. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +10 -3
  54. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py +10 -3
  55. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_k_diffusion.py +9 -2
  56. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_ldm3d.py +17 -8
  57. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py +10 -3
  58. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py +10 -3
  59. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_paradigms.py +10 -3
  60. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py +10 -3
  61. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py +10 -3
  62. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +10 -3
  63. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +10 -3
  64. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +10 -3
  65. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +3 -5
  66. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +75 -3
  67. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +76 -6
  68. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +1 -2
  69. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +10 -3
  70. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +10 -3
  71. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +11 -4
  72. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +1 -1
  73. diffusers/pipelines/versatile_diffusion/modeling_text_unet.py +131 -28
  74. diffusers/schedulers/scheduling_consistency_models.py +70 -57
  75. diffusers/schedulers/scheduling_ddim.py +76 -71
  76. diffusers/schedulers/scheduling_ddim_inverse.py +76 -44
  77. diffusers/schedulers/scheduling_ddim_parallel.py +11 -8
  78. diffusers/schedulers/scheduling_ddpm.py +68 -67
  79. diffusers/schedulers/scheduling_ddpm_parallel.py +18 -15
  80. diffusers/schedulers/scheduling_deis_multistep.py +93 -85
  81. diffusers/schedulers/scheduling_dpmsolver_multistep.py +118 -120
  82. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +116 -109
  83. diffusers/schedulers/scheduling_dpmsolver_sde.py +57 -43
  84. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +122 -121
  85. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +54 -44
  86. diffusers/schedulers/scheduling_euler_discrete.py +63 -56
  87. diffusers/schedulers/scheduling_heun_discrete.py +57 -45
  88. diffusers/schedulers/scheduling_ipndm.py +27 -22
  89. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +54 -41
  90. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +52 -41
  91. diffusers/schedulers/scheduling_karras_ve.py +55 -45
  92. diffusers/schedulers/scheduling_lms_discrete.py +58 -52
  93. diffusers/schedulers/scheduling_pndm.py +77 -62
  94. diffusers/schedulers/scheduling_repaint.py +56 -38
  95. diffusers/schedulers/scheduling_sde_ve.py +62 -50
  96. diffusers/schedulers/scheduling_sde_vp.py +32 -11
  97. diffusers/schedulers/scheduling_unclip.py +3 -3
  98. diffusers/schedulers/scheduling_unipc_multistep.py +131 -91
  99. diffusers/schedulers/scheduling_utils.py +41 -35
  100. diffusers/schedulers/scheduling_utils_flax.py +8 -2
  101. diffusers/schedulers/scheduling_vq_diffusion.py +39 -68
  102. diffusers/utils/__init__.py +2 -2
  103. diffusers/utils/dummy_pt_objects.py +15 -0
  104. diffusers/utils/dummy_torch_and_transformers_objects.py +15 -0
  105. diffusers/utils/hub_utils.py +105 -2
  106. diffusers/utils/import_utils.py +0 -4
  107. diffusers/utils/pil_utils.py +19 -0
  108. {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/METADATA +5 -7
  109. {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/RECORD +113 -112
  110. {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/WHEEL +1 -1
  111. {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/entry_points.txt +0 -1
  112. diffusers/models/cross_attention.py +0 -94
  113. {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/LICENSE +0 -0
  114. {diffusers-0.19.3.dist-info → diffusers-0.20.1.dist-info}/top_level.txt +0 -0
@@ -105,36 +105,24 @@ def gamma_schedules(num_diffusion_timesteps: int, gamma_cum_start=0.000009, gamm
105
105
 
106
106
  class VQDiffusionScheduler(SchedulerMixin, ConfigMixin):
107
107
  """
108
- The VQ-diffusion transformer outputs predicted probabilities of the initial unnoised image.
108
+ A scheduler for vector quantized diffusion.
109
109
 
110
- The VQ-diffusion scheduler converts the transformer's output into a sample for the unnoised image at the previous
111
- diffusion timestep.
112
-
113
- [`~ConfigMixin`] takes care of storing all config attributes that are passed in the scheduler's `__init__`
114
- function, such as `num_train_timesteps`. They can be accessed via `scheduler.config.num_train_timesteps`.
115
- [`SchedulerMixin`] provides general loading and saving functionality via the [`SchedulerMixin.save_pretrained`] and
116
- [`~SchedulerMixin.from_pretrained`] functions.
117
-
118
- For more details, see the original paper: https://arxiv.org/abs/2111.14822
110
+ This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic
111
+ methods the library implements for all schedulers such as loading and saving.
119
112
 
120
113
  Args:
121
114
  num_vec_classes (`int`):
122
115
  The number of classes of the vector embeddings of the latent pixels. Includes the class for the masked
123
116
  latent pixel.
124
-
125
- num_train_timesteps (`int`):
126
- Number of diffusion steps used to train the model.
127
-
128
- alpha_cum_start (`float`):
117
+ num_train_timesteps (`int`, defaults to 100):
118
+ The number of diffusion steps to train the model.
119
+ alpha_cum_start (`float`, defaults to 0.99999):
129
120
  The starting cumulative alpha value.
130
-
131
- alpha_cum_end (`float`):
121
+ alpha_cum_end (`float`, defaults to 0.00009):
132
122
  The ending cumulative alpha value.
133
-
134
- gamma_cum_start (`float`):
123
+ gamma_cum_start (`float`, defaults to 0.00009):
135
124
  The starting cumulative gamma value.
136
-
137
- gamma_cum_end (`float`):
125
+ gamma_cum_end (`float`, defaults to 0.99999):
138
126
  The ending cumulative gamma value.
139
127
  """
140
128
 
@@ -189,14 +177,14 @@ class VQDiffusionScheduler(SchedulerMixin, ConfigMixin):
189
177
 
190
178
  def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device] = None):
191
179
  """
192
- Sets the discrete timesteps used for the diffusion chain. Supporting function to be run before inference.
180
+ Sets the discrete timesteps used for the diffusion chain (to be run before inference).
193
181
 
194
182
  Args:
195
183
  num_inference_steps (`int`):
196
- the number of diffusion steps used when generating samples with a pre-trained model.
197
-
198
- device (`str` or `torch.device`):
199
- device to place the timesteps and the diffusion process parameters (alpha, beta, gamma) on.
184
+ The number of diffusion steps used when generating samples with a pre-trained model.
185
+ device (`str` or `torch.device`, *optional*):
186
+ The device to which the timesteps and diffusion process parameters (alpha, beta, gamma) should be moved
187
+ to.
200
188
  """
201
189
  self.num_inference_steps = num_inference_steps
202
190
  timesteps = np.arange(0, self.num_inference_steps)[::-1].copy()
@@ -218,30 +206,27 @@ class VQDiffusionScheduler(SchedulerMixin, ConfigMixin):
218
206
  return_dict: bool = True,
219
207
  ) -> Union[VQDiffusionSchedulerOutput, Tuple]:
220
208
  """
221
- Predict the sample at the previous timestep via the reverse transition distribution i.e. Equation (11). See the
222
- docstring for `self.q_posterior` for more in depth docs on how Equation (11) is computed.
209
+ Predict the sample from the previous timestep by the reverse transition distribution. See
210
+ [`~VQDiffusionScheduler.q_posterior`] for more details about how the distribution is computer.
223
211
 
224
212
  Args:
225
213
  log_p_x_0: (`torch.FloatTensor` of shape `(batch size, num classes - 1, num latent pixels)`):
226
214
  The log probabilities for the predicted classes of the initial latent pixels. Does not include a
227
215
  prediction for the masked class as the initial unnoised image cannot be masked.
228
-
229
216
  t (`torch.long`):
230
217
  The timestep that determines which transition matrices are used.
231
-
232
- x_t: (`torch.LongTensor` of shape `(batch size, num latent pixels)`):
233
- The classes of each latent pixel at time `t`
234
-
235
- generator: (`torch.Generator` or None):
236
- RNG for the noise applied to p(x_{t-1} | x_t) before it is sampled from.
237
-
238
- return_dict (`bool`):
239
- option for returning tuple rather than VQDiffusionSchedulerOutput class
218
+ x_t (`torch.LongTensor` of shape `(batch size, num latent pixels)`):
219
+ The classes of each latent pixel at time `t`.
220
+ generator (`torch.Generator`, or `None`):
221
+ A random number generator for the noise applied to `p(x_{t-1} | x_t)` before it is sampled from.
222
+ return_dict (`bool`, *optional*, defaults to `True`):
223
+ Whether or not to return a [`~schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput`] or
224
+ `tuple`.
240
225
 
241
226
  Returns:
242
- [`~schedulers.scheduling_utils.VQDiffusionSchedulerOutput`] or `tuple`:
243
- [`~schedulers.scheduling_utils.VQDiffusionSchedulerOutput`] if `return_dict` is True, otherwise a `tuple`.
244
- When returning a tuple, the first element is the sample tensor.
227
+ [`~schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput`] or `tuple`:
228
+ If return_dict is `True`, [`~schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput`] is
229
+ returned, otherwise a tuple is returned where the first element is the sample tensor.
245
230
  """
246
231
  if timestep == 0:
247
232
  log_p_x_t_min_1 = model_output
@@ -259,32 +244,24 @@ class VQDiffusionScheduler(SchedulerMixin, ConfigMixin):
259
244
 
260
245
  def q_posterior(self, log_p_x_0, x_t, t):
261
246
  """
262
- Calculates the log probabilities for the predicted classes of the image at timestep `t-1`. I.e. Equation (11).
263
-
264
- Instead of directly computing equation (11), we use Equation (5) to restate Equation (11) in terms of only
265
- forward probabilities.
266
-
267
- Equation (11) stated in terms of forward probabilities via Equation (5):
268
-
269
- Where:
270
- - the sum is over x_0 = {C_0 ... C_{k-1}} (classes for x_0)
247
+ Calculates the log probabilities for the predicted classes of the image at timestep `t-1`:
271
248
 
249
+ ```
272
250
  p(x_{t-1} | x_t) = sum( q(x_t | x_{t-1}) * q(x_{t-1} | x_0) * p(x_0) / q(x_t | x_0) )
251
+ ```
273
252
 
274
253
  Args:
275
- log_p_x_0: (`torch.FloatTensor` of shape `(batch size, num classes - 1, num latent pixels)`):
254
+ log_p_x_0 (`torch.FloatTensor` of shape `(batch size, num classes - 1, num latent pixels)`):
276
255
  The log probabilities for the predicted classes of the initial latent pixels. Does not include a
277
256
  prediction for the masked class as the initial unnoised image cannot be masked.
278
-
279
- x_t: (`torch.LongTensor` of shape `(batch size, num latent pixels)`):
280
- The classes of each latent pixel at time `t`
281
-
282
- t (torch.Long):
257
+ x_t (`torch.LongTensor` of shape `(batch size, num latent pixels)`):
258
+ The classes of each latent pixel at time `t`.
259
+ t (`torch.Long`):
283
260
  The timestep that determines which transition matrix is used.
284
261
 
285
262
  Returns:
286
263
  `torch.FloatTensor` of shape `(batch size, num classes, num latent pixels)`:
287
- The log probabilities for the predicted classes of the image at timestep `t-1`. I.e. Equation (11).
264
+ The log probabilities for the predicted classes of the image at timestep `t-1`.
288
265
  """
289
266
  log_onehot_x_t = index_to_log_onehot(x_t, self.num_embed)
290
267
 
@@ -380,25 +357,19 @@ class VQDiffusionScheduler(SchedulerMixin, ConfigMixin):
380
357
  self, *, t: torch.int, x_t: torch.LongTensor, log_onehot_x_t: torch.FloatTensor, cumulative: bool
381
358
  ):
382
359
  """
383
- Returns the log probabilities of the rows from the (cumulative or non-cumulative) transition matrix for each
360
+ Calculates the log probabilities of the rows from the (cumulative or non-cumulative) transition matrix for each
384
361
  latent pixel in `x_t`.
385
362
 
386
- See equation (7) for the complete non-cumulative transition matrix. The complete cumulative transition matrix
387
- is the same structure except the parameters (alpha, beta, gamma) are the cumulative analogs.
388
-
389
363
  Args:
390
- t (torch.Long):
364
+ t (`torch.Long`):
391
365
  The timestep that determines which transition matrix is used.
392
-
393
366
  x_t (`torch.LongTensor` of shape `(batch size, num latent pixels)`):
394
367
  The classes of each latent pixel at time `t`.
395
-
396
368
  log_onehot_x_t (`torch.FloatTensor` of shape `(batch size, num classes, num latent pixels)`):
397
- The log one-hot vectors of `x_t`
398
-
369
+ The log one-hot vectors of `x_t`.
399
370
  cumulative (`bool`):
400
- If cumulative is `False`, we use the single step transition matrix `t-1`->`t`. If cumulative is `True`,
401
- we use the cumulative transition matrix `0`->`t`.
371
+ If cumulative is `False`, the single step transition matrix `t-1`->`t` is used. If cumulative is
372
+ `True`, the cumulative transition matrix `0`->`t` is used.
402
373
 
403
374
  Returns:
404
375
  `torch.FloatTensor` of shape `(batch size, num classes - 1, num latent pixels)`:
@@ -37,6 +37,7 @@ from .doc_utils import replace_example_docstring
37
37
  from .dynamic_modules_utils import get_class_from_dynamic_module
38
38
  from .hub_utils import (
39
39
  HF_HUB_OFFLINE,
40
+ PushToHubMixin,
40
41
  _add_variant,
41
42
  _get_model_file,
42
43
  extract_commit_hash,
@@ -64,7 +65,6 @@ from .import_utils import (
64
65
  is_note_seq_available,
65
66
  is_omegaconf_available,
66
67
  is_onnx_available,
67
- is_safetensors_available,
68
68
  is_scipy_available,
69
69
  is_tensorboard_available,
70
70
  is_tf_available,
@@ -80,7 +80,7 @@ from .import_utils import (
80
80
  )
81
81
  from .logging import get_logger
82
82
  from .outputs import BaseOutput
83
- from .pil_utils import PIL_INTERPOLATION, numpy_to_pil, pt_to_pil
83
+ from .pil_utils import PIL_INTERPOLATION, make_image_grid, numpy_to_pil, pt_to_pil
84
84
  from .torch_utils import is_compiled_module, randn_tensor
85
85
 
86
86
 
@@ -32,6 +32,21 @@ class AutoencoderKL(metaclass=DummyObject):
32
32
  requires_backends(cls, ["torch"])
33
33
 
34
34
 
35
+ class AutoencoderTiny(metaclass=DummyObject):
36
+ _backends = ["torch"]
37
+
38
+ def __init__(self, *args, **kwargs):
39
+ requires_backends(self, ["torch"])
40
+
41
+ @classmethod
42
+ def from_config(cls, *args, **kwargs):
43
+ requires_backends(cls, ["torch"])
44
+
45
+ @classmethod
46
+ def from_pretrained(cls, *args, **kwargs):
47
+ requires_backends(cls, ["torch"])
48
+
49
+
35
50
  class ControlNetModel(metaclass=DummyObject):
36
51
  _backends = ["torch"]
37
52
 
@@ -602,6 +602,21 @@ class StableDiffusionDiffEditPipeline(metaclass=DummyObject):
602
602
  requires_backends(cls, ["torch", "transformers"])
603
603
 
604
604
 
605
+ class StableDiffusionGLIGENPipeline(metaclass=DummyObject):
606
+ _backends = ["torch", "transformers"]
607
+
608
+ def __init__(self, *args, **kwargs):
609
+ requires_backends(self, ["torch", "transformers"])
610
+
611
+ @classmethod
612
+ def from_config(cls, *args, **kwargs):
613
+ requires_backends(cls, ["torch", "transformers"])
614
+
615
+ @classmethod
616
+ def from_pretrained(cls, *args, **kwargs):
617
+ requires_backends(cls, ["torch", "transformers"])
618
+
619
+
605
620
  class StableDiffusionImageVariationPipeline(metaclass=DummyObject):
606
621
  _backends = ["torch", "transformers"]
607
622
 
@@ -17,13 +17,22 @@
17
17
  import os
18
18
  import re
19
19
  import sys
20
+ import tempfile
20
21
  import traceback
21
22
  import warnings
22
23
  from pathlib import Path
23
24
  from typing import Dict, Optional, Union
24
25
  from uuid import uuid4
25
26
 
26
- from huggingface_hub import HfFolder, ModelCard, ModelCardData, hf_hub_download, whoami
27
+ from huggingface_hub import (
28
+ HfFolder,
29
+ ModelCard,
30
+ ModelCardData,
31
+ create_repo,
32
+ hf_hub_download,
33
+ upload_folder,
34
+ whoami,
35
+ )
27
36
  from huggingface_hub.file_download import REGEX_COMMIT_HASH
28
37
  from huggingface_hub.utils import (
29
38
  EntryNotFoundError,
@@ -280,7 +289,7 @@ def _get_model_file(
280
289
  if (
281
290
  revision in DEPRECATED_REVISION_ARGS
282
291
  and (weights_name == WEIGHTS_NAME or weights_name == SAFETENSORS_WEIGHTS_NAME)
283
- and version.parse(version.parse(__version__).base_version) >= version.parse("0.20.0")
292
+ and version.parse(version.parse(__version__).base_version) >= version.parse("0.22.0")
284
293
  ):
285
294
  try:
286
295
  model_file = hf_hub_download(
@@ -359,3 +368,97 @@ def _get_model_file(
359
368
  f"Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a directory "
360
369
  f"containing a file named {weights_name}"
361
370
  )
371
+
372
+
373
+ class PushToHubMixin:
374
+ """
375
+ A Mixin to push a model, scheduler, or pipeline to the Hugging Face Hub.
376
+ """
377
+
378
+ def _upload_folder(
379
+ self,
380
+ working_dir: Union[str, os.PathLike],
381
+ repo_id: str,
382
+ token: Optional[str] = None,
383
+ commit_message: Optional[str] = None,
384
+ create_pr: bool = False,
385
+ ):
386
+ """
387
+ Uploads all files in `working_dir` to `repo_id`.
388
+ """
389
+ if commit_message is None:
390
+ if "Model" in self.__class__.__name__:
391
+ commit_message = "Upload model"
392
+ elif "Scheduler" in self.__class__.__name__:
393
+ commit_message = "Upload scheduler"
394
+ else:
395
+ commit_message = f"Upload {self.__class__.__name__}"
396
+
397
+ logger.info(f"Uploading the files of {working_dir} to {repo_id}.")
398
+ return upload_folder(
399
+ repo_id=repo_id, folder_path=working_dir, token=token, commit_message=commit_message, create_pr=create_pr
400
+ )
401
+
402
+ def push_to_hub(
403
+ self,
404
+ repo_id: str,
405
+ commit_message: Optional[str] = None,
406
+ private: Optional[bool] = None,
407
+ token: Optional[str] = None,
408
+ create_pr: bool = False,
409
+ safe_serialization: bool = True,
410
+ variant: Optional[str] = None,
411
+ ) -> str:
412
+ """
413
+ Upload model, scheduler, or pipeline files to the 🤗 Hugging Face Hub.
414
+
415
+ Parameters:
416
+ repo_id (`str`):
417
+ The name of the repository you want to push your model, scheduler, or pipeline files to. It should
418
+ contain your organization name when pushing to an organization. `repo_id` can also be a path to a local
419
+ directory.
420
+ commit_message (`str`, *optional*):
421
+ Message to commit while pushing. Default to `"Upload {object}"`.
422
+ private (`bool`, *optional*):
423
+ Whether or not the repository created should be private.
424
+ token (`str`, *optional*):
425
+ The token to use as HTTP bearer authorization for remote files. The token generated when running
426
+ `huggingface-cli login` (stored in `~/.huggingface`).
427
+ create_pr (`bool`, *optional*, defaults to `False`):
428
+ Whether or not to create a PR with the uploaded files or directly commit.
429
+ safe_serialization (`bool`, *optional*, defaults to `True`):
430
+ Whether or not to convert the model weights to the `safetensors` format.
431
+ variant (`str`, *optional*):
432
+ If specified, weights are saved in the format `pytorch_model.<variant>.bin`.
433
+
434
+ Examples:
435
+
436
+ ```python
437
+ from diffusers import UNet2DConditionModel
438
+
439
+ unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-2", subfolder="unet")
440
+
441
+ # Push the `unet` to your namespace with the name "my-finetuned-unet".
442
+ unet.push_to_hub("my-finetuned-unet")
443
+
444
+ # Push the `unet` to an organization with the name "my-finetuned-unet".
445
+ unet.push_to_hub("your-org/my-finetuned-unet")
446
+ ```
447
+ """
448
+ repo_id = create_repo(repo_id, private=private, token=token, exist_ok=True).repo_id
449
+
450
+ # Save all files.
451
+ save_kwargs = {"safe_serialization": safe_serialization}
452
+ if "Scheduler" not in self.__class__.__name__:
453
+ save_kwargs.update({"variant": variant})
454
+
455
+ with tempfile.TemporaryDirectory() as tmpdir:
456
+ self.save_pretrained(tmpdir, **save_kwargs)
457
+
458
+ return self._upload_folder(
459
+ tmpdir,
460
+ repo_id,
461
+ token=token,
462
+ commit_message=commit_message,
463
+ create_pr=create_pr,
464
+ )
@@ -306,10 +306,6 @@ def is_torch_available():
306
306
  return _torch_available
307
307
 
308
308
 
309
- def is_safetensors_available():
310
- return _safetensors_available
311
-
312
-
313
309
  def is_tf_available():
314
310
  return _tf_available
315
311
 
@@ -1,3 +1,5 @@
1
+ from typing import List
2
+
1
3
  import PIL.Image
2
4
  import PIL.ImageOps
3
5
  from packaging import version
@@ -46,3 +48,20 @@ def numpy_to_pil(images):
46
48
  pil_images = [Image.fromarray(image) for image in images]
47
49
 
48
50
  return pil_images
51
+
52
+
53
+ def make_image_grid(images: List[PIL.Image.Image], rows: int, cols: int, resize: int = None) -> PIL.Image.Image:
54
+ """
55
+ Prepares a single grid of images. Useful for visualization purposes.
56
+ """
57
+ assert len(images) == rows * cols
58
+
59
+ if resize is not None:
60
+ images = [img.resize((resize, resize)) for img in images]
61
+
62
+ w, h = images[0].size
63
+ grid = Image.new("RGB", size=(cols * w, rows * h))
64
+
65
+ for i, img in enumerate(images):
66
+ grid.paste(img, box=(i % cols * w, i // cols * h))
67
+ return grid
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: diffusers
3
- Version: 0.19.3
3
+ Version: 0.20.1
4
4
  Summary: Diffusers
5
5
  Home-page: https://github.com/huggingface/diffusers
6
6
  Author: The HuggingFace team
7
7
  Author-email: patrick@huggingface.co
8
8
  License: Apache
9
9
  Keywords: deep learning
10
- Platform: UNKNOWN
11
10
  Classifier: Development Status :: 5 - Production/Stable
12
11
  Classifier: Intended Audience :: Developers
13
12
  Classifier: Intended Audience :: Education
@@ -21,6 +20,7 @@ Classifier: Programming Language :: Python :: 3.9
21
20
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
21
  Requires-Python: >=3.7.0
23
22
  Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
24
  Requires-Dist: importlib-metadata
25
25
  Requires-Dist: filelock
26
26
  Requires-Dist: huggingface-hub (>=0.13.2)
@@ -33,7 +33,7 @@ Provides-Extra: dev
33
33
  Requires-Dist: urllib3 (<=2.0.0) ; extra == 'dev'
34
34
  Requires-Dist: black (~=23.1) ; extra == 'dev'
35
35
  Requires-Dist: isort (>=5.5.4) ; extra == 'dev'
36
- Requires-Dist: ruff (>=0.0.241) ; extra == 'dev'
36
+ Requires-Dist: ruff (==0.0.280) ; extra == 'dev'
37
37
  Requires-Dist: hf-doc-builder (>=0.3.0) ; extra == 'dev'
38
38
  Requires-Dist: compel (==0.1.8) ; extra == 'dev'
39
39
  Requires-Dist: datasets ; extra == 'dev'
@@ -69,7 +69,7 @@ Provides-Extra: quality
69
69
  Requires-Dist: urllib3 (<=2.0.0) ; extra == 'quality'
70
70
  Requires-Dist: black (~=23.1) ; extra == 'quality'
71
71
  Requires-Dist: isort (>=5.5.4) ; extra == 'quality'
72
- Requires-Dist: ruff (>=0.0.241) ; extra == 'quality'
72
+ Requires-Dist: ruff (==0.0.280) ; extra == 'quality'
73
73
  Requires-Dist: hf-doc-builder (>=0.3.0) ; extra == 'quality'
74
74
  Provides-Extra: test
75
75
  Requires-Dist: compel (==0.1.8) ; extra == 'test'
@@ -101,7 +101,7 @@ Requires-Dist: Jinja2 ; extra == 'training'
101
101
 
102
102
  <p align="center">
103
103
  <br>
104
- <img src="https://github.com/huggingface/diffusers/blob/main/docs/source/en/imgs/diffusers_library.jpg" width="400"/>
104
+ <img src="https://raw.githubusercontent.com/huggingface/diffusers/main/docs/source/en/imgs/diffusers_library.jpg" width="400"/>
105
105
  <br>
106
106
  <p>
107
107
  <p align="center">
@@ -327,5 +327,3 @@ We also want to thank @heejkoo for the very helpful overview of papers, code and
327
327
  howpublished = {\url{https://github.com/huggingface/diffusers}}
328
328
  }
329
329
  ```
330
-
331
-