AI Infra Interviews logo

Karpathy’s 7 Repositories: A Practical AI Engineering Learning Path

Learn from micrograd, minbpe, nanoGPT, llm.c, nanochat and autoresearch with concrete exercises, current repository caveats and a path from gradients to evaluation.

BY OWEN HARTLEY · AIINFRAINTERVIEWS EDITORIAL · UPDATED NOVEMBER 24, 2026 · 5 MIN READ

PRACTICE THIS:Build a tiny language model (free) ·Read the MiniMind guide ·Study training infrastructure ·Practice fixed-budget evaluation (Premium)

Karpathy's repositories can form a useful path from gradients to language-model training, kernels and automated experiments. The value comes from producing an explanation or a working artifact at each step. Reading seven READMEs, collecting stars or completing a list does not demonstrate that you can operate a model service.

The sequence below uses official repositories checked on November 24, 2026. It combines code reading with original exercises and links to our practice material. You can begin the small exercises on CPU; later training and CUDA work have separate hardware requirements. No training-cost or speed claim from the screenshots is treated as a result we reproduced.

Choose a starting point by the gap you need to close

If you cannot explain how a shared variable receives gradient contributions, begin with micrograd. If that is familiar but model inputs feel opaque, start with minbpe. If you already train small models and want to reason about GPU execution, use llm.c with its reference implementation.

The ordering is a teaching recommendation, not a dependency chain that requires running every repository. The MiniMind reading guide is an alternative compact route through a training pipeline. Use whichever implementation lets you trace a complete example without losing track of its tensors.

Seven repositories, seven observable outputs
Comparison
RepositoryStudy this boundaryProduce this artifact
microgradA scalar computation graph and its backward traversalOne derivative checked against a numerical estimate
nn-zero-to-heroLanguage-model inputs, loss and samplingA notebook explaining one full update
minbpeUTF-8 bytes, merge rules and token IDsRound-trip tests and a saved tokenizer comparison
nanoGPTA compact model and training loopA checkpoint-resume equivalence check
llm.cReference math and C/CUDA executionA numerical comparison before a timing claim
nanochatTokenization through evaluation and inferenceA run manifest linking every stage
autoresearchProposal, bounded run and selectionAn experiment ledger plus a held-out final evaluation
Original learning assignments. Hardware needs depend on the selected exercise; these are not seven completed benchmark reproductions.

1. micrograd: explain accumulation before optimization

micrograd implements scalar reverse-mode automatic differentiation. Trace a value used by two branches and explain why contributions add into the same gradient.

For an original pencil exercise, let f(w)=w²+3w. At w=2, f=10 and df/dw=2w+3=7. Compare that with the centered numerical estimate (f(2+ε)−f(2−ε))/(2ε) at ε=0.0001. The two branches contribute 4 and 3. A backward implementation that overwrites instead of accumulating a gradient loses one contribution.

Next repeat backward without clearing gradients and inspect what accumulates. Forward Pass, Backpropagation and Optimizer Steps connects that behavior to a training update. The exit condition is being able to explain every contribution, including repeated uses of the same parameter.

2. nn-zero-to-hero: follow a whole training example

nn-zero-to-hero contains lecture notebooks and exercises. Choose one language-model notebook and trace an input batch to target IDs, logits, loss, gradients and an optimizer step.

Record the shapes on that path. Change one target and predict which loss terms should change before running the notebook. Keep training and evaluation data distinct. The artifact is a short annotated trace, not a screenshot of a decreasing loss curve. Our tiny language model project provides a separate CPU exercise if you want a bounded implementation to complete first.

3. minbpe: treat the tokenizer as model state

minbpe exposes byte-level BPE training, encoding and decoding. Train a tiny tokenizer on a declared corpus, save it, reload it and check round trips on accented text, emoji, whitespace and repeated punctuation.

Then train another tokenizer with a changed corpus or vocabulary size. Compare token IDs for the same input. Correct round trips do not make those tokenizers interchangeable with a model trained on different IDs. Store tokenizer identity with the checkpoint and record any special-token policy. Tokens, Embeddings and Logits explains why visible text is insufficient to identify the model's actual input.

