All formulas

Machine learning building blocks

RMS normalization

ml.rms-normAlso called rms norm, rmsnorm, root mean square normalization, rms normalization

yi=xi1n∑j=1nxj2+ϵγiy_i = \frac{x_i}{\sqrt{\frac{1}{n}\sum_{j=1}^{n} x_j^2 + \epsilon}}\gamma_i

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

xx

features of one example

x ∈ ℝn

γ\gamma

per-feature scale

γ ∈ ℝn · default 1 in every entry

ϵ\epsilon

added to the mean square before the square root

ε ≥ 0 · default 1e-6 · also common: 1e-5, 1e-8, 0

nn

number of entries

Size, at least 1

yy

Result: the normalized features

vector

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=[3,4],ϵ=0x = [3, 4], \epsilon = 0

    Result

    y=(325,425)\displaystyle y = \left(\frac{3 \sqrt{2}}{5}, \frac{4 \sqrt{2}}{5}\right)

    ≈ (0.848528137424, 1.1313708499)

  2. Given

    x=[1,1,1,1],γ=[1,2,3,4],ϵ=0x = [1, 1, 1, 1], \gamma = [1, 2, 3, 4], \epsilon = 0

    Result

    y=(1,2,3,4)\displaystyle y = \left(1, 2, 3, 4\right)
  3. Given

    x=[2]x = [2]

    Result

    y=(200040000014000001)\displaystyle y = \left(\frac{2000 \sqrt{4000001}}{4000001}\right)

    ≈ (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.

    arxiv.org