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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. diffusers/__init__.py +16 -2
  2. diffusers/configuration_utils.py +1 -0
  3. diffusers/dependency_versions_check.py +1 -14
  4. diffusers/dependency_versions_table.py +5 -4
  5. diffusers/image_processor.py +186 -14
  6. diffusers/loaders/__init__.py +82 -0
  7. diffusers/loaders/ip_adapter.py +157 -0
  8. diffusers/loaders/lora.py +1415 -0
  9. diffusers/loaders/lora_conversion_utils.py +284 -0
  10. diffusers/loaders/single_file.py +631 -0
  11. diffusers/loaders/textual_inversion.py +459 -0
  12. diffusers/loaders/unet.py +735 -0
  13. diffusers/loaders/utils.py +59 -0
  14. diffusers/models/__init__.py +12 -1
  15. diffusers/models/attention.py +165 -14
  16. diffusers/models/attention_flax.py +9 -1
  17. diffusers/models/attention_processor.py +286 -1
  18. diffusers/models/autoencoder_asym_kl.py +14 -9
  19. diffusers/models/autoencoder_kl.py +3 -18
  20. diffusers/models/autoencoder_kl_temporal_decoder.py +402 -0
  21. diffusers/models/autoencoder_tiny.py +20 -24
  22. diffusers/models/consistency_decoder_vae.py +37 -30
  23. diffusers/models/controlnet.py +59 -39
  24. diffusers/models/controlnet_flax.py +19 -18
  25. diffusers/models/embeddings_flax.py +2 -0
  26. diffusers/models/lora.py +131 -1
  27. diffusers/models/modeling_flax_utils.py +2 -1
  28. diffusers/models/modeling_outputs.py +17 -0
  29. diffusers/models/modeling_utils.py +27 -19
  30. diffusers/models/normalization.py +2 -2
  31. diffusers/models/resnet.py +390 -59
  32. diffusers/models/transformer_2d.py +20 -3
  33. diffusers/models/transformer_temporal.py +183 -1
  34. diffusers/models/unet_2d_blocks_flax.py +5 -0
  35. diffusers/models/unet_2d_condition.py +9 -0
  36. diffusers/models/unet_2d_condition_flax.py +13 -13
  37. diffusers/models/unet_3d_blocks.py +957 -173
  38. diffusers/models/unet_3d_condition.py +16 -8
  39. diffusers/models/unet_kandi3.py +589 -0
  40. diffusers/models/unet_motion_model.py +48 -33
  41. diffusers/models/unet_spatio_temporal_condition.py +489 -0
  42. diffusers/models/vae.py +63 -13
  43. diffusers/models/vae_flax.py +7 -0
  44. diffusers/models/vq_model.py +3 -1
  45. diffusers/optimization.py +16 -9
  46. diffusers/pipelines/__init__.py +65 -12
  47. diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +93 -23
  48. diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +97 -25
  49. diffusers/pipelines/animatediff/pipeline_animatediff.py +34 -4
  50. diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
  51. diffusers/pipelines/auto_pipeline.py +6 -0
  52. diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
  53. diffusers/pipelines/controlnet/pipeline_controlnet.py +217 -31
  54. diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +101 -32
  55. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +136 -39
  56. diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +119 -37
  57. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +196 -35
  58. diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +102 -31
  59. diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
  60. diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
  61. diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
  62. diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
  63. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
  64. diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
  65. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
  66. diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
  67. diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
  68. diffusers/pipelines/dit/pipeline_dit.py +1 -0
  69. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
  70. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
  71. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
  72. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
  73. diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
  74. diffusers/pipelines/kandinsky3/__init__.py +49 -0
  75. diffusers/pipelines/kandinsky3/kandinsky3_pipeline.py +452 -0
  76. diffusers/pipelines/kandinsky3/kandinsky3img2img_pipeline.py +460 -0
  77. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +65 -6
  78. diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +55 -3
  79. diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
  80. diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
  81. diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
  82. diffusers/pipelines/pipeline_flax_utils.py +4 -2
  83. diffusers/pipelines/pipeline_utils.py +33 -13
  84. diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +196 -36
  85. diffusers/pipelines/score_sde_ve/pipeline_score_sde_ve.py +1 -0
  86. diffusers/pipelines/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -0
  87. diffusers/pipelines/stable_diffusion/__init__.py +64 -21
  88. diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +8 -3
  89. diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py +18 -2
  90. diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
  91. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
  92. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
  93. diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint_legacy.py +1 -0
  94. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +88 -9
  95. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_attend_and_excite.py +1 -0
  96. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
  97. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py +1 -0
  98. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen.py +1 -0
  99. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen_text_image.py +1 -0
  100. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
  101. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -9
  102. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +92 -9
  103. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py +1 -0
  104. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +17 -13
  105. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_k_diffusion.py +1 -0
  106. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +1 -0
  107. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_ldm3d.py +1 -0
  108. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py +1 -0
  109. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py +1 -0
  110. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_paradigms.py +1 -0
  111. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py +1 -0
  112. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py +1 -0
  113. diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +1 -0
  114. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +103 -8
  115. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +113 -8
  116. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +115 -9
  117. diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +16 -12
  118. diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
  119. diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +649 -0
  120. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
  121. diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +109 -14
  122. diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
  123. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +1 -0
  124. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +18 -3
  125. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +4 -2
  126. diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +872 -0
  127. diffusers/pipelines/versatile_diffusion/modeling_text_unet.py +29 -40
  128. diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +1 -0
  129. diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +1 -0
  130. diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +1 -0
  131. diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
  132. diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
  133. diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
  134. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
  135. diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +1 -1
  136. diffusers/schedulers/__init__.py +2 -4
  137. diffusers/schedulers/deprecated/__init__.py +50 -0
  138. diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
  139. diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
  140. diffusers/schedulers/scheduling_ddim.py +1 -3
  141. diffusers/schedulers/scheduling_ddim_inverse.py +1 -3
  142. diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
  143. diffusers/schedulers/scheduling_ddpm.py +1 -3
  144. diffusers/schedulers/scheduling_ddpm_parallel.py +1 -3
  145. diffusers/schedulers/scheduling_deis_multistep.py +15 -5
  146. diffusers/schedulers/scheduling_dpmsolver_multistep.py +15 -5
  147. diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +15 -5
  148. diffusers/schedulers/scheduling_dpmsolver_sde.py +1 -3
  149. diffusers/schedulers/scheduling_dpmsolver_singlestep.py +15 -5
  150. diffusers/schedulers/scheduling_euler_ancestral_discrete.py +1 -3
  151. diffusers/schedulers/scheduling_euler_discrete.py +40 -13
  152. diffusers/schedulers/scheduling_heun_discrete.py +15 -5
  153. diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +15 -5
  154. diffusers/schedulers/scheduling_k_dpm_2_discrete.py +15 -5
  155. diffusers/schedulers/scheduling_lcm.py +123 -29
  156. diffusers/schedulers/scheduling_lms_discrete.py +1 -3
  157. diffusers/schedulers/scheduling_pndm.py +1 -3
  158. diffusers/schedulers/scheduling_repaint.py +1 -3
  159. diffusers/schedulers/scheduling_unipc_multistep.py +15 -5
  160. diffusers/utils/__init__.py +1 -0
  161. diffusers/utils/constants.py +11 -6
  162. diffusers/utils/dummy_pt_objects.py +45 -0
  163. diffusers/utils/dummy_torch_and_transformers_objects.py +60 -0
  164. diffusers/utils/dynamic_modules_utils.py +4 -4
  165. diffusers/utils/export_utils.py +8 -3
  166. diffusers/utils/logging.py +10 -10
  167. diffusers/utils/outputs.py +5 -5
  168. diffusers/utils/peft_utils.py +88 -44
  169. diffusers/utils/torch_utils.py +2 -2
  170. diffusers/utils/versions.py +117 -0
  171. {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/METADATA +83 -64
  172. {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/RECORD +176 -157
  173. {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/WHEEL +1 -1
  174. {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/entry_points.txt +1 -0
  175. diffusers/loaders.py +0 -3336
  176. {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/LICENSE +0 -0
  177. {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/top_level.txt +0 -0
@@ -50,14 +50,14 @@ logger = logging.get_logger(__name__) # pylint: disable=invalid-name
50
50
  class MotionModules(nn.Module):
51
51
  def __init__(
52
52
  self,
53
- in_channels,
54
- layers_per_block=2,
55
- num_attention_heads=8,
56
- attention_bias=False,
57
- cross_attention_dim=None,
58
- activation_fn="geglu",
59
- norm_num_groups=32,
60
- max_seq_length=32,
53
+ in_channels: int,
54
+ layers_per_block: int = 2,
55
+ num_attention_heads: int = 8,
56
+ attention_bias: bool = False,
57
+ cross_attention_dim: Optional[int] = None,
58
+ activation_fn: str = "geglu",
59
+ norm_num_groups: int = 32,
60
+ max_seq_length: int = 32,
61
61
  ):
62
62
  super().__init__()
63
63
  self.motion_modules = nn.ModuleList([])
@@ -82,13 +82,13 @@ class MotionAdapter(ModelMixin, ConfigMixin):
82
82
  @register_to_config
83
83
  def __init__(
84
84
  self,
85
- block_out_channels=(320, 640, 1280, 1280),
86
- motion_layers_per_block=2,
87
- motion_mid_block_layers_per_block=1,
88
- motion_num_attention_heads=8,
89
- motion_norm_num_groups=32,
90
- motion_max_seq_length=32,
91
- use_motion_mid_block=True,
85
+ block_out_channels: Tuple[int, ...] = (320, 640, 1280, 1280),
86
+ motion_layers_per_block: int = 2,
87
+ motion_mid_block_layers_per_block: int = 1,
88
+ motion_num_attention_heads: int = 8,
89
+ motion_norm_num_groups: int = 32,
90
+ motion_max_seq_length: int = 32,
91
+ use_motion_mid_block: bool = True,
92
92
  ):
93
93
  """Container to store AnimateDiff Motion Modules
94
94
 
@@ -174,6 +174,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
174
174
  This model inherits from [`ModelMixin`]. Check the superclass documentation for it's generic methods implemented
175
175
  for all models (such as downloading or saving).
176
176
  """
177
+
177
178
  _supports_gradient_checkpointing = True
178
179
 
179
180
  @register_to_config
@@ -182,31 +183,33 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
182
183
  sample_size: Optional[int] = None,
183
184
  in_channels: int = 4,
184
185
  out_channels: int = 4,
185
- down_block_types: Tuple[str] = (
186
+ down_block_types: Tuple[str, ...] = (
186
187
  "CrossAttnDownBlockMotion",
187
188
  "CrossAttnDownBlockMotion",
188
189
  "CrossAttnDownBlockMotion",
189
190
  "DownBlockMotion",
190
191
  ),
191
- up_block_types: Tuple[str] = (
192
+ up_block_types: Tuple[str, ...] = (
192
193
  "UpBlockMotion",
193
194
  "CrossAttnUpBlockMotion",
194
195
  "CrossAttnUpBlockMotion",
195
196
  "CrossAttnUpBlockMotion",
196
197
  ),
197
- block_out_channels: Tuple[int] = (320, 640, 1280, 1280),
198
+ block_out_channels: Tuple[int, ...] = (320, 640, 1280, 1280),
198
199
  layers_per_block: int = 2,
199
200
  downsample_padding: int = 1,
200
201
  mid_block_scale_factor: float = 1,
201
202
  act_fn: str = "silu",
202
- norm_num_groups: Optional[int] = 32,
203
+ norm_num_groups: int = 32,
203
204
  norm_eps: float = 1e-5,
204
205
  cross_attention_dim: int = 1280,
205
206
  use_linear_projection: bool = False,
206
- num_attention_heads: Optional[Union[int, Tuple[int]]] = 8,
207
- motion_max_seq_length: Optional[int] = 32,
207
+ num_attention_heads: Union[int, Tuple[int, ...]] = 8,
208
+ motion_max_seq_length: int = 32,
208
209
  motion_num_attention_heads: int = 8,
209
210
  use_motion_mid_block: int = True,
211
+ encoder_hid_dim: Optional[int] = None,
212
+ encoder_hid_dim_type: Optional[str] = None,
210
213
  ):
211
214
  super().__init__()
212
215
 
@@ -247,6 +250,9 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
247
250
  act_fn=act_fn,
248
251
  )
249
252
 
253
+ if encoder_hid_dim_type is None:
254
+ self.encoder_hid_proj = None
255
+
250
256
  # class embedding
251
257
  self.down_blocks = nn.ModuleList([])
252
258
  self.up_blocks = nn.ModuleList([])
@@ -448,7 +454,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
448
454
 
449
455
  return model
450
456
 
451
- def freeze_unet2d_params(self):
457
+ def freeze_unet2d_params(self) -> None:
452
458
  """Freeze the weights of just the UNet2DConditionModel, and leave the motion modules
453
459
  unfrozen for fine tuning.
454
460
  """
@@ -472,9 +478,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
472
478
  for param in motion_modules.parameters():
473
479
  param.requires_grad = True
474
480
 
475
- return
476
-
477
- def load_motion_modules(self, motion_adapter: Optional[MotionAdapter]):
481
+ def load_motion_modules(self, motion_adapter: Optional[MotionAdapter]) -> None:
478
482
  for i, down_block in enumerate(motion_adapter.down_blocks):
479
483
  self.down_blocks[i].motion_modules.load_state_dict(down_block.motion_modules.state_dict())
480
484
  for i, up_block in enumerate(motion_adapter.up_blocks):
@@ -492,7 +496,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
492
496
  variant: Optional[str] = None,
493
497
  push_to_hub: bool = False,
494
498
  **kwargs,
495
- ):
499
+ ) -> None:
496
500
  state_dict = self.state_dict()
497
501
 
498
502
  # Extract all motion modules
@@ -582,7 +586,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
582
586
  fn_recursive_attn_processor(name, module, processor)
583
587
 
584
588
  # Copied from diffusers.models.unet_3d_condition.UNet3DConditionModel.enable_forward_chunking
585
- def enable_forward_chunking(self, chunk_size=None, dim=0):
589
+ def enable_forward_chunking(self, chunk_size: Optional[int] = None, dim: int = 0) -> None:
586
590
  """
587
591
  Sets the attention processor to use [feed forward
588
592
  chunking](https://huggingface.co/blog/reformer#2-chunked-feed-forward-layers).
@@ -612,7 +616,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
612
616
  fn_recursive_feed_forward(module, chunk_size, dim)
613
617
 
614
618
  # Copied from diffusers.models.unet_3d_condition.UNet3DConditionModel.disable_forward_chunking
615
- def disable_forward_chunking(self):
619
+ def disable_forward_chunking(self) -> None:
616
620
  def fn_recursive_feed_forward(module: torch.nn.Module, chunk_size: int, dim: int):
617
621
  if hasattr(module, "set_chunk_feed_forward"):
618
622
  module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)
@@ -624,7 +628,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
624
628
  fn_recursive_feed_forward(module, None, 0)
625
629
 
626
630
  # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
627
- def set_default_attn_processor(self):
631
+ def set_default_attn_processor(self) -> None:
628
632
  """
629
633
  Disables custom attention processors and sets the default attention implementation.
630
634
  """
@@ -639,12 +643,12 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
639
643
 
640
644
  self.set_attn_processor(processor, _remove_lora=True)
641
645
 
642
- def _set_gradient_checkpointing(self, module, value=False):
646
+ def _set_gradient_checkpointing(self, module, value: bool = False) -> None:
643
647
  if isinstance(module, (CrossAttnDownBlockMotion, DownBlockMotion, CrossAttnUpBlockMotion, UpBlockMotion)):
644
648
  module.gradient_checkpointing = value
645
649
 
646
650
  # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.enable_freeu
647
- def enable_freeu(self, s1, s2, b1, b2):
651
+ def enable_freeu(self, s1: float, s2: float, b1: float, b2: float) -> None:
648
652
  r"""Enables the FreeU mechanism from https://arxiv.org/abs/2309.11497.
649
653
 
650
654
  The suffixes after the scaling factors represent the stage blocks where they are being applied.
@@ -669,7 +673,7 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
669
673
  setattr(upsample_block, "b2", b2)
670
674
 
671
675
  # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.disable_freeu
672
- def disable_freeu(self):
676
+ def disable_freeu(self) -> None:
673
677
  """Disables the FreeU mechanism."""
674
678
  freeu_keys = {"s1", "s2", "b1", "b2"}
675
679
  for i, upsample_block in enumerate(self.up_blocks):
@@ -685,10 +689,11 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
685
689
  timestep_cond: Optional[torch.Tensor] = None,
686
690
  attention_mask: Optional[torch.Tensor] = None,
687
691
  cross_attention_kwargs: Optional[Dict[str, Any]] = None,
692
+ added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,
688
693
  down_block_additional_residuals: Optional[Tuple[torch.Tensor]] = None,
689
694
  mid_block_additional_residual: Optional[torch.Tensor] = None,
690
695
  return_dict: bool = True,
691
- ) -> Union[UNet3DConditionOutput, Tuple]:
696
+ ) -> Union[UNet3DConditionOutput, Tuple[torch.Tensor]]:
692
697
  r"""
693
698
  The [`UNetMotionModel`] forward method.
694
699
 
@@ -768,6 +773,16 @@ class UNetMotionModel(ModelMixin, ConfigMixin, UNet2DConditionLoadersMixin):
768
773
 
769
774
  emb = self.time_embedding(t_emb, timestep_cond)
770
775
  emb = emb.repeat_interleave(repeats=num_frames, dim=0)
776
+
777
+ if self.encoder_hid_proj is not None and self.config.encoder_hid_dim_type == "ip_image_proj":
778
+ if "image_embeds" not in added_cond_kwargs:
779
+ raise ValueError(
780
+ f"{self.__class__} has the config param `encoder_hid_dim_type` set to 'ip_image_proj' which requires the keyword argument `image_embeds` to be passed in `added_conditions`"
781
+ )
782
+ image_embeds = added_cond_kwargs.get("image_embeds")
783
+ image_embeds = self.encoder_hid_proj(image_embeds).to(encoder_hidden_states.dtype)
784
+ encoder_hidden_states = torch.cat([encoder_hidden_states, image_embeds], dim=1)
785
+
771
786
  encoder_hidden_states = encoder_hidden_states.repeat_interleave(repeats=num_frames, dim=0)
772
787
 
773
788
  # 2. pre-process