MCPcopy Create free account
hub / github.com/MiniMax-AI/VTP / LayerNormFp32

Class LayerNormFp32

vtp/models/layers/normalization.py:34–40  ·  view source on GitHub ↗

Subclass torch's LayerNorm to handle fp16 (by casting to float32 and back).

Source from the content-addressed store, hash-verified

32
33
34class LayerNormFp32(nn.LayerNorm):
35 """Subclass torch's LayerNorm to handle fp16 (by casting to float32 and back)."""
36
37 def forward(self, x: torch.Tensor):
38 orig_type = x.dtype
39 x = F.layer_norm(x.to(torch.float32), self.normalized_shape, self.weight, self.bias, self.eps)
40 return x.to(orig_type)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected