Machine learning building blocks
RMS normalization
ml.rms-normAlso called rms norm, rmsnorm, root mean square normalization, rms normalization
Divides a feature vector by its root mean square, without centering it, then applies a per-feature scale γ. The default ε = 1e-6 is common in transformer codebases.
Notation
features of one example
x ∈ ℝn
per-feature scale
γ ∈ ℝn · default 1 in every entry
added to the mean square before the square root
ε ≥ 0 · default 1e-6 · also common: 1e-5, 1e-8, 0
number of entries
Size, at least 1
Result: the normalized features
vector
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ (0.848528137424, 1.1313708499)
Given
Result
Given
Result
≈ (0.999999875)
Common mistakes
Adds ε to the RMS
ε is added after the square root instead of to the mean square.
Fix: Add ε to the mean of squares, then take the square root.
Centers the features first
The mean is subtracted, which turns RMS normalization into layer normalization without a shift.
Fix: Divide x by its root mean square without subtracting the mean.
Divides by the L2 norm
The squares are summed, not averaged, so the result is smaller by about √n.
Fix: Divide the sum of squares by n before the square root.
Notes
- ε guards against division by zero. Its default differs between libraries, which changes the result when the mean square is small.
Source
Zhang and Sennrich 2019
Zhang, Biao; Sennrich, Rico. Root Mean Square Layer Normalization. In Advances in Neural Information Processing Systems 32, pp. 12381-12392, 2019.