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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. diffusers/__init__.py +26 -2
  2. diffusers/commands/fp16_safetensors.py +10 -11
  3. diffusers/configuration_utils.py +13 -8
  4. diffusers/dependency_versions_check.py +0 -1
  5. diffusers/dependency_versions_table.py +5 -5
  6. diffusers/experimental/rl/value_guided_sampling.py +1 -1
  7. diffusers/image_processor.py +463 -51
  8. diffusers/loaders/__init__.py +82 -0
  9. diffusers/loaders/ip_adapter.py +159 -0
  10. diffusers/loaders/lora.py +1553 -0
  11. diffusers/loaders/lora_conversion_utils.py +284 -0
  12. diffusers/loaders/single_file.py +637 -0
  13. diffusers/loaders/textual_inversion.py +455 -0
  14. diffusers/loaders/unet.py +828 -0
  15. diffusers/loaders/utils.py +59 -0
  16. diffusers/models/__init__.py +26 -9
  17. diffusers/models/activations.py +9 -6
  18. diffusers/models/attention.py +301 -29
  19. diffusers/models/attention_flax.py +9 -1
  20. diffusers/models/attention_processor.py +378 -6
  21. diffusers/models/autoencoders/__init__.py +5 -0
  22. diffusers/models/{autoencoder_asym_kl.py → autoencoders/autoencoder_asym_kl.py} +17 -12
  23. diffusers/models/{autoencoder_kl.py → autoencoders/autoencoder_kl.py} +47 -23
  24. diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +402 -0
  25. diffusers/models/{autoencoder_tiny.py → autoencoders/autoencoder_tiny.py} +24 -28
  26. diffusers/models/{consistency_decoder_vae.py → autoencoders/consistency_decoder_vae.py} +51 -44
  27. diffusers/models/{vae.py → autoencoders/vae.py} +71 -17
  28. diffusers/models/controlnet.py +59 -39
  29. diffusers/models/controlnet_flax.py +19 -18
  30. diffusers/models/downsampling.py +338 -0
  31. diffusers/models/embeddings.py +112 -29
  32. diffusers/models/embeddings_flax.py +2 -0
  33. diffusers/models/lora.py +131 -1
  34. diffusers/models/modeling_flax_utils.py +14 -8
  35. diffusers/models/modeling_outputs.py +17 -0
  36. diffusers/models/modeling_utils.py +37 -29
  37. diffusers/models/normalization.py +110 -4
  38. diffusers/models/resnet.py +299 -652
  39. diffusers/models/transformer_2d.py +22 -5
  40. diffusers/models/transformer_temporal.py +183 -1
  41. diffusers/models/unet_2d_blocks_flax.py +5 -0
  42. diffusers/models/unet_2d_condition.py +46 -0
  43. diffusers/models/unet_2d_condition_flax.py +13 -13
  44. diffusers/models/unet_3d_blocks.py +957 -173
  45. diffusers/models/unet_3d_condition.py +16 -8
  46. diffusers/models/unet_kandinsky3.py +535 -0
  47. diffusers/models/unet_motion_model.py +48 -33
  48. diffusers/models/unet_spatio_temporal_condition.py +489 -0
  49. diffusers/models/upsampling.py +454 -0
  50. diffusers/models/uvit_2d.py +471 -0
  51. diffusers/models/vae_flax.py +7 -0
  52. diffusers/models/vq_model.py +12 -3
  53. diffusers/optimization.py +16 -9
  54. diffusers/pipelines/__init__.py +137 -76
  55. diffusers/pipelines/amused/__init__.py +62 -0
  56. diffusers/pipelines/amused/pipeline_amused.py +328 -0
  57. diffusers/pipelines/amused/pipeline_amused_img2img.py +347 -0
  58. diffusers/pipelines/amused/pipeline_amused_inpaint.py +378 -0
  59. diffusers/pipelines/animatediff/pipeline_animatediff.py +66 -8
  60. diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
  61. diffusers/pipelines/auto_pipeline.py +23 -13
  62. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
  63. diffusers/pipelines/controlnet/pipeline_controlnet.py +238 -35
  64. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +148 -37
  65. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +155 -41
  66. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +123 -43
  67. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +216 -39
  68. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +106 -34
  69. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
  70. diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
  71. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
  72. diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
  73. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
  74. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
  75. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
  76. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
  77. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
  78. diffusers/pipelines/deprecated/__init__.py +153 -0
  79. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/__init__.py +3 -3
  80. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion.py +177 -34
  81. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_alt_diffusion_img2img.py +182 -37
  82. diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/pipeline_output.py +1 -1
  83. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/__init__.py +1 -1
  84. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/mel.py +2 -2
  85. diffusers/pipelines/{audio_diffusion → deprecated/audio_diffusion}/pipeline_audio_diffusion.py +4 -4
  86. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/__init__.py +1 -1
  87. diffusers/pipelines/{latent_diffusion_uncond → deprecated/latent_diffusion_uncond}/pipeline_latent_diffusion_uncond.py +4 -4
  88. diffusers/pipelines/{pndm → deprecated/pndm}/__init__.py +1 -1
  89. diffusers/pipelines/{pndm → deprecated/pndm}/pipeline_pndm.py +4 -4
  90. diffusers/pipelines/{repaint → deprecated/repaint}/__init__.py +1 -1
  91. diffusers/pipelines/{repaint → deprecated/repaint}/pipeline_repaint.py +5 -5
  92. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/__init__.py +1 -1
  93. diffusers/pipelines/{score_sde_ve → deprecated/score_sde_ve}/pipeline_score_sde_ve.py +5 -4
  94. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/__init__.py +6 -6
  95. diffusers/pipelines/{spectrogram_diffusion/continous_encoder.py → deprecated/spectrogram_diffusion/continuous_encoder.py} +2 -2
  96. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/midi_utils.py +1 -1
  97. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/notes_encoder.py +2 -2
  98. diffusers/pipelines/{spectrogram_diffusion → deprecated/spectrogram_diffusion}/pipeline_spectrogram_diffusion.py +8 -7
  99. diffusers/pipelines/deprecated/stable_diffusion_variants/__init__.py +55 -0
  100. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_cycle_diffusion.py +34 -13
  101. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_onnx_stable_diffusion_inpaint_legacy.py +7 -6
  102. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_inpaint_legacy.py +12 -11
  103. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_model_editing.py +17 -11
  104. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_paradigms.py +11 -10
  105. diffusers/pipelines/{stable_diffusion → deprecated/stable_diffusion_variants}/pipeline_stable_diffusion_pix2pix_zero.py +14 -13
  106. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/__init__.py +1 -1
  107. diffusers/pipelines/{stochastic_karras_ve → deprecated/stochastic_karras_ve}/pipeline_stochastic_karras_ve.py +4 -4
  108. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/__init__.py +3 -3
  109. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/modeling_text_unet.py +83 -51
  110. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion.py +4 -4
  111. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_dual_guided.py +7 -6
  112. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_image_variation.py +7 -6
  113. diffusers/pipelines/{versatile_diffusion → deprecated/versatile_diffusion}/pipeline_versatile_diffusion_text_to_image.py +7 -6
  114. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/__init__.py +3 -3
  115. diffusers/pipelines/{vq_diffusion → deprecated/vq_diffusion}/pipeline_vq_diffusion.py +5 -5
  116. diffusers/pipelines/dit/pipeline_dit.py +1 -0
  117. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
  118. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
  119. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  120. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
  121. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
  122. diffusers/pipelines/kandinsky3/__init__.py +49 -0
  123. diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +98 -0
  124. diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +589 -0
  125. diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +654 -0
  126. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +111 -11
  127. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +102 -9
  128. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
  129. diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
  130. diffusers/pipelines/onnx_utils.py +8 -5
  131. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
  132. diffusers/pipelines/pipeline_flax_utils.py +11 -8
  133. diffusers/pipelines/pipeline_utils.py +63 -42
  134. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +247 -38
  135. diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +3 -3
  136. diffusers/pipelines/stable_diffusion/__init__.py +37 -65
  137. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +75 -78
  138. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
  139. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
  140. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
  141. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +174 -11
  142. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
  143. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
  144. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +178 -11
  145. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +224 -13
  146. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +74 -20
  147. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +4 -0
  148. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +7 -0
  149. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +5 -0
  150. diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +5 -0
  151. diffusers/pipelines/stable_diffusion_attend_and_excite/__init__.py +48 -0
  152. diffusers/pipelines/{stable_diffusion → stable_diffusion_attend_and_excite}/pipeline_stable_diffusion_attend_and_excite.py +6 -2
  153. diffusers/pipelines/stable_diffusion_diffedit/__init__.py +48 -0
  154. diffusers/pipelines/{stable_diffusion → stable_diffusion_diffedit}/pipeline_stable_diffusion_diffedit.py +3 -3
  155. diffusers/pipelines/stable_diffusion_gligen/__init__.py +50 -0
  156. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen.py +3 -2
  157. diffusers/pipelines/{stable_diffusion → stable_diffusion_gligen}/pipeline_stable_diffusion_gligen_text_image.py +4 -3
  158. diffusers/pipelines/stable_diffusion_k_diffusion/__init__.py +60 -0
  159. diffusers/pipelines/{stable_diffusion → stable_diffusion_k_diffusion}/pipeline_stable_diffusion_k_diffusion.py +7 -1
  160. diffusers/pipelines/stable_diffusion_ldm3d/__init__.py +48 -0
  161. diffusers/pipelines/{stable_diffusion → stable_diffusion_ldm3d}/pipeline_stable_diffusion_ldm3d.py +51 -7
  162. diffusers/pipelines/stable_diffusion_panorama/__init__.py +48 -0
  163. diffusers/pipelines/{stable_diffusion → stable_diffusion_panorama}/pipeline_stable_diffusion_panorama.py +57 -8
  164. diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +58 -6
  165. diffusers/pipelines/stable_diffusion_sag/__init__.py +48 -0
  166. diffusers/pipelines/{stable_diffusion → stable_diffusion_sag}/pipeline_stable_diffusion_sag.py +68 -10
  167. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +194 -17
  168. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +205 -16
  169. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +206 -17
  170. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +23 -17
  171. diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
  172. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +652 -0
  173. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
  174. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +115 -14
  175. diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
  176. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +6 -0
  177. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +23 -3
  178. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +334 -10
  179. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +1331 -0
  180. diffusers/pipelines/unclip/pipeline_unclip.py +2 -1
  181. diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +1 -0
  182. diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +1 -1
  183. diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
  184. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
  185. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
  186. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
  187. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +5 -1
  188. diffusers/schedulers/__init__.py +4 -4
  189. diffusers/schedulers/deprecated/__init__.py +50 -0
  190. diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
  191. diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
  192. diffusers/schedulers/scheduling_amused.py +162 -0
  193. diffusers/schedulers/scheduling_consistency_models.py +2 -0
  194. diffusers/schedulers/scheduling_ddim.py +1 -3
  195. diffusers/schedulers/scheduling_ddim_inverse.py +2 -7
  196. diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
  197. diffusers/schedulers/scheduling_ddpm.py +47 -3
  198. diffusers/schedulers/scheduling_ddpm_parallel.py +47 -3
  199. diffusers/schedulers/scheduling_deis_multistep.py +28 -6
  200. diffusers/schedulers/scheduling_dpmsolver_multistep.py +28 -6
  201. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +28 -6
  202. diffusers/schedulers/scheduling_dpmsolver_sde.py +3 -3
  203. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +28 -6
  204. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +59 -3
  205. diffusers/schedulers/scheduling_euler_discrete.py +102 -16
  206. diffusers/schedulers/scheduling_heun_discrete.py +17 -5
  207. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +17 -5
  208. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +17 -5
  209. diffusers/schedulers/scheduling_lcm.py +123 -29
  210. diffusers/schedulers/scheduling_lms_discrete.py +3 -3
  211. diffusers/schedulers/scheduling_pndm.py +1 -3
  212. diffusers/schedulers/scheduling_repaint.py +1 -3
  213. diffusers/schedulers/scheduling_unipc_multistep.py +28 -6
  214. diffusers/schedulers/scheduling_utils.py +3 -1
  215. diffusers/schedulers/scheduling_utils_flax.py +3 -1
  216. diffusers/training_utils.py +1 -1
  217. diffusers/utils/__init__.py +1 -2
  218. diffusers/utils/constants.py +10 -12
  219. diffusers/utils/dummy_pt_objects.py +75 -0
  220. diffusers/utils/dummy_torch_and_transformers_objects.py +105 -0
  221. diffusers/utils/dynamic_modules_utils.py +18 -22
  222. diffusers/utils/export_utils.py +8 -3
  223. diffusers/utils/hub_utils.py +24 -36
  224. diffusers/utils/logging.py +11 -11
  225. diffusers/utils/outputs.py +5 -5
  226. diffusers/utils/peft_utils.py +88 -44
  227. diffusers/utils/state_dict_utils.py +8 -0
  228. diffusers/utils/testing_utils.py +199 -1
  229. diffusers/utils/torch_utils.py +4 -4
  230. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/METADATA +86 -69
  231. diffusers-0.25.0.dist-info/RECORD +360 -0
  232. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/WHEEL +1 -1
  233. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/entry_points.txt +0 -1
  234. diffusers/loaders.py +0 -3336
  235. diffusers-0.23.1.dist-info/RECORD +0 -323
  236. /diffusers/pipelines/{alt_diffusion → deprecated/alt_diffusion}/modeling_roberta_series.py +0 -0
  237. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/LICENSE +0 -0
  238. {diffusers-0.23.1.dist-info → diffusers-0.25.0.dist-info}/top_level.txt +0 -0
