One-line definition
A normalization layer is parameterized by (a) which dimensions you normalize across and (b) which dimensions get learnable scale/shift parameters. BatchNorm and LayerNorm differ on both axes, and the way LayerNorm is used in transformers is not the same as how it was originally specified for sequence models.
The general form
Every normalization layer does:
y = gamma * (x - mu) / sqrt(sigma^2 + eps) + beta
The whole question is: over which axes are μ and σ computed? And: which axes do γ and β have?
For a 4-D activation tensor of shape (N, C, H, W) (batch, channel, height, width):
| Norm | Stats computed across | γ, β shape |
|---|---|---|
| BatchNorm (BN) | N, H, W (per channel) | C |
| LayerNorm in CNNs (LN-CNN) | C, H, W (per sample) | C, H, W |
| LayerNorm in transformers (LN-TX) | D (per token) | D |
| InstanceNorm | H, W (per sample, per channel) | C |
| GroupNorm | G groups of C/G channels, H, W | C |
The key insight from the original LayerNorm paper that almost everyone misremembers: LayerNorm normalizes across all features of a sample. In CNNs that means C×H×W. In transformers that means just D (the embedding dim). Different norms entirely, despite the same name.
Why the difference matters
BatchNorm:
- Couples samples in a batch together (statistics are computed across N).
- Behaves differently at train and eval time (eval uses running averages).
- Breaks at small batch sizes (statistics get noisy when N < ~16).
- Breaks for sequence models with variable-length inputs and packed batches.
- Strong regularizer (the noise from batch statistics is the regularization).
LayerNorm:
- Each sample is normalized independently. No batch coupling.
- Same behavior at train and eval.
- Works at any batch size, including 1.
- Works for sequence models with variable lengths.
- Much weaker regularizer; you usually need additional regularization.
This is why CNNs adopted BN and transformers adopted LN. The choice was not stylistic; it was forced by the structural properties of each architecture.
What an interviewer expects you to say
If asked “BatchNorm vs LayerNorm”:
- State the general form (subtract mean, divide by std, scale-shift).
- Specify which axes the statistics are computed over for each.
- Mention train/eval mode difference for BN; absence for LN.
- Explain why each is used where it is, CNNs (BN) vs transformers (LN), and why.
- Bonus: mention the LN-CNN vs LN-Transformer wrinkle (different normalization axes despite the same name).
Discussing pre-norm vs post-norm transformers and RMSNorm marks senior-level knowledge.
The transformer-specific wrinkle most people miss
In a transformer, an activation has shape (B, T, D) where T = sequence length, D = embedding dim.
LayerNorm normalizes only across the D dimension: per (b, t). It does not normalize across T (that would mix tokens) and not across B (that would couple samples like BN does).
This is critical for two reasons:
- Variable-length sequences work natively. Each token’s statistics depend only on its own D values; padding doesn’t pollute them.
- Sequence packing works. When you concatenate multiple short sequences into a packed batch, LN doesn’t care, statistics are per-token. (BN would catastrophically fail here; the statistics would mix examples.)
The strongest answer to “why don’t transformers use BatchNorm”: it doesn’t just work worse, BN actively breaks what makes transformer training tractable.
RMSNorm: the modern variant
Most production LLMs from 2023 onward use RMSNorm instead of LayerNorm:
y = gamma * x / sqrt(mean(x^2) + eps)
The difference: skip the mean-subtraction, just normalize by the root mean square. Two consequences:
- ~7-15% faster (one fewer reduction).
- Empirically equivalent or better quality.
In high dimensions, random projection means are near-zero anyway, so subtraction is mostly noise. Empirically validated.
RMSNorm knowledge is expected in 2026 transformer discussions.
Pre-norm vs post-norm
Where you put the LN matters:
- Post-norm (original transformer):
y = LN(x + Sublayer(x)). Norm is after the residual. Hard to train at depth without a careful warm-up schedule. - Pre-norm (modern default):
y = x + Sublayer(LN(x)). Norm is before the sublayer. Easier to train, more stable at scale, but slightly worse final quality at small scales.
Almost all modern LLMs use pre-norm. If you write a transformer and put the LN after the residual, you’re inviting training instability.
Common confusions
- “LayerNorm normalizes across the layer.” No, it normalizes across the features within a sample. The “layer” in the name is historical and misleading.
- “BatchNorm and LayerNorm are interchangeable.” They have very different inductive biases; swapping them is a real architectural change, not a stylistic one.
- “BatchNorm regularizes by reducing internal covariate shift.” This was the original justification; subsequent papers showed it’s actually wrong. BN works for other reasons (smoother loss landscape, implicit regularization from batch noise). Don’t say “internal covariate shift” in a 2026 interview unless you’re prepared to immediately note that the explanation is contested.
- “LayerNorm is just BatchNorm with batch size 1.” No. The axes being normalized over are different.
Why interviewers care
This question tests whether you understand:
- Activation tensor shapes and axes.
- The relationship between architecture and normalization choice.
- Train/eval mode subtleties.
- Whether your knowledge has been updated since 2018.
Easy to fumble; easy to ace. Worth memorizing.
Related: FlashAttention for the other transformer-specific optimization that’s often paired with this in questions.