Paper Breakdowns  /  LayerNorm & RMSNorm
Paper 47~11 min read2016 & 2019worked math + runnable code
Paper Breakdown

LayerNorm & RMSNorm,
explained.

Batch normalization transformed vision, but it has a flaw that makes it awkward for language: it depends on the batch. Layer normalization fixed that by normalizing within a single example — and became the quiet workhorse inside every transformer. Then RMSNorm asked a sharp question: do we even need to subtract the mean? Here are both, the precise invariances that separate them, and the tidy case where they're exactly the same.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

The batch-dependence problem

Batch normalization computes its statistics across the examples in a mini-batch. That is fine for a stack of images, but it breaks down for language. Sequences vary in length; batches are often small; and in autoregressive generation you process one token at a time — there is no batch to average over. Worse, batch statistics make one example's output depend on which others happen to share its batch, which is a strange property for a model that should treat each input on its own terms.

Layer normalization sidesteps all of it with one change of axis: instead of normalizing each feature across examples, normalize each example across its own features. Now the computation involves only the single example in front of it — identical at train and test time, indifferent to batch size, perfect for sequences.

The one-sentence version

Batch norm normalizes down the batch; layer norm normalizes across one example's features — so it needs no batch, which is exactly what a transformer wants.

02

LayerNorm: normalize the example

For a single feature vector x (say the hidden state at one token position), layer norm computes the mean and variance over that vector's own components, standardizes, then applies a learnable per-feature scale γ and shift β — the same γ/β for every position, learned during training.

μ = mean(x)   σ² = var(x)   y = γ · (x − μ)/√(σ² + ε) + β

The shape of the transform is identical to batch norm's; only the axis of the statistics moved. That single move is why it slots cleanly into transformers — it appears before or after each attention and feed-forward sub-layer (the "pre-norm" vs "post-norm" choice), keeping activations at a controlled scale block after block, all the way down a hundred-layer stack.

03

RMSNorm: drop the mean

RMSNorm asked whether the mean-centering earns its keep. Its answer: mostly no. It removes both the mean subtraction and the learnable shift β, and simply rescales the vector by its root-mean-square. Side by side:

LayerNorm:   y = γ · (x − μ) / √(σ² + ε) + β
RMSNorm:    y = γ · x / √( mean(x²) + ε )

RMSNorm keeps the useful part — bounding the vector's magnitude so the next layer sees a controlled scale — and drops the centering. It computes one statistic instead of two and skips a subtraction across the whole hidden dimension, which at billions of parameters and trillions of tokens is a real saving. In practice it matches LayerNorm's quality, so most recent LLMs (LLaMA, and many since) use it. The runnable version below shows the exact consequence of dropping the mean — and the case where it makes no difference at all.

04

The invariances that differ

The mathematical difference between the two is captured entirely by their invariances — what you can do to the input without changing the output. Both are invariant to rescaling the input vector (multiply every component by a constant and the normalization cancels it). But only LayerNorm is invariant to shifting — adding a constant to every component — because only LayerNorm subtracts the mean.

Transform on inputLayerNormRMSNorm
Rescale (x → c·x)invariantinvariant
Shift (x → x + b)invariantchanges the output
When mean(x) = 0the two are exactly identical (β = 0)

That last row is the punchline: RMSNorm is precisely LayerNorm with the centering deleted, so on any already-centered input they compute the very same thing. The empirical success of RMSNorm is essentially the finding that, for deep transformers, the shift-invariance LayerNorm provided was not doing much load-bearing work.

RUN IT YOURSELF

Two normalizers, and where they diverge

Both layers in a few lines, with their defining properties made checkable. LayerNorm standardizes a single vector to mean 0 / variance 1 and is invariant to shifting and rescaling it. RMSNorm scales to unit root-mean-square and is invariant to rescaling — but shifting the input does change its output, the one real difference. And on a zero-mean input the two produce byte-for-byte the same numbers. Edit the vector (try one that isn't centered) and watch the shift sensitivity appear.

CPython · WebAssembly
05

Which, and where

A quick map of the normalization landscape and when each is the right reach:

NormNormalizes overTypical home
Batch normeach feature, across the batchCNNs / vision
Layer normall features of one exampletransformers, RNNs (original)
RMSNormone example, RMS only (no mean)modern LLMs (LLaMA-style)
Group / instance normfeature groups of one examplevision where batches are small

Inside a transformer block, the other live decision is placement: post-norm (original) applies the norm after the residual addition; pre-norm applies it inside the residual branch, before the sub-layer. Pre-norm makes very deep stacks far more stable to train, which is why nearly all large models use it — often with RMSNorm as the norm of choice.

06

Why it matters

Open the source of any modern language model and you will find a normalization layer at the top of every block — almost always LayerNorm or RMSNorm. They are not glamorous, but they are load-bearing: without them, gradients through a deep pre-norm stack would not stay well-scaled, and training the models we take for granted would be far harder. Layer norm is one of the three or four ideas that made the transformer trainable at scale.

RMSNorm's arc is a small lesson in engineering, too. It won not by adding capability but by removing a piece — the mean subtraction — that careful measurement showed was carrying little weight. Faster and simpler, at no measured cost in quality: exactly the kind of subtraction that compounds when you are training a model a trillion tokens at a time.

Worth knowing

Because RMSNorm has no mean subtraction and no bias, it also has fewer parameters and a simpler backward pass — small per-layer savings that add up across dozens of layers and every token of a long training run.

Frequently asked

Quick answers

LayerNorm vs batch norm?

Batch norm normalizes each feature across the batch; layer norm normalizes all features within one example. Layer norm needs no batch, so it fits transformers and RNNs.

What does RMSNorm remove?

The mean-centering and the learnable shift β. It just divides by the root-mean-square and scales by γ — cheaper, and equal to LayerNorm when the input is already zero-mean.

Why do modern LLMs prefer RMSNorm?

It matches LayerNorm's quality while computing one statistic instead of two and skipping a subtraction — a real saving at LLM scale, with fewer parameters.

What's the key mathematical difference?

Both are invariant to rescaling the input; only LayerNorm is invariant to shifting it, because only LayerNorm subtracts the mean.

Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns