| 49 | |
| 50 | |
| 51 | class MotionModules(nn.Module): |
| 52 | def __init__( |
| 53 | self, |
| 54 | in_channels: int, |
| 55 | layers_per_block: int = 2, |
| 56 | num_attention_heads: int = 8, |
| 57 | attention_bias: bool = False, |
| 58 | cross_attention_dim: Optional[int] = None, |
| 59 | activation_fn: str = "geglu", |
| 60 | norm_num_groups: int = 32, |
| 61 | max_seq_length: int = 32, |
| 62 | ): |
| 63 | super().__init__() |
| 64 | self.motion_modules = nn.ModuleList([]) |
| 65 | |
| 66 | for i in range(layers_per_block): |
| 67 | self.motion_modules.append( |
| 68 | TransformerTemporalModel( |
| 69 | in_channels=in_channels, |
| 70 | norm_num_groups=norm_num_groups, |
| 71 | cross_attention_dim=cross_attention_dim, |
| 72 | activation_fn=activation_fn, |
| 73 | attention_bias=attention_bias, |
| 74 | num_attention_heads=num_attention_heads, |
| 75 | attention_head_dim=in_channels // num_attention_heads, |
| 76 | positional_embeddings="sinusoidal", |
| 77 | num_positional_embeddings=max_seq_length, |
| 78 | ) |
| 79 | ) |
| 80 | |
| 81 | |
| 82 | class MotionAdapter(ModelMixin, ConfigMixin): |