01 / 11 · The build contract
Define the machine before you build it
Turn “build an LLM” into a ladder of testable artifacts: scalar autograd, a character model, a Transformer, then a budgeted training run.
Watch, then build
The Karpathy workshop is embedded beside a shorter narrated build-along. Use the workshop for the full derivation; use the build-along to understand the mechanism, implementation order, and failure checks before you type.
Skim the ten-video sequence; do not start the GPT-2 capstone yet. Open on YouTube ↗
Pause after each scene and reproduce the visible invariant in your own repository.
Before pressing play
Predict first.
Write a one-sentence prediction for the mechanism below. Keep it visible while you work; revise it only after the build gives you evidence.
Demonstrated objectives
- Distinguish a toy language model, a pretrained base model, and a chat assistant.
- Choose a capstone tier that matches available compute.
- Explain the course’s recurring training loop in one minute.
The mental model
These three ideas are the reference layer behind the videos. If a narrated step feels too fast, return here and trace the causal claim in prose.
The finish line is behavior, not parameter count
A useful first build is small enough to inspect. You should be able to overfit one batch, trace tensor shapes, sample text, and explain why the loss moves. GPT-2-scale reproduction is a later systems exercise, not proof that the fundamentals are understood.
Three different things are often called “an LLM”
A base model predicts continuations from pretraining data. Supervised fine-tuning changes the dataset and behavior. Preference or reinforcement stages further shape responses. This course builds the base-model mechanism first and labels assistant training as a separate extension.
Pick a compute lane now
The CPU lane trains tiny character or byte models. The single-GPU lane scales the same code to a compact Transformer. The cluster lane reproduces GPT-2-style throughput work. The concepts are shared; the batch size, model width, dataset, and runtime are not.
The workbench
Type this shape yourself. The snippet is a compass, not a complete solution.
# One invariant survives every scale
logits = model(x) # [batch, time, vocab]
loss = cross_entropy(logits, y) # one scalar
loss.backward() # gradients for parameters
optimizer.step() # a slightly better modelBuild gate
- Create a repository with data.py, model.py, train.py, sample.py, and tests/.
- Write down your lane: CPU, single GPU, or cluster.
- Set one observable finish line: “generate 200 tokens after training and explain every tensor shape.”
- Record a hard budget for time and cloud spend before any long run.
Failure signatures
Diagnostic checks
A correct click is practice, not proof. Explain the answer aloud and use the build gate for demonstrated mastery.
1. Which artifact is produced directly by ordinary next-token pretraining?
2. What is the strongest first-course finish line?
Primary evidence
Evidence record IDs
ev_0a9c8a2be1259dd831c9 · ev_595344e0b1cb01a5f986 · ev_1219445d15f2f3af28de
These IDs connect the page, narration, visual cues, checks, and frozen source snapshot.