4. nanoGPT: learn from a compact historical implementation

The nanoGPT README now explicitly calls the project old and deprecated and points readers to nanochat. That changes how to recommend it: it remains useful for studying a compact model and loop, while current end-to-end experiments should consider the successor's documented path.

For a small controlled exercise, save at an optimizer boundary. Compare an uninterrupted continuation with a restored continuation using the same batch order. Check parameters, optimizer state, random state and step counters under the chosen determinism settings. A model that loads and generates text has not yet demonstrated faithful training resumption. Fault-Tolerant Training develops the operational version of this requirement.

5. llm.c: establish numerical agreement before speed

llm.c includes C/CUDA implementations and a PyTorch reference. Pick one operation, specify inputs and compare its forward output and backward gradients against the reference before measuring performance.

For GPU timing, warm up the path and time completed device work. Record shape, dtype, compiler settings and device. A timer around asynchronous submission measures something different. If you lack a CUDA device, study the CPU reference and label that scope; it does not reproduce a GPU speed comparison. The Kernels and the Machine course provides the progression from memory access to profiling evidence.

6. nanochat: connect the stages into one record

nanochat covers tokenization, pretraining, fine-tuning, evaluation and inference. Follow one documented small configuration through those stages, with a budget appropriate to your hardware.

Create a manifest containing the repository revision, tokenizer revision, data split identities, training configuration, checkpoint, evaluation command and inference template. When changing a stage, identify which downstream artifacts must be regenerated. A better chat response after a template change cannot automatically be attributed to training. The evaluation infrastructure concept explains how to preserve that chain of evidence.

7. autoresearch: evaluate the experiment loop itself

autoresearch uses a small single-GPU training setup for repeated agent-proposed experiments with a five-minute training budget. Its repository instructions describe the experiment, not authority for an agent to change an unrelated workspace or spend an unbounded budget.

Begin by reviewing one proposed change yourself. Fix the allowed files, compute limit, metric direction and failure policy. Keep attempted runs, crashes and rejected changes in the ledger. At the inspected revision, GitHub did not identify a license; verify licensing before redistributing or incorporating its code rather than assuming that public visibility grants the same rights as the MIT-licensed projects above.

Keep selection feedback away from the final evaluation

Step 1 of 4: Specify one hypothesis

  1. Specify one hypothesis

    Name the expected improvement and keep the compute budget and evaluation protocol fixed.

  2. Run the bounded experiment

    Preserve the exact revision, configuration, elapsed time and failures.

  3. Select using development results

    Compare the candidate with the baseline; retain rejected attempts in the record.

  4. Evaluate the frozen choice

    Use a held-out final set after selection. If it guides another change, it has become development data.

Repeated optimization can adapt to an evaluation set even when that set never supplies training gradients.

Turn the reading path into engineering evidence

For each stage, keep four things: what you predicted, what you ran, what you observed and what the observation does not prove. A gradient check does not qualify distributed training. A local chat demo does not establish multi-user latency or safe failure recovery. Extend the artifact when the next task requires those properties.

The fixed-training-budget lesson adds a selection exercise for repeated experiments. Use it after you can reproduce one baseline. If a project becomes too large to explain, reduce the data, model or operation until the next result tests one concrete hypothesis.

PRACTICE THIS

Turn it into offers. Work the real questions and concepts this maps to:

FAQ

Start with micrograd if gradients and backpropagation are unfamiliar, then use nn-zero-to-hero for the training sequence. If those ideas are already clear, enter at the tokenizer, training-loop or kernel exercise that matches your gap.

Discussion (3)

Owen HartleyEditor

A resume test is easier to diagnose when the next batch is saved explicitly. Otherwise a different data-order state can look like a broken optimizer restore.

Morgan FosterEditor

An experiment ledger should keep the unsuccessful runs. Showing only the winner hides how much selection was performed against the development metric.

Ruiqi ZhouEditor

For finite differences, sweep epsilon. A single matching value is reassuring, but cancellation and rounding can make the estimate unstable as epsilon gets too small.