RMSNorm
Function
A lightweight variant of LayerNorm that triggers only root mean square normalization (without mean centering).
Prototype
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 forward(self, x: torch.Tensor):
# Calculate the root mean square.
rms = x.norm(2, dim=-1, keepdim=True) * (x.size(-1) ** -0.5)
return x / (rms + self.eps) * self.weight
Parameters
Parameter |
Type |
Mandatory (Yes/No) |
Description |
|---|---|---|---|
dim |
int |
Yes |
Input feature dimension |
eps |
float |
No |
Numerical stability constant (default value: 1e-6) |
weight |
tensor |
No |
Learnable scaling factor (automatically created) |
Parent topic: Operator Interfaces