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

Method forward

wan/modules/multitalk_model.py:274–318  ·  view source on GitHub ↗
(
        self,
        x,
        e,
        seq_lens,
        grid_sizes,
        freqs,
        context,
        context_lens,
        audio_embedding=None,
        ref_target_masks=None,
        human_num=None,
    )

Source from the content-addressed store, hash-verified

272
273
274 def forward(
275 self,
276 x,
277 e,
278 seq_lens,
279 grid_sizes,
280 freqs,
281 context,
282 context_lens,
283 audio_embedding=None,
284 ref_target_masks=None,
285 human_num=None,
286 ):
287
288 dtype = x.dtype
289 assert e.dtype == torch.float32
290 with amp.autocast(dtype=torch.float32):
291 e = (self.modulation.to(e.device) + e).chunk(6, dim=1)
292 assert e[0].dtype == torch.float32
293
294 # self-attention
295 y, x_ref_attn_map = self.self_attn(
296 (self.norm1(x).float() * (1 + e[1]) + e[0]).type_as(x), seq_lens, grid_sizes,
297 freqs, ref_target_masks=ref_target_masks)
298 with amp.autocast(dtype=torch.float32):
299 x = x + y * e[2]
300
301 x = x.to(dtype)
302
303 # cross-attention of text
304 x = x + self.cross_attn(self.norm3(x), context, context_lens)
305
306 # cross attn of audio
307 x_a = self.audio_cross_attn(self.norm_x(x), encoder_hidden_states=audio_embedding,
308 shape=grid_sizes[0], x_ref_attn_map=x_ref_attn_map, human_num=human_num)
309 x = x + x_a
310
311 y = self.ffn((self.norm2(x).float() * (1 + e[4]) + e[3]).to(dtype))
312 with amp.autocast(dtype=torch.float32):
313 x = x + y * e[5]
314
315
316 x = x.to(dtype)
317
318 return x
319
320
321class Head(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected