passdrill
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 020/024 medium

Xiong et al. (2020), "On Layer Normalization in the Transformer Architecture," compare two ways of placing layer normalization relative to each sublayer's residual connection: Post-LN, used in the original Transformer, and Pre-LN. What did they find about training stability, and what practical consequence follows for Post-LN training?

  1. Pre-LN and Post-LN produce identical gradient magnitudes at initialization, so the choice between them has no measurable effect on how training proceeds
  2. Post-LN, which applies layer normalization after the residual addition, produces expected gradients near the output layer that grow large at initialization, which the authors show makes a learning-rate warm-up stage necessary; placing layer normalization inside the residual block instead (Pre-LN) keeps gradients well-behaved at initialization without requiring warm-up
  3. Pre-LN requires a longer warm-up stage than Post-LN because normalizing before each sublayer slows down how quickly gradient magnitudes stabilize during the first training steps
  4. The placement of layer normalization only affects inference-time computation cost and has no bearing on gradient behavior or the need for a warm-up stage during training
Next card → Shuffle