What Is Layer Norm? Pre-Norm vs Post-Norm, Explained
What layer norm does, why pre-norm and post-norm put it in different places, and what that changes in training, for your AI interview.
In short
Layer norm rescales one token's numbers to a steady average and spread. Post-norm puts it after each block adds its input back, while pre-norm puts it before the block. Xiong and colleagues found that pre-norm's gradients are well-behaved at the start.
11 min readAdvancedCommon · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
Layer norm rescales one token's numbers so their average is zero and their spread is one, which keeps the numbers steady from layer to layer. The question is where it sits. The original Transformer put it after each block adds its input back, which is post-norm. Pre-norm puts it before the block. Xiong and colleagues found that pre-norm's gradients are well-behaved at the start, and that it reached comparable results without warm-up in their tests. Pre-norm also needs one final norm before the prediction, and I'd test quality on the real task before switching.
A transformer passes every token through a stack of blocks, and each block adds new numbers to it. Those numbers can drift: some grow very large, others shrink towards zero. Layer norm fixes the scale. For one token, it takes that token's own numbers, subtracts their average, divides by their spread, and then applies two learned values that let the model choose its scale again. It looks only at that one token, never at other examples in the batch. Batch norm does the opposite and averages across the batch.
The hard question is where the norm goes. The 2017 Transformer paper wrapped each sub-layer in a residual connection and then applied layer normalisation. That is post-norm. Pre-norm moves the norm inside the branch, so the skip path carries the input untouched. Xiong and colleagues showed that post-norm's gradients near the output are large at the start, which is why it usually needs a warm-up stage. In their tests, pre-norm reached comparable results without that stage.
The cost is one extra step. A pre-norm stack's final output is not normalised, so the model adds one final layer norm right before the prediction. Meta's Llama paper also uses pre-norm, normalising the input of each sub-layer to improve training stability. It uses RMSNorm, a variant of layer norm.
In an interview, I'd name the two placements, explain why warm-up matters, and say that the choice depends on testing against my own task.
What is layer norm, in plain words?
A transformer passes every token through a stack of blocks, and each block adds new numbers to it. Those numbers can drift: some grow very large, others shrink towards zero. Layer norm rescales one token's numbers so they have an average of 0 and a spread of 1. It then applies a learned gain (a scale) and bias (an offset), so the model can still pick its own scale.
Think of a loan officer comparing applicants. One sends income as a monthly figure, another as a yearly one, a third as a weekly average. She restates each on the same scale before she compares them. Layer norm does that for each token before the next step. The AI version: a claims-triage model at an insurer gets one token whose numbers come out ten times bigger than its neighbour's. Layer norm rescales each token on its own, so the next layer sees them on one scale.
It works on one token's own numbers. It never looks at other examples in the batch, so it behaves the same whether a batch holds one example or a thousand.
Key words
- Layer norm
- Rescales one token's numbers to a steady average and spread, then applies a learned gain and bias.
- Residual connection
- The input copied around a block and added back to the block's output.
- Sub-layer
- One block inside a transformer layer, such as attention or the feed-forward part.
- Gradient
- The signal that tells each weight which way to move during training.
- Warm-up
- Starting training with a small learning rate and raising it slowly.
How does layer norm work, step by step?
- 1
Average the token's numbers
Add them up and divide by how many there are.
- 2
Measure the spread
Work out how far the numbers typically sit from that average.
- 3
Rescale each number
Subtract the average, then divide by the spread. A tiny extra amount stops it dividing by zero.
- 4
Apply a learned gain and bias
Two values per feature, learned during training, let the model set its own scale again.
Here it is in plain Python. We run it on two copies of one token's numbers, the second ten times bigger. After the norm, they match.
# One token's hidden numbers from a claims-triage model (made-up), before and after layer norm.
import math
import statistics
def layer_norm(x, eps=1e-5):
mean = statistics.fmean(x)
var = statistics.pvariance(x)
return [(v - mean) / math.sqrt(var + eps) for v in x]
calm = [4.0, 8.0, 12.0, 16.0]
spiky = [40.0, 80.0, 120.0, 160.0] # same pattern, ten times the scale
for name, vec in [("calm", calm), ("spiky", spiky)]:
out = layer_norm(vec)
print(name, [round(v, 3) for v in out], round(statistics.fmean(out), 3), round(statistics.pstdev(out), 3))Output
calm [-1.342, -0.447, 0.447, 1.342] 0.0 1.0 spiky [-1.342, -0.447, 0.447, 1.342] 0.0 1.0
- Batch norm
Across examples
It averages each feature over a mini-batch of training examples, so its result depends on the batch size.
- Layer norm
Across one token's features
It averages over one token's own numbers, one training case at a time, so batch size makes no difference.
Tip
Say 'across one token's features', never 'across the batch'. Across the batch describes batch norm.
Where does the norm go: pre-norm or post-norm?
Post-norm is the 2017 design. Each sub-layer's output is added to its input, and the sum is then normalised. Pre-norm normalises the input first, runs the sub-layer on that copy, and adds the untouched input back. The sub-layer is either attention or the feed-forward block.
“We employ a residual connection [11] around each of the two sub-layers, followed by layer normalization [1].”
Vaswani and colleagues, the 2017 Transformer paper
“for the original-designed Post-LN Transformer, which places the layer normalization between the residual blocks, the expected gradients of the parameters near the output layer are large”
Xiong and colleagues, on post-norm
“if the layer normalization is put inside the residual blocks (recently proposed as Pre-LN Transformer), the gradients are well-behaved at initialization”
Xiong and colleagues, on pre-norm
Where the layer norm sits
Token vector in
one token's list of numbers
Post-norm (2017 design)
Sub-layer
attention or feed-forward
Add the input back
the skip path joins here
LayerNorm
normalises after the add
Pre-norm
LayerNorm first
normalises only the branch input
Sub-layer
attention or feed-forward
Add the input back
the skip path is never normalised
Needs a warm-up
slow start, more tuning
Can skip warm-up
comparable results in Xiong's tests
- 1Post-norm sends the vector into the sub-layer first.
- 2The sub-layer's output is added to its input.
- 3The sum is normalised before it moves on.
- 4Early on, the gradients near the output are large, so training needs a warm-up.
- 5Pre-norm normalises the input before the branch.
- 6The normalised copy goes into the sub-layer.
- 7The sub-layer's output is added to the untouched input.
- 8At the start, the gradients stay well behaved.
Xiong and colleagues, from ICML 2020, showed that the placement matters at the start. Post-norm's gradients near the output are large, so training usually needs a learning rate warm-up. Pre-norm reached comparable results without that stage in their tests.
The cost is one extra step. A pre-norm stack's final output is not normalised, so the model adds one final layer norm right before the prediction. Meta's Llama paper also uses pre-norm, normalising the input of each sub-layer to improve training stability. It uses RMSNorm, a variant of layer norm.
How would you fix a deep model that diverges at the start?
A team trains a deep post-norm model. In the first steps the loss jumps and then turns to NaN, which means not a number, so training is dead. They chose a high learning rate to save time. Here is how I'd work through it.
- 1
Check the norm placement
Confirm the model is post-norm. Xiong and colleagues tie that design's early instability to large gradients near the output.
- 2
Add a warm-up
Start with a small learning rate and raise it over the first stretch of steps. It works, but it means a slower start and more settings to tune.
- 3
Or move the norm into the block
Pre-norm reached comparable results without warm-up in their tests. The cost is one extra final norm, and quality must be measured again.
- 4
Test on a small run first
A short run shows whether the loss stays finite before the team spends days of compute.
Tip
A good answer names both fixes, what each costs, and a small test before the full run.
What does the interviewer want to hear?
A strong answer covers
- Layer norm rescales one token's numbers to a steady average and spread.
- It works across one token's features, never across the batch.
- Post-norm puts it after the add. Pre-norm puts it before the sub-layer.
- Post-norm usually needs a warm-up. Pre-norm reached comparable results without one in Xiong's tests.
- Pre-norm needs one final norm before the prediction.
- Test on your own task before switching designs.
Common traps
Trap"Layer norm works across the batch, like batch norm."
BetterIt works across one token's features. Batch norm is the one that averages across the batch.
Trap"Pre-norm is always better, so use it everywhere."
BetterIt trained more smoothly at the start in one paper's tests. Check quality on your own task before switching.
Trap"The norm makes the model smaller."
BetterIt rescales the numbers. It removes no weights and shrinks nothing. It keeps the numbers steady, so the next layer sees them on one scale.
Can you spot the mistake?
Spot the mistake
A teammate's design note for a claims-triage model has one wrong line. Which one?
Quick check
A deep post-norm model diverges in its first steps. Which change is most likely to help, with the design left as it is?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q053What do residual connections do?12 min
- Q054What does the feed-forward block do?10 min
- Q041What is a transformer?10 min
- Q426Vanishing and exploding gradients?Coming soon
- Q427What is batch normalisation?Coming soon
Learn it in depth
Last updated on 26 November 2026
Training a model that won't settle?
I design and build AI products and agents, the UI and the system behind them. Book a short call and tell me what you need.