AI Research Scientist · Transformer Architecture Components
Layer normalization mechanics
Layer normalization mechanics
LayerNorm sublayer
LayerNorm is applied around each attention block and each feed-forward block — normalizing either the block’s input before it runs (pre-norm) or the residual sum just after the block’s output rejoins the stream (post-norm).Computing LayerNorm Per Sample
- 1MeanCompute across this one sample’s own features.
- 2VarianceCompute the same way — per sample, not per batch, since batch statistics are unreliable in transformers.
- 3Normalize gives this sample zero mean, unit variance.
- 4Scale & shift lets the network relearn a useful scale.
- 1Without LayerNorm, the scale compounds roughly 4× per block.WhyUnnormalized growth multiplies across depth, risking overflow.
- 2With LayerNorm, each block’s output is reset to zero mean, unit variance.WhyPer-sample rescaling erases the prior growth every single layer.
- LayerNorm sits inside the residual branch, before the sublayer: .
- The raw input skips into the sum unnormalized.
- LayerNorm sits after the residual sum.
- The normalization applies once, after summing the branch.
Recall check from the same lesson
In a pre-norm transformer block, LayerNorm is applied to the input before it enters the attention or feed-forward sublayer, and the raw unnormalized input is what gets added into the residual sum.
Review the explanation
Answer: True. This matches pre-norm's structure: $x+\text{Sublayer}(\text{LN}(x))$ — LayerNorm sits inside the branch, before the sublayer runs, while the residual addition uses the original unnormalized $x$. Post-norm instead applies LayerNorm to the already-summed output, $\text{LN}(x+\text{Sublayer}(x))$.
Sources
One sitting · 20–30 minutes
A focused session on your AI Research Scientist interview
LearnBench starts from what you already know — skip what you have, master what you’re missing.
Start now