Explain batch normalisation: what it computes at training versus inference time, and why it helps. Why do transformers use layer norm or RMSNorm instead, and does pre-norm vs post-norm placement matter?
Answer
Model answer, written in a candidate's voice
In short
- Per-feature normalisation over the batch with learnable gamma/beta; inference uses running mean/variance.
- Helps optimisation and higher learning rates; covariate-shift story is disputed.
- Batch-dependent and fragile with small batches or variable sequence lengths, so transformers normalise per token.
- RMSNorm drops mean-centring and is cheaper.
- Pre-norm stabilises deep stacks; post-norm needs careful warmup.
In full
Batch normalisation normalises each feature using statistics computed over the current batch, then applies learnable scale gamma and shift beta; at inference it uses running mean and variance accumulated during training rather than the current batch. It generally smooths optimisation and permits higher learning rates, though the classic internal-covariate-shift explanation is disputed and the benefit is broader than that story. Because the statistics depend on the batch, it is sensitive to batch size and is awkward with small batches or variable-length sequences, which is why transformers typically normalise per token across features instead. LayerNorm subtracts the mean and divides by the standard deviation within a token; RMSNorm skips the mean-centring and just divides by the root mean square, making it cheaper while often performing similarly. Placement matters: pre-norm puts the normalisation before each sublayer so the residual stream stays unnormalised and deep stacks train more stably, whereas post-norm normalises after the sublayer and can work well but usually needs careful warmup and tuning.
What a strong answer covers
- Per-feature normalisation over the batch, with learnable γ and β; running statistics used at inference.
- Allows higher learning rates and smoother optimisation; the covariate-shift explanation is disputed.
- Depends on batch size and breaks with small batches or variable sequence lengths, so transformers normalise per token (LayerNorm).
- RMSNorm drops mean-centring and is cheaper.
- Pre-norm stabilises deep stacks; post-norm needs careful warmup.
Common mistakes
- Forgetting the train/eval-mode difference.
- Stating the internal-covariate-shift story as settled.