RepositoryPython
KA

karpathy/nanoGPT

The simplest, fastest repository for training/finetuning medium-sized GPTs.

65.2kstars
11.2kforks
249issues
4views

🚀 Minimalist GPT Training, Maximum Hackability

A tiny, readable codebase that trains GPT-2 from scratch or finetunes pretrained checkpoints in days, not weeks.

nanoGPT, by Andrej Karpathy, is a plain and readable rewrite of minGPT focused on training and finetuning medium-sized GPTs. Built for developers who want to understand and modify the training loop, it reproduces GPT-2 (124M) on OpenWebText in ~4 days on a single 8xA100 40GB node. The core code is just train.py (~300 lines) and model.py (~300 lines), optionally loading GPT-2 weights from OpenAI.

✨ Highlights

  • Simple training loop: ~300-line train.py boilerplate for clarity and easy hacking.
  • Clean model definition: ~300-line model.py GPT implementation, optionally loading GPT-2 weights.
  • GPT-2 reproduction: Trains GPT-2 (124M) on OpenWebText in ~4 days on 8xA100 40GB.
  • Finetuning support: Easily finetune pretrained checkpoints like GPT-2 1.3B.
  • Shakespeare quick start: Train a character-level GPT on Shakespeare in ~3 minutes on GPU.
  • CPU and Mac support: Runs on CPU and Apple Silicon with --device=mps for faster training.
  • Minimal dependencies: Only requires torch, numpy, transformers, datasets, tiktoken, wandb, and tqdm.
  • Active development: Continuously improved despite being labeled old and deprecated in favor of nanochat.

💡 Why it matters

nanoGPT strips away complexity without sacrificing functionality, making it ideal for learning, experimenting, and prototyping GPT models. Its minimalism lets developers quickly grasp and modify the training pipeline, unlike heavier frameworks. Best suited for researchers and hobbyists who value readability and control over out-of-the-box performance.


#AI #MachineLearning #GPT #OpenSource #TiniX