Batch Norm vs Layer Norm
Q: What does normalization do, and why do transformers use LayerNorm?
Normalize activations to zero mean / unit variance, then apply learned scale γ and shift β. Smoother loss landscape, allows higher learning rates, less sensitivity to init.
- BatchNorm: statistics over the batch (per channel). Needs running averages for inference; behaves poorly with small or variable batches and sequences. Standard in CNNs.
- LayerNorm: statistics over the features of each example → independent of batch size, same at train/inference; standard in transformers/RNNs. RMSNorm drops the mean subtraction (LLaMA).
- Pre-LN (normalize before the sublayer) trains more stably than Post-LN in deep transformers.
tensor [batch N, features C]
BatchNorm: normalize each column (over N) LayerNorm: normalize each row (over C)