🟣 Technical 10 min read

Normalization in Deep Learning: Batch Norm, Layer Norm, and Beyond

Normalization layers are everywhere in modern deep learning, but why? This guide explains what each technique does, when to use it, and why transformers prefer layer norm over batch norm.

View all deep learning depths β†’

Every modern neural network architecture uses some form of normalization. It’s in every transformer block, every ResNet residual connection, every GAN generator. Yet most practitioners treat normalization layers as black boxes β€” you add them because the architecture diagram says to. Let’s fix that.

Why normalize at all?

During training, the distribution of inputs to each layer changes as the preceding layers’ weights update. This phenomenon β€” called internal covariate shift β€” means each layer is constantly adapting to a moving target. Training becomes slower and more fragile as networks get deeper.

Normalization stabilizes these distributions. By ensuring each layer receives inputs with consistent statistical properties (roughly zero mean, unit variance), we allow the network to train faster, use higher learning rates, and generalize better.

Batch Normalization

The technique that started it all (Ioffe & Szegedy, 2015). For each feature in a mini-batch, batch norm computes:

$$\hat{x} = \frac{x - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}}$$

Where $\mu_B$ and $\sigma_B^2$ are the mean and variance computed across the batch dimension. It then applies learned scale ($\gamma$) and shift ($\beta$) parameters:

$$y = \gamma \hat{x} + \beta$$

What it normalizes: Each feature independently, using statistics from the mini-batch.

Works well for: CNNs, where spatial features benefit from being normalized across the batch. ResNets, EfficientNets, and most vision architectures use batch norm.

Problems:

  • Depends on batch size. Small batches give noisy statistics.
  • Behaves differently at train time (batch statistics) vs inference time (running statistics). This train/eval mismatch causes subtle bugs.
  • Doesn’t work well for variable-length sequences (common in NLP).

Layer Normalization

Layer norm (Ba et al., 2016) normalizes across features rather than across the batch:

$$\hat{x} = \frac{x - \mu_L}{\sqrt{\sigma_L^2 + \epsilon}}$$

Where $\mu_L$ and $\sigma_L^2$ are computed across all features for a single sample.

What it normalizes: All features within a single input, independent of other samples in the batch.

Why transformers use it: Layer norm doesn’t depend on batch size, works identically at train and inference time, and handles variable-length sequences naturally. Every transformer since the original uses layer norm.

Pre-norm vs post-norm: The original transformer applied layer norm after the residual connection (post-norm). Modern transformers apply it before (pre-norm), which improves training stability, especially for deep models. GPT, LLaMA, and most recent architectures use pre-norm.

RMSNorm

A simplification of layer norm that skips the mean-centering step:

$$\hat{x} = \frac{x}{\sqrt{\frac{1}{n}\sum x_i^2 + \epsilon}}$$

RMSNorm is computationally cheaper (no mean computation, no subtraction) and has been shown to perform comparably to layer norm. LLaMA, Mistral, and many recent LLMs use RMSNorm.

Group Normalization

Splits channels into groups and normalizes within each group. A compromise between layer norm (one group) and instance norm (each channel is its own group).

Best for: Computer vision tasks with small batch sizes, such as object detection and segmentation where memory constraints limit batch size.

Instance Normalization

Normalizes each channel of each sample independently. Commonly used in style transfer and image generation, where you want to remove instance-specific contrast information.

Choosing the right normalization

ArchitectureRecommendedWhy
CNN (large batches)Batch NormBest-studied, strong results
CNN (small batches)Group NormStable with small batches
TransformerLayer Norm or RMSNormBatch-independent, handles sequences
GAN generatorInstance Norm or Group NormStyle-agnostic features
RNN/LSTMLayer NormHandles variable sequences

Practical tips

Don’t combine batch norm with dropout. They interact poorly β€” dropout changes the effective batch statistics, making batch norm’s estimates noisier. Use one or the other.

Learning rate and normalization are coupled. Models with normalization can typically handle higher learning rates. If you remove normalization, reduce the learning rate.

Watch for train/eval discrepancies with batch norm. Always call model.eval() before inference. Forgetting this is one of the most common PyTorch bugs.

Pre-norm transformers are easier to train. If you’re building a transformer from scratch, use pre-norm unless you have a specific reason not to.

Normalization isn’t glamorous, but it’s load-bearing. Understanding what it does β€” and why your architecture uses the variant it does β€” makes you a better practitioner.

Simplify

← Mixture-of-Experts Explained

Go deeper

Deep Learning Overfitting: A Practical Guide to Prevention and Diagnosis β†’

Related reads

deep-learningnormalizationbatch-normlayer-normtraining

Stay ahead of the AI curve

Weekly insights on AI β€” explained at the level that's right for you. No hype, no jargon, just what matters.

No spam. Unsubscribe anytime. We respect your inbox.