Generative models · build one by hand
Build a Large Language Model — From Scratch
A linearized, first-principles build of a GPT: from a single character to a model that writes text, classifies spam, and follows instructions. Every piece — the tokenizer, embeddings, attention, the transformer block, the training loop, fine-tuning — is derived as the forced answer to one question, not asserted because "GPT has it."
This is the gentle, hands-on sibling of the systems-heavy CS336 — Language Modeling from Scratch. CS336's spine is a fixed compute budget spent at frontier scale (GPUs, kernels, parallelism, scaling laws, serving). This track stays at the workbench: we build every matrix by hand, watch the machine generate text, and only at the end name what changes at scale — handing you off to CS336 and the six-lesson Mini GPT post-training tour when you're ready.
The spine — one forced chain
Read the diagram left to right, top row then bottom. Each box is a wall; the arrow into the next box is the idea it forces. Nothing is here "because LLMs have it" — remove any link and the chain breaks.
The lessons
How to use this
- Read it linearly. Each lesson is the answer to the wall the last one hit. Attention (04) only makes sense as the fix for the rigid average of lesson 03; instruction tuning (13) only as the thing classification (12) can't do.
- Touch every knob. Each widget has a setting that breaks — attention that freezes without the √d_k scale, a deep stack that explodes without residuals, a run that diverges, a model that overfits. Find it. The failure is the lesson.
- Follow the cross-links. Where a sibling track goes deeper — scale, kernels, parallelism, preference optimization — this track links out instead of repeating.