MCPcopy Create free account
hub / github.com/MotrixLab/MotionDiffuse / forward

Method forward

text2motion/models/transformer.py:242–262  ·  view source on GitHub ↗

x: B, T, D xf: B, N, L

(self, x, xf, emb)

Source from the content-addressed store, hash-verified

240 self.proj_out = StylizationBlock(latent_dim, time_embed_dim, dropout)
241
242 def forward(self, x, xf, emb):
243 """
244 x: B, T, D
245 xf: B, N, L
246 """
247 B, T, D = x.shape
248 N = xf.shape[1]
249 H = self.num_head
250 # B, T, 1, D
251 query = self.query(self.norm(x)).unsqueeze(2)
252 # B, 1, N, D
253 key = self.key(self.text_norm(xf)).unsqueeze(1)
254 query = query.view(B, T, H, -1)
255 key = key.view(B, N, H, -1)
256 # B, T, N, H
257 attention = torch.einsum('bnhd,bmhd->bnmh', query, key) / math.sqrt(D // H)
258 weight = self.dropout(F.softmax(attention, dim=2))
259 value = self.value(self.text_norm(xf)).view(B, N, H, -1)
260 y = torch.einsum('bnmh,bmhd->bnhd', weight, value).reshape(B, T, D)
261 y = x + self.proj_out(y, emb)
262 return y
263
264class TemporalDiffusionTransformerDecoderLayer(nn.Module):
265

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected