← Explainer Library

Interactive Explainer

BatchNorm vs LayerNorm vs GroupNorm vs InstanceNorm

Four normalization layers, one equation shape: subtract a mean, divide by a standard deviation. The only thing that changes is which slice of the activation tensor the mean and variance are pooled over. That single design choice is why BatchNorm ruled CNNs, LayerNorm rules Transformers, and GroupNorm rescued small-batch training. Pick a norm below and watch exactly which elements share one statistic.

Prelude

One equation, four slices

Take a batch of activations shaped $(N, C, H, W)$ — $N$ examples, $C$ channels, and an $H\times W$ spatial map per channel. Every normalization layer applies the same transform to each element, then a learned scale $\gamma$ and shift $\beta$:

$$\hat{x} = \gamma \cdot \frac{x - \mu}{\sqrt{\sigma^2 + \epsilon}} + \beta .$$

The mean $\mu$ and variance $\sigma^2$ are what differ. Each method sums over a different set of axes — a different slice of the tensor — and therefore produces a different number of independent statistics:

The Lab

Which elements share one statistic?

Below is one activation tensor. Rows are the $N$ examples in the batch, columns are the $C$ channels, and each little tile is that channel's $H\times W$ spatial map (here $2\times2$). Choose a normalization scheme — the highlighted cells are exactly the elements averaged together for one $(\mu,\sigma^2)$. Click any tile to move the reference cell and see which slice it belongs to.

Each tile is a channel's 2×2 spatial map. Blue tiles are pooled into one mean & variance.
averaged together (one $\mu,\sigma^2$) other elements reference cell · click to move
Mean $\mu$ of highlighted
Variance $\sigma^2$ of highlighted
Elements pooled
Try this. Keep the reference tile fixed and flip between BatchNorm and LayerNorm. Watch the mean pill: BatchNorm pools a whole channel across the batch, so its statistic barely moves when you click a different sample — but LayerNorm re-computes a fresh mean for each sample, so it jumps. That batch-vs-sample split is the entire story: BatchNorm couples examples together (great with big batches, fragile with tiny ones); LayerNorm treats every example alone (perfect for variable-length Transformer sequences). Now drag $G$ under GroupNorm from $1$ up to $C$ — at $G=1$ it is InstanceNorm, and at $G=C$ it is LayerNorm.
The Payoff

Why each wins where it wins

And RMSNorm? The modern Transformer favourite is just LayerNorm with the mean-centering dropped: $\hat{x} = \gamma \cdot x / \sqrt{\overline{x^2} + \epsilon}$. Same slice as LayerNorm (across $C$), but it skips subtracting $\mu$ — one fewer statistic and one fewer parameter for near-identical accuracy. Every method here is a variation on the same question you were just clicking through: over which axes do we pool?