A transformer block can be written post-LN, , or pre-LN, . How do gradients flow back through layers in the two, and why does post-LN usually need learning-rate warm-up?
Sequence models and transformers, Transformers
Level L4 Advanced. Length Long. Nature Th+Mat Both.
What's being asked
Whether you can see that pre-LN keeps an identity path for the gradient while post-LN passes it through a layer norm at every block.
Key idea
Pre-LN: , so there is always an identity path. Post-LN: , with a layer-norm Jacobian at every layer (later layers multiply on the left).
Steps
- Pre-LN: write . Then .
- Multiplying over layers and expanding, . The identity term carries the loss gradient from the output to any layer with no attenuation. The LN sits inside the branch, not on the residual path.
- Post-LN: , where is the layer-norm Jacobian. For input it contains and projects out the mean and scale directions.
- The residual stream is rescaled at each layer, so there is no clean identity path. The product of Jacobians can shrink or grow.
- Xiong et al. (2020) analyse both at initialisation. For post-LN, the gradient of the last layer's parameters is of order whatever is, and it is large near the output and decays towards lower layers. For pre-LN it is of order and about the same size in every layer. A large early learning rate on the big post-LN gradients near the output makes training unstable, so warm-up is needed. For pre-LN the gradients are well-behaved and warm-up can often be dropped.
- Trade-off: in pre-LN the residual stream norm grows with depth, so deep layers add relatively little to it, and a final layer norm is needed before the output. Post-LN can give slightly better final quality when it trains.
Common mistakes
- Saying pre-LN "has no layer norm on the residual path" without saying why that matters for the gradient.
- Claiming post-LN has vanishing gradients at every layer; the issue at initialisation is the scale mismatch across layers.
- Forgetting the final layer norm in pre-LN.
How long your answer should be
Half a page to a page; 6–8 minutes.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: How can softmax attention be written as a kernel smoother? Why does replacing by a feature-map kernel reduce the cost from to ? How can causal linear attention be computed as an RNN, and what is lost?
Next in Sequence models and transformers: What is an induction head, and how can a two-layer attention-only transformer use a pair of heads to complete a pattern such as ? What evidence ties induction heads to in-context learning?