Layer normalization is a normalization technique that standardizes the activations of a single token position across its feature dimensions, independently of every other position and example in the batch. Introduced by Jimmy Ba, Jamie Kiros, and Geoffrey Hinton in 2016 for recurrent networks, it became a fixed component of the Transformer, whose blocks wrap their attention and feed-forward sublayers in the paper's "add and norm" pattern: a residual connection followed by normalization.12 Its per-position statistics made deep residual stacks trainable at any batch size, which is why it displaced batch normalization in sequence models and survives, in full or simplified form, in every modern large language model.1

Role in the network

A Transformer block alternates an attention sublayer and a feed-forward sublayer, each wrapped in a residual connection and a normalization. The normalization's job is to hold the statistics of the residual stream in check: as additions accumulate through dozens of layers, the mean and scale of the activations drift, and deep stacks become hard to optimize. Layer normalization re-standardizes each token's vector before or after each sublayer, so every sublayer sees inputs with controlled moments regardless of what happened upstream.1

The design was a deliberate answer to batch normalization, the 2015 technique that standardized each feature across the examples of a training batch.5 Batch statistics fail for variable-length text in two ways. Sequence batches vary in length and composition, so a feature's batch mean at training time is not a stable property of the data. And autoregressive inference decodes one token at a time with no batch to average over, so the operation would depend on stored running statistics that cannot match the shifting distribution of real decoding. Layer normalization sidesteps both problems: because the statistics come from within a single position, the operation behaves identically in training and inference and at any batch size, the property that made it preferable to batch normalization for sequence models, whose batches vary in length and composition.1

The mathematics

For one token's activation vector \(x \in \mathbb{R}^{d}\), with \(d\) the model dimension, layer normalization computes the mean and variance over the feature dimension:

$$\mu = \frac{1}{d} \sum_{i=1}^{d} x_i, \qquad \sigma^2 = \frac{1}{d} \sum_{i=1}^{d} \left( x_i - \mu \right)^2$$

It then standardizes the vector and applies a learned per-feature scale and shift:

$$y = \frac{x - \mu}{\sqrt{\sigma^2 + \epsilon}} \odot \gamma + \beta$$
Symbol Shape Meaning
\(x\) \(d\) activation vector at one token position
\(\mu\), \(\sigma^2\) scalars mean and variance of \(x\) across its \(d\) features
\(\epsilon\) scalar small constant for numerical stability (typically \(10^{-5}\))
\(\gamma\), \(\beta\) \(d\) each learned per-feature scale and shift
\(y\) \(d\) normalized output

The subtraction, division, scale, and shift are elementwise, and the division uses \(\sqrt{\sigma^2 + \epsilon}\) so that a constant input never divides by zero.1

The 2017 Transformer normalized after each residual addition, an arrangement now called post-norm; later work moved the normalization inside the residual branch, called pre-norm. With \(\mathrm{Sublayer}\) standing for attention or the feed-forward network, and \(x\) the incoming residual stream:23

$$\text{post-norm:}\quad z = \mathrm{LayerNorm}\!\left( x + \mathrm{Sublayer}(x) \right), \qquad \text{pre-norm:}\quad z = x + \mathrm{Sublayer}\!\left( \mathrm{LayerNorm}(x) \right)$$

In the post-norm form every path through the block is re-standardized, so the residual stream itself always holds normalized values, but gradients must pass backwards through every normalization. In the pre-norm form the residual stream is an unbroken identity path from input to output, which Xiong et al. showed lets gradients flow unimpeded and removes the need for learning-rate warm-up; pre-norm became the default in GPT-style and open-weight models.3

Worked example: normalizing one token

Take \(d = 4\) and \(x = (2, 4, 4, 6)\), with \(\epsilon\) small enough to ignore. The mean is \(\mu = (2 + 4 + 4 + 6)/4 = 16/4 = 4\). The deviations are \((-2, 0, 0, 2)\), so the variance is \(\sigma^2 = (4 + 0 + 0 + 4)/4 = 2\) and the standard deviation is \(\sqrt{2} \approx 1.4142\). Dividing the deviations by \(\sqrt{2}\):

$$\hat{x} = \frac{x - \mu}{\sqrt{\sigma^2}} = \left( \frac{-2}{1.4142},\ 0,\ 0,\ \frac{2}{1.4142} \right) \approx (-1.4142,\ 0,\ 0,\ 1.4142) = (-\sqrt{2},\ 0,\ 0,\ \sqrt{2})$$

With \(\gamma = (1, 1, 1, 1)\) and \(\beta = (0, 0, 0, 0)\), the output \(y = \hat{x}\) is exactly the standardized vector: its mean is \((-1.4142 + 0 + 0 + 1.4142)/4 = 0\) and its variance is \((2 + 0 + 0 + 2)/4 = 1\), which is what standardization promises. In a trained model, \(\gamma\) and \(\beta\) reintroduce a per-feature scale and offset on top of this neutral starting point.

Intuition

Statistically, layer normalization re-expresses every token in units of its own standard deviation: the raw magnitudes a token happens to carry are discarded as drift, and the network re-learns the magnitudes it actually wants through \(\gamma\) and \(\beta\). Those two learned vectors keep the operation from being a straitjacket, since with them the layer can still represent any per-feature affine rescaling; standardization costs the model no expressivity, only two reductions over the feature dimension.1

The per-token granularity is what fits text. A token's information is carried in its own feature vector, so standardizing within the vector keeps each position self-contained: sentences of different lengths and batches of different compositions all normalize the same way, and decoding a single token at inference time is no different from training.1 The placement question is about gradients rather than statistics. Xiong et al. showed that in post-norm stacks the gradients near the output layer are large at initialization, which destabilizes training unless the learning rate is warmed up slowly, while the pre-norm identity path keeps gradients well-behaved from the start.3

Variants and extensions

The dominant simplification is RMSNorm, proposed by Zhang and Sennrich in 2019, which drops the mean subtraction and the learned shift and rescales by the root mean square of the features; it matched layer normalization's stability at lower cost and now dominates new designs.4 The placement variants, post-norm and pre-norm, are the other main axis along which the 2017 design has been modified, and they compose with either normalization function.3

Adoption

Layer normalization is built into every Transformer since the 2017 paper's "add and norm" pattern.2 Beyond the Transformer lineage, it is standard wherever residual stacks appear, from BERT-style encoders to the Vision Transformer and the denoising backbones of Stable Diffusion. Its per-token formulation also suits autoregressive inference, where batch composition cannot be known in advance, one reason it survived essentially unmodified from the GPT-1 era into current frontier stacks, where full layer normalization or its RMSNorm descendant precedes every sublayer.

Limitations and critiques

The operation is cheap in FLOPs but not free: it adds two reductions and two learned vectors per site, it is bound by memory bandwidth rather than arithmetic, and at inference it sits on the critical path of every sublayer, one motivation for the leaner RMSNorm.4 The placement trade is also real. Post-norm keeps the residual stream itself standardized but trains poorly at depth without careful learning-rate warm-up; pre-norm trains stably but leaves the residual stream unnormalized, so the stream's magnitude can drift with depth and the final normalization before the output projection carries the whole burden of readout.3 Finally, nothing in the operation aligns statistics across positions: layer normalization is a per-token device by construction, and any cross-token structure passes through it untouched.

History

Batch normalization had standardized activations across the batch dimension in 2015, transforming convolutional training but fitting sequence models poorly.5 Ba, Kiros, and Hinton published layer normalization in July 2016, targeting recurrent networks, whose variable-length sequences make batch statistics awkward.1 Vaswani et al. made it a fixture of the Transformer in June 2017, applied after every residual addition.2 GPT-style decoder models then moved the normalization inside the residual branch, and Xiong et al. explained in February 2020 why that change stabilizes deep training.3 Zhang and Sennrich's RMSNorm (2019) then simplified the operation itself by dropping the mean-centering, and now dominates new designs.4

See also

References


  1. Ba, L. J., Kiros, J. R., and Hinton, G. E., "Layer Normalization," arXiv:1607.06450, July 2016. ↩↩↩↩↩↩↩↩

  2. Vaswani, A., et al., "Attention Is All You Need," arXiv:1706.03762, June 2017. ↩↩↩↩

  3. Xiong, R., et al., "On Layer Normalization in the Transformer Architecture," arXiv:2002.04745, February 2020. ↩↩↩↩↩↩

  4. Zhang, B., and Sennrich, R., "Root Mean Square Layer Normalization," arXiv:1910.07467, October 2019. ↩↩↩

  5. Ioffe, S., and Szegedy, C., "Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift," arXiv:1502.03167, February 2015. ↩↩