@@ -162,9 +162,7 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
162
162
  self.betas = torch.linspace(beta_start, beta_end, num_train_timesteps, dtype=torch.float32)
163
163
  elif beta_schedule == "scaled_linear":
164
164
  # this schedule is very specific to the latent diffusion model.
165
- self.betas = (
166
- torch.linspace(beta_start**0.5, beta_end**0.5, num_train_timesteps, dtype=torch.float32) ** 2
167
- )
165
+ self.betas = torch.linspace(beta_start**0.5, beta_end**0.5, num_train_timesteps, dtype=torch.float32) ** 2
168
166
  elif beta_schedule == "squaredcos_cap_v2":
169
167
  # Glide cosine schedule
170
168
  self.betas = betas_for_alpha_bar(num_train_timesteps)
@@ -177,6 +175,7 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
177
175
  self.alpha_t = torch.sqrt(self.alphas_cumprod)
178
176
  self.sigma_t = torch.sqrt(1 - self.alphas_cumprod)
179
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
180
179
 
181
180
  # standard deviation of the initial noise distribution
182
181
  self.init_noise_sigma = 1.0
@@ -199,6 +198,7 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
199
198
  self.solver_p = solver_p
200
199
  self.last_sample = None
201
200
  self._step_index = None
201
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
202
202
 
