VOSR / models /rmsnorm.py
41-807's picture
Upload models/rmsnorm.py with huggingface_hub
006b3cc verified
Raw
History Blame Contribute Delete
479 Bytes
# Minimal RMSNorm used by LightningDiT (fairscale-free).
import torch
class RMSNorm(torch.nn.Module):
def __init__(self, dim: int, eps: float = 1e-6):
super().__init__()
self.eps = eps
self.weight = torch.nn.Parameter(torch.ones(dim))
def _norm(self, x):
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
def forward(self, x):
output = self._norm(x.float()).type_as(x)
return output * self.weight