Skip to content
Road to Intelligence

Concept · Chapter 7: Transformers

Layer Normalization

Must knowUnderstand10 minDifficulty

Layer normalization rescales each token's vector to zero mean and unit variance (then applies a learned scale and shift), keeping activations in a stable range.

The problem

As vectors pass through many layers, their scale can drift up or down, making training unstable and sensitive to the learning rate.

The solution

Normalize each vector across its own features — independently of other examples in the batch — before (or after) each sublayer.

The consequence

Deep Transformers train stably. Where the normalization sits (before each sublayer, 'pre-LN') and its exact form (e.g. RMSNorm) are small choices that matter at scale.

You should understand first

  1. Vectors
  2. Layer Normalization

What it computes

For one token's vector xx with dd features:

LN(x)=γ⊙x−μσ2+ϵ+β\text{LN}(x) = \gamma \odot \frac{x - \mu}{\sqrt{\sigma^2 + \epsilon}} + \beta

where μ\mu and σ2\sigma^2 are the mean and variance of xx's own dd entries. After normalization every token vector has a predictable scale; γ\gamma and β\beta are learned so the model can undo the normalization where useful.

Pre-LN vs post-LN

The original Transformer normalized after each residual addition. GPT-2 and most later models normalize the input to each sublayer instead, leaving the residual path untouched — which trains more stably in deep models.

What to remember

  • Normalize each token's vector: subtract its mean, divide by its standard deviation.
  • Learned γ (scale) and β (shift) restore flexibility.
  • Pre-LN (before each sublayer) is the common modern placement.

Key papers

Important

Layer Normalization

Jimmy Lei Ba, Jamie Ryan Kiros, Geoffrey E. Hinton · 2016

The normalization used inside Transformers; it keeps activations at a stable scale regardless of batch size.

~30 min readarXiv:1607.06450✓ verified 2026-09-26
Optional

On Layer Normalization in the Transformer Architecture

Ruibin Xiong, Yunchang Yang et al. · 2020 · ICML 2020

Explains why modern Transformers put layer normalization before each sublayer ('pre-LN') rather than after it.

~1 h readarXiv:2002.04745✓ verified 2026-09-26