LLM · Theory · LM12
LM12-T1 — Capstone Brief and Scoping for Limited Compute
The best capstone is the smallest one that can show the whole method. Decide what you will not do before you start, and write down what would count as success.
Modules 1 to 11 gave you the parts: data, tokenizers, attention, GPT, pretraining, fine-tuning, evaluation, architecture and applications. The capstone asks you to assemble them into one small system and to defend what you found. Most capstones that fail do so before the first training run, because the scope does not fit the compute, the success criterion is vague or nothing is there to compare with. This lesson gives a way to choose a feasible project, to calculate its cost on paper and to plan four milestones with checkpoints where you may shrink the scope. The notebooks LM12-L1 to LM12-L3 and the review lab LM12-L4 follow the same plan on a default project.
Learning objectives
After this lesson, you should be able to:
- Choose a capstone project that fits CPU or modest GPU compute and state a measurable success criterion.
- Estimate parameters, training FLOPs, time and memory from simple formulas.
- Plan four milestones with decision gates and the baselines that each result must beat.
- Write a one-page brief and a risk list.
The idea: show the whole method on something small
What is assessed in a capstone is the method, not the size: a clear question, honest data handling, a baseline, a controlled experiment, an evaluation with uncertainty, an application that treats the model as untrusted, and a report whose claims match its evidence. A tiny model on a closed task shows all of that. A 7-billion-parameter fine-tune that you cannot afford to repeat shows none of it, because you cannot run the baselines, the ablation or the extra seeds.
Pick a project type that fits
| Project type | What you build | Compute | What it shows | Main risk |
|---|---|---|---|---|
| A. Small GPT on a closed task | data pipeline, tiny GPT trained from scratch, evaluation, application layer | CPU, minutes | the whole pipeline end to end; the default of this track | the task is so regular that a rule-based system wins |
| B. Classification fine-tune | fine-tune a small pretrained model for a labelled task, compare with baselines | CPU or one GPU, tens of minutes | transfer, evaluation with imbalanced classes | label noise, leakage between train and test |
| C. Parameter-efficient fine-tune | LoRA on a small instruction model, compare with a full fine-tune of a smaller model | one GPU with 8 to 16 GB | adaptation trade-offs, memory arithmetic | compute for repeats; evaluation noise |
| D. Retrieval application | chunking, retrieval, grounded answering, citations, injection tests | CPU for retrieval; a hosted or local model for generation | application-level evaluation and security | weak gold labels, generator variance |
| E. Evaluation study | compare existing models or prompts on a carefully built test set | little training compute | measurement, statistics, honest reporting | a test set too small to separate the systems |
If you are unsure, choose A or D: both run on a laptop and leave room for baselines, seeds and failure analysis. Whatever you choose, state the question as something with a measurable answer: “Does masking the prompt in the loss improve exact match on unseen bay numbers?” is a question; “build a good model” is not.
The one-page brief
- Question,One sentence, answerable by an experiment.
- Data,Source, size, licence, how it is split, what is held out and why.
- Baselines,At least two: a trivial one (majority, nearest neighbour, random) and a competent one (a rule-based system, a simpler model, a pretrained model you do not train).
- Method,The model and training setup in three lines; what you vary in the ablation.
- Metrics and success criterion,The metric, the test set, the interval method and the threshold that counts as success, fixed before you see results.
- Compute budget,Estimated FLOPs, memory and wall-clock, and what you will cut if it is too much.
- Risks,The three things most likely to go wrong, each with a mitigation.
Write the success criterion first
The mathematics: what will it cost?
Four formulas cover most scoping decisions. For a model with N parameters trained on D tokens (Module 5):
- N
- number of parameters; for a GPT with width d, L layers, vocabulary V and context nctx: L(12d² + 13d) + 2Vd + nctx·d + 2d (for the PyTorch attention module with biases).
- D
- tokens processed = batch size × sequence length × steps.
- effective FLOP/s
- what the hardware really delivers on your code, usually 20 to 60% of the peak on a GPU and much less on a CPU for small models; measure it once.
The default project. The tiny GPT of notebooks LM12-L2 and LM12-L3 has d = 64, L = 2, V = 49, nctx = 75: N = 111,168 (the code below, and PyTorch, agree). A run of 1,000 steps with batch 32 and sequence 75 processes D = 2.4 million tokens: 6 · 111,168 · 2.4·106 = 1.6·1012 FLOPs. At an effective 50 GFLOP/s this is 32 s, which matches the 20 to 25 seconds measured on a laptop to within the accuracy of the assumption. Training memory is 16 · 111,168 = 1.78 MB plus activations: trivially small.
A larger project. One pass of a 124-million-parameter model over one million tokens costs 6 · 124·106 · 106 = 7.4·1014 FLOPs, 4.1 hours at 50 GFLOP/s, and 16 · 124·106 = 2 GB of training state before activations. Pretraining it on 300 million tokens would take 1,240 hours on that CPU and about 1.6 hours on a 100 TFLOP/s GPU at 40% utilisation: possible there, not on a laptop. Fine-tuning for classification on 20,000 tokens: 0.08 hours on the CPU.
Repeats multiply cost. Baselines, an ablation with two variants and three seeds each means 6 training runs: budget six times the single-run time, plus evaluation. A project that can be run once can be reported only as an anecdote.
A worked example: the budget calculator
The code computes parameters, FLOPs, time and memory for the default project and for two larger ones, and prints a comparison across hardware. Use it for your own project before you commit to it.
def gpt_params(d, layers, vocab, ctx):
block = 12 * d * d + 13 * d # attention (4d² + 4d), MLP (8d² + 5d), two LayerNorms (4d)
return layers * block + vocab * d + ctx * d + 2 * d + vocab * d # blocks, token table, positions, final norm, output head
def train_flops(params, batch, seq, steps):
return 6 * params * batch * seq * steps # about 6 FLOPs per parameter per token (forward + backward)
def train_memory_bytes(params):
return 16 * params # float32 weights, gradients and two AdamW moments
def hours(flops, flops_per_second):
return flops / flops_per_second / 3600
n = gpt_params(64, 2, 49, 75)
print(n) # 111168
f = train_flops(n, 32, 75, 1000)
print(f"{f:.3g}", round(f / 5e10, 1)) # 1.6e+12 32.0 (seconds at an effective 50 GFLOP/s)
print(round(train_memory_bytes(n) / 1e6, 2)) # 1.78 (MB)
big = train_flops(124e6, 1, 1_000_000, 1) # one pass over one million tokens with a 124M-parameter model
print(f"{big:.3g}", round(hours(big, 5e10), 1)) # 7.44e+14 4.1 (hours on the same CPU)
print(round(train_memory_bytes(124e6) / 1e9, 2)) # 1.98 (GB, before activations)
options = [("command parser from scratch", 1.6e12), ("classifier fine-tune, 124M, 20k tokens", 6 * 124e6 * 20_000),
("pretrain 124M on 300M tokens", 6 * 124e6 * 300e6)]
for name, fl in options:
print(f"{name:42s} {hours(fl, 5e10):10.2f} h on a CPU, {hours(fl, 1e14 * 0.4):8.3f} h on a 100 TFLOP/s GPU at 40%")
# command parser from scratch 0.01 h on a CPU, 0.000 h on a 100 TFLOP/s GPU at 40%
# classifier fine-tune, 124M, 20k tokens 0.08 h on a CPU, 0.000 h on a 100 TFLOP/s GPU at 40%
# pretrain 124M on 300M tokens 1240.00 h on a CPU, 1.550 h on a 100 TFLOP/s GPU at 40%
The effective rate of 50 GFLOP/s is an assumption; if your first run takes twice as long as predicted, halve the rate and recompute. The point of the calculator is to be right about the order of magnitude: a project that needs 1,240 hours does not fit a laptop however carefully you plan the milestones.
The four milestones and their gates
| Milestone | Deliverable | Gate before the next | If the gate fails |
|---|---|---|---|
| 1 · Data and pipeline | dataset, split without leakage, tokenizer, dataset card, passing tests | Gate A: does the full plan fit the compute budget? | reduce data, model size or number of variants |
| 2 · Model and experiment | baselines, training loop, logged runs with seeds, ablation | Gate B: does the model beat the baselines, and do you have enough runs to compare? | simplify the task or report the negative result honestly |
| 3 · Evaluation and application | intervals, slices, error taxonomy, paired test, validated application | Gate C: is every claim supported by a number you can show? | weaken the claim; add evidence if cheap |
| 4 · Report | report, README, reproduction instructions | final review with the rubric of Lab LM12-L4 | fix the lowest-rated items |
Risk list for the default project
| Risk | Early sign | Mitigation |
|---|---|---|
| Leakage between train and test | near-perfect scores immediately | split before any other processing; check shared inputs (Notebook LM12-L1) |
| Task too easy | a rule-based baseline scores 100% | say so in the report; add a harder slice or choose a task that needs learning |
| Noise hides the effect | seeds disagree by as much as the variants | more seeds; paired tests; a larger evaluation set |
| Time runs out | milestone 2 still not done at the half-way point | cut variants, not evaluation or the report |
| Overclaiming | adjectives like “clearly” | check each claim against Lab LM12-L4 |
Engineering implications and limitations
Do the arithmetic before the code. A five-line calculator prevents most infeasible plans. Record the prediction, then compare it with the measured time and learn your effective FLOP/s.
Keep a project repository from day one. One folder, one environment file, one script per milestone, results written to files, and the brief at the top of the README. You will thank yourself at milestone 4.
Fix the evaluation before the model. Build the test set and the metric in milestone 1 and do not look at them while developing. The temptation to change the test set to make a result work is the largest source of unreproducible results.
Reserve a third of the time for evaluation and writing. Training is the visible part; the evidence and the report are what is judged.
Prefer a smaller question answered well. A clean negative result (“masking made no detectable difference with this setup and these seeds”) is publishable in a report; a muddled positive one is not.
For robots. If your project drives or advises a robot, the application layer and the safety policy are part of the scope, not an extension. Decide in the brief which actions the system may ever propose, and test the validator with hostile input (Module 11). The Physical AI and VLA tracks on this site cover the robot side in depth.
Common misconceptions
“A bigger model makes a better capstone.”
A model you can retrain, ablate and evaluate several times shows more than one you can train once.
“Baselines are optional if the model works.”
Without baselines you do not know whether it works; a rule-based or trivial system can match it.
“I can decide what counts as success after I see the results.”
That is how a chosen comparison becomes a claim. Fix the criterion first.
“Compute estimates are only for big projects.”
They keep small projects honest too: they tell you how many seeds you can afford.
“The report is the easy part.”
It is where unsupported claims appear; plan time for it.
Engineering takeaways
- Choose the smallest project that shows the whole method, state a measurable question and fix the success criterion before running anything.
- Training cost: FLOPs ≈ 6·N·D, memory ≈ 16·N bytes plus activations; time = FLOPs / effective FLOP/s. The default project has 111,168 parameters, 1.6·10¹² FLOPs per run and takes about half a minute on a laptop.
- Plan four milestones with three gates (fit the compute, beat the baselines, back every claim) and cut scope at a gate rather than late.
- Budget for repeats: baselines, ablation variants and several seeds multiply the single-run cost.
- Write the one-page brief and a risk list now; they become the skeleton of the report.
References and further reading
The cost formulas are the standard approximations also used in Modules 5 and 8; every number in this lesson was computed by the code shown. The effective rate of 50 GFLOP/s is an assumption for a laptop CPU, not a measurement of your hardware.
- Raschka, S. (2024). Build a Large Language Model (From Scratch). Manning (the book on which this track is based); companion code at the repository named in the track resources.
- Kaplan, J. et al. (2020). Scaling laws for neural language models. arXiv:2001.08361.
- Hoffmann, J. et al. (2022). Training compute-optimal large language models. arXiv:2203.15556.
- Build a Large Language Model (From Scratch), the whole book (primary book reference)
- Publisher page for the book (primary book reference)
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
A model has 50 million parameters and you train it on 100 million tokens. Estimate the FLOPs, and the time at an effective 2×10¹³ FLOP/s.
Explanation
6 × 50·10⁶ × 100·10⁶ = 3·10¹⁶ FLOPs; 3·10¹⁶ / 2·10¹³ = 1,500 s, 25 minutes.
Question 2
Why is a capstone with a rule-based baseline that scores 100% still valuable, and what must the report say?
Explanation
It still shows the method: pipeline, experiment, evaluation and application. But the report must state that a simple rule-based system solves the task, so the learned model is not justified on performance and the project is about the method, not the product.
Question 3
You have time for 6 training runs. Which design is better: 6 variants with one seed each, or 2 variants with 3 seeds each?
Explanation
Two variants with three seeds each: the comparison needs an estimate of seed-to-seed variation, which one seed per variant cannot give, and fewer variants keep the question focused.
What’s next
Next: experiment design and reproducibility: baselines, ablations, seeds and logs.
Related content
Nothing below is required to finish this lesson.
- BeforeLM11-T6: Security, Prompt Injection and Robot Safety
Recognise injection and unsafe-action risks and keep a safety layer between a model and a robot.
- LabLM12-L1: Capstone Milestone 1: Dataset, Tokenizer and Pipeline
Prepare a dataset, a tokenizer and a data pipeline with checks.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.