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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. diffusers/__init__.py +11 -1
  2. diffusers/commands/fp16_safetensors.py +10 -11
  3. diffusers/configuration_utils.py +12 -8
  4. diffusers/dependency_versions_table.py +3 -2
  5. diffusers/experimental/rl/value_guided_sampling.py +1 -1
  6. diffusers/image_processor.py +286 -46
  7. diffusers/loaders/ip_adapter.py +11 -9
  8. diffusers/loaders/lora.py +198 -60
  9. diffusers/loaders/single_file.py +24 -18
  10. diffusers/loaders/textual_inversion.py +10 -14
  11. diffusers/loaders/unet.py +130 -37
  12. diffusers/models/__init__.py +18 -12
  13. diffusers/models/activations.py +9 -6
  14. diffusers/models/attention.py +137 -16
  15. diffusers/models/attention_processor.py +133 -46
  16. diffusers/models/autoencoders/__init__.py +5 -0
  17. diffusers/models/{autoencoder_asym_kl.py → autoencoders/autoencoder_asym_kl.py} +4 -4
  18. diffusers/models/{autoencoder_kl.py → autoencoders/autoencoder_kl.py} +45 -6
  19. diffusers/models/{autoencoder_kl_temporal_decoder.py → autoencoders/autoencoder_kl_temporal_decoder.py} +8 -8
  20. diffusers/models/{autoencoder_tiny.py → autoencoders/autoencoder_tiny.py} +4 -4
  21. diffusers/models/{consistency_decoder_vae.py → autoencoders/consistency_decoder_vae.py} +14 -14
  22. diffusers/models/{vae.py → autoencoders/vae.py} +9 -5
  23. diffusers/models/downsampling.py +338 -0
  24. diffusers/models/embeddings.py +112 -29
  25. diffusers/models/modeling_flax_utils.py +12 -7
  26. diffusers/models/modeling_utils.py +10 -10
  27. diffusers/models/normalization.py +108 -2
  28. diffusers/models/resnet.py +15 -699
  29. diffusers/models/transformer_2d.py +2 -2
  30. diffusers/models/unet_2d_condition.py +37 -0
  31. diffusers/models/{unet_kandi3.py → unet_kandinsky3.py} +105 -159
  32. diffusers/models/upsampling.py +454 -0
  33. diffusers/models/uvit_2d.py +471 -0
  34. diffusers/models/vq_model.py +9 -2
  35. diffusers/pipelines/__init__.py +81 -73
  36. diffusers/pipelines/amused/__init__.py +62 -0
  37. diffusers/pipelines/amused/pipeline_amused.py +328 -0
  38. diffusers/pipelines/amused/pipeline_amused_img2img.py +347 -0
  39. diffusers/pipelines/amused/pipeline_amused_inpaint.py +378 -0
  40. diffusers/pipelines/animatediff/pipeline_animatediff.py +38 -10
  41. diffusers/pipelines/auto_pipeline.py +17 -13
  42. diffusers/pipelines/controlnet/pipeline_controlnet.py +27 -10
  43. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +47 -5
  44. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +25 -8
  45. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +4 -6
  46. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +26 -10
  47. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +4 -3
  48. diffusers/pipelines/deprecated/__init__.py +153 -0
  49. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/__init__.py +3 -3
  50. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion.py +91 -18
  51. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py +91 -18
  52. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_output.py +1 -1
  53. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/__init__.py +1 -1
  54. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/mel.py +2 -2
  55. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py +4 -4
  56. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/__init__.py +1 -1
  57. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/pipeline_latent_diffusion_uncond.py +4 -4
  58. diffusers/pipelines/{pndm → deprecated/pndm}/__init__.py +1 -1
  59. diffusers/pipelines/{pndm → deprecated/pndm}/pipeline_pndm.py +4 -4
  60. diffusers/pipelines/{repaint → deprecated/repaint}/__init__.py +1 -1
  61. diffusers/pipelines/{repaint → deprecated/repaint}/pipeline_repaint.py +5 -5
  62. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/__init__.py +1 -1
  63. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/pipeline_score_sde_ve.py +4 -4
  64. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/__init__.py +6 -6
  65. diffusers/pipelines/{spectrogram_diffusion/continous_encoder.py → deprecated/spectrogram_diffusion/continuous_encoder.py} +2 -2
  66. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/midi_utils.py +1 -1
  67. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py +2 -2
  68. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/pipeline_spectrogram_diffusion.py +7 -7
  69. diffusers/pipelines/deprecated/stable_diffusion_variants/__init__.py +55 -0
  70. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_cycle_diffusion.py +16 -11
  71. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_onnx_stable_diffusion_inpaint_legacy.py +6 -6
  72. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_inpaint_legacy.py +11 -11
  73. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_model_editing.py +16 -11
  74. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_paradigms.py +10 -10
  75. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_pix2pix_zero.py +13 -13
  76. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/__init__.py +1 -1
  77. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/pipeline_stochastic_karras_ve.py +4 -4
  78. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/__init__.py +3 -3
  79. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/modeling_text_unet.py +54 -11
  80. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion.py +4 -4
  81. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_dual_guided.py +6 -6
  82. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_image_variation.py +6 -6
  83. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_text_to_image.py +6 -6
  84. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/__init__.py +3 -3
  85. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/pipeline_vq_diffusion.py +5 -5
  86. diffusers/pipelines/kandinsky3/__init__.py +4 -4
  87. diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +98 -0
  88. diffusers/pipelines/kandinsky3/{kandinsky3_pipeline.py → pipeline_kandinsky3.py} +172 -35
  89. diffusers/pipelines/kandinsky3/{kandinsky3img2img_pipeline.py → pipeline_kandinsky3_img2img.py} +228 -34
  90. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +46 -5
  91. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +47 -6
  92. diffusers/pipelines/onnx_utils.py +8 -5
  93. diffusers/pipelines/pipeline_flax_utils.py +7 -6
  94. diffusers/pipelines/pipeline_utils.py +32 -31
  95. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +51 -2
  96. diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +3 -3
  97. diffusers/pipelines/stable_diffusion/__init__.py +1 -72
  98. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +67 -75
  99. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +92 -8
  100. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -8
  101. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +138 -10
  102. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +57 -7
  103. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +3 -0
  104. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +6 -0
  105. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -0
  106. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -0
  107. diffusers/pipelines/stable_diffusion_attend_and_excite/__init__.py +48 -0
  108. diffusers/pipelines/{stable_diffusion → stable_diffusion_attend_and_excite}/pipeline_stable_diffusion_attend_and_excite.py +5 -2
  109. diffusers/pipelines/stable_diffusion_diffedit/__init__.py +48 -0
  110. diffusers/pipelines/{stable_diffusion → stable_diffusion_diffedit}/pipeline_stable_diffusion_diffedit.py +2 -3
  111. diffusers/pipelines/stable_diffusion_gligen/__init__.py +50 -0
  112. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py +2 -2
  113. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen_text_image.py +3 -3
  114. diffusers/pipelines/stable_diffusion_k_diffusion/__init__.py +60 -0
  115. diffusers/pipelines/{stable_diffusion → stable_diffusion_k_diffusion}/pipeline_stable_diffusion_k_diffusion.py +6 -1
  116. diffusers/pipelines/stable_diffusion_ldm3d/__init__.py +48 -0
  117. diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py +50 -7
  118. diffusers/pipelines/stable_diffusion_panorama/__init__.py +48 -0
  119. diffusers/pipelines/{stable_diffusion → stable_diffusion_panorama}/pipeline_stable_diffusion_panorama.py +56 -8
  120. diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +58 -6
  121. diffusers/pipelines/stable_diffusion_sag/__init__.py +48 -0
  122. diffusers/pipelines/{stable_diffusion → stable_diffusion_sag}/pipeline_stable_diffusion_sag.py +67 -10
  123. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +97 -15
  124. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +98 -14
  125. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +97 -14
  126. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +7 -5
  127. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +12 -9
  128. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +6 -0
  129. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +5 -0
  130. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +5 -0
  131. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +331 -9
  132. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +468 -9
  133. diffusers/pipelines/unclip/pipeline_unclip.py +2 -1
  134. diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -0
  135. diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
  136. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +4 -0
  137. diffusers/schedulers/__init__.py +2 -0
  138. diffusers/schedulers/scheduling_amused.py +162 -0
  139. diffusers/schedulers/scheduling_consistency_models.py +2 -0
  140. diffusers/schedulers/scheduling_ddim_inverse.py +1 -4
  141. diffusers/schedulers/scheduling_ddpm.py +46 -0
  142. diffusers/schedulers/scheduling_ddpm_parallel.py +46 -0
  143. diffusers/schedulers/scheduling_deis_multistep.py +13 -1
  144. diffusers/schedulers/scheduling_dpmsolver_multistep.py +13 -1
  145. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +13 -1
  146. diffusers/schedulers/scheduling_dpmsolver_sde.py +2 -0
  147. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +13 -1
  148. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +58 -0
  149. diffusers/schedulers/scheduling_euler_discrete.py +62 -3
  150. diffusers/schedulers/scheduling_heun_discrete.py +2 -0
  151. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +2 -0
  152. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +2 -0
  153. diffusers/schedulers/scheduling_lms_discrete.py +2 -0
  154. diffusers/schedulers/scheduling_unipc_multistep.py +13 -1
  155. diffusers/schedulers/scheduling_utils.py +3 -1
  156. diffusers/schedulers/scheduling_utils_flax.py +3 -1
  157. diffusers/training_utils.py +1 -1
  158. diffusers/utils/__init__.py +0 -2
  159. diffusers/utils/constants.py +2 -5
  160. diffusers/utils/dummy_pt_objects.py +30 -0
  161. diffusers/utils/dummy_torch_and_transformers_objects.py +45 -0
  162. diffusers/utils/dynamic_modules_utils.py +14 -18
  163. diffusers/utils/hub_utils.py +24 -36
  164. diffusers/utils/logging.py +1 -1
  165. diffusers/utils/state_dict_utils.py +8 -0
  166. diffusers/utils/testing_utils.py +199 -1
  167. diffusers/utils/torch_utils.py +3 -3
  168. {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/METADATA +55 -53
  169. {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/RECORD +174 -155
  170. {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/WHEEL +1 -1
  171. {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/entry_points.txt +0 -1
  172. /diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/modeling_roberta_series.py +0 -0
  173. {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/LICENSE +0 -0
  174. {diffusers-0.24.0.dist-info → diffusers-0.25.1.dist-info}/top_level.txt +0 -0
@@ -92,6 +92,43 @@ def betas_for_alpha_bar(
92
92
  return torch.tensor(betas, dtype=torch.float32)
93
93
 
94
94
 
95
+ # Copied from diffusers.schedulers.scheduling_ddim.rescale_zero_terminal_snr
96
+ def rescale_zero_terminal_snr(betas):
97
+ """
98
+ Rescales betas to have zero terminal SNR Based on https://arxiv.org/pdf/2305.08891.pdf (Algorithm 1)
99
+
100
+
101
+ Args:
102
+ betas (`torch.FloatTensor`):
103
+ the betas that the scheduler is being initialized with.
104
+
105
+ Returns:
106
+ `torch.FloatTensor`: rescaled betas with zero terminal SNR
107
+ """
108
+ # Convert betas to alphas_bar_sqrt
109
+ alphas = 1.0 - betas
110
+ alphas_cumprod = torch.cumprod(alphas, dim=0)
111
+ alphas_bar_sqrt = alphas_cumprod.sqrt()
112
+
113
+ # Store old values.
114
+ alphas_bar_sqrt_0 = alphas_bar_sqrt[0].clone()
115
+ alphas_bar_sqrt_T = alphas_bar_sqrt[-1].clone()
116
+
117
+ # Shift so the last timestep is zero.
118
+ alphas_bar_sqrt -= alphas_bar_sqrt_T
119
+
120
+ # Scale so the first timestep is back to the old value.
121
+ alphas_bar_sqrt *= alphas_bar_sqrt_0 / (alphas_bar_sqrt_0 - alphas_bar_sqrt_T)
122
+
123
+ # Convert alphas_bar_sqrt to betas
124
+ alphas_bar = alphas_bar_sqrt**2 # Revert sqrt
125
+ alphas = alphas_bar[1:] / alphas_bar[:-1] # Revert cumprod
126
+ alphas = torch.cat([alphas_bar[0:1], alphas])
127
+ betas = 1 - alphas
128
+
129
+ return betas
130
+
131
+
95
132
  class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
96
133
  """
97
134
  Euler scheduler.
@@ -128,6 +165,10 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
128
165
  An offset added to the inference steps. You can use a combination of `offset=1` and
129
166
  `set_alpha_to_one=False` to make the last step use step 0 for the previous alpha product like in Stable
130
167
  Diffusion.
168
+ rescale_betas_zero_snr (`bool`, defaults to `False`):
169
+ Whether to rescale the betas to have zero terminal SNR. This enables the model to generate very bright and
170
+ dark samples instead of limiting it to samples with medium brightness. Loosely related to
171
+ [`--offset_noise`](https://github.com/huggingface/diffusers/blob/74fd735eb073eb1d774b1ab4154a0876eb82f055/examples/dreambooth/train_dreambooth.py#L506).
131
172
  """
132
173
 
133
174
  _compatibles = [e.name for e in KarrasDiffusionSchedulers]
@@ -149,6 +190,7 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
149
190
  timestep_spacing: str = "linspace",
150
191
  timestep_type: str = "discrete", # can be "discrete" or "continuous"
151
192
  steps_offset: int = 0,
193
+ rescale_betas_zero_snr: bool = False,
152
194
  ):
153
195
  if trained_betas is not None:
154
196
  self.betas = torch.tensor(trained_betas, dtype=torch.float32)
@@ -163,9 +205,17 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
163
205
  else:
164
206
  raise NotImplementedError(f"{beta_schedule} does is not implemented for {self.__class__}")
165
207
 
208
+ if rescale_betas_zero_snr:
209
+ self.betas = rescale_zero_terminal_snr(self.betas)
210
+
166
211
  self.alphas = 1.0 - self.betas
167
212
  self.alphas_cumprod = torch.cumprod(self.alphas, dim=0)
168
213
 
214
+ if rescale_betas_zero_snr:
215
+ # Close to 0 without being 0 so first sigma is not inf
216
+ # FP16 smallest positive subnormal works well here
217
+ self.alphas_cumprod[-1] = 2**-24
218
+
169
219
  sigmas = np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5)
170
220
  timesteps = np.linspace(0, num_train_timesteps - 1, num_train_timesteps, dtype=float)[::-1].copy()
171
221
 
@@ -187,14 +237,16 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
187
237
  self.use_karras_sigmas = use_karras_sigmas
188
238
 
189
239
  self._step_index = None
240
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
190
241
 
191
242
  @property
192
243
  def init_noise_sigma(self):
193
244
  # standard deviation of the initial noise distribution
245
+ max_sigma = max(self.sigmas) if isinstance(self.sigmas, list) else self.sigmas.max()
194
246
  if self.config.timestep_spacing in ["linspace", "trailing"]:
195
- return self.sigmas.max()
247
+ return max_sigma
196
248
 
197
- return (self.sigmas.max() ** 2 + 1) ** 0.5
249
+ return (max_sigma**2 + 1) ** 0.5
198
250
 
199
251
  @property
200
252
  def step_index(self):
@@ -269,7 +321,7 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
269
321
  if self.config.interpolation_type == "linear":
270
322
  sigmas = np.interp(timesteps, np.arange(0, len(sigmas)), sigmas)
271
323
  elif self.config.interpolation_type == "log_linear":
272
- sigmas = torch.linspace(np.log(sigmas[-1]), np.log(sigmas[0]), num_inference_steps + 1).exp()
324
+ sigmas = torch.linspace(np.log(sigmas[-1]), np.log(sigmas[0]), num_inference_steps + 1).exp().numpy()
273
325
  else:
274
326
  raise ValueError(
275
327
  f"{self.config.interpolation_type} is not implemented. Please specify interpolation_type to either"
@@ -290,6 +342,7 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
290
342
 
291
343
  self.sigmas = torch.cat([sigmas, torch.zeros(1, device=sigmas.device)])
292
344
  self._step_index = None
345
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
293
346
 
294
347
  def _sigma_to_t(self, sigma, log_sigmas):
295
348
  # get log sigma
@@ -419,6 +472,9 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
419
472
  if self.step_index is None:
420
473
  self._init_step_index(timestep)
421
474
 
475
+ # Upcast to avoid precision issues when computing prev_sample
476
+ sample = sample.to(torch.float32)
477
+
422
478
  sigma = self.sigmas[self.step_index]
423
479
 
424
480
  gamma = min(s_churn / (len(self.sigmas) - 1), 2**0.5 - 1) if s_tmin <= sigma <= s_tmax else 0.0
@@ -455,6 +511,9 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
455
511
 
456
512
  prev_sample = sample + derivative * dt
457
513
 
514
+ # Cast sample back to model compatible dtype
515
+ prev_sample = prev_sample.to(model_output.dtype)
516
+
458
517
  # upon completion increase step index by one
459
518
  self._step_index += 1
460
519
 
@@ -148,6 +148,7 @@ class HeunDiscreteScheduler(SchedulerMixin, ConfigMixin):
148
148
  self.use_karras_sigmas = use_karras_sigmas
149
149
 
150
150
  self._step_index = None
151
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
151
152
 
152
153
  def index_for_timestep(self, timestep, schedule_timesteps=None):
153
154
  if schedule_timesteps is None:
@@ -269,6 +270,7 @@ class HeunDiscreteScheduler(SchedulerMixin, ConfigMixin):
269
270
  self.dt = None
270
271
 
271
272
  self._step_index = None
273
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
272
274
 
273
275
  # (YiYi Notes: keep this for now since we are keeping add_noise function which use index_for_timestep)
274
276
  # for exp beta schedules, such as the one for `pipeline_shap_e.py`
@@ -140,6 +140,7 @@ class KDPM2AncestralDiscreteScheduler(SchedulerMixin, ConfigMixin):
140
140
  # set all values
141
141
  self.set_timesteps(num_train_timesteps, None, num_train_timesteps)
142
142
  self._step_index = None
143
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
143
144
 
144
145
  # Copied from diffusers.schedulers.scheduling_heun_discrete.HeunDiscreteScheduler.index_for_timestep
145
146
  def index_for_timestep(self, timestep, schedule_timesteps=None):
@@ -295,6 +296,7 @@ class KDPM2AncestralDiscreteScheduler(SchedulerMixin, ConfigMixin):
295
296
  self._index_counter = defaultdict(int)
296
297
 
297
298
  self._step_index = None
299
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
298
300
 
299
301
  # Copied from diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler._sigma_to_t
300
302
  def _sigma_to_t(self, sigma, log_sigmas):
@@ -140,6 +140,7 @@ class KDPM2DiscreteScheduler(SchedulerMixin, ConfigMixin):
140
140
  self.set_timesteps(num_train_timesteps, None, num_train_timesteps)
141
141
 
142
142
  self._step_index = None
143
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
143
144
 
144
145
  # Copied from diffusers.schedulers.scheduling_heun_discrete.HeunDiscreteScheduler.index_for_timestep
145
146
  def index_for_timestep(self, timestep, schedule_timesteps=None):
@@ -284,6 +285,7 @@ class KDPM2DiscreteScheduler(SchedulerMixin, ConfigMixin):
284
285
  self._index_counter = defaultdict(int)
285
286
 
286
287
  self._step_index = None
288
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
287
289
 
288
290
  @property
289
291
  def state_in_first_order(self):
@@ -168,6 +168,7 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin):
168
168
  self.is_scale_input_called = False
169
169
 
170
170
  self._step_index = None
171
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
171
172
 
172
173
  @property
173
174
  def init_noise_sigma(self):
@@ -279,6 +280,7 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin):
279
280
  self.sigmas = torch.from_numpy(sigmas).to(device=device)
280
281
  self.timesteps = torch.from_numpy(timesteps).to(device=device)
281
282
  self._step_index = None
283
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
282
284
 
283
285
  self.derivatives = []
284
286
 
@@ -175,6 +175,7 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
175
175
  self.alpha_t = torch.sqrt(self.alphas_cumprod)
176
176
  self.sigma_t = torch.sqrt(1 - self.alphas_cumprod)
177
177
  self.lambda_t = torch.log(self.alpha_t) - torch.log(self.sigma_t)
178
+ self.sigmas = ((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5
178
179
 
179
180
  # standard deviation of the initial noise distribution
180
181
  self.init_noise_sigma = 1.0
@@ -197,6 +198,7 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
197
198
  self.solver_p = solver_p
198
199
  self.last_sample = None
199
200
  self._step_index = None
201
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
200
202
 
201
203
  @property
202
204
  def step_index(self):
@@ -267,6 +269,7 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
267
269
 
268
270
  # add an index counter for schedulers that allow duplicated timesteps
269
271
  self._step_index = None
272
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
270
273
 
271
274
  # Copied from diffusers.schedulers.scheduling_ddpm.DDPMScheduler._threshold_sample
272
275
  def _threshold_sample(self, sample: torch.FloatTensor) -> torch.FloatTensor:
@@ -827,7 +830,16 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
827
830
  schedule_timesteps = self.timesteps.to(original_samples.device)
828
831
  timesteps = timesteps.to(original_samples.device)
829
832
 
830
- step_indices = [(schedule_timesteps == t).nonzero().item() for t in timesteps]
833
+ step_indices = []
834
+ for timestep in timesteps:
835
+ index_candidates = (schedule_timesteps == timestep).nonzero()
836
+ if len(index_candidates) == 0:
837
+ step_index = len(schedule_timesteps) - 1
838
+ elif len(index_candidates) > 1:
839
+ step_index = index_candidates[1].item()
840
+ else:
841
+ step_index = index_candidates[0].item()
842
+ step_indices.append(step_index)
831
843
 
832
844
  sigma = sigmas[step_indices].flatten()
833
845
  while len(sigma.shape) < len(original_samples.shape):
@@ -18,6 +18,7 @@ from enum import Enum
18
18
  from typing import Optional, Union
19
19
 
20
20
  import torch
21
+ from huggingface_hub.utils import validate_hf_hub_args
21
22
 
22
23
  from ..utils import BaseOutput, PushToHubMixin
23
24
 
@@ -81,6 +82,7 @@ class SchedulerMixin(PushToHubMixin):
81
82
  has_compatibles = True
82
83
 
83
84
  @classmethod
85
+ @validate_hf_hub_args
84
86
  def from_pretrained(
85
87
  cls,
86
88
  pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
@@ -120,7 +122,7 @@ class SchedulerMixin(PushToHubMixin):
120
122
  local_files_only(`bool`, *optional*, defaults to `False`):
121
123
  Whether to only load local model weights and configuration files or not. If set to `True`, the model
122
124
  won't be downloaded from the Hub.
123
- use_auth_token (`str` or *bool*, *optional*):
125
+ token (`str` or *bool*, *optional*):
124
126
  The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
125
127
  `diffusers-cli login` (stored in `~/.huggingface`) is used.
126
128
  revision (`str`, *optional*, defaults to `"main"`):
@@ -20,6 +20,7 @@ from typing import Optional, Tuple, Union
20
20
 
21
21
  import flax
22
22
  import jax.numpy as jnp
23
+ from huggingface_hub.utils import validate_hf_hub_args
23
24
 
24
25
  from ..utils import BaseOutput, PushToHubMixin
25
26
 
@@ -70,6 +71,7 @@ class FlaxSchedulerMixin(PushToHubMixin):
70
71
  has_compatibles = True
71
72
 
72
73
  @classmethod
74
+ @validate_hf_hub_args
73
75
  def from_pretrained(
74
76
  cls,
75
77
  pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
@@ -110,7 +112,7 @@ class FlaxSchedulerMixin(PushToHubMixin):
110
112
  Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
111
113
  local_files_only(`bool`, *optional*, defaults to `False`):
112
114
  Whether or not to only look at local files (i.e., do not try to download the model).
113
- use_auth_token (`str` or *bool*, *optional*):
115
+ token (`str` or *bool*, *optional*):
114
116
  The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
115
117
  when running `transformers-cli login` (stored in `~/.huggingface`).
116
118
  revision (`str`, *optional*, defaults to `"main"`):
@@ -67,7 +67,7 @@ def unet_lora_state_dict(unet: UNet2DConditionModel) -> Dict[str, torch.Tensor]:
67
67
  current_lora_layer_sd = lora_layer.state_dict()
68
68
  for lora_layer_matrix_name, lora_param in current_lora_layer_sd.items():
69
69
  # The matrix name can either be "down" or "up".
70
- lora_state_dict[f"unet.{name}.lora.{lora_layer_matrix_name}"] = lora_param
70
+ lora_state_dict[f"{name}.lora.{lora_layer_matrix_name}"] = lora_param
71
71
 
72
72
  return lora_state_dict
73
73
 
@@ -21,7 +21,6 @@ from .. import __version__
21
21
  from .constants import (
22
22
  CONFIG_NAME,
23
23
  DEPRECATED_REVISION_ARGS,
24
- DIFFUSERS_CACHE,
25
24
  DIFFUSERS_DYNAMIC_MODULE_NAME,
26
25
  FLAX_WEIGHTS_NAME,
27
26
  HF_MODULES_CACHE,
@@ -38,7 +37,6 @@ from .doc_utils import replace_example_docstring
38
37
  from .dynamic_modules_utils import get_class_from_dynamic_module
39
38
  from .export_utils import export_to_gif, export_to_obj, export_to_ply, export_to_video
40
39
  from .hub_utils import (
41
- HF_HUB_OFFLINE,
42
40
  PushToHubMixin,
43
41
  _add_variant,
44
42
  _get_model_file,
@@ -14,15 +14,13 @@
14
14
  import importlib
15
15
  import os
16
16
 
17
- from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE, hf_cache_home
17
+ from huggingface_hub.constants import HF_HOME
18
18
  from packaging import version
19
19
 
20
20
  from ..dependency_versions_check import dep_version_check
21
21
  from .import_utils import ENV_VARS_TRUE_VALUES, is_peft_available, is_transformers_available
22
22
 
23
23
 
24
- default_cache_path = HUGGINGFACE_HUB_CACHE
25
-
26
24
  MIN_PEFT_VERSION = "0.6.0"
27
25
  MIN_TRANSFORMERS_VERSION = "4.34.0"
28
26
  _CHECK_PEFT = os.environ.get("_CHECK_PEFT", "1") in ENV_VARS_TRUE_VALUES
@@ -35,9 +33,8 @@ ONNX_WEIGHTS_NAME = "model.onnx"
35
33
  SAFETENSORS_WEIGHTS_NAME = "diffusion_pytorch_model.safetensors"
36
34
  ONNX_EXTERNAL_WEIGHTS_NAME = "weights.pb"
37
35
  HUGGINGFACE_CO_RESOLVE_ENDPOINT = os.environ.get("HF_ENDPOINT", "https://huggingface.co")
38
- DIFFUSERS_CACHE = default_cache_path
39
36
  DIFFUSERS_DYNAMIC_MODULE_NAME = "diffusers_modules"
40
- HF_MODULES_CACHE = os.getenv("HF_MODULES_CACHE", os.path.join(hf_cache_home, "modules"))
37
+ HF_MODULES_CACHE = os.getenv("HF_MODULES_CACHE", os.path.join(HF_HOME, "modules"))
41
38
  DEPRECATED_REVISION_ARGS = ["fp16", "non-ema"]
42
39
 
43
40
  # Below should be `True` if the current version of `peft` and `transformers` are compatible with
@@ -302,6 +302,21 @@ class UNetSpatioTemporalConditionModel(metaclass=DummyObject):
302
302
  requires_backends(cls, ["torch"])
303
303
 
304
304
 
305
+ class UVit2DModel(metaclass=DummyObject):
306
+ _backends = ["torch"]
307
+
308
+ def __init__(self, *args, **kwargs):
309
+ requires_backends(self, ["torch"])
310
+
311
+ @classmethod
312
+ def from_config(cls, *args, **kwargs):
313
+ requires_backends(cls, ["torch"])
314
+
315
+ @classmethod
316
+ def from_pretrained(cls, *args, **kwargs):
317
+ requires_backends(cls, ["torch"])
318
+
319
+
305
320
  class VQModel(metaclass=DummyObject):
306
321
  _backends = ["torch"]
307
322
 
@@ -645,6 +660,21 @@ class ScoreSdeVePipeline(metaclass=DummyObject):
645
660
  requires_backends(cls, ["torch"])
646
661
 
647
662
 
663
+ class AmusedScheduler(metaclass=DummyObject):
664
+ _backends = ["torch"]
665
+
666
+ def __init__(self, *args, **kwargs):
667
+ requires_backends(self, ["torch"])
668
+
669
+ @classmethod
670
+ def from_config(cls, *args, **kwargs):
671
+ requires_backends(cls, ["torch"])
672
+
673
+ @classmethod
674
+ def from_pretrained(cls, *args, **kwargs):
675
+ requires_backends(cls, ["torch"])
676
+
677
+
648
678
  class CMStochasticIterativeScheduler(metaclass=DummyObject):
649
679
  _backends = ["torch"]
650
680
 
@@ -32,6 +32,51 @@ class AltDiffusionPipeline(metaclass=DummyObject):
32
32
  requires_backends(cls, ["torch", "transformers"])
33
33
 
34
34
 
35
+ class AmusedImg2ImgPipeline(metaclass=DummyObject):
36
+ _backends = ["torch", "transformers"]
37
+
38
+ def __init__(self, *args, **kwargs):
39
+ requires_backends(self, ["torch", "transformers"])
40
+
41
+ @classmethod
42
+ def from_config(cls, *args, **kwargs):
43
+ requires_backends(cls, ["torch", "transformers"])
44
+
45
+ @classmethod
46
+ def from_pretrained(cls, *args, **kwargs):
47
+ requires_backends(cls, ["torch", "transformers"])
48
+
49
+
50
+ class AmusedInpaintPipeline(metaclass=DummyObject):
51
+ _backends = ["torch", "transformers"]
52
+
53
+ def __init__(self, *args, **kwargs):
54
+ requires_backends(self, ["torch", "transformers"])
55
+
56
+ @classmethod
57
+ def from_config(cls, *args, **kwargs):
58
+ requires_backends(cls, ["torch", "transformers"])
59
+
60
+ @classmethod
61
+ def from_pretrained(cls, *args, **kwargs):
62
+ requires_backends(cls, ["torch", "transformers"])
63
+
64
+
65
+ class AmusedPipeline(metaclass=DummyObject):
66
+ _backends = ["torch", "transformers"]
67
+
68
+ def __init__(self, *args, **kwargs):
69
+ requires_backends(self, ["torch", "transformers"])
70
+
71
+ @classmethod
72
+ def from_config(cls, *args, **kwargs):
73
+ requires_backends(cls, ["torch", "transformers"])
74
+
75
+ @classmethod
76
+ def from_pretrained(cls, *args, **kwargs):
77
+ requires_backends(cls, ["torch", "transformers"])
78
+
79
+
35
80
  class AnimateDiffPipeline(metaclass=DummyObject):
36
81
  _backends = ["torch", "transformers"]
37
82
 
@@ -25,7 +25,8 @@ from pathlib import Path
25
25
  from typing import Dict, Optional, Union
26
26
  from urllib import request
27
27
 
28
- from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
28
+ from huggingface_hub import cached_download, hf_hub_download, model_info
29
+ from huggingface_hub.utils import validate_hf_hub_args
29
30
  from packaging import version
30
31
 
31
32
  from .. import __version__
@@ -194,6 +195,7 @@ def find_pipeline_class(loaded_module):
194
195
  return pipeline_class
195
196
 
196
197
 
198
+ @validate_hf_hub_args
197
199
  def get_cached_module_file(
198
200
  pretrained_model_name_or_path: Union[str, os.PathLike],
199
201
  module_file: str,
@@ -201,7 +203,7 @@ def get_cached_module_file(
201
203
  force_download: bool = False,
202
204
  resume_download: bool = False,
203
205
  proxies: Optional[Dict[str, str]] = None,
204
- use_auth_token: Optional[Union[bool, str]] = None,
206
+ token: Optional[Union[bool, str]] = None,
205
207
  revision: Optional[str] = None,
206
208
  local_files_only: bool = False,
207
209
  ):
@@ -232,7 +234,7 @@ def get_cached_module_file(
232
234
  proxies (`Dict[str, str]`, *optional*):
233
235
  A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
234
236
  'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
235
- use_auth_token (`str` or *bool*, *optional*):
237
+ token (`str` or *bool*, *optional*):
236
238
  The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
237
239
  when running `transformers-cli login` (stored in `~/.huggingface`).
238
240
  revision (`str`, *optional*, defaults to `"main"`):
@@ -244,7 +246,7 @@ def get_cached_module_file(
244
246
 
245
247
  <Tip>
246
248
 
247
- You may pass a token in `use_auth_token` if you are not logged in (`huggingface-cli long`) and want to use private
249
+ You may pass a token in `token` if you are not logged in (`huggingface-cli login`) and want to use private
248
250
  or [gated models](https://huggingface.co/docs/hub/models-gated#gated-models).
249
251
 
250
252
  </Tip>
@@ -289,7 +291,7 @@ def get_cached_module_file(
289
291
  proxies=proxies,
290
292
  resume_download=resume_download,
291
293
  local_files_only=local_files_only,
292
- use_auth_token=False,
294
+ token=False,
293
295
  )
294
296
  submodule = "git"
295
297
  module_file = pretrained_model_name_or_path + ".py"
@@ -307,7 +309,7 @@ def get_cached_module_file(
307
309
  proxies=proxies,
308
310
  resume_download=resume_download,
309
311
  local_files_only=local_files_only,
310
- use_auth_token=use_auth_token,
312
+ token=token,
311
313
  )
312
314
  submodule = os.path.join("local", "--".join(pretrained_model_name_or_path.split("/")))
313
315
  except EnvironmentError:
@@ -332,13 +334,6 @@ def get_cached_module_file(
332
334
  else:
333
335
  # Get the commit hash
334
336
  # TODO: we will get this info in the etag soon, so retrieve it from there and not here.
335
- if isinstance(use_auth_token, str):
336
- token = use_auth_token
337
- elif use_auth_token is True:
338
- token = HfFolder.get_token()
339
- else:
340
- token = None
341
-
342
337
  commit_hash = model_info(pretrained_model_name_or_path, revision=revision, token=token).sha
343
338
 
344
339
  # The module file will end up being placed in a subfolder with the git hash of the repo. This way we get the
@@ -359,13 +354,14 @@ def get_cached_module_file(
359
354
  force_download=force_download,
360
355
  resume_download=resume_download,
361
356
  proxies=proxies,
362
- use_auth_token=use_auth_token,
357
+ token=token,
363
358
  revision=revision,
364
359
  local_files_only=local_files_only,
365
360
  )
366
361
  return os.path.join(full_submodule, module_file)
367
362
 
368
363
 
364
+ @validate_hf_hub_args
369
365
  def get_class_from_dynamic_module(
370
366
  pretrained_model_name_or_path: Union[str, os.PathLike],
371
367
  module_file: str,
@@ -374,7 +370,7 @@ def get_class_from_dynamic_module(
374
370
  force_download: bool = False,
375
371
  resume_download: bool = False,
376
372
  proxies: Optional[Dict[str, str]] = None,
377
- use_auth_token: Optional[Union[bool, str]] = None,
373
+ token: Optional[Union[bool, str]] = None,
378
374
  revision: Optional[str] = None,
379
375
  local_files_only: bool = False,
380
376
  **kwargs,
@@ -414,7 +410,7 @@ def get_class_from_dynamic_module(
414
410
  proxies (`Dict[str, str]`, *optional*):
415
411
  A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
416
412
  'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
417
- use_auth_token (`str` or `bool`, *optional*):
413
+ token (`str` or `bool`, *optional*):
418
414
  The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
419
415
  when running `transformers-cli login` (stored in `~/.huggingface`).
420
416
  revision (`str`, *optional*, defaults to `"main"`):
@@ -426,7 +422,7 @@ def get_class_from_dynamic_module(
426
422
 
427
423
  <Tip>
428
424
 
429
- You may pass a token in `use_auth_token` if you are not logged in (`huggingface-cli long`) and want to use private
425
+ You may pass a token in `token` if you are not logged in (`huggingface-cli login`) and want to use private
430
426
  or [gated models](https://huggingface.co/docs/hub/models-gated#gated-models).
431
427
 
432
428
  </Tip>
@@ -449,7 +445,7 @@ def get_class_from_dynamic_module(
449
445
  force_download=force_download,
450
446
  resume_download=resume_download,
451
447
  proxies=proxies,
452
- use_auth_token=use_auth_token,
448
+ token=token,
453
449
  revision=revision,
454
450
  local_files_only=local_files_only,
455
451
  )