Visual explainer
Batch Normalization
Follow batch centering, variance scaling and learned affine parameters, then distinguish training companions from stored evaluation statistics.
Batch normalization uses a group's mean and variance to center and scale activations, followed by learned scale and shift. During training the group usually includes multiple examples; evaluation commonly uses stored statistics instead. The two dot plots share one activation scale: batch A is with mean 3, while batch B is shifted by 10 with mean 13. Neither cloud is asserted to be Gaussian.
Changing upstream parameters can change activation statistics, as discussed in the original BN paper. These invented batches illustrate a statistical shift; they do not establish a complete explanation of BN's optimization benefits or a guaranteed speedup.
Center And Scale
Use batch A for the worked example. Subtracting mean 3 moves every point left by three units, leaving . The axes keep the same units, so the equal displacements are literal. The divisor- batch variance is . The unbiased sample variance would be , a different estimator.
Next divide centered values by . We deliberately choose to make its effect visible, not as a recommended setting. The denominator is , giving normalized values . Mean is zero, but variance is , rather than exactly one. Standardizing these moments does not make a distribution Gaussian.
Learn The Output Scale
The upper points are the normalized values just computed; the lower points apply with . Both rows use the same value scale. Spacing doubles and the center moves from zero to one. Outputs are approximately . The affine parameters let training change each channel's output scale and offset; they do not recover every possible representation or force the final output to unit variance.
Evaluate With Stored Statistics
For this separate evaluation example, assume stored mean 3 and variance 5, with . One new activation maps to . The plotted straight line uses those fixed statistics, so this layer's output does not depend on accompanying evaluation examples.
Stored estimates need not equal one training batch's moments. PyTorch BatchNorm2d uses the divisor- estimator in the training forward pass and an unbiased variance estimate for running updates. It normally uses stored moments during evaluation; disabling running-stat tracking changes that behavior. This example does not claim variance 5 is the running value produced by the earlier batch.
Companions Matter During Training
The square marks activation 4 in both groups. With companions , its normalized value is . With three companions also equal to 4, the mean is 4, variance zero and normalized value zero. Stacked markers in group B all have the same horizontal coordinate; vertical stacking only shows multiplicity. The numbers at right are normalized outputs, while the horizontal axes show raw activations. Training therefore couples examples through their shared moments, which can also introduce noise into the representation.
Choose Which Values To Pool
For this two-dimensional sample-by-feature matrix, rows are samples and columns are features. Batch norm pools one feature across samples; layer norm pools the selected features within one sample. The solid column and dashed row identify membership, rather than data magnitudes. Actual normalization axes depend on tensor shape and layer configuration. There is no universal batch-size cutoff of 32 that determines which method works; batch composition, spatial size, task and architecture all matter.
Handle Constant Values
Four identical activations 4 have mean 4 and variance zero. Their centered values are zero, and positive epsilon keeps the denominator finite: . The affine output is therefore . The drawing stacks identical values vertically only to count them. This is a degenerate forward representation, not a division-by-zero failure. It also does not imply every local gradient vanishes: mean-coupling derivatives and gradients for beta require separate analysis. APIs may reject training configurations with only one value in a reduction group rather than evaluating that formula.
Count Spatial Values Too
For convolutional activations, BatchNorm2d pools each channel over batch and spatial axes. One image with one channel containing supplies four values, not one. The flattening arrow shows reduction membership; it is not an extra model layer. Other channels get their own moments. Thus batch size does not alone imply a singleton reduction group: here .
Keep Epsilon In The Arithmetic
Before learned affine scaling, normalized variance is . At , epsilon values 0, 1 and 5 give variances 1, and .5. Bar lengths share a linear variance scale. Epsilon zero is included only as a mathematical comparison for this strictly positive variance; positive epsilon protects nearly constant groups. For typical small epsilon and much larger variance, the result is close to one, but equality should not be asserted generally.
Where It Breaks
Hold stored mean 3, variance 5 and epsilon 1 fixed, with identity affine parameters. Reference inputs lie symmetrically around normalized zero. Shifted evaluation inputs instead map to approximately . Both rows share the same normalized scale; the shifted cloud lies entirely positive. Stored moments do not automatically adapt to a new distribution. This reveals a train/eval mismatch risk, not an invented accuracy loss or a guarantee that recomputing moments will fix the model.
The Quick Version
- Training moments couple values within each normalization group.
- Centering and scaling do not make activations Gaussian.
- Learned affine parameters change output scale and offset.
- Stored moments permit single-example evaluation with fixed behavior.
- Spatial positions can supply multiple values per channel.
- Stale moments can miscenter shifted evaluation data.