---
title: "Compare batch and layer normalisation: what they normalise over, train/inference behaviour, and why transformers use…"
url: https://gurkanozkan.ai/learn/questions/mle-batchnorm-vs-layernorm-13/
markdown: https://gurkanozkan.ai/learn/questions/mle-batchnorm-vs-layernorm-13.md
kind: question
role: ML engineering
stage: Technical
difficulty: Medium
json: https://gurkanozkan.ai/api/learn/questions/mle-batchnorm-vs-layernorm-13.json
robots: noindex
---

# Compare batch and layer normalisation: what they normalise over, train/inference behaviour, and why transformers use LayerNorm (or RMSNorm).

ML engineering · Technical · Medium

## Answer

*Model answer, written in a candidate's voice*

### In short

- BN normalises each feature across the batch (and spatial positions in CNNs), using batch statistics in training and running mean/variance at inference.
- BN is sensitive to small batches, batch-size changes, and train/test distribution shift.
- LN normalises each example across its features, so train and inference behave the same and examples stay independent.
- Transformers use LN/RMSNorm because tokens and variable-length sequences have no stable batch statistics and need per-token scale control.
- Pre-norm is generally more stable for deep transformers; post-norm can work but is harder to optimise; RMSNorm drops mean-centring for a cheaper, similar normaliser.

### In full

BatchNorm normalises a feature across the batch, so in training it uses the current batch mean and variance, while at inference it switches to running statistics; that makes it sensitive to small batches, batch-size changes, and distribution shift. LayerNorm instead normalises each example across its features, so every token or sequence is scaled independently and train and inference behave the same, which fits variable-length sequences and examples that should not depend on each other. Transformers therefore use LayerNorm or RMSNorm rather than BatchNorm: there is no meaningful stable batch statistic across tokens, and per-token normalisation keeps the residual stream well scaled. In practice, pre-norm is usually more stable for deep transformers, while post-norm can be competitive but is harder to optimise. RMSNorm keeps the same per-example idea but drops the mean-centring step, making it cheaper while still controlling scale.

*Checked against sources by an independent AI reviewer.*

## What a strong answer covers

- BN normalises per feature across the batch, keeps running stats for inference, and is sensitive to small batches and distribution shift.
- LN normalises per example across features, so train and inference behave the same and it suits variable-length sequences.
- Pre-norm vs post-norm stability in transformers; RMSNorm drops the mean-centring.

## Common mistakes

- forgetting that BN behaves differently in train and eval mode (a classic debugging-round bug).

## Topic guides

- [Deep learning fundamentals](https://gurkanozkan.ai/learn/topics/deep-learning.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
