05. Pre-norm vs post-norm — where the inspector stands¶
7 minutes. Same station. Move the inspector one step, and deep training changes.
Built on the ELI5 in
00-eli5.md. The quality inspector — layer normalization checking scale — now changes how clean the shortcut pipe stays.
Mental model first¶
One station has two heavy jobs. First the social bench. Then the private bench. The only question here is location. Where does the quality inspector stand? In pre-norm, the inspector stands before each heavy job. The branch gets normalized. The shortcut pipe carries the old packet unchanged. Then the add happens. In post-norm, the heavy job runs first. Then the old packet and new edit are added. Then the combined packet is normalized. So the next layer never sees a perfectly untouched identity path. See the two layouts.
Pre-norm
x ------------------------------+
| |
|--> LN --> Attention ----------+--> u
u ------------------------------+
| |
|--> LN --> FFN ----------------+--> y
Post-norm
x ------------------------------+
| |
|--> Attention -----------------+--> add --> LN --> u
u ------------------------------+
| |
|--> FFN -----------------------+--> add --> LN --> y
x to the add.
In post-norm, the pipe value gets mixed and then normalized.
So the direct copy path is less direct.
This is why pre-norm became the practical default for deep LLMs.
Depth punishes dirty identity paths.
A clean pipe buys stability.
Formula view¶
Write one block with two sublayers.
Now look only at the copy route. For pre-norm, the block is close tox + small edits.
For post-norm, the block is closer to LN(x + small edits).
That difference matters in backprop too.
For one pre-norm sublayer,
The important symbol is I.
There is always a direct gradient route.
The model can fall back to near-identity behavior.
For one post-norm sublayer,
Now the route is multiplied by J_LN.
The identity path still exists, but it is no longer untouched.
Each layer can shrink or stretch some directions.
Stack many layers and the chain gets harder to manage.
A useful memory line is this.
Post-norm does have one real advantage.
The block output always passes through normalization.
So the outgoing representation is more explicitly standardized.
That can help in some settings.
But very deep decoder training usually values the cleaner path more.
Worked numerical examples with ASCII diagrams¶
Start with a toy gradient story.
Do not over-read the numbers.
They only show the chain.
Assume each sublayer contributes a small derivative 0.05.
Assume the LayerNorm Jacobian on one direction has size 0.8.
For pre-norm, one layer contributes about:
12 layers,
For post-norm, one layer contributes about:
Across 12 layers,
Same edit size.
Different inspector placement.
That is the clean-path story in one glance.
Now do a forward-pass toy example.
Take the incoming residual stream:
In pre-norm, inspect first.
Suppose the social bench writes:
Then add through the shortcut pipe.
Inspect u again.
Let the private bench write:
Final add:
ASCII picture:
raw x -----------+
+----> [4.2, 1.9, 0.0] -----------+
LN -> Attn edit -+ +----> [4.3, 2.1, -0.1]
|
LN -> FFN edit-+
x is sharper.
Add first.
Now normalize the combined result.
Suppose the private bench writes:
Add and normalize again.
ASCII picture:
What changed?
In pre-norm, the branch was normalized.
In post-norm, the combined stream was normalized.
So the direct copy path was cleaner in pre-norm.
Stability cheat sheet¶
Use this table when the interview gets fast. | Question | Pre-norm | Post-norm | |---|---|---| | LN location | Before each sublayer | After each residual add | | Identity path | Cleaner | Modified by LN | | Deep training | Usually easier | Often harder | | Final block output normalized? | Not guaranteed | Yes | | Common in modern LLMs? | Very common | Less common | Why do GPT, LLaMA, Mistral, Gemma, and many Claude-like stacks prefer pre-norm? Because very deep decoder stacks need reliable optimization. Because the residual stream needs a stable highway. Because the shortcut pipe should stay as untouched as possible. When might someone still like post-norm? When they care about the block output always being normalized. When the stack is not extremely deep. When a specific training setup is tuned for it.
Where this lives in the wild¶
- ChatGPT and GPT-style models use pre-norm style blocks because stable deep training matters more than post-norm neatness.
- Meta LLaMA models use RMSNorm-first blocks, which keep the same pre-norm spirit with a slightly different inspector.
- Mistral and Mixtral normalize before heavy work, then add edits back into the residual stream.
- Google Gemma follows the same normalize-first habit because scaling depth is easier with cleaner residual paths.
- Many open Hugging Face decoder checkpoints also choose pre-norm or RMSNorm-first layouts for the same reason.
Interview Q&A¶
Q: Why do modern LLMs usually prefer pre-norm?
A: Because the shortcut pipe keeps a cleaner identity route, so gradients survive deep stacks more reliably.
Common wrong answer to avoid: "Because pre-norm is newer."
That is not the reason.
The real reason is optimization stability.
Q: What is the main mathematical difference in the gradient path?
A: Pre-norm keeps an I + ... route, while post-norm multiplies the route by the LayerNorm Jacobian at every layer.
Common wrong answer to avoid: "Post-norm has no residual connection."
Wrong.
It still has residual addition.
The issue is that the identity route is normalized afterward.
Q: Does post-norm have any advantage?
A: Yes. The block output always passes through normalization, which can help keep representations well-shaped in some settings.
Q: If a 96-layer decoder diverges, what is one architecture question to ask first?
A: Ask whether the stack is post-norm and whether moving the inspector before each sublayer would stabilize training.
Apply now (5 min)¶
Draw both layouts from memory. Label the quality inspector and the shortcut pipe. Then write these two lines without looking:
Now answer in one sentence. Why is the shortcut pipe cleaner in pre-norm? Last step. Sketch from memory the two ASCII stations and the gradient comparison1.05^12 versus 0.84^12.
Bridge. You now know where the inspector stands. Next, see the whole station at once:
06-transformer-block.md.