Layer Normalization › Layer Normalization

Michael BrenndoerferUpdated June 11, 20254 min read
Language AI HandbookAll chapters
Part 15 of 67Transformer Blocks
Chapter 104Layer Normalization › Layer Normalization
Reading section 1 of 16 · Layer Normalization · 4 minSection 1 of 16 · 4 min

Book contents

Section 1 of 16 · 4 min read

Layer Normalization › Layer NormalizationOne section · Sections in this chapter1 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Batch normalization transformed how we train deep feedforward networks, but it stumbles when applied to transformers. The batch dimension becomes problematic: batch sizes vary, sequences have different lengths, and the statistics computed across a batch of diverse sentences lack semantic coherence. Layer normalization, introduced by Ba et al. (2016), sidesteps these issues entirely by normalizing across features rather than across the batch. This seemingly simple change made layer normalization the default normalization technique for transformers, from the original "Attention is All You Need" architecture to modern large language models.

In this chapter, we'll explore why layer normalization works so well for transformers, how it differs from batch normalization in both computation and behavior, and the subtle implementation details that affect training stability. We'll also examine how the placement of layer normalization within transformer blocks affects learning dynamics, a design choice that has evolved significantly since the original transformer architecture.

To appreciate why layer normalization matters, you need to first understand what can go wrong without it. Deep neural networks are sensitive creatures. The gradient signal that propagates through dozens or hundreds of layers is amplified and attenuated by countless multiplication operations. When activations at one layer are large, subsequent layers receive outsized gradients that cause unstable weight updates. When activations are small, gradients vanish before they can reach the earliest layers. Without intervention, training can become brittle or slow and may fail catastrophically.

Normalization techniques solve this by actively constraining the statistical distribution of activations at each layer. Rather than hoping that careful initialization and learning rate schedules will keep activations well-behaved throughout training, normalization directly resets the distribution at predefined points in the network. The question is not whether to normalize, but how. Different normalization strategies make different tradeoffs between computational cost, statistical quality, and architectural compatibility. Batch normalization was the answer for convolutional networks. Layer normalization turned out to be the answer for transformers.

The key intuition is that transformers process each token as an independent entity. When the model applies attention, each token gathers context from others, but each token's representation still flows through the layers as a distinct vector. It makes sense, then, to normalize each representation individually, based on its own statistics, rather than blending its statistics with those of other samples in the batch. Layer normalization does exactly this, and the result is a normalization scheme that works consistently regardless of batch size, sequence length, or what other samples happen to be processed at the same time.

Historical Context: The Road to Stable Deep Learning

The problem of training instability in deep networks predates transformers by decades. Early neural networks in the 1980s and 1990s were often limited to just two or three layers, partly because deeper networks were nearly impossible to train reliably. Vanishing and exploding gradients, first formally analyzed by Hochreiter in 1991 and Bengio et al. in 1994, explained why: gradients either shrank exponentially as they propagated backward, starving early layers of learning signal, or grew exponentially, causing catastrophic weight updates.

Batch normalization, introduced by Ioffe and Szegedy in 2015, was a breakthrough for convolutional networks, enabling stable training of very deep architectures. However, its reliance on batch statistics made it unsuitable for recurrent models and transformers. Layer normalization (Ba et al., 2016) solved this by shifting from batch statistics to per-sample statistics. The original transformer paper (Vaswani et al., 2017) adopted layer normalization from the outset, and every major language model since, including BERT, GPT, T5, and LLaMA, has built on this foundation. More recently, variants like RMSNorm and Pre-LayerNorm have refined the approach further, trading some statistical richness for computational efficiency.