Overview

Normalization techniques stabilize and accelerate training by normalizing inputs to each layer. The two main types are Batch Normalization and Layer Normalization, which differ in what they normalize.

Quick Comparison

AspectBatch NormalizationLayer Normalization
Normalizes acrossBatch dimension (samples)Feature dimension (within sample)
TargetEach feature across batchAll features within one sample
DependencyRequires batch statisticsIndependent of batch size
Best forCNNs, large batchesRNNs, Transformers, small batches
Training vs InferenceDifferent behaviorSame behavior

Batch Normalization

See Layer & Batch Normalization - Batch Normalization.

Layer Normalization

See Layer & Batch Normalization - Layer Normalization.

When to Use Which?

Use Batch Normalization When

  • Working with CNNs (Convolutional Neural Networks)
  • Have large batch sizes (>32)
  • Training feedforward networks
  • Want additional regularization effect
  • Batch statistics are meaningful (e.g., images are IID)

Use Layer Normalization When

  • Working with Transformers or RNNs
  • Have small batch sizes or online learning (batch size = 1)
  • Sequence lengths vary (RNNs, NLP tasks)
  • Batch statistics are not meaningful
  • Need consistent behavior between training and inference

Example Use Cases

TaskRecommended
Image Classification (CNN)Batch Norm
Object DetectionBatch Norm
Language Models (Transformer)Layer Norm
Machine Translation (RNN)Layer Norm
Time Series (varying batch)Layer Norm
Few-shot LearningLayer Norm

Other Normalization Techniques

Instance Normalization

Normalizes each sample and each channel independently. Used in style transfer.

nn.InstanceNorm2d(num_features)

Group Normalization

Divides channels into groups and normalizes within each group. Middle ground between LayerNorm and InstanceNorm.

nn.GroupNorm(num_groups, num_channels)

Summary

Key Insight: The main difference is the normalization axis:

  • BatchNorm: Normalizes across the batch dimension (each feature separately)
  • LayerNorm: Normalizes across the feature dimension (each sample separately)

Choose based on:

  1. Architecture (CNN → BatchNorm, Transformer → LayerNorm)
  2. Batch size (Large → BatchNorm, Small → LayerNorm)
  3. Task requirements (Sequence models → LayerNorm)

References

  1. BatchNorm and LayerNorm | by Florian June | Medium
  2. Why do transformers use layer norm instead of batch norm? - Cross Validated
  3. PowerNorm: Rethinking Batch Normalization in Transformers
  4. Batch Normalization Paper (Ioffe & Szegedy, 2015)
  5. Layer Normalization Paper (Ba et al., 2016)