Normalization
Normalization stabilizes training by rescaling activations or features. In modern sequence models, LayerNorm and RMSNorm are especially important.
The general pattern is:
where and are computed over a chosen axis, and are learned scale and shift parameters, and prevents division by zero.
Axis Contract
Normalization is defined by which axes provide statistics and which axes keep separate statistics.
For :
| Method | Statistics Usually Over | Keeps Separate |
|---|---|---|
| LayerNorm | feature axis | batch and token positions |
| RMSNorm | feature axis , without mean subtraction | batch and token positions |
| BatchNorm | batch axis and sometimes spatial axes | channels/features |
| GroupNorm | channels within each group | batch and spatial positions |
| InstanceNorm | spatial axes per example/channel | batch and channel |
Writing “normalization” without the axis is incomplete because it changes train/inference behavior, distributed training behavior, and what information can leak across examples.
LayerNorm
Layer normalization computes statistics across the feature dimension for each token or example:
For a token matrix , LayerNorm usually normalizes each row independently. This makes it common in Transformer blocks where batch size or sequence length can vary.
RMSNorm
RMSNorm removes mean subtraction:
RMSNorm keeps the direction of closer to the original vector and reduces computation slightly. Many modern large sequence models use RMSNorm instead of LayerNorm.
BatchNorm
Batch normalization computes statistics over the batch and often spatial dimensions:
During inference, BatchNorm usually uses running estimates rather than current-batch statistics. This train/inference difference is why BatchNorm can be fragile with tiny batches, distribution shift, or gradient accumulation.
Train vs Inference Boundary
LayerNorm and RMSNorm usually compute statistics from the current example at both train and inference time. BatchNorm usually has two modes:
and similarly for variance. This creates a stateful boundary:
must be saved and restored with the model when BatchNorm is used.
Pre-Norm vs Post-Norm
For a residual block :
Pre-norm often improves optimization stability in deep Transformers because gradients can flow through the residual path more directly.
Scale and Residual Interaction
Normalization controls feature scale before or after residual updates. In deep residual stacks:
lets the identity path carry directly. Post-norm:
renormalizes the residual stream after every block. This can improve bounded activations but make gradient flow harder in very deep Transformers.
Parameter and Decay Boundary
Normalization parameters are often excluded from weight decay:
This is a training recipe choice, not a law. If weight decay is applied to normalization scales, the run record should say so because it can affect calibration and stability.
Where It Appears
- Pre-norm and post-norm Transformer blocks.
- Stabilizing deep residual networks.
- Training large sequence models with long contexts.
- CNNs and vision models through BatchNorm, GroupNorm, or LayerNorm variants.
Checks
- Identify LayerNorm, BatchNorm, RMSNorm, or GroupNorm.
- Check whether normalization happens before or after residual branches.
- BatchNorm depends on batch statistics; LayerNorm does not.
- Normalization can change behavior between training and inference depending on type.
- Check the normalized axis: feature, channel, batch, group, token, or spatial dimension.
- Check whether and are present and whether bias is disabled in adjacent layers.
- Check whether running statistics exist and are saved in the checkpoint.
- Check whether normalization parameters are included in weight decay.
- For distributed training, check whether statistics are local, synchronized, or example-wise.