203
203
  @property
204
204
  def step_index(self):
@@ -269,6 +269,7 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
269
269
 
270
270
  # add an index counter for schedulers that allow duplicated timesteps
271
271
  self._step_index = None
272
+ self.sigmas.to("cpu") # to avoid too much CPU/GPU communication
272
273
 
273
274
  # Copied from diffusers.schedulers.scheduling_ddpm.DDPMScheduler._threshold_sample
274
275
  def _threshold_sample(self, sample: torch.FloatTensor) -> torch.FloatTensor:
@@ -339,8 +340,20 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
339
340
  def _convert_to_karras(self, in_sigmas: torch.FloatTensor, num_inference_steps) -> torch.FloatTensor:
340
341
  """Constructs the noise schedule of Karras et al. (2022)."""
341
342
 
342
- sigma_min: float = in_sigmas[-1].item()
343
- sigma_max: float = in_sigmas[0].item()
343
+ # Hack to make sure that other schedulers which copy this function don't break
344
+ # TODO: Add this logic to the other schedulers
345
+ if hasattr(self.config, "sigma_min"):
346
+ sigma_min = self.config.sigma_min
347
+ else:
348
+ sigma_min = None
349
+
350
+ if hasattr(self.config, "sigma_max"):
351
+ sigma_max = self.config.sigma_max
352
+ else:
353
+ sigma_max = None
354
+
355
+ sigma_min = sigma_min if sigma_min is not None else in_sigmas[-1].item()
356
+ sigma_max = sigma_max if sigma_max is not None else in_sigmas[0].item()
344
357
 
