| name | nanogpt |
| description | Educational GPT implementation in ~300 lines. Reproduces GPT-2 (124M) on OpenWebText. Clean, hackable code for learning transformers. By Andrej Karpathy. Perfect for understanding GPT architecture from scratch. Train on Shakespeare (CPU) or OpenWebText (multi-GPU). |
| category | ml-training |
| version | 1.0.0 |
| author | Synthetic Sciences |
| license | MIT |
| tags | ["Model Architecture","NanoGPT","GPT-2","Educational","Andrej Karpathy","Transformer","Minimalist","From Scratch","Training"] |
| dependencies | ["torch","transformers","datasets","tiktoken","wandb"] |
nanoGPT - Minimalist GPT Training
Quick start
nanoGPT is a simplified GPT implementation designed for learning and experimentation.
Installation:
pip install torch numpy transformers datasets tiktoken wandb tqdm
Train on Shakespeare (CPU-friendly):
python data/shakespeare_char/prepare.py
python train.py config/train_shakespeare_char.py
python sample.py --out_dir=out-shakespeare-char
Output:
ROMEO:
What say'st thou? Shall I speak, and be a man?
JULIET:
I am afeard, and yet I'll speak; for thou art
One that hath been a man, and yet I know not
What thou art.
Common workflows
Workflow 1: Character-level Shakespeare
Complete training pipeline:
python data/shakespeare_char/prepare.py
python train.py config/train_shakespeare_char.py
python sample.py --out_dir=out-shakespeare-char
Config (config/train_shakespeare_char.py):
n_layer = 6
n_head = 6
n_embd = 384
block_size = 256
batch_size = 64
learning_rate = 1e-3
max_iters = 5000
eval_interval = 500
device = 'cpu'
compile = False