MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / Head

Class Head

models/transformer/wan/modules/t2m_model.py:454–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452
453
454class Head(nn.Module):
455
456 def __init__(self, dim, out_dim, patch_size, eps=1e-6):
457 super().__init__()
458 self.dim = dim
459 self.out_dim = out_dim
460 self.patch_size = patch_size
461 self.eps = eps
462
463 # layers
464 out_dim = math.prod(patch_size) * out_dim
465 self.norm = WanLayerNorm(dim, eps)
466 self.head = nn.Linear(dim, out_dim)
467
468 # modulation
469 self.modulation = nn.Parameter(torch.randn(1, 2, dim) / dim**0.5)
470
471 def forward(self, x, e):
472 assert e.dtype == torch.float32
473 with amp.autocast(dtype=torch.float32, device_type="cuda"):
474 e = (self.modulation.to(dtype=e.dtype, device=e.device) + e.unsqueeze(1)).chunk(2, dim=1)
475 x = (self.head(self.norm(x) * (1 + e[1]) + e[0]))
476 return x
477
478
479class MLPProj(torch.nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected