Foundations to Frontier
Tests
E. Deep Learning › E5 Normalization Layers (one page each)

RMSNorm

RMSNorm is LayerNorm without the mean subtraction: it divides each example's features by their root mean square and multiplies by a learned gain. It keeps LayerNorm's rescaling invariance, drops the re-centring that turned out to matter little, and saves computation, so it is used in most recent large language models (T5, LLaMA, Mistral and others). This page covers the formula, what is lost by not centring, its gradient, and its cost. In the exercises you implement and gradient-check RMSNorm and show it equals LayerNorm on zero-mean inputs, then train a pre-norm residual network and find it matched LayerNorm (slightly better at a higher learning rate).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Only fix the size

LayerNorm does two things to each example’s features: it moves their average to zero and scales their spread to one. RMSNorm does only the second: it divides by the typical size of the features (their root mean square). It turns out the first step adds little, so RMSNorm gets nearly all the benefit with less work, which matters when it runs hundreds of times in every forward pass of a large model.

Normalisation layers: which values share a mean and variance?
channels →ex 1ex 2ex 3ex 4ex 5ex 6
Click a cell. Highlighted cells (16 values each) are pooled to compute the mean (not subtracted: RMSNorm only rescales) and variance used to normalise it.
per-example mean / sd after normalising0.90/0.44 0.77/0.63 -0.31/0.95 0.59/0.80 0.40/0.92 0.28/0.96
per-channel mean / sd after normalising0.95/0.34 0.92/0.67 0.46/1.05 -0.28/0.59 -0.44/0.76 0.13/0.96 0.80/0.36 0.99/0.70
BatchNorm noise: with batch size 6, a channel's batch mean is off from its population mean by 0.288 on average.
BatchNorm makes every channel have mean 0 and sd 1 across the batch, but each example's own statistics still vary, and its statistics depend on which other examples are in the batch: shrink N to 1 or 2 and watch the noise grow. LayerNorm, InstanceNorm and GroupNorm compute everything within one example, so they work the same at any batch size and at test time; they differ in which channels they pool.
Why engineers care

Most modern language models (LLaMA, Mistral, Gemma, T5 and many more) use RMSNorm. In a large model normalisation layers run in every block, so a cheaper normalisation saves real time, and fewer reductions are easier to fuse into a single GPU kernel.

📝 Quick check (Level 0)
0/3 answered
  1. 1. RMSNorm skips…
  2. 2. RMSNorm divides by…
  3. 3. RMSNorm is used in…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Definition: RMS(x) = √(mean(xᵢ²) + ε); y = g ⊙ x/RMS(x).
  • Example: x = (3, 4): RMS = √12.5 ≈ 3.54, so y ≈ (0.85, 1.13). For x = (2, −2): RMS = 2, y = (1, −1).
  • Parameters: a gain g per feature, d in all (4096 for d = 4096); LayerNorm usually also has a bias, 2d.
  • Invariances: y(ax) = y(x) for a > 0, but y(x + c) ≠ y(x). Adding 1 to (1, −1) gives (2, 0), whose RMS-normalised form (1.41, 0) differs from (1, −1).
  • Equal to LayerNorm when the features already have mean zero.
  • Cost: one reduction (sum of squares) instead of LayerNorm’s mean and variance.
📝 Quick check (Level 1)
0/3 answered
  1. 1. RMS of (2, −2):
  2. 2. RMSNorm is invariant to…
  3. 3. RMSNorm parameters for d = 4096 (gain only):

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

RMSNorm in code

Exercise 1.

  • Each normalised row had RMS exactly 1.
  • The analytic gradient matched finite differences.
  • Scaling the input by 3 changed nothing, shifting it by 5 changed the output, and on zero-mean inputs RMSNorm equalled LayerNorm.

Practice.

  • PyTorch has nn.RMSNorm(d) (since 2.4); many codebases define it in a few lines.
  • Compute the statistic in float32 even when activations are in bfloat16 or float16, to avoid overflow in the sum of squares.
  • In pre-norm transformers, replace each LayerNorm, including the final one, by RMSNorm; keep ε around 10⁻⁶–10⁻⁵.
class RMSNorm(torch.nn.Module):
    def __init__(self, d, eps=1e-6): super().__init__(); self.g = torch.nn.Parameter(torch.ones(d)); self.eps = eps
    def forward(self, x): return self.g * x * torch.rsqrt(x.float().pow(2).mean(-1, keepdim=True) + self.eps).to(x.dtype)
🐍 Exercise 1: RMSNorm
Implement RMSNorm and its backward pass, gradient-check it, and compare it with LayerNorm.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The sum of squares should be computed in…
  2. 2. PyTorch's built-in class is…
  3. 3. On zero-mean inputs, RMSNorm equals…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Re-scaling, not re-centring. Zhang and Sennrich (2019) argued that LayerNorm’s success comes mainly from its re-scaling invariance, which makes the layer’s output independent of the scale of its inputs and weights and stabilises gradients. RMSNorm keeps this invariance and reported comparable accuracy with 7–64% less time in the normalisation itself across their models.

Gradient. With u = x/r: ∂L/∂x = (g − u·mean(g ⊙ u))/r, where g = ∂L/∂u. The component along x is removed, consistent with scale invariance (the gradient is orthogonal to x).

What re-centring did. LayerNorm’s subtraction of the mean removes any constant offset shared by all features. Without it, a large common offset becomes part of the representation. In pre-norm residual networks the residual stream is what carries offsets, and the following linear layer can absorb a constant, so in practice little is lost.

pRMSNorm. Estimating the RMS from a fraction of the features saves more computation with little loss, though it is rarely used.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Zhang & Sennrich attribute LN's benefit mainly to…
  2. 2. RMSNorm's gradient is orthogonal to…
  3. 3. A shared constant offset under RMSNorm…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

RMSNorm versus LayerNorm

History.

  • B. Zhang and R. Sennrich (2019) introduced RMSNorm.
  • C. Raffel et al. (2020) used it in T5.
  • H. Touvron et al. (2023) used it in LLaMA, after which it became standard in open LLMs.

Exercise 2. An 8-block pre-norm residual MLP (the block layout of modern transformers, width 32) on spirals, trained with Adam for 400 steps, with LayerNorm, RMSNorm or no normalisation (no learned gain, for a like-for-like comparison). Means of three seeds:

norm η test accuracy test CE mean abs value of h at the head
none 0.003 0.999 0.007 2.39
LayerNorm 0.003 0.996 0.022 2.16
RMSNorm 0.003 0.997 0.010 2.21
none 0.03 0.995 0.036 4.37
LayerNorm 0.03 0.982 0.060 3.47
RMSNorm 0.03 0.998 0.007 3.58
  • RMSNorm matched LayerNorm at the lower rate and was slightly better at the higher one.
  • Without normalisation, η = 0.03 was on the edge of stability: it gave 0.995 natively but only 0.808 (test CE 1.40) in the browser, where rounding differs slightly. Both normalisations were stable on both platforms (LayerNorm 0.991 in the browser).
  • Lesson: dropping the mean subtraction cost nothing here, which supports RMSNorm’s use as a cheaper default.
🐍 Exercise 2 (research): RMSNorm versus LayerNorm
Train a pre-norm residual network with LayerNorm, RMSNorm and no normalisation at two learning rates, and compare.

RMSNorm in AI, robotics and aerospace

  • Large language and multimodal models, including those used for planning and robot instruction following, use RMSNorm throughout.
  • On-device transformers: fewer reductions mean faster, simpler kernels for embedded accelerators.
  • Mixed-precision training benefits from computing the RMS in float32.

References

  1. B. Zhang, R. Sennrich (2019). “Root mean square layer normalization.” Advances in NeurIPS.
  2. C. Raffel et al. (2020). “Exploring the limits of transfer learning with a unified text-to-text transformer.” JMLR 21.
  3. H. Touvron et al. (2023). “LLaMA: open and efficient foundation language models.” arXiv:2302.13971.