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

Method forward

wan/modules/model.py:130–159  ·  view source on GitHub ↗

r""" Args: x(Tensor): Shape [B, L, num_heads, C / num_heads] seq_lens(Tensor): Shape [B] grid_sizes(Tensor): Shape [B, 3], the second dimension contains (F, H, W) freqs(Tensor): Rope freqs, shape [1024, C / num_heads / 2]

(self, x, seq_lens, grid_sizes, freqs)

Source from the content-addressed store, hash-verified

128 self.norm_k = WanRMSNorm(dim, eps=eps) if qk_norm else nn.Identity()
129
130 def forward(self, x, seq_lens, grid_sizes, freqs):
131 r"""
132 Args:
133 x(Tensor): Shape [B, L, num_heads, C / num_heads]
134 seq_lens(Tensor): Shape [B]
135 grid_sizes(Tensor): Shape [B, 3], the second dimension contains (F, H, W)
136 freqs(Tensor): Rope freqs, shape [1024, C / num_heads / 2]
137 """
138 b, s, n, d = *x.shape[:2], self.num_heads, self.head_dim
139
140 # query, key, value function
141 def qkv_fn(x):
142 q = self.norm_q(self.q(x)).view(b, s, n, d)
143 k = self.norm_k(self.k(x)).view(b, s, n, d)
144 v = self.v(x).view(b, s, n, d)
145 return q, k, v
146
147 q, k, v = qkv_fn(x)
148
149 x = flash_attention(
150 q=rope_apply(q, grid_sizes, freqs),
151 k=rope_apply(k, grid_sizes, freqs),
152 v=v,
153 k_lens=seq_lens,
154 window_size=self.window_size)
155
156 # output
157 x = x.flatten(2)
158 x = self.o(x)
159 return x
160
161
162class WanT2VCrossAttention(WanSelfAttention):

Callers

nothing calls this directly

Calls 3

qkv_fnFunction · 0.85
flash_attentionFunction · 0.85
rope_applyFunction · 0.70

Tested by

no test coverage detected