The Transformer

Layer 2 · Mechanics

The Transformer

Pre-LN vs post-LN placement, encoder/decoder vs decoder-only architectures, and how the pieces assemble into a full model.

10 min read70 XP

The block from Layer 1 has one crucial design choice left unspecified: exactly *where* normalization sits relative to the residual connection. This single placement decision determines whether a 96-layer model trains at all.

Post-LN (original 2017 Transformer)

  • x ← Norm(x + Sublayer(x))
  • Normalizes the residual stream itself
  • Deeper stacks are unstable to train
  • Needs careful learning-rate warmup

Pre-LN (GPT-2 onward, current default)

  • x ← x + Sublayer(Norm(x))
  • Residual stream itself is never normalized
  • Gradients flow cleanly through many layers
  • Trains stably even at 100+ layers
Pre-LN won because it makes the residual stream's identity path completely untouched.
Go deeper: L3 Code