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.
#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 and a learned shift , 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:
Read the right-hand one slowly. Square every entry, take the average of the squares, add a tiny , 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 .
The figure applies both norms to the same input. LayerNorm first subtracts the mean; RMSNorm divides the original vector by its root mean square.
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 .
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 . So becomes : 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 . Subtracting the mean always lands on the line : it removes the component along the all-ones direction . Then it rescales onto the circle. With two numbers the line meets the circle at only two points, and , so every two-number input becomes one of two outputs. Most of the information is gone.
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.
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 . 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.
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 | (, ) | () |
| 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.
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.
A reference implementation
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 gainThree 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 , 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 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 ; 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.