Word pieces
Built BPE from scratch (3.87 chars/piece at 4k vocab) across TinyStories and 10 Gutenberg novels.
My try at building an LLM from scratch · open source
From a MacBook Air to 286.7 million knobs on rented GPUs for $2.45, and how it compares to GPT and Claude.
knobs in the biggest brain, trained from random numbers
total rented-GPU spend across all three cloud runs
faster training on a rented RTX A5000 vs the MacBook Air M4
preference win-rate after taste training on the flagship
pieces the JavaScript browser engine matches with PyTorch
Why I built this
Everyone uses ChatGPT and Claude. I wanted to build one myself in pure PyTorch with no training frameworks, so every piece stays visible and now runs right inside your browser.
User: write a short story about a brave little owl and a golden key.
● A real run of the 13.8M model, replayed
Live · 14 MB brain
Loads into this tab, then writes at about 90 pieces a second on an M-series Mac.
What I did on my Mac · $0.00
I started with a 4.8M character-level Shakespeare model, wrote a BPE tokenizer from scratch, upgraded to Llama-style parts one change at a time, and ran all three post-training stages on a 16 GB MacBook Air M4.
Built BPE from scratch (3.87 chars/piece at 4k vocab) across TinyStories and 10 Gutenberg novels.
Upgraded one piece at a time: RoPE, RMSNorm, SwiGLU, bf16 autocast and fused SDPA attention.
Prompt masking (-100) taught chat manners; anchored DPO fixed reward hacking cleanly.
Packed 4-bit quantization (7x smaller) + KV cache (89 tok/s) in Mac app, iPhone and browser.
Guess the next piece millions of times. Val score dropped 8.501 → 2.080 → 1.795.
13.8M val 1.795
13,852 pairs graded only on the reply (-100 prompt mask). Now it answers and stops.
13.8M 1.438 · 97.6M 1.336
Two stories, one liked. Learns to stay on topic and drop clumsy repetition.
win-rate 92.5% → 96.7% → 98.3%
Lily loves Lily's key. Lily does Lily's mom's idea…
Cramming "Lily's" in widened the score gap. The score went up; the stories fell apart. Reward hacking at 14M knobs.
An anchor for fluency.
Adding 0.5x chosen NLL kept liked stories grammatical, as Llama 3 did. The loophole closed and win-rate hit 92.5% peak.
26.2M total knobs, only 11.6M awake per word. Loss 2.461 → 1.966. moe.py
Baby Hedwig taught by the 13.8M teacher (6.8 MB), still writes full stories. distill.py
Training step 596 → 99 ms, identical next 80 pieces to PyTorch. mlx_bench.py
Layers streamed from SSD: 52.9 → 18.8 MB held in memory, 33 tok/s. ssd_runner.py
64-seat Core ML export matching PyTorch, plus Swift tokenizer. export_iphone.py
2.56M knobs on public-domain Dumas & Verne, val 7.776 → 3.541. lang_hedwig.py
Same 13.8M chat brain, same test, lower is better. 8-bit is free; 4-bit costs 0.023.
Why the Mac wasn't enough & why GPUs are faster
Training work scales as FLOPs = 6 × knobs × tokens. A full pass over TinyStories takes ~20 hours on a fanless MacBook Air M4 as it thermally throttles from 66s to 110s per 250 steps, and a 4k dictionary chops rare names apart. I rehearsed a 2-step dry run on Mac (92s) and rented RunPod GPUs.
Why NVIDIA GPUs fly
Data-center GPUs run thousands of dedicated bf16 Tensor Cores in parallel, execute fused CUDA FlashAttention in fast SRAM, push hundreds of GB/s across 24 to 48 GB VRAM, and keep active cooling so speed never drops.
Why 14M failed Harry Potter
Without a single token for "Potter", 14M Hedwig saw "pot" + "ter", latched onto "pot", and turned Harry into a puppy or Timmy making a pot of soup. At 8k and 16k vocab, the whole name stays whole.
Keep scrolling →
How much we improved
Different dictionaries (4k, 8k and 16k) make raw reading scores unfair to compare. Comparing the models side by side across specs and unedited outputs from docs/STORY_SHOWDOWN.md shows the exact improvement.
| Metric | 13.8M Mac | 97.6M Cloud | 286.7M Flagship |
|---|---|---|---|
| Layout (layers × width × heads) | 6 × 384 × 6 | 12 × 768 × 12 | 20 × 1024 × 16 |
| Context / Vocabulary | 256 / 4,096 | 256 / 8,192 | 512 / 16,384 |
| Hardware & Cost | Mac M4 · $0.00 | 1× A40 (66m) · $0.65 | 1× 4090 (115m) · $1.70 |
| Tokens seen (per knob) | ~125M (~9 / knob) | ~164M (~1.7 / knob) | ~205M (~0.7 / knob) |
| Stage 2 SFT / Stage 3 DPO win | 1.438 / 92.5% | 1.336 / 96.7% | 1.341 / 98.3% |
| 4-bit compressed size | 7.9 MB | 55.2 MB | 161.9 MB |
From docs/STORY_SHOWDOWN.md, seed 42, temperature 0.65. Cut for length, never rewritten.
Hedwig vs GPT & Claude
ChatGPT and Claude use the same Transformer blocks and three-stage training (Pretrain, SFT, DPO/RLHF). Frontier models aren't hiding a secret algorithm: they wire 10,000 to 100,000+ GPUs together to read 20+ tokens per knob across trillions of web, code and book tokens.
| Model | Knobs | GPUs Used | Tokens Read | Tokens / Knob | Cost (est.) |
|---|---|---|---|---|---|
| Mac Hedwig | 13.8M | 1× MacBook Air M4 | ~125M | ~9.0 | $0.00 |
| Cloud Hedwig | 97.6M | 1× NVIDIA A40 | ~164M | ~1.7 | $0.65 |
| Flagship Hedwig | 286.7M | 1× NVIDIA RTX 4090 | ~205M | ~0.7 | $1.70 |
| GPT-2 Small (2019) | 124M | 32× Cloud TPU v3 | ~10B | ~80 | ~$1k-$5k |
| GPT-3 (2020) | 175B | ~1k-10k× V100 | ~300B | ~1.7 | ~$4.6M |
| Llama 3 (2024) | 405B | 16,384× H100 | 15.6T | ~38.5 | ~$50M+ |
| GPT-4/5 · Claude Opus | 1T+ (est.) | 10k-100k+ H100/B200 | 10T-20T+ | ~20+ & RL | $50M-$500M+ |
All public domain or openly licensed. No outputs from closed commercial models.
The receipts & what I learnt
Every cloud run was rehearsed on the Mac first with a 2-step dry run, so no rented minute went to finding bugs.
RECEIPT · 15-20 NOV 2026
THANK YOU FOR TRAINING SMALL

Small models, cheap community GPUs, one rehearsed script, no wasted runs. The flagship read about 0.7 pieces per knob, far under the Chinchilla rule of about 20, to stay on budget. Its weaker grammar edits are the exact cost of that trade.
On screen



Said plainly & what I learnt
A frog grabs Lily's umbrella, then thanks Lily for helping it. The 14M brain renamed an owl three times in one story.
286.7M read ~0.7 tokens per knob vs 97.6M's ~1.7 tokens per knob, so 97.6M fixed "I goes" to "I go" while 286.7M missed it.
Open source
Six days, three brains, $2.45, and a model that now lives in a browser tab. Built to understand how GPT and Claude work, one measured step at a time.