Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Keeping values in range

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.

Move the norm

Interactive

Keep the stream, add an update

The network reads the original token. Its update is added to the unchanged residual path.

One residual branch, with normalisation in different positionsA token travels down the residual stream on the left. A branch on the right reads it through a feed-forward network and adds an update. Move the RMSNorm box to the branch input, branch output, or after the residual addition. The coloured vectors are calculated with the same network weights in every arrangement.“rabbit”Residual streamFeed-forward+Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.507Coordinate 2: -0.081Coordinate 3: 0.649Coordinate 4: 1.100Coordinate 5: 0.947Coordinate 6: 0.902Coordinate 7: 0.443Coordinate 8: 4.588Coordinate 9: -2.412Coordinate 10: -1.749Coordinate 11: -2.372Coordinate 12: -2.528Coordinate 13: -2.872Coordinate 14: 0.201Coordinate 15: -0.799Coordinate 16: -3.104Coordinate 17: -0.905Coordinate 18: 2.702Current token computation.Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.507Coordinate 2: -0.081Coordinate 3: 0.649Coordinate 4: 1.100Coordinate 5: 0.947Coordinate 6: 0.902Coordinate 7: 0.443Coordinate 8: 4.588Coordinate 9: -2.412Coordinate 10: -1.749Coordinate 11: -2.372Coordinate 12: -2.528Coordinate 13: -2.872Coordinate 14: 0.201Coordinate 15: -0.799Coordinate 16: -3.104Coordinate 17: -0.905Coordinate 18: 2.702Current token computation.Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.932Coordinate 2: -1.455Coordinate 3: 0.211Coordinate 4: 0.147Coordinate 5: -0.439Coordinate 6: -0.077Coordinate 7: 0.480Coordinate 8: 0.981Coordinate 9: 0.887Coordinate 10: 0.778Coordinate 11: 1.336Coordinate 12: 0.284Coordinate 13: 0.361Coordinate 14: 0.615Coordinate 15: 1.315Coordinate 16: 0.508Coordinate 17: -0.133Coordinate 18: 1.028Current token computation.Earlier context is dimmed; outlined columns are current.Coordinate 1: 1.439Coordinate 2: -1.536Coordinate 3: 0.860Coordinate 4: 1.247Coordinate 5: 0.508Coordinate 6: 0.824Coordinate 7: 0.924Coordinate 8: 5.569Coordinate 9: -1.525Coordinate 10: -0.970Coordinate 11: -1.036Coordinate 12: -2.244Coordinate 13: -2.510Coordinate 14: 0.815Coordinate 15: 0.516Coordinate 16: -2.596Coordinate 17: -1.038Coordinate 18: 3.730Current token computation.ReadsUpdateNext representationRMSNorm7,1687,1687,1687,168Same token, same learned network; a different place to normalise.

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:

RMSNorm before attention and feed-forward, beside the residual streamRunning token representationResidual streamRMSNormAttentionUpdateRMSNormFeed-forwardUpdateUpdated token representation
Each branch reads a normalised input. Its update is added to the running residual stream.

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

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.

← Browse all subjectsBack to the beginning ↑