RepositoryPython
KA

karpathy/nanochat

The best ChatGPT that $100 can buy.

61.0kstars
8.6kforks
30issues
2views

🤖 nanochat: $50 GPT-2

Train GPT-2-grade LLM for under $50. One script, one GPU node, full pipeline.

nanochat — minimal, hackable LLM training harness by karpathy. Covers every stage: tokenization, pretraining, finetuning, evaluation, inference, chat UI. Train GPT-2 capability on 8XH100 for ~$48 (~2 hours). Spot instances drop cost to ~$15. Original GPT-2 cost ~$43,000 in 2019.

✨ Highlights

  • Single dial --depth: sets layer count. Width, heads, learning rate, training horizon, weight decay — all auto-calculated from optimal scaling laws.
  • Full pipeline: tokenization → pretraining → finetuning → evaluation → inference → web UI. No glue code.
  • Speedrun script: runs/speedrun.sh trains GPT-2-grade model end-to-end in ~2 hours on 8XH100.
  • Cost record: $48 on on-demand GPUs, ~$15 on spot. GPT-2 (2019): $43,000.
  • Leaderboard: wall-clock race to GPT-2 CORE score (0.256525). Current record: 1.65 hours (autoresearch round 2).
  • uv deps: uv sync --extra gpu for CUDA, --extra cpu for CPU/MPS. Dev group adds pytest, matplotlib, transformers.
  • Single GPU mode: drop torchrun, code auto-switches to gradient accumulation. 8x slower, identical results.
  • Chat UI: python -m scripts.chat_web serves ChatGPT-like interface. Visit printed URL.

💡 Why it matters

nanochat compresses full LLM stack into minimal, readable code. No complex pipelines — one script trains and serves. The --depth abstraction kills hyperparameter tuning: set layers, scaling laws handle the rest.

Leaderboard turns training into a community speedrun. Under-$50 GPT-2 democratizes LLM experimentation. Best fit: researchers, hobbyists, educators wanting end-to-end LLM understanding without infrastructure overhead.


#LLM #OpenSource #GPT2 #TiniX