345
358
  rho = 7.0 # 7.0 is the value used in the paper
346
359
  ramp = np.linspace(0, 1, num_inference_steps)
@@ -817,7 +830,16 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
817
830
  schedule_timesteps = self.timesteps.to(original_samples.device)
818
831
  timesteps = timesteps.to(original_samples.device)
819
832
 
820
- 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)
821
843
 
822
844
  sigma = sigmas[step_indices].flatten()
823
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,
@@ -89,6 +87,7 @@ from .logging import get_logger
89
87
  from .outputs import BaseOutput
90
88
  from .peft_utils import (
91
89
  check_peft_version,
90
+ delete_adapter_layers,
92
91
  get_adapter_name,
93
92
  get_peft_kwargs,
94
93
  recurse_remove_peft_layers,
@@ -14,17 +14,16 @@
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
- from .import_utils import is_peft_available, is_transformers_available
21
20
  from ..dependency_versions_check import dep_version_check
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
- MIN_PEFT_VERSION = "0.5.0"
27
- MIN_TRANSFORMERS_VERSION = "4.33.3"
24
+ MIN_PEFT_VERSION = "0.6.0"
25
+ MIN_TRANSFORMERS_VERSION = "4.34.0"
26
+ _CHECK_PEFT = os.environ.get("_CHECK_PEFT", "1") in ENV_VARS_TRUE_VALUES
28
27
 
29
28
 
30
29
  CONFIG_NAME = "config.json"
@@ -34,23 +33,22 @@ ONNX_WEIGHTS_NAME = "model.onnx"
34
33
  SAFETENSORS_WEIGHTS_NAME = "diffusion_pytorch_model.safetensors"
35
34
  ONNX_EXTERNAL_WEIGHTS_NAME = "weights.pb"
36
35
  HUGGINGFACE_CO_RESOLVE_ENDPOINT = os.environ.get("HF_ENDPOINT", "https://huggingface.co")
37
- DIFFUSERS_CACHE = default_cache_path
38
36
  DIFFUSERS_DYNAMIC_MODULE_NAME = "diffusers_modules"
39
- 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"))
40
38
  DEPRECATED_REVISION_ARGS = ["fp16", "non-ema"]
41
39
 
42
40
  # Below should be `True` if the current version of `peft` and `transformers` are compatible with
43
41
  # PEFT backend. Will automatically fall back to PEFT backend if the correct versions of the libraries are
44
42
  # available.
45
- # For PEFT it is has to be greater than 0.6.0 and for transformers it has to be greater than 4.33.1.
43
+ # For PEFT it is has to be greater than or equal to 0.6.0 and for transformers it has to be greater than or equal to 4.34.0.
46
44
  _required_peft_version = is_peft_available() and version.parse(
47
45
  version.parse(importlib.metadata.version("peft")).base_version
48
- ) > version.parse(MIN_PEFT_VERSION)
46
+ ) >= version.parse(MIN_PEFT_VERSION)
49
47
  _required_transformers_version = is_transformers_available() and version.parse(
50
48
  version.parse(importlib.metadata.version("transformers")).base_version
51
- ) > version.parse(MIN_TRANSFORMERS_VERSION)
49
+ ) >= version.parse(MIN_TRANSFORMERS_VERSION)
52
50
 
