Highlights

Contents

A HAND-DRAWN FIELD GUIDE / OCTLM UNIT IIThe ModernBlockFrom the 2019 GPT-2 layer to the 2024 Llama 3 layer,one upgrade at a time.MODERN DECODER BLOCKRMSNormq, k, v (GQA)RoPE on q, kSDPA / FlashRMSNormSwiGLU MLP++residualstream× 32 of these in Llama 3 8BCHAPTER 2 / EVERY UPGRADE, COUNTED AND CODEDsame skeleton,better parts.
Before we start

How to read this chapter

The older decoder works, but its components leave room for better scale control, feature selection, and memory use. This chapter explains the changes behind the modern recipe.

Each part asks what an upgrade replaces, why it helps, and which conventions a correct implementation must match. Start with the attention and decoder-block guide. Use the drawings to explain the change before consulting its formula or code.

Each part ends with an “In one breath” recap. The interview page has questions, graded exercises, and worked solutions; try the reasoning before reading the answer.

The running example

Meet Finch-24

Finch-24 rebuilds Finch-19 with the 2024 recipe. Width, depth, vocabulary, and query-head count stay fixed, so the comparison focuses on architecture. Llama 3 8B supplies the larger-model reference.

Setting Finch-19 (2019 recipe) Finch-24 (2024 recipe) Changed in
Vocabulary V 32,000 32,000
Width d_model 512 512
Layers N 8 8
Query heads H 8 8
Key/value heads H_kv 8 2 Part IV
Head size d_head 64 64
Positions learned table, 1,024 rows RoPE, base 10,000, no table Part I
Context T_max 1,024 4,096 Part I
Normalization LayerNorm, pre-norm RMSNorm, pre-norm, ε = 1e-5 Part II
MLP GELU, 2,048 wide SwiGLU, 1,536 wide Part III
Attention kernel written by hand SDPA / FlashAttention Parts V, VI
Biases everywhere none Part VII
Output head tied to embeddings tied to embeddings
Parameters 42,128,384 40,509,952 Part VII

An upgrade need not make a model larger. Shared KV heads reduce retained history; RMSNorm simplifies scale control; SwiGLU adds input-dependent feature selection. Whether the combined recipe improves quality still requires training and evaluation.

The map

What is inside

Seven parts, one upgrade each, then the assembled block. The map shows the modern block with every changed part marked; each part lights up its own piece.

YOU ARE HEREMODERN DECODER BLOCKATTENTION HALFRMSNormq, k, v projRoPE (q, k)GQA: 8 q, 2 kvSDPAFlash kernelo proj+MLP HALFRMSNormgate, up projSiLU(g) ⊙ udown proj+residual stream: x + Attn(Norm(x)), then h + MLP(Norm(h))what changed since GPT-2: positions, norm, MLP, K/V sharing, the attention kernel, and no biases
  1. 01RoPE, ProperlySections 1 to 6. Rotary positions must match the saved model.
  2. 02RMSNorm: Rescale, Skip the Re-CentringSections 7 to 11. Deep stacks need reliable scale control.
  3. 03SwiGLU: A Gated MLPSections 12 to 16. An MLP can learn content and its gate separately.
  4. 04Grouped-Query AttentionSections 17 to 21. Generation repeatedly reads stored attention history.
  5. 05SDPA: One Call, Several KernelsSections 22 to 26. An attention API can select different implementations.
  6. 06FlashAttention: Exact Attention That Respects MemorySections 27 to 32. Attention can spend more time moving intermediates than computing them.
  7. 07The Modern Decoder Block, AssembledSections 33 to 38. The upgrades leave the decoder's basic structure intact.
  8. +Interview prepInterview question bank, graded exercises and worked solutions.