nanoGPT
Minimal PyTorch codebase for training and fine-tuning medium-sized GPTs, reproducing GPT-2 on OpenWebText.
About
Two files of about 300 lines each, model.py and train.py, are the entire core of nanoGPT, Andrej Karpathy's minimal codebase for training and fine-tuning medium-sized GPTs. It reproduces the 124M-parameter GPT-2 on OpenWebText in about four days on an 8xA100 40GB node, loads OpenAI's released GPT-2 checkpoints for fine-tuning, and scales down to a character-level Shakespeare model that trains in minutes on a single GPU or even a CPU. Dependencies are just PyTorch, NumPy, transformers, datasets, tiktoken, wandb, and tqdm, with PyTorch 2.0 compilation on by default, and multi-node training works over DDP. The MIT-licensed repository has around 61,700 stars and spawned an active speedrun community that competes on wall-clock time to GPT-2 quality. A README notice added in late 2025 steers newcomers to the full-stack successor nanochat, but nanoGPT remains the standard teaching codebase for LLM pretraining: readable in an afternoon, hackable by design, and the starting point for countless research forks, ports, and educational videos.
Should you use nanoGPT?
Pick it when
Use it to learn or teach GPT pretraining from code small enough to read in an afternoon, or as a hackable research baseline, from character-level Shakespeare on a laptop to GPT-2 124M on an 8xA100 node.
Look elsewhere when
The README itself now steers newcomers to nanochat, which adds tokenizer training, SFT, and a chat UI. For fine-tuning modern models like Llama or Qwen, nanoGPT only loads GPT-2 checkpoints, so use LitGPT or LLaMA-Factory.
Alternatives to nanoGPT
- nanochat
Successor covering the full chatbot pipeline through RL and a web UI; more code to read, but ends with something you can chat with.
- llm.c
Same GPT-2 training rewritten in C and CUDA with no PyTorch, for studying kernels rather than editing Python.
- LitGPT
Readable from-scratch code for 20+ modern architectures with LoRA and serving, where nanoGPT is GPT-2 only.
Reviews (0)
Leave a Review
No reviews yet. Be the first to review!
Details
- Category
- Model Training & Fine-Tuning
- Price
- Free
- Platform
- Local/Desktop
- Difficulty
- Intermediate (3/5)
- License
- MIT
- Added
- Jul 29, 2026