class_docstr: A modified conditional 2D UNet model that takes a noisy sample, conditional state, and a timestep and returns a
  sample shaped output.
  
  This model inherits from [`ModelMixin`]. Check the superclass documentation for it's generic methods implemented
  for all models (such as downloading or saving).
code: def from_unet2d(
      cls,
      unet: UNet2DConditionModel,
      motion_adapter: Optional[MotionAdapter] = None,
      load_weights: bool = True,
  ):
      has_motion_adapter = motion_adapter is not None
  
      # based on https://github.com/guoyww/AnimateDiff/blob/895f3220c06318ea0760131ec70408b466c49333/animatediff/models/unet.py#L459
      config = unet.config
      config["_class_name"] = cls.__name__
  
      down_blocks = []
      for down_blocks_type in config["down_block_types"]:
          if "CrossAttn" in down_blocks_type:
              down_blocks.append("CrossAttnDownBlockMotion")
          else:
              down_blocks.append("DownBlockMotion")
      config["down_block_types"] = down_blocks
  
      up_blocks = []
      for down_blocks_type in config["up_block_types"]:
          if "CrossAttn" in down_blocks_type:
              up_blocks.append("CrossAttnUpBlockMotion")
          else:
              up_blocks.append("UpBlockMotion")
  
      config["up_block_types"] = up_blocks
  
      if has_motion_adapter:
          config["motion_num_attention_heads"] = motion_adapter.config[
              "motion_num_attention_heads"
          ]
          config["motion_max_seq_length"] = motion_adapter.config[
              "motion_max_seq_length"
          ]
          config["use_motion_mid_block"] = motion_adapter.config[
              "use_motion_mid_block"
          ]
  
      # Need this for backwards compatibility with UNet2DConditionModel checkpoints
      if not config.get("num_attention_heads"):
          config["num_attention_heads"] = config["attention_head_dim"]
  
      model = cls.from_config(config)
  
      if not load_weights:
          return model
  
      model.conv_in.load_state_dict(unet.conv_in.state_dict())
      model.time_proj.load_state_dict(unet.time_proj.state_dict())
      model.time_embedding.load_state_dict(
          unet.time_embedding.state_dict()
      )
  
      for i, down_block in enumerate(unet.down_blocks):
          model.down_blocks[i].resnets.load_state_dict(
              down_block.resnets.state_dict()
          )
          if hasattr(model.down_blocks[i], "attentions"):
              model.down_blocks[i].attentions.load_state_dict(
                  down_block.attentions.state_dict()
              )
          if model.down_blocks[i].downsamplers:
              model.down_blocks[i].downsamplers.load_state_dict(
                  down_block.downsamplers.state_dict()
              )
  
      for i, up_block in enumerate(unet.up_blocks):
          model.up_blocks[i].resnets.load_state_dict(
              up_block.resnets.state_dict()
          )
          if hasattr(model.up_blocks[i], "attentions"):
              model.up_blocks[i].attentions.load_state_dict(
                  up_block.attentions.state_dict()
              )
          if model.up_blocks[i].upsamplers:
              model.up_blocks[i].upsamplers.load_state_dict(
                  up_block.upsamplers.state_dict()
              )
  
      model.mid_block.resnets.load_state_dict(
          unet.mid_block.resnets.state_dict()
      )
      model.mid_block.attentions.load_state_dict(
          unet.mid_block.attentions.state_dict()
      )
  
      if unet.conv_norm_out is not None:
          model.conv_norm_out.load_state_dict(
              unet.conv_norm_out.state_dict()
          )
      if unet.conv_act is not None:
          model.conv_act.load_state_dict(unet.conv_act.state_dict())
      model.conv_out.load_state_dict(unet.conv_out.state_dict())
  
      if has_motion_adapter:
          model.load_motion_modules(motion_adapter)
  
      # ensure that the Motion UNet is the same dtype as the UNet2DConditionModel
      model.to(unet.dtype)
  
      return model
  
imports: from typing import Any, Dict, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.utils.checkpoint
  from ..configuration_utils import ConfigMixin, register_to_config
  from ..loaders import UNet2DConditionLoadersMixin
  from ..utils import logging
  from .attention_processor import ADDED_KV_ATTENTION_PROCESSORS, CROSS_ATTENTION_PROCESSORS, AttentionProcessor, AttnAddedKVProcessor, AttnProcessor
  from .embeddings import TimestepEmbedding, Timesteps
  from .modeling_utils import ModelMixin
  from .transformer_temporal import TransformerTemporalModel
  from .unet_2d_blocks import UNetMidBlock2DCrossAttn
  from .unet_2d_condition import UNet2DConditionModel
  from .unet_3d_blocks import CrossAttnDownBlockMotion, CrossAttnUpBlockMotion, DownBlockMotion, UNetMidBlockCrossAttnMotion, UpBlockMotion, get_down_block, get_up_block
  from .unet_3d_condition import UNet3DConditionOutput
label_desc: Use image node_id 2 for calling the UNetMotionModel obj's underlying member method code with example usage: obj.from_unet2d(cls, unet, motion_adapter, load_weights) and returns: model, model