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

Class Head

wan/modules/model.py:320–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318
319
320class Head(nn.Module):
321
322 def __init__(self, dim, out_dim, patch_size, eps=1e-6):
323 super().__init__()
324 self.dim = dim
325 self.out_dim = out_dim
326 self.patch_size = patch_size
327 self.eps = eps
328
329 # layers
330 out_dim = math.prod(patch_size) * out_dim
331 self.norm = WanLayerNorm(dim, eps)
332 self.head = nn.Linear(dim, out_dim)
333
334 # modulation
335 self.modulation = nn.Parameter(torch.randn(1, 2, dim) / dim**0.5)
336
337 def forward(self, x, e):
338 r"""
339 Args:
340 x(Tensor): Shape [B, L1, C]
341 e(Tensor): Shape [B, C]
342 """
343 assert e.dtype == torch.float32
344 with amp.autocast(dtype=torch.float32):
345 e = (self.modulation.to(e.device) + e.unsqueeze(1)).chunk(2, dim=1)
346 x = (self.head(self.norm(x) * (1 + e[1]) + e[0]))
347 return x
348
349
350class MLPProj(torch.nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected