MCPcopy Create free account
hub / github.com/MeiGen-AI/MultiTalk / forward

Method forward

wan/modules/model.py:278–317  ·  view source on GitHub ↗

r""" Args: x(Tensor): Shape [B, L, C] e(Tensor): Shape [B, 6, C] seq_lens(Tensor): Shape [B], length of each sequence in batch grid_sizes(Tensor): Shape [B, 3], the second dimension contains (F, H, W) freqs(Tensor): Rope freqs, shap

(
        self,
        x,
        e,
        seq_lens,
        grid_sizes,
        freqs,
        context,
        context_lens,
    )

Source from the content-addressed store, hash-verified

276 self.modulation = nn.Parameter(torch.randn(1, 6, dim) / dim**0.5)
277
278 def forward(
279 self,
280 x,
281 e,
282 seq_lens,
283 grid_sizes,
284 freqs,
285 context,
286 context_lens,
287 ):
288 r"""
289 Args:
290 x(Tensor): Shape [B, L, C]
291 e(Tensor): Shape [B, 6, C]
292 seq_lens(Tensor): Shape [B], length of each sequence in batch
293 grid_sizes(Tensor): Shape [B, 3], the second dimension contains (F, H, W)
294 freqs(Tensor): Rope freqs, shape [1024, C / num_heads / 2]
295 """
296 assert e.dtype == torch.float32
297 with amp.autocast(dtype=torch.float32):
298 e = (self.modulation.to(e.device) + e).chunk(6, dim=1)
299 assert e[0].dtype == torch.float32
300
301 # self-attention
302 y = self.self_attn(
303 self.norm1(x).float() * (1 + e[1]) + e[0], seq_lens, grid_sizes,
304 freqs)
305 with amp.autocast(dtype=torch.float32):
306 x = x + y * e[2]
307
308 # cross-attention & ffn function
309 def cross_attn_ffn(x, context, context_lens, e):
310 x = x + self.cross_attn(self.norm3(x), context, context_lens)
311 y = self.ffn(self.norm2(x).float() * (1 + e[4]) + e[3])
312 with amp.autocast(dtype=torch.float32):
313 x = x + y * e[5]
314 return x
315
316 x = cross_attn_ffn(x, context, context_lens, e)
317 return x
318
319
320class Head(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected