Neural network → LLM · in 17 steps
Seventeen small, runnable Python scripts that climb from a 60-line neural network to a 2026-architecture, instruction- and preference-tuned GPT — down to a quantized KV cache. No black boxes — every idea inside a frontier model, built and run by hand.
The arc
Each script teaches exactly one new idea and builds directly on the last. Nothing is imported that you haven't already built yourself.
A neural net learns "what comes next." Counting, then gradient descent, then turning text into tokens.
Embeddings and context windows, how autograd works, and the switch to PyTorch so gradients compute themselves.
Attention, the transformer block, a real GPT on Shakespeare — then sampling, training, and alignment up to 2026 spec.
The climb
Seventeen rungs, each its own page — the idea, the key formula, the theory, the real terminal output, and the full source. Every page also links to an executed Jupyter notebook you can run yourself.

predict the next character by counting
→
softmax + cross-entropy via gradient descent
→
char-level and Byte-Pair Encoding (BPE)

the Bengio MLP — names start looking real
→
a mini-micrograd — how backprop automates itself
→
all the hand-coded backprop collapses to one line

the mechanism that makes transformers work
→
multi-head attention + MLP + residuals + norm
→
trained on Shakespeare — it generates text

temperature, top-k, top-p — one model, many writers
→
resumable checkpoints + LR warmup/decay
→
base model → assistant (the ChatGPT leap)

the modern alternative to RLHF
→
RoPE · RMSNorm · SwiGLU · GQA
Checked May 2026
The transformer hasn't been replaced; it's been refined. Two fronts have moved since 2017 — the architecture, and how models are aligned after pre-training. Steps #13 and #14 bring this ladder up to current spec.
| Component | Classic | Modern |
|---|---|---|
| Position | learned absolute | RoPE |
| Norm | LayerNorm | RMSNorm |
| Feed-forward | ReLU MLP | SwiGLU |
| Attention | multi-head | GQA |
| Result | val 1.674 / 465K | val 1.634 / 418K |
Every major model this past year — DeepSeek-R1, Nemotron, GPT-5-class — uses a modular stack rather than plain RLHF:
SFT · #12 instruction following
DPO · #13 preference alignment, no reward model
GRPO RL with verifiable rewards, for reasoning
The other front is inference efficiency (steps #15–#16): the KV cache, then quantizing it to ~3 bits with Google's TurboQuant. Beyond that, all variations on what you've built — Multi-Latent Attention (DeepSeek) compresses the cache further; Mixture-of-Experts routes each token to a few specialist MLPs; QK-Norm adds stability. The atom is unchanged — it's attention, all the way down.
Get going
Pure Python. One-time setup, then run any script. The GPT trains in ~2 minutes on a laptop CPU and caches its weights so every later step loads instantly.
# one-time setup python3 -m venv .venv .venv/bin/pip install numpy torch # climb the ladder (run from the repo root) .venv/bin/python steps/01_foundation/00_neural_network.py # the atom .venv/bin/python steps/04_transformer/09_tiny_gpt.py # a real GPT on Shakespeare .venv/bin/python steps/06_sota_2026/14_modern_gpt.py # the 2026 architecture