MCPcopy Create free account
hub / github.com/MatrixTeam-AI/RAIN / forward

Method forward

src/models/motion_module.py:146–182  ·  view source on GitHub ↗
(self, hidden_states, encoder_hidden_states=None, attention_mask=None)

Source from the content-addressed store, hash-verified

144 self.proj_out = nn.Linear(inner_dim, in_channels)
145
146 def forward(self, hidden_states, encoder_hidden_states=None, attention_mask=None):
147 assert (
148 hidden_states.dim() == 5
149 ), f"Expected hidden_states to have ndim=5, but got ndim={hidden_states.dim()}."
150 video_length = hidden_states.shape[2]
151 hidden_states = rearrange(hidden_states, "b c f h w -> (b f) c h w")
152
153 batch, channel, height, weight = hidden_states.shape
154 residual = hidden_states
155
156 hidden_states = self.norm(hidden_states)
157 inner_dim = hidden_states.shape[1]
158 hidden_states = hidden_states.permute(0, 2, 3, 1).reshape(
159 batch, height * weight, inner_dim
160 )
161 hidden_states = self.proj_in(hidden_states)
162
163 # Transformer Blocks
164 for block in self.transformer_blocks:
165 hidden_states = block(
166 hidden_states,
167 encoder_hidden_states=encoder_hidden_states,
168 video_length=video_length,
169 )
170
171 # output
172 hidden_states = self.proj_out(hidden_states)
173 hidden_states = (
174 hidden_states.reshape(batch, height, weight, inner_dim)
175 .permute(0, 3, 1, 2)
176 .contiguous()
177 )
178
179 output = hidden_states + residual
180 output = rearrange(output, "(b f) c h w -> b c f h w", f=video_length)
181
182 return output
183
184
185class TemporalTransformerBlock(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected