02 Foundations

Normalization, from BatchNorm to RMSNorm

Normalization keeps a network's activations or weights in a well-behaved range, so training stays fast and stable. Batch Norm suits CNNs with large batches. Layer Norm is the default for Transformers and RNNs. RMSNorm is the cheaper, modern drop-in that skips re-centering. Group Norm handles small batch sizes. Instance Norm is used for style transfer, and Weight Norm smooths the loss landscape by normalizing weights directly. Pick the one that matches your architecture and batch regime.

Why normalization matters

If you have ever watched a training run diverge at epoch 3 or plateau for hours, the culprit is often un-normalized activations. I reach for normalization first for a few reasons:

  • Faster optimization. Normalization prevents weights from exploding by restricting them to a certain range, so the optimizer can take larger, more confident steps.
  • Unbiased features. Without normalization, features with naturally larger magnitudes dominate the gradient signal. Normalization gives each feature comparable influence.
  • Implicit regularization. Adding noise through mini-batch statistics (or channel statistics) acts as a lightweight regularizer, reducing overfitting in practice.

Normalization accelerates and stabilizes learning. The harder question is which normalization to use, and that is what the rest of this post covers.


What normalization does

Every normalization technique follows roughly the same template:

output = (input - mean) / std · γ + β

You compute a mean and standard deviation over some set of dimensions, normalize, then let the network learn a scale (γ) and shift (β) to recover any representation it needs. The techniques differ only in which dimensions you compute those statistics over. That single design choice determines when and where a method works well.

Normalization statistics computed over different tensor dimensions
Figure 1 Normalization dimensions at a glance.

Layer Norm

Layer Norm normalizes each individual example across all of its features. For a single sample in the batch, you compute the mean and variance over the entire [C, H, W] volume (or, in a Transformer, across the hidden dimension).

pout = (pin - μt) / σt · γe + βe

What I like about Layer Norm:

  • Re-centering. It makes the model insensitive to shift noise on both inputs and weights.
  • Re-scaling. It keeps output representations intact when inputs and weights are randomly scaled.
  • Applied at test time with the same formula, so there is no need to track running statistics.
When to reach for it. Layer Norm is the default in Transformers and works well in RNNs. If you are building anything sequence-to-sequence, start here.
Layer Norm normalizes each example across all of its features
Figure 2 Layer Norm normalizes per example.

Batch Norm

Batch Norm goes the other direction: instead of normalizing within a single example, it normalizes across the mini-batch dimension for each feature channel. You subtract the batch mean and divide by the batch standard deviation, then apply learned γ and β per channel.

pout = (pin - μc) / σc · γc + βc

Batch Norm eases optimization and enables very deep networks to converge. It also serves as a regularization technique because the per-batch statistics inject noise.

The problems I keep running into

  • Small batches hurt it. Batch Norm's error increases rapidly when the batch size drops below about 8. If you are on a single GPU with large images, this is a real problem.
  • RNNs are a bad fit. Sequences from different samples can have different lengths, so you would need a separate normalization layer for each timestep, which is space-consuming and awkward.
Batch Norm error rises as batch size falls
Figure 3 Batch Norm error against batch size.
Batch Norm algorithm recap. Given a mini-batch B = {x1 ... xm} and learnable parameters γ, β: (1) compute mini-batch mean, (2) compute variance, (3) normalize with a small stability constant ε, (4) scale and shift. Full algorithm on page 10 of the PDF.

Batch Norm remains the best choice for CNN tasks with large, fixed-size batches. Outside that regime, look elsewhere.


Group Norm

Group Norm is the batch-size-independent alternative I reach for whenever Batch Norm is not viable. It divides the channels of each training example into G groups and computes mean and variance within each group.

μi = (1/m) ∑ xk
σi = √( (1/m) ∑ (xk - μi)2 + ε )

Because statistics are computed per-example, there is zero dependence on batch size. Whether you are running batch size 2 or 64, Group Norm gives you the same behavior.

Two special cases worth memorizing:

  • Set G = 1 (one group containing all channels) and you get Layer Norm.
  • Set G = C (each channel is its own group) and you get Instance Norm.

The TensorFlow implementation from the original paper is compact:

def GroupNorm(x, gamma, beta, G, eps=1e-5):
    N, C, H, W = x.shape
    x = tf.reshape(x, [N, G, C // G, H, W])
    mean, var = tf.nn.moments(x, [2, 3, 4], keep_dims=True)
    x = (x - mean) / tf.sqrt(var + eps)
    x = tf.reshape(x, [N, C, H, W])
    return x * gamma + beta
Group Norm splits channels into groups within each example
Figure 4 Group Norm forms channel groups within each example.

RMSNorm

RMSNorm is the normalization you will find inside LLaMA, Gemma, and most recent large language models. It is an extension of Layer Norm that drops the re-centering step entirely and normalizes by the root mean square of the activations instead.

RMS(a) = √( (1/n) ∑ ai2 )
āi = (ai / RMS(a)) · gi

Why I prefer it for large-scale training:

  • One pass instead of two. Layer Norm needs a pass to compute the mean and another for variance. RMSNorm only needs one pass to compute the RMS, which is real wall-clock savings at scale.
  • Re-scaling invariance and implicit learning rate adaptation, without the cost of re-centering.
  • Better with high-variance data, since it handles large activation magnitudes more gracefully than standard Layer Norm.
Practical note. If you are fine-tuning any modern LLM (LLaMA, Mistral, Gemma), you are already using RMSNorm whether you realize it or not. Understanding it helps you debug training instabilities.

Instance Norm and Weight Norm

These two are more specialized, but worth knowing.

Instance Norm

Instance Norm is like Layer Norm but normalizes across each channel independently in each training example. It is applied at test time, just like Layer Norm.

ytijk = (xtijk - μti) / √(σti2 + ε)

Its main use is to make the network agnostic to the contrast of the original image, which is why it became the default in style transfer and image generation tasks.

Weight Norm

Weight Norm normalizes the weights of the layer rather than the activations. It separates the weight vector into a magnitude and a direction:

w = (g / ||v||) · v

This decoupling gives you a smoother loss landscape and more stable training. I have found it most useful in CNN tasks, often as a complement to other normalization methods.

Instance Norm and Weight Norm diagrams
Figure 5 Instance Norm and Weight Norm.

MNIST convergence

I ran Batch Norm, Layer Norm, Instance Norm, and Group Norm on MNIST to see how they compare on a simple task:

  • Training error. Group Norm and Batch Norm converge fastest.
  • Validation error. Batch Norm achieves the lowest error, which suggests its implicit regularization from batch statistics helps on well-behaved, large-batch CNN tasks.
Training and validation error curves on MNIST
Figure 6 Training and validation error curves on MNIST.

When to use what

My decision process:

  1. Transformer or RNN? Use Layer Norm (or RMSNorm if you want efficiency).
  2. CNN with large batches? Use Batch Norm.
  3. CNN with small/variable batches? Use Group Norm.
  4. Style transfer or generative images? Use Instance Norm.
  5. Want a smoother loss landscape on CNNs? Try Weight Norm.
  6. Training a large language model from scratch? Use RMSNorm.

Quick reference

Technique Normalizes Over Batch Dependent? Best For Test Time
Batch Norm Mini-batch (N) per channel Yes CNNs, large batches Running stats
Layer Norm All features per example [C,H,W] No Transformers, RNNs Same formula
Group Norm Channel groups per example No CNNs, small batches Same formula
RMSNorm All features (RMS only) No LLMs, high-variance data Same formula
Instance Norm Per channel, per example No Style transfer Same formula
Weight Norm Weight vectors No CNNs, smooth optimization Same formula

Based on my presentation "Survey of Normalization Techniques" at Berkeley EECS. The original slides, including all diagrams and the full algorithm pseudocode, are in Normalization_Techniques.pdf.