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

Method forward

wan/modules/multitalk_model.py:396–429  ·  view source on GitHub ↗
(self, audio_embeds, audio_embeds_vf)

Source from the content-addressed store, hash-verified

394 self.norm = nn.LayerNorm(output_dim) if norm_output_audio else nn.Identity()
395
396 def forward(self, audio_embeds, audio_embeds_vf):
397 video_length = audio_embeds.shape[1] + audio_embeds_vf.shape[1]
398 B, _, _, S, C = audio_embeds.shape
399
400 # process audio of first frame
401 audio_embeds = rearrange(audio_embeds, "bz f w b c -> (bz f) w b c")
402 batch_size, window_size, blocks, channels = audio_embeds.shape
403 audio_embeds = audio_embeds.view(batch_size, window_size * blocks * channels)
404
405 # process audio of latter frame
406 audio_embeds_vf = rearrange(audio_embeds_vf, "bz f w b c -> (bz f) w b c")
407 batch_size_vf, window_size_vf, blocks_vf, channels_vf = audio_embeds_vf.shape
408 audio_embeds_vf = audio_embeds_vf.view(batch_size_vf, window_size_vf * blocks_vf * channels_vf)
409
410 # first projection
411 audio_embeds = torch.relu(self.proj1(audio_embeds))
412 audio_embeds_vf = torch.relu(self.proj1_vf(audio_embeds_vf))
413 audio_embeds = rearrange(audio_embeds, "(bz f) c -> bz f c", bz=B)
414 audio_embeds_vf = rearrange(audio_embeds_vf, "(bz f) c -> bz f c", bz=B)
415 audio_embeds_c = torch.concat([audio_embeds, audio_embeds_vf], dim=1)
416 batch_size_c, N_t, C_a = audio_embeds_c.shape
417 audio_embeds_c = audio_embeds_c.view(batch_size_c*N_t, C_a)
418
419 # second projection
420 audio_embeds_c = torch.relu(self.proj2(audio_embeds_c))
421
422 context_tokens = self.proj3(audio_embeds_c).reshape(batch_size_c*N_t, self.context_tokens, self.output_dim)
423
424 # normalization and reshape
425 with amp.autocast(dtype=torch.float32):
426 context_tokens = self.norm(context_tokens)
427 context_tokens = rearrange(context_tokens, "(bz f) m c -> bz f m c", f=video_length)
428
429 return context_tokens
430
431
432class WanModel(ModelMixin, ConfigMixin):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected