npx skills add ...
npx skills add firecrawl/ai-research-skills --skill nanogpt
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).
npx skills add firecrawl/ai-research-skills --skill nanogpt
nanoGPT is a simplified GPT implementation designed for learning and experimentation.
Installation:
Train on Shakespeare (CPU-friendly):
Output:
Complete training pipeline:
Config (config/train_shakespeare_char.py):
Training time: ~5 minutes (CPU), ~1 minute (GPU)
Multi-GPU training on OpenWebText:
Config (config/train_gpt2.py):
Training time: ~4 days (8× A100)
Start from OpenAI checkpoint:
Example config (config/finetune_shakespeare.py):
Train on your own text:
Train:
Use nanoGPT when:
Simplicity advantages:
model.pytrain.pyUse alternatives instead:
Issue: CUDA out of memory
Reduce batch size or context length:
Issue: Training too slow
Enable compilation (PyTorch 2.0+):
Use mixed precision:
Issue: Poor generation quality
Train longer:
Lower temperature:
Issue: Can't load GPT-2 weights
Install transformers:
Check model name:
Model architecture: See references/architecture.md for GPT block structure, multi-head attention, and MLP layers explained simply.
Training loop: See references/training.md for learning rate schedule, gradient accumulation, and distributed data parallel setup.
Data preparation: See references/data.md for tokenization strategies (character-level vs BPE) and binary format details.
Shakespeare (char-level):
GPT-2 (124M):
GPT-2 Medium (350M):
Performance:
compile=True: 2× speedupdtype=bfloat16: 50% memory reduction