Normalization
Normalization layers standardize activations to zero mean and unit variance inside the network, then hand the model a learnable scale and shift to undo the constraint when it pays to. Batch normalization does this across the batch and must keep separate train-time and test-time statistics; layer, instance, and group norm change only the axes they average over.
╌╌╌╌
A deep stack has a moving-target problem. Every layer is trained assuming the distribution of its inputs is fixed, but those inputs are the outputs of the layers below, whose weights are changing on every step. The signal that arrives at layer drifts in mean and scale throughout training, so each layer must continually re-adapt to a drifting distribution. Normalization attacks this directly: rescale the activations to a fixed first and second moment inside the forward pass, then let the network learn back any scale it actually needs. The standardization is a differentiable layer, not a preprocessing step on the data; its statistics flow through backpropagation like everything else.
The one decision that separates the whole family is which axes you average over. Standardizing is always the same three operations — subtract a mean, divide by a standard deviation, apply a learnable affine map. What changes from batch norm to layer norm to group norm is only the set of tensor entries pooled into each mean and variance. This lesson derives batch normalization in full (forward pass, running statistics, the backward pass through the batch moments), then walks the family by re-choosing that axis set, and closes on why the whole construction speeds up and regularizes training.
Batch normalization
Fix one feature (one coordinate of the activation vector, or one channel of a convolutional map). Over a minibatch of that feature's values, batch normalization computes the batch mean and variance, standardizes, then applies a learnable affine map:
The small constant (typically ) keeps the denominator away from zero. The pair is learned per feature by gradient descent; they are the layer's only parameters.1
Read the four equations in order. The first two summarize the batch: is where this feature's values sit on average, is how spread out they are. The third centers and rescales every value so the batch has mean and variance ; after this step the feature is on a fixed, canonical scale no matter what the layers below produced. The fourth returns two learnable parameters to the network: stretches the standardized feature and shifts it, so the network can place the final distribution anywhere.
A concrete pass. Take a minibatch of values of one feature, . Then and , so (ignoring ) the standardized values are — mean , variance , as promised. With learned the outputs are : recentered on and spread by . Change to and is unchanged: the standardization is invariant to any shift of the whole batch, which is the point.
Where the parameters live. Normalization runs per feature, so the statistics and parameters are vectors indexed by the channel axis. For a convolutional activation of shape — batch , channels , height , width — batch norm computes one and one per channel by pooling the entries of that channel, and it holds one and one per channel. The parameter count is therefore , independent of batch size or spatial resolution.
The affine map is what keeps the layer from losing expressive power. Forcing unit variance is a constraint; the network can cancel it whenever the constraint hurts.
The standardization moves a feature's distribution to a canonical position and the affine map relocates it — now under the optimizer's explicit control through two parameters, rather than as a byproduct of the layers below.
The forward pass as an algorithm
Collecting the four equations gives the training-time forward pass for a single feature; in practice the same operations run vectorized over every feature at once.
- 1batch mean
- 2batch variance
- 3for to do
- 4standardize
- 5scale and shift
- 6accumulate running mean
- 7accumulate running variance
- 8return
The layer is differentiable end to end. Backprop must route gradients not only through the affine but also through and , since both depend on every in the batch — so the gradient with respect to one input mixes in contributions from all the others.
The parameter gradients are the easy half: and appear only in the final affine, so they just sum the upstream gradient over the batch, weighted by for the scale and unweighted for the shift:
The input gradient is the interesting half. Writing for the gradient after the affine, the chain rule carries back through the three paths by which reaches the loss: directly through its own , through the shared mean , and through the shared variance . Collecting the three paths gives
with . The first term is the naive gradient you would get if and were constants. The second subtracts the batch mean of the upstream gradient — the correction from 's influence on . The third subtracts an -weighted mean — the correction from its influence on . Together the two corrections project the incoming gradient onto the subspace orthogonal to constant shifts and to rescalings of ; that projection is what leaves the layer's output invariant to the mean and scale of its input, and it is the reason an example's gradient depends on which other examples share its batch.2
The dataflow makes the coupling visible: every input feeds the two batch statistics, which in turn feed the normalization of every input, before the per-feature affine finishes the map.
Train versus inference
The batch statistics are a property of the batch, not the example — they are unavailable at test time, where inputs may arrive one at a time and predictions must not depend on which other examples happen to be present. The fix is to accumulate running estimates during training (lines 6–7 of the algorithm, an exponential moving average with momentum ) and freeze them for inference:
The running statistics are buffers, not parameters: updated by a formula, never by a gradient. Each training step folds the current batch moments into the running estimate with momentum (typically , or its complement depending on the convention),
so that after enough steps track the population mean and variance of the activation while the batch statistics still do the normalizing during training. At test time the layer becomes a fixed affine map of its input,
a single scale-and-shift with no batch and no per-example coupling, which is why it can be folded into the preceding linear layer at inference for free.3
The train/test asymmetry is the single richest source of batch-norm bugs. Confuse the two modes and the network silently misbehaves:
| Bug | Cause | Symptom |
|---|---|---|
| Test accuracy collapses | model left in train mode at eval (model.train() not model.eval()) | predictions depend on batch order; single-example inference garbage |
| Train fine, deploy broken | running stats never warmed up (too few steps, or frozen from init) | stale or zero, so test-time standardization is wrong |
| Batch size 1 | variance over one example is (or undefined) | division by blows activations up |
| Fine-tuning drift | BN stats inherited from a different data distribution | frozen mismatch the new domain |
The first row is the canonical one: with the layer in training mode at test time, each prediction normalizes by the statistics of whatever batch it arrives in, so the same input yields different outputs depending on its neighbors.
Why it helps
Batch norm reliably lets you train deeper networks at higher learning rates, but why has been contested. Two explanations compete.
The original account was internal covariate shift: because lower layers keep changing, the distribution feeding each layer drifts, forcing upper layers to perpetually re-adapt. Fixing the mean and variance of every layer's input is meant to halt this drift, so each layer sees a stationary distribution and can learn faster.4
The modern account is that the covariate-shift explanation is at best incomplete: networks can be trained with deliberately injected post-norm distribution shift and still retain batch norm's benefits. The better-supported explanation is that normalization conditions the optimization — it makes the loss and its gradient smoother (smaller, more predictable curvature along the update direction), so larger, more reliable steps are safe. The decoupling of each weight's effective scale from the loss is a second mechanism: scaling a weight by leaves a normalized layer's output unchanged, which reduces the loss surface's sensitivity to weight magnitude.5
The family: which axes are normalized
Batch norm is one choice of which axes to average over. For a 4-D activation tensor of shape — batch , channels , spatial — the variants differ only in the set of axes contributing to each . Layer norm averages over the features of a single example (so it is batch- independent); instance norm normalizes each channel of each example on its own; group norm splits channels into groups and normalizes within a group, a middle ground that, like layer/instance norm, never touches the batch axis.
The cleanest way to see the whole family is as different shadings of the same tensor. Lay the activation out as an grid of spatial maps (each cell is one slice). Every scheme computes its statistics over the shaded cells, and only the shading changes.
The table below makes the trade-offs explicit. The decisive column is batch- dependent? — the one property that determines whether a layer behaves identically at train and test, and whether it survives a batch of size one.
| Norm | Normalized over | Batch-dependent? | Typical use |
|---|---|---|---|
| Batch norm | batch and spatial , per channel | yes | CNN classifiers (large batch) |
| Layer norm | channels and spatial, per example | no | RNN, Transformer |
| Instance norm | spatial , per example per channel | no | style transfer, generation |
| Group norm | a channel group and spatial, per example | no | CNN with small batch (detection) |
| RMS norm | features, per example (no centering) | no | large language models |
Layer norm, written out. For one example with feature vector , layer norm pools all features into a single mean and variance:
The formulas are batch norm's with the sum running over features instead of over the batch. Because no other example enters, the computation is identical at train and test time, and a batch of size one is handled exactly like a batch of a thousand — the property that makes it the default in Transformers, where the batch axis carries variable-length sequences, and in recurrent networks, where the same statistics must apply at every timestep.
RMS norm drops the mean-centering: it divides by the root-mean-square of the features and keeps only a scale, no shift.
Skipping the subtraction of costs almost nothing in accuracy on large Transformers while removing one reduction and one buffer per layer, which is why recent large language models tend to use it in place of layer norm.
Batch norm's accuracy degrades when the batch is small because become noisy estimates of the population moments; the batch-independent variants sidestep this entirely, which is why detection and segmentation models (forced into tiny batches by memory) use group norm, and why sequence models, whose batch axis carries variable-length examples, use layer norm.6
Placement
Where the layer sits relative to the linear map and the activation is a genuine design choice. The original prescription was linear norm activation, so the normalized pre-activation feeds the nonlinearity; a common alternative normalizes the activation output instead. In residual architectures the analogous question is pre-norm versus post-norm: whether normalization sits inside the residual branch (before the sublayer) or after the residual addition.
Pre-norm leaves an unnormalized identity path from input to output of each block, so the gradient reaches early layers without passing through a normalization at every step — the reason very deep Transformers train more stably with pre-norm, often without learning-rate warmup. Post-norm can reach slightly better final quality when it trains at all, but is more fragile at depth.
| Placement | Norm position | Gradient path | Trains deep nets |
|---|---|---|---|
| Post-norm | after residual add | through norm each block | fragile, needs warmup |
| Pre-norm | inside branch, before sublayer | clean identity skip | stable to great depth |
Normalization, revisited
Goodfellow §8.7.1 introduces batch normalization (Ioffe & Szegedy, 2015) and gives the internal-covariate-shift motivation; the public literature since has both challenged that motivation and multiplied the variants. The covariate-shift explanation was directly tested by Santurkar et al. (2018), who trained batch-norm networks with deliberately injected post-normalization distribution shift and found the training speedup intact — evidence that the operative mechanism is the loss-surface smoothing described above, not the drift the name suggests. The technique works; the name is a historical accident.
The batch-independent variants each arose from a specific need. Layer norm (Ba et al., 2016) freed normalization from the batch axis for recurrent and sequence models; instance norm (Ulyanov et al., 2016) suited style transfer; group norm (Wu & He, 2018) filled the small-batch gap for detection and segmentation; and RMS norm (Zhang & Sennrich, 2019) dropped the mean-centering for a cheaper layer. The decisive outcome is architectural: modern large language models are built almost entirely on pre-norm layer or RMS normalization, because the clean identity path through each residual block (shown above) is what lets very deep transformers train stably, often without the learning-rate warmup post-norm requires. Batch norm remains the default for convolutional image classifiers with large batches, but the sequence world it never fit well moved to the batch-independent family and stayed there.
The regularizing side effect
Batch norm is filed under regularization for a concrete reason: it injects noise. Each example's normalized value depends on the random minibatch it was sampled with, through and . Two identical inputs in different batches get slightly different activations — a stochastic perturbation closely analogous to dropout, which is why models with batch norm often need less of it.7
The effect cuts both ways: the noise that regularizes also destabilizes small batches and forces the train/test statistic split. Normalization trades a constraint on the activations for better conditioning and a mild dose of noise, at the bookkeeping cost of maintaining running statistics. It composes with the other tools in this module: parameter penalties, dropout and augmentation, and early stopping all attack overfitting from different angles, and normalization is the one that also reshapes the loss surface the optimizer has to descend.
Footnotes
- Goodfellow, Deep Learning, §8.7.1 — Batch Normalization: standardizing each feature over the minibatch, then the learnable affine that can recover the identity so the constraint never costs expressive power. ↩
- Goodfellow, Deep Learning, §8.7.1 — Batch norm backprop: because and depend on every example, the gradient through one input mixes in contributions from all the others in its batch. ↩
- Chollet, Deep Learning with Python, §7.4.2 — Batch Normalization: the practical layer, its running-statistics buffers for inference, and the train/eval mode switch that is the canonical source of batch-norm bugs. ↩
- Goodfellow, Deep Learning, §8.7.1 — Internal covariate shift: the original motivation, pinning the first two moments of each layer's input to halt the distributional drift caused by updates to lower layers. ↩
- Goodfellow, Deep Learning, §8.7 — Optimization Strategies: normalization smooths and reconditions the loss surface and decouples a weight's scale from the loss, the better-supported account of why it speeds training. ↩
- Goodfellow, Deep Learning, §8.7.1 — Normalization variants: batch norm pools the batch axis (and so needs a batch), while layer, instance, and group norm change only which axes the statistics average over, staying batch-independent. ↩
- Goodfellow, Deep Learning, §8.7.1 — Batch noise as regularizer: estimating from a random batch perturbs each activation by noise of order , a dropout-like effect that fades as the batch grows. ↩
╌╌ END ╌╌