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).
★☆☆☆☆ 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?
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.
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. RMSNorm skips…
2. RMSNorm divides by…
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. RMS of (2, −2):
2. RMSNorm is invariant to…
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⁻⁵.
Implement RMSNorm and its backward pass, gradient-check it, and compare it with LayerNorm.
📝 Quick check (Level 2)
0/3 answered
1. The sum of squares should be computed in…
2. PyTorch's built-in class is…
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.
★★★★★ 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
B. Zhang, R. Sennrich (2019). “Root mean square layer normalization.” Advances in NeurIPS.
C. Raffel et al. (2020). “Exploring the limits of transfer learning with a unified text-to-text transformer.” JMLR 21.
H. Touvron et al. (2023). “LLaMA: open and efficient foundation language models.” arXiv:2302.13971.
In exercise 2 RMSNorm matched LayerNorm, and both kept training stable where the unnormalised network was on the edge.
Practice
Show:
Level 0
Problem 1Level 0
RMS of (2, −2)?
2.
Problem 2Level 0
RMSNorm gain parameters for d = 4096?
4096.
Problem 3Level 0
RMS of every row after RMSNorm (no gain)?
1.
Level 1
Problem 4Level 1
RMS of (3, 4)?
√12.5 ≈ 3.536.
Problem 5Level 1
Second entry of RMSNorm(3, 4)?
4/3.536 ≈ 1.131.
Problem 6Level 1
First entry of RMSNorm(2, 0)?
2/√2 ≈ 1.414.
Problem 7Level 1
LayerNorm parameters (gain and bias) for d = 4096?
8192.
Level 2
Problem 8Level 2
RMSNorm accuracy at η = 0.03 in exercise 2?
0.998.
Problem 9Level 2
LayerNorm accuracy at η = 0.03?
0.982.
Problem 10Level 2
LayerNorm test CE at η = 0.03?
0.060.
Problem 11Level 2
RMSNorm accuracy at η = 0.003?
0.997.
Problem 12Level 2
Mean abs value of h at the head with RMSNorm at η = 0.03?
3.58.
Problem 13Level 2
Number of reductions RMSNorm needs?
1 (sum of squares).
Level 3
Problem 14Level 3
Show that RMSNorm equals LayerNorm on zero-mean inputs.
If mean(x) = 0, LayerNorm’s centring does nothing and its variance is mean(x²), so it divides by √(mean(x²) + ε) = RMS(x), exactly RMSNorm. ∎
Problem 15Level 3
Show that RMSNorm’s gradient is orthogonal to x.
With u = x/r, the gradient is (ḡ − u·mean(ḡ ⊙ u))/r. Its dot product with x = ru is (ḡ·u − (u·u)·mean(ḡ ⊙ u))·r/r = ḡ·u − d·(ḡ·u)/d = 0, since u·u = d (u has RMS 1). This is the consequence of scale invariance: scaling x does not change the output. ∎
Problem 16Level 3
Explain why dropping re-centring costs little in pre-norm transformers.
A constant offset shared by all features is one direction in feature space. The normalised vector is next multiplied by a learned weight matrix, which can ignore or use that direction as needed, and the residual stream carries the un-normalised signal past each block anyway. So removing the offset before the linear layer adds little; what matters for stability is controlling the scale, which RMSNorm still does. ∎
Problem 17Level 3
Advise whether to switch an onboard transformer from LayerNorm to RMSNorm.
For a model trained from scratch, RMSNorm is a sensible default: similar accuracy with cheaper, simpler kernels. For an existing trained model, switching requires retraining or careful fine-tuning, because the weights were learned with centred inputs. Measure the actual latency gain on the target hardware (normalisation may be a small share of runtime) and compute the RMS in float32 if running in reduced precision. ∎
Level 4
Problem 18Level 4
RMSNorm test CE at η = 0.03?
0.007.
Problem 19Level 4
LayerNorm accuracy at η = 0.003?
0.996.
Problem 20Level 4
No-normalisation accuracy at η = 0.003?
0.999.
Coding practice
🐍 Code 1 (Level 0): root mean square
√mean(x²).
🐍 Code 2 (Level 0): RMS-normalise
x/√(mean(x²) + ε) along the last axis.
🐍 Code 3 (Level 0): parameters
2d for LayerNorm, d for RMSNorm.
🐍 Code 4 (Level 0): reductions
2 for LayerNorm, 1 for RMSNorm.
🐍 Code 5 (Level 1): effect of a shift
Max change in RMSNorm's output when a constant is added.
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
RMSNorm: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.