Pre-norm and post-norm: follow the residual path
Pre-norm (Pre-LN) and post-norm (Post-LN) change where normalisation sits around the residual branch. What does that do to the layer?
Which vector should we normalise?
Our rabbit’s representation travels along the residual stream. A network reads it, calculates an update, and adds that update back.
We have learned how RMSNorm can control a vector’s scale. But there are several vectors here. Which one should it change?
Start without a norm below. Follow the original token down the left, then follow the branch that calculates its update.
Give the network a normalised copy
Choose Branch input. The norm changes what the network reads, while the original token continues down the residual path.
This is pre-norm: normalise before the attention or feed-forward calculation.
Or control what the network adds
What if we want the network to read the original vector, but control the size of the update it sends back?
Choose Branch output. The norm now waits for the network’s result. The vector labelled Reads changes, and so does the calculation that follows.
The original token still reaches the addition untouched. Only the update is normalised.
What if the norm goes on the stream?
Choose After addition. First combine the token and its update. Then normalise that whole result.
This is post-norm. It changes the combined stream, including the contribution carried along the skip.
That is why moving the box matters. Normalising an update before addition is different from normalising the sum afterwards.
Back to the whole layer
The same choice applies to both attention and feed-forward. In this pre-norm arrangement, each branch gets its own normalised input:
The residual route stays direct through the additions. Across many layers, that also gives training signals a path that does not repeatedly pass through a norm.
We can put norms inside attention too. QK-norm follows what happens when we normalise the queries and keys before comparing them.
Sources
- On Layer Normalization in the Transformer Architecture, Xiong and colleagues: pre-norm, post-norm, their residual paths and gradient behaviour at initialisation.
- Llama reference implementation: norms on the inputs to attention and feed-forward, with residual additions outside them.
- 2 OLMo 2 Furious: reordered normalisation on branch outputs, before residual addition. This differs from original Transformer post-norm, which normalises the residual sum.
- Attention Is All You Need: LayerNorm after the sublayer and residual addition. Placement and the choice between LayerNorm and RMSNorm are separate decisions.
The interactive figure uses RMSNorm with unit learned scales and one fixed feed-forward network: an expanding matrix, SiLU, and a contracting matrix. All coloured vectors are calculated from that network. Dimension labels show the selected model’s token width.