Learn
Architecture

What is RMSNorm, and why use pre-norm?

The short answer

RMSNorm rescales each token's vector by its root mean square, then applies a learned per-dimension scale. It skips the mean subtraction and bias that LayerNorm uses, which makes it cheaper and slightly more stable in low precision. Pre-norm means normalising before each sub-layer so gradients flow cleanly through the residual path, which is what lets very deep transformers train.

On this page

What normalisation is for

Each transformer block adds its output to a shared residual vector. Over 32 or 80 layers those additions accumulate, and the scale of the vector drifts upward - sometimes by an order of magnitude between early and late layers. Without normalisation, learning rates that work at layer 3 are wrong at layer 60, and low-precision arithmetic overflows or underflows depending on where you are in the stack.

Normalisation fixes the scale at each sub-layer input, so every block sees activations with a predictable distribution. That makes the loss surface smoother, allows a single learning rate across depth, and keeps bf16 or fp16 arithmetic inside its useful range. It is one of the two or three choices that made deep transformers practical at all.

The standard tool is LayerNorm: subtract the mean across the hidden dimension, divide by the standard deviation, then apply a learned scale gamma and bias beta, per dimension. It works well, costs two reductions over the hidden vector, and has been the default since the original transformer.

What RMSNorm removes

RMSNorm, introduced by Zhang and Sennrich in 2019, keeps the rescaling and drops the re-centring. Instead of mean and variance it computes only the root mean square: rms(x) = sqrt(mean(x^2) + epsilon). The output is y = gamma * x / rms(x), with no subtraction and no bias term.

The argument for dropping the mean is empirical and slightly subtle. Re-centring makes LayerNorm invariant to adding a constant to every dimension, but the linear layer that follows can already absorb a constant shift through its bias - and modern models have removed biases anyway. What actually matters for stability is controlling magnitude, and the root mean square measures exactly that. In practice the mean subtraction contributes little to quality and costs a reduction over the hidden dimension.

Removing beta also removes parameters, though only d per layer, which is negligible against a 135M-parameter feed-forward. The real saving is arithmetic and memory traffic: one reduction instead of two, no separate bias vector to load, and a simpler kernel. The original paper reported 7-64% faster normalisation depending on the model, which translates to a few percent end-to-end - not dramatic, but free.

The formula and what each part does

Write it out: given a hidden vector x of dimension d, compute s = sqrt((1/d) sum x_i^2 + epsilon), then output y_i = gamma_i * x_i / s. The epsilon, typically 1e-5 or 1e-6, prevents division by zero when a vector is all zeros, which can happen after masking or in a degenerate batch.

gamma is a learned vector of length d, initialised to ones. It lets the model restore or amplify individual dimensions after normalisation, which is essential: without it the layer would force every dimension to unit RMS and destroy information the network needs. Crucially, gamma is a per-dimension scale, so it can learn that dimension 37 should be large and dimension 38 small.

Because the layer is scale-invariant apart from epsilon, multiplying x by any positive constant leaves the output unchanged. That is a genuinely useful property: if one layer's weights grow during training, the next block's normalisation removes the effect rather than amplifying it. The exception is a single huge outlier dimension, which inflates the RMS and suppresses everything else - a known issue in low-precision inference with models that develop massive activations.

Why it became the default

  • Cheaper: one reduction instead of two, and no bias vector to load or update.
  • Stable in bf16: fewer intermediate quantities means less rounding error, and the computation is easy to keep in fp32 where it matters.
  • Fewer parameters and simpler kernels, which helps fusion with the following matrix multiply.
  • No measurable quality loss at LLM scale in published comparisons; most frontier open models use it.
  • Composes cleanly with tensor parallelism, since the norm is replicated and only needs the full hidden vector locally.
  • Works well with the pre-norm layout, where the norm sits directly on the residual stream.

Pre-norm versus post-norm

The original transformer normalised after each sub-layer: x = LayerNorm(x + Sublayer(x)). This is post-norm. Gradients must pass through the normalisation on the way back, and at depth the interaction between the residual addition and the normalisation makes training unstable unless you warm up the learning rate carefully and keep it small. It works, but it is fussy.

Pre-norm moves the normalisation inside the branch: x = x + Sublayer(Norm(x)). Now the residual path from input to output is a pure sum with no normalisation in it, so gradients reach early layers almost unchanged. Stacks of 80 or 100 layers train without warmup heroics, and the model is far less sensitive to learning-rate choice. GPT-2 onward, essentially every large language model is pre-norm.

The cost is that the residual stream's magnitude grows with depth, since nothing rescales it between blocks. A final normalisation before the unembedding handles that, and in practice the growth is benign. Pre-norm models sometimes underperform matched post-norm models slightly at shallow depth, which is why some vision transformers still use post-norm with careful initialisation.

Reading the residual stream

Because pre-norm leaves the residual path untouched, each block's contribution is added to a vector whose norm keeps increasing. Interpretability work exploits this: you can read the residual stream at any layer and project it to vocabulary scores, and you see a prediction forming progressively - early layers weakly favour the right answer, later layers sharpen it.

It also means individual layers can be ablated or swapped with limited immediate damage, because their output is one term in a long sum rather than the only path forward. That property underpins techniques like layer skipping, early exit and activation steering, all of which manipulate the residual stream directly.

The practical consequence for debugging is that a broken layer often does not crash the model - it just adds noise to the sum. Loss curves look fine, samples look like text, and quality is quietly worse. When something feels subtly off after a checkpoint conversion, compare residual norms per layer against the reference; a spike or a collapse localises the bug quickly.

Variants worth knowing

DeepNorm scales the residual branch and initialises weights so that very deep post-norm stacks - 1,000 layers in the original paper - train stably. It is used mainly in machine translation and vision, not in LLM pretraining.

QK-norm applies a normalisation to queries and keys per head before the attention score computation, which bounds the logits and prevents attention entropy collapse during long training runs. It appears in several large multimodal models and in architectures trained at very long context.

Sandwich normalisation adds a norm after each sub-layer in addition to before it, which helps at extreme depth and in low precision. Gemma-style models apply RMSNorm with a (1 + gamma) parameterisation, a small change that improves gradient behaviour at initialisation. None of these are exotic; they are all variations on the same theme of controlling scale where it matters.

Implementation details that bite

  • Compute the mean of squares in fp32. In bf16 the sum over 4,096 or 8,192 dimensions loses enough precision to change results.
  • Match epsilon between training and inference. A checkpoint trained with 1e-6 and served with 1e-5 behaves slightly differently, which matters at long context.
  • Initialise gamma to one, and exclude norm parameters from weight decay - decaying them toward zero degrades every layer at once.
  • In tensor parallelism, keep norm weights replicated on every device; the norm needs the full hidden vector, so sharding it forces an extra all-reduce.
  • Do not apply the final norm twice. Pre-norm models need exactly one final RMSNorm before the unembedding, and a duplicated one scales the logits.
  • Keep the whole normalisation in a fused kernel. Done naively it becomes several memory-bound passes over the hidden vector, which is slower than the arithmetic suggests.

Sizing and cost

RMSNorm adds d parameters per layer, or 2d for LayerNorm with its bias. A 32-layer model with d_model 4,096 has 131K normalisation parameters - about 0.002% of a 7B model. The cost is not parameters but memory traffic: each norm reads and writes the full hidden vector, so at batch 32 and 4,096 tokens it touches 32 x 4,096 x 4,096 x 2 bytes ~ 1 GiB per layer if not fused.

That is why fusion matters more than the arithmetic. A fused RMSNorm that runs in one pass, keeps the result in registers and immediately feeds the next matmul can be several times faster than a naive three-pass implementation. Most serving stacks already do this; if you are writing custom kernels, it is the first thing to check.

For capacity planning, ignore the norm. For latency debugging at long context, do not: normalisation is a small fraction of FLOPs but a non-trivial fraction of memory traffic, and it is the layer most often left unfused in hand-rolled inference code.

Normalisation and low-precision inference

Trained transformers develop outlier features: a handful of dimensions whose values are 50-100x larger than the rest. LayerNorm's mean subtraction partially tames them, because subtracting a large mean shifts every dimension. RMSNorm does not subtract anything, so a single huge dimension inflates the root mean square and scales the entire vector down, burying the smaller features in quantisation noise.

This is the main practical difficulty when quantising an RMSNorm model to int8. Per-tensor scaling has to accommodate the outlier, which leaves the other 4,095 dimensions with very few effective bits. The usual fixes are per-channel scaling for the weights, keeping the outlier dimensions in higher precision, or applying a learned smoothing transform before quantisation that shifts magnitude from activations into weights.

At fp16 and bf16 the effect is mild, and at 8-bit weights with 16-bit activations it is usually invisible. It becomes visible at 4-bit weights with 8-bit activations or when quantising the key-value cache, and it is one reason a quantised model can pass a short-prompt smoke test and fail on long-context retrieval. If you quantise, evaluate at the context length you serve.

Common mistakes

The most damaging mistake is mixing layouts. A checkpoint trained with pre-norm will not work if you load it into a post-norm implementation: the weights have learned to expect normalised inputs at the branch and an unnormalised residual stream. The model will run, produce plausible-looking tokens, and be substantially worse than reported. Check the code path, not just the parameter shapes.

The second is assuming RMSNorm and LayerNorm are interchangeable. They are close enough that a conversion sometimes appears to work, but the missing mean subtraction changes the effective function, and gamma has been trained under different assumptions. Convert the architecture definition, not just the state dict keys.

The third is numerical. Running the norm in bf16, using an epsilon that is too small for the activation range, or forgetting to upcast before the sum of squares all produce losses that look normal and outputs that are subtly degraded, especially at long context where the residual stream grows largest.

A fourth is subtler: tuning epsilon to make a smoke test pass. Epsilon is a numerical guard, not a hyperparameter, and changing it to hide a precision bug moves the failure to a longer sequence or a different batch size. Fix the precision, then leave epsilon alone.

Why pre-norm won

Pre-norm won because it removed a tuning problem. Post-norm transformers require learning-rate warmup, careful initialisation and a bit of luck to train at 24 layers and beyond; pre-norm transformers train at 100 layers with the same recipe you would use at 12. When a change turns a fragile recipe into a boring one, it spreads, and the small quality difference at shallow depth stops mattering.

The combination that defines the current consensus stack - pre-norm RMSNorm, SwiGLU feed-forward, rotary position embeddings, grouped-query attention - is not the product of one breakthrough. It is four separate simplifications that each made training or serving a little more predictable. Reading a model card, those four names tell you more about how the model behaves than the parameter count does.

Page feedback

Was this helpful?

A quick signal helps improve these notes.

Report a mistake Straight to the lab inbox

Put it to work

See the models, datasets and gateway this lab runs.