53
51
  USE_PEFT_BACKEND = _required_peft_version and _required_transformers_version
54
52
 
55
- if USE_PEFT_BACKEND:
53
+ if USE_PEFT_BACKEND and _CHECK_PEFT:
56
54
  dep_version_check("peft")
@@ -32,6 +32,21 @@ class AutoencoderKL(metaclass=DummyObject):
32
32
  requires_backends(cls, ["torch"])
33
33
 
34
34
 
35
+ class AutoencoderKLTemporalDecoder(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 AutoencoderTiny(metaclass=DummyObject):
36
51
  _backends = ["torch"]
37
52
 
@@ -77,6 +92,21 @@ class ControlNetModel(metaclass=DummyObject):
77
92
  requires_backends(cls, ["torch"])
78
93
 
79
94
 
95
+ class Kandinsky3UNet(metaclass=DummyObject):
96
+ _backends = ["torch"]
97
+
98
+ def __init__(self, *args, **kwargs):
99
+ requires_backends(self, ["torch"])
100
+
101
+ @classmethod
102
+ def from_config(cls, *args, **kwargs):
103
+ requires_backends(cls, ["torch"])
104
+
105
+ @classmethod
106
+ def from_pretrained(cls, *args, **kwargs):
107
+ requires_backends(cls, ["torch"])
108
+
109
+
80
110
  class ModelMixin(metaclass=DummyObject):
81
111
  _backends = ["torch"]
82
112
 
@@ -257,6 +287,36 @@ class UNetMotionModel(metaclass=DummyObject):
257
287
  requires_backends(cls, ["torch"])
258
288
 
259
289
 
290
+ class UNetSpatioTemporalConditionModel(metaclass=DummyObject):
291
+ _backends = ["torch"]
292
+
293
+ def __init__(self, *args, **kwargs):
294
+ requires_backends(self, ["torch"])
295
+
296
+ @classmethod
297
+ def from_config(cls, *args, **kwargs):
298
+ requires_backends(cls, ["torch"])
299
+
300
+ @classmethod
301
+ def from_pretrained(cls, *args, **kwargs):
302
+ requires_backends(cls, ["torch"])
303
+
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
+
260
320
  class VQModel(metaclass=DummyObject):
261
321
  _backends = ["torch"]
262
322
 
@@ -600,6 +660,21 @@ class ScoreSdeVePipeline(metaclass=DummyObject):
600
660
  requires_backends(cls, ["torch"])
601
661
 
602
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
+
603
678
  class CMStochasticIterativeScheduler(metaclass=DummyObject):
604
679
  _backends = ["torch"]
605
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
 
@@ -242,6 +287,36 @@ class ImageTextPipelineOutput(metaclass=DummyObject):
242
287
  requires_backends(cls, ["torch", "transformers"])
243
288
 
244
289
 
290
+ class Kandinsky3Img2ImgPipeline(metaclass=DummyObject):
291
+ _backends = ["torch", "transformers"]
292
+
293
+ def __init__(self, *args, **kwargs):
294
+ requires_backends(self, ["torch", "transformers"])
295
+
296
+ @classmethod
297
+ def from_config(cls, *args, **kwargs):
298
+ requires_backends(cls, ["torch", "transformers"])
299
+
300
+ @classmethod
301
+ def from_pretrained(cls, *args, **kwargs):
302
+ requires_backends(cls, ["torch", "transformers"])
303
+
304
+
305
+ class Kandinsky3Pipeline(metaclass=DummyObject):
306
+ _backends = ["torch", "transformers"]
307
+
308
+ def __init__(self, *args, **kwargs):
309
+ requires_backends(self, ["torch", "transformers"])
310
+
311
+ @classmethod
312
+ def from_config(cls, *args, **kwargs):
313
+ requires_backends(cls, ["torch", "transformers"])
314
+
315
+ @classmethod
316
+ def from_pretrained(cls, *args, **kwargs):
317
+ requires_backends(cls, ["torch", "transformers"])
318
+
319
+
245
320
  class KandinskyCombinedPipeline(metaclass=DummyObject):
246
321
  _backends = ["torch", "transformers"]
247
322
 
@@ -1142,6 +1217,21 @@ class StableUnCLIPPipeline(metaclass=DummyObject):
1142
1217
  requires_backends(cls, ["torch", "transformers"])
1143
1218
 
1144
1219
 
1220
+ class StableVideoDiffusionPipeline(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
+
1145
1235
  class TextToVideoSDPipeline(metaclass=DummyObject):
1146
1236
  _backends = ["torch", "transformers"]
1147
1237
 
@@ -1172,6 +1262,21 @@ class TextToVideoZeroPipeline(metaclass=DummyObject):
1172
1262
  requires_backends(cls, ["torch", "transformers"])
1173
1263
 
1174
1264
 
1265
+ class TextToVideoZeroSDXLPipeline(metaclass=DummyObject):
1266
+ _backends = ["torch", "transformers"]
1267
+
1268
+ def __init__(self, *args, **kwargs):
1269
+ requires_backends(self, ["torch", "transformers"])
1270
+
1271
+ @classmethod
1272
+ def from_config(cls, *args, **kwargs):
1273
+ requires_backends(cls, ["torch", "transformers"])
1274
+
1275
+ @classmethod
1276
+ def from_pretrained(cls, *args, **kwargs):
1277
+ requires_backends(cls, ["torch", "transformers"])
1278
+
1279
+
1175
1280
  class UnCLIPImageVariationPipeline(metaclass=DummyObject):
1176
1281
  _backends = ["torch", "transformers"]
1177
1282
 
@@ -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__
@@ -87,9 +88,9 @@ def get_relative_imports(module_file):
87
88
  content = f.read()
88
89
 
89
90
  # Imports of the form `import .xxx`
90
- relative_imports = re.findall("^\s*import\s+\.(\S+)\s*$", content, flags=re.MULTILINE)
91
+ relative_imports = re.findall(r"^\s*import\s+\.(\S+)\s*$", content, flags=re.MULTILINE)
91
92
  # Imports of the form `from .xxx import yyy`
92
- relative_imports += re.findall("^\s*from\s+\.(\S+)\s+import", content, flags=re.MULTILINE)
93
+ relative_imports += re.findall(r"^\s*from\s+\.(\S+)\s+import", content, flags=re.MULTILINE)
93
94
  # Unique-ify
94
95
  return list(set(relative_imports))
95
96
 
@@ -131,9 +132,9 @@ def check_imports(filename):
131
132
  content = f.read()
132
133
 
133
134
  # Imports of the form `import xxx`
134
- imports = re.findall("^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
135
+ imports = re.findall(r"^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
135
136
  # Imports of the form `from xxx import yyy`
136
- imports += re.findall("^\s*from\s+(\S+)\s+import", content, flags=re.MULTILINE)
137
+ imports += re.findall(r"^\s*from\s+(\S+)\s+import", content, flags=re.MULTILINE)
137
138
  # Only keep the top-level module
138
139
  imports = [imp.split(".")[0] for imp in imports if not imp.startswith(".")]
139
140
 
@@ -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
  )
@@ -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)