Phase 2 — Transformer Foundations

The "under the hood" phase. Every serving optimization, cost behavior, and model-page number you'll meet later is a consequence of what's in this phase. You don't implement transformers here — you learn them deeply enough to reason about memory, latency, and cost on sight.

Why this phase matters

Phase 1 gave you the vocabulary; Phase 2 gives you the mechanisms behind it. After this, KV cache OOMs, prefill/decode latency, MoE memory surprises, and reasoning-model cost are all predictable rather than mysterious.

Documents

#DocumentWhat you'll be able to do
00The Transformer Big PictureMap any cost/perf question to a component
01Token EmbeddingsReason about embeddings, RoPE, and context extension
02Attention and Self-AttentionExplain O(n²) cost, GQA, FlashAttention, sliding windows
03Feed-Forward LayersSee where params/knowledge live; understand MoE's target
04LayerNorm and ResidualsUse the residual-stream model; know RMSNorm/pre-norm
05Autoregressive GenerationReason about serial decode, latency, and speedups
06KV CacheCompute KV memory; understand PagedAttention/prefix caching
07Prefill vs DecodeAttribute latency to the right phase and fix it
08MoE and Dense ModelsDecode 26B-A4B; predict memory vs speed
09Reasoning ModelsRoute by difficulty; control reasoning cost/latency

How to work through it

Read in order — each builds on the last (embeddings → attention → FFN → norm/residual → generation → KV cache → prefill/decode → MoE → reasoning). Do the labs: they produce a memory/KV calculator and latency-measurement tools you'll reuse in Phases 6–8.

Phase 2 artifacts

  • An architecture-tracing script + memory/KV calculator (GQA- and MoE-aware)
  • From-scratch attention, FFN (+SwiGLU), RMSNorm/residual block, and an autoregressive generator
  • Latency benchmarks: prefill-vs-decode, TTFT/TPOT, and a reasoning on/off + difficulty router
  • Notes/diagrams: the symptom→component map, residual stream, and the total-vs-active param rule

Next

Phase 3 — Model Cards and System Cards