Zenaique

Pre-norm versus post-norm: which placement makes deep stacks stable?

MCQ·Medium·4.0 · 0·~1 min·Asked atBaiduOlaSalesforce·Relevant atMeta
Attempt it
TL;DR

Pre-norm puts LayerNorm inside the residual branch so the residual path is never normalized. Gradients flow cleanly back, deep stacks train without warmup, and every modern decoder LLM uses it.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a long telephone game played across 80 people. Post-norm is like having each person whisper to the next but a referee retunes the volume after every pair speaks. The retuning makes early whispers fade away because every retune slightly attenuates what came before. Pre-norm is like setting the volume once before each person speaks but leaving the original whisper untouched in a backchannel. The backchannel carries the original message clean across all 80 people; the retuning only affects what each person says into the channel. The second setup lets messages survive long chains, which is exactly what gradients need to do in deep networks.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

The placement of LayerNorm relative to the residual connection is one of the smallest architectural choices in transformers and one of the most consequential for training stability. The wrong placement (post-norm at depth) requires elaborate learning-rate warmup to even train. The right placement (pre-norm) lets you train 100-layer stacks with vanilla initialization and minimal warmup. The difference is gradient flow through the residual path.

This deep dive walks the gradient-flow argument that motivates pre-norm, traces the historical transition from the Vaswani 2017 post-norm layout to GPT-2's pre-norm switch, addresses the variance-growth concern that comes with pre-norm and the final-LayerNorm fix, and surveys the modern landscape of normalization choices in production LLMs.

Mental model: pre-norm gives the residual stream a clean identity path that gradients can flow through unattenuated. Post-norm puts a LayerNorm on every residual path, compounding the gradient distortion across depth.

The two formulas and what each does to the residual path

The residual connection is the structural innovation that made very deep networks trainable. The standard recursion is:

xl+1=xl+fl(xl)x_{l+1} = x_l + f_l(x_l)

where f_l is the sub-layer (attention or FFN). The residual path lets gradients flow back through depth without passing through the (potentially attenuating) f_l operation.

LayerNorm is the standard normalization in transformers. The question is where to insert it.

Post-norm formula

xl+1=LN(xl+fl(xl))x_{l+1} = \text{LN}(x_l + f_l(x_l))

The LN is applied AFTER the residual add. The entire residual stream gets normalized at every layer.

Pre-norm formula

xl+1=xl+fl(LN(xl))x_{l+1} = x_l + f_l(\text{LN}(x_l))

The LN is applied INSIDE the residual branch, on the input to f_l. The residual path itself is never normalized.

Why the difference matters for gradient flow

Unroll pre-norm over L layers:

xL=x0+l=0L1fl(LN(xl))x_L = x_0 + \sum_{l=0}^{L-1} f_l(\text{LN}(x_l))

The Jacobian dx_L / dx_0 has an identity term (from the unattenuated residual sum) plus contributions from each f_l. Gradients reach x_0 cleanly through the identity path.

Unroll post-norm. The recursion is:

xl+1=LN(xl+fl(xl))x_{l+1} = \text{LN}(x_l + f_l(x_l))

The Jacobian dx_L / dx_0 involves L compositions of LN's Jacobian along the gradient path. Each LN has Jacobian rank-deficient (removes the mean direction) and scales by inverse variance, which can be much less than 1 if activations have large variance. Compounded over L = 50 or 100 layers, the gradient signal in early layers degrades sharply.

The historical transition
The variance-growth concern and the final LayerNorm
Modern variants and edge cases
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
PropertyPost-normPre-norm
Formulax_out = LN(x_in + f(x_in))x_out = x_in + f(LN(x_in))
Residual path through LN?Yes (every layer)No (identity path)
Gradient stability at depthPoor without warmupStable with standard init
Used by GPT-1, BERT, Vaswani 2017YesNo
Used by GPT-2+, Llama, Mistral, modern LLMsNoYes
Needs final LN before LM headNoYes (variance grows)

Real products, models, and research that use this idea.

  • GPT-2 (2019) switched from post-norm (used in GPT-1 following Vaswani) to pre-norm and dramatically reduced warmup requirements.
  • GPT-3/4/5 series all use pre-norm; Llama 1/2/3/4 Maverick all use pre-norm with RMSNorm.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy does pre-norm's residual-stream variance grow unboundedly with depth, and what fixes it?
A

Each layer adds a contribution f_l(LN(x_l)) to the residual without rescaling. The variance of the sum grows as the variance of one term times L. Models compensate with a final LayerNorm before the LM head, and often with output-projection initialization scaled by 1/sqrt(L) so each layer's contribution to the running variance is bounded.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Believing the original Vaswani layout (post-norm) is what modern LLMs use. GPT-2 already switched to pre-norm in 2019 and every frontier LLM since has followed.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Formula difference between pre-norm and post-norm

  • Why pre-norm gives cleaner gradient flow through the residual path

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium