Highlights

Contents

Part II
02

RMSNorm: Rescale, Skip the Re-Centring

Deep stacks need reliable scale control. RMSNorm simplifies LayerNorm by omitting centering. Compare the geometric difference, gain convention, placement, and precision choices a port must preserve.

YOU ARE HEREMODERN DECODER BLOCKATTENTION HALFRMSNormq, k, v projRoPE (q, k)GQA: 8 q, 2 kvSDPAFlash kernelo proj+MLP HALFRMSNormgate, up projSiLU(g) ⊙ udown proj+residual stream: x + Attn(Norm(x)), then h + MLP(Norm(h))what changed since GPT-2: positions, norm, MLP, K/V sharing, the attention kernel, and no biases

#Section 7Two Jobs, and the 2019 Question

Recall LayerNorm from Chapter 1, Section 66. For each token’s vector it does two separate things. First it re-centres: subtract the average of the vector’s entries, so they average to zero. Then it rescales: divide by their standard deviation, so their spread is one. Finally a learned gain γ\gamma and a learned shift β\beta, one per channel, let the model undo either effect where useful.

Why normalize at all? A deep network passes each token's vector through dozens of layers, and if each layer can make its output a bit larger or smaller, the scale drifts multiplicatively. A drift of 10% per layer compounds to a factor of 17 over 30 layers. Normalization resets the scale before each sub-layer, so every sub-layer sees inputs of a familiar size no matter what happened before. That keeps training stable and makes the learning rate meaningful across depth.

Zhang and Sennrich proposed RMSNorm in 2019 after finding that scale control could retain quality without mean subtraction in their experiments. Re-scaling invariance means a positive rescaling leaves the normalized direction unchanged, ignoring epsilon's effect near zero.

#Section 8The Computation, Side by Side

Here are both formulas:

LayerNorm(x)=x−μσ2+ε⊙γ+βRMSNorm(x)=x1d∑ixi2+ε⊙γ\text{LayerNorm}(x) = \frac{x - \mu}{\sqrt{\sigma^2 + \varepsilon}} \odot \gamma + \beta \qquad \text{RMSNorm}(x) = \frac{x}{\sqrt{\tfrac{1}{d}\sum_{i} x_i^2 + \varepsilon}} \odot \gamma

Read the right-hand one slowly. Square every entry, take the average of the squares, add a tiny ε\varepsilon, take the square root, and divide the vector by the result. That denominator is the root mean square, RMS, of the vector: literally the square root of the mean of the squares, a way of measuring its typical size. Then multiply each entry by its learned gain. No mean is subtracted and there is no β\beta.

The figure applies both norms to the same input. LayerNorm first subtracts the mean; RMSNorm divides the original vector by its root mean square.

SAME INPUT, TWO NORMS (x = [2, −1, 4, 3], γ = 1, β = 0, ε IGNORED)LayerNormx2-143mean = 2 (pass 1)x − mean0-321var = 3.5, sd = 1.871 (pass 2)÷ sd0-1.6041.0690.535× γ + βRMSNormx2-143mean of squares = 30 / 4 = 7.5 (one pass)÷ √7.5 = 2.7390.730-0.3651.4611.095× γ, no βno centring:one fewer pass,no β to learnLayerNorm output has mean 0 and spread 1. RMSNorm output keeps the input’s direction and has root-mean-square 1.
Figure 2.10The same input through both norms. LayerNorm takes two passes over the vector and centres it; RMSNorm takes one pass and keeps its direction.

Before learned gain and shift, LayerNorm centers the vector. RMSNorm instead preserves its direction while controlling size.

#Section 9What the Two Norms Do Geometrically

To picture the difference, use a vector with just two numbers, so it is a point on a flat plane. Take x=(2.0,0.6)x = (2.0, 0.6).

RMSNorm keeps the point's direction and slides it along that direction until its root mean square is 1. With two numbers, "root mean square 1" means the point lies on a circle of radius 2\sqrt 2. So (2.0,0.6)(2.0, 0.6) becomes (1.355,0.406)(1.355, 0.406): the same direction, on the circle. Every possible input direction maps to a different point on the circle, so no directional information is lost.

LayerNorm first subtracts the mean, 1.3, giving (0.7,−0.7)(0.7, -0.7). Subtracting the mean always lands on the line x1+x2=0x_1 + x_2 = 0: it removes the component along the all-ones direction (1,1)(1, 1). Then it rescales onto the circle. With two numbers the line meets the circle at only two points, (1,−1)(1, -1) and (−1,1)(-1, 1), so every two-number input becomes one of two outputs. Most of the information is gone.

TWO NUMBERS, SO A POINT ON A PLANE: WHERE EACH NORM SENDS x = (2.0, 0.6)RMSNormx(1.35, 0.41)same direction, slid onto the circleLayerNormxx₁ + x₂ = 0(1, −1)(−1, 1)centred onto the line, then the circle: only 2 possible outputs
Figure 2.11Where each norm sends the point (2.0, 0.6). RMSNorm keeps its direction and moves it onto the circle. LayerNorm first projects it onto the line x₁ + x₂ = 0, so only two outputs are possible.

With hundreds of numbers instead of two, LayerNorm loses much less: it discards exactly one direction out of 512, the all-ones direction, and keeps the other 511. But that is still one direction thrown away for no clear benefit, and a computation spent doing it.

What each norm ignores

Ignoring epsilon, both norms cancel positive input scaling. Only LayerNorm cancels a constant offset across channels. RMSNorm therefore preserves directional information that centering removes.

WHAT EACH NORM IGNORES: CHANGE THE INPUT, DOES THE OUTPUT CHANGE?LayerNormRMSNormx = [2, −1, 4, 3]reference2 × x = [4, −2, 8, 6]scaleignored ✓ignored ✓x + 3 = [5, 2, 7, 6]shiftignored ✓changes: [0.94, 0.37, 1.31, 1.12]the paper’s finding: ignoring scale is what matters, not ignoring shift
Figure 2.12Both norms ignore scaling the input. Only LayerNorm ignores shifting it. The RMSNorm paper's result is that ignoring shifts was never what made LayerNorm useful.

The surprising empirical finding is that losing shift invariance costs nothing measurable. The residual stream does not tend to drift by a constant offset across all channels in the way it drifts in overall scale, so there is nothing for re-centring to fix.

#Section 10The Learned Gain and What You Save

γ: one learned number per channel

After normalizing, RMSNorm multiplies each channel by its gain γi\gamma_i. The gain starts at 1 for every channel, so at initialization the norm only rescales. During training, the model learns to make some channels louder and others quieter, which matters because the normalization itself treats every channel identically.

A TRAINED γ: ONE GAIN PER CHANNEL, MOSTLY NEAR 1, A FEW HUGE (ILLUSTRATIVE, 64 CHANNELS)1outlier channelschannel index
Figure 2.13A trained RMSNorm gain vector. Most entries stay near 1, where they started; a couple of channels grow far larger. (Illustrative, but the pattern is well documented.)

In trained models most gains stay near their starting value, but a handful of channels typically grow very large. These outlier channels are well documented in large models. They seem to be part of how the model works internally, and they cause real trouble when people compress models into 8-bit integers, because one scale factor has to cover both the tiny ordinary channels and the huge outliers.

What you save

A reduction sums across a vector. RMSNorm needs a squared-value reduction without first subtracting a mean, and it omits the learned bias. Actual kernel savings depend on how the operations are fused.

LayerNorm RMSNorm
Reductions per vector 2 (mean, variance) 1 (mean of squares)
Learned parameters 2d2d (γ\gamma, β\beta) dd (γ\gamma)
Ignores input scale yes yes
Ignores input shift yes no
Finch model norm parameters 17,408 (Finch-19) 8,704 (Finch-24)

On its own, normalization is a small share of a training step, so the saving is a few percent of the total rather than a dramatic speed-up. But norms run twice in every block, the kernel is simpler to fuse with neighbouring operations, and fewer parts means fewer things to get wrong.

#Section 11Where the Norms Sit, and the ε

Pre-norm, sandwich and QK-norm

Modern models do not all put norms in the same places. Pre-norm, as in Chapter 1, puts one RMSNorm before attention and one before the MLP, with a final RMSNorm before the output head. Llama, Mistral and Finch-24 do this. Sandwich norm adds a second norm after each sub-layer too, before its output is added back to the stream; Gemma 2 does this, which bounds how much any one sub-layer can add. QK-norm also normalizes the queries and the keys inside attention, after their projections and before RoPE and the dot product. That stops attention scores from growing out of control in large or long training runs, a failure mode where a few logits become huge, softmax saturates and the loss spikes. OLMo 2, Gemma 3 and Qwen3 use QK-norm.

THREE PLACES MODERN MODELS PUT NORMSpre-normLlama, Mistral, Finch-24RMSNormattention+ residualRMSNormMLP+ residualsandwichGemma 2RMSNormattentionRMSNorm+ residualRMSNormMLPRMSNormQK-normOLMo 2, Gemma 3, Qwen3RMSNormq, k, v projRMSNorm(q), RMSNorm(k)RoPE, attention+ residual…
Figure 2.14Three placements. Pre-norm normalizes the input of each sub-layer; sandwich norm also normalizes each output; QK-norm also normalizes queries and keys inside attention.

What ε does

Epsilon prevents division by zero. For sufficiently large inputs its effect is small; near zero it dominates the denominator, preventing tiny noise from being amplified to full scale.

OUTPUT SIZE AGAINST INPUT SIZE FOR RMSNorm, ε = 1e-5 (LOG SCALES)input RMS (log10)output RMS (log10)√ε ≈ 0.00321e-61e-41e-21e0normal inputs:output size 1tiny inputs: ε wins,output shrinks too
Figure 2.15Output size against input size for RMSNorm. Above the square root of ε, outputs have size 1. Below it, ε takes over and the output shrinks with the input.

A reference implementation

python
class RMSNorm(nn.Module):
    def __init__(self, dim, eps=1e-5):
        super().__init__()
        self.eps = eps
        self.weight = nn.Parameter(torch.ones(dim))       # gamma starts at 1

    def forward(self, x):                                  # x: (B, T, dim), often bf16
        x32 = x.float()                                    # square in fp32
        x32 = x32 * torch.rsqrt(x32.pow(2).mean(-1, keepdim=True) + self.eps)
        return self.weight * x32.type_as(x)                # back to input dtype, then gain

Three details in eight lines are worth noticing. The weight starts at all ones, so the norm is a pure rescale at initialization. The input is converted to 32-bit floats before squaring, because in 16-bit formats squaring a moderately large activation can overflow or lose precision. And rsqrt computes one over the square root in a single operation, so the division becomes a multiplication.

Sharp edges of RMSNorm

Gemma stores γ − 1. Gemma's RMSNorm computes x⋅(1+γ)x \cdot (1 + \gamma), so its saved weights sit near 0 instead of near 1. Load them into ordinary RMSNorm code and every layer's output is multiplied by roughly zero. Check how the weight is applied before porting.

Squaring in bf16. Skip the conversion to 32-bit and large activations can overflow when squared, or lose enough precision to change results. Convert before the power, convert back after.

Weight decay on γ. Weight decay pulls weights toward zero. For a gain, zero means "silence this channel", which is not a sensible default. Exclude norm weights (and biases, where they exist) from weight decay.

ε inside or outside the root. Most code adds ε\varepsilon inside the square root; some adds it outside. The difference is tiny but enough to make numerical checks against a reference implementation fail. Match the reference exactly.

The order of the cast and the gain. Llama's reference casts back to the input type before multiplying by γ\gamma; some other code multiplies in 32-bit first. Outputs differ in the last bits, which matters when you are checking a port against reference logits.