Transformers

Dive into Deep Learning · §11

Transformers: From One Block to Frontier Architectures
residual stream · pre-norm & SwiGLU · GPT · KV cache & roofline · encoders & ViT · scaling laws · Mixture of Experts

Why Attention Alone Is Not Enough

Motivation

  • Missing per-token nonlinearity: Without a position-wise FFN, stacked attention layers cannot synthesize hierarchical nonlinear features within each token vector.
  • Depth instability & bandwidth walls: Deep stacks require pre-norm residual streams, and generation streams all 12 L d^2 block weights and the KV cache from HBM.

The Four Architectural Pillars of Chapter 11

Architectural Roadmap

  • 1. Build & Train (§§11.1–11.2): Pre-norm, RMSNorm, QK-Norm, 1/\sqrt{2L} scaling, SwiGLU, and decoder-only GPT pretraining.
  • 2. Serve & Compress (§11.3): KV caching, roofline analysis, GQA, low-rank MLA, and attention sinks.
  • 3. Rewire & Scale (§§11.4–11.7): Encoders, cross-attention, ViT patches, Chinchilla scaling laws, and sparse Mixture of Experts (MoE).

Concrete Single-GPU Benchmarks Across Chapter 11

Running Examples

  • Every architectural mechanism in this chapter is verified on reproducible models that train or profile on a single GPU in minutes:
  • End-to-end validation: From 32-layer initialization audits and byte-level WikiText-103 pretraining to RTX 4090 roofline profiling, 15-model IsoFLOP fits, and 8-expert MoE routing.

From the 2017 Transformer to the Modern Recipe

The Modern Recipe

  • Every model in this chapter is an instance of one parameterized constructor whose defaults match frontier open-weights LLMs (RMSNorm, RoPE, SwiGLU, GQA/MLA, MoE).
  • Up next (§11.1 The Transformer Block): How pre-norm placement, RMSNorm, QK-Norm, and SwiGLU prevent token collapse and keep gradients well-behaved across depth.