nanoGPT Minimal GPT Training Guide
A hands-on guide to nanoGPT: train a tiny Shakespeare model on CPU or reproduce GPT-2 (124M) on multi-GPU, step by step.
EducationIntermediate★ 12,111⑂ 881AI score 8/10Last updated: Jun 16, 2026
What it does
- Walks through the full nanoGPT pipeline — data prep, training, sampling — with exact commands for Shakespeare, OpenWebText, fine-tuning and custom datasets.
- Explains the key hyperparameters in
train_shakespeare_char.py,train_gpt2.pyandfinetune_shakespeare.py(n_layer, n_head, block_size, learning rate, gradient accumulation). - Provides fixes for common failures: CUDA OOM, slow training, poor sample quality, failing GPT-2 weight loading.
- Lists realistic runtime/VRAM expectations (CPU, T4, 1× and 8× A100) and when to switch to HuggingFace, Megatron-LM or LitGPT instead.
Who it's for
- Learners who want to understand transformer/GPT internals at the code level.
- Instructors and study groups needing a reproducible small-LLM training exercise.
- ML engineers and researchers prototyping architecture variants quickly.
Examples
- "I only have a laptop CPU — can I train an LM in 5 minutes?" → three-command shakespeare_char prep/train/sample flow.
- "How do I reproduce GPT-2 124M on 8 GPUs?" → torchrun DDP command plus batch and gradient-accumulation settings.
- "Train on my own text file" → character-level tokenizer script that writes train.bin / val.bin.
· · · Install guide · · ·
Try it now, no install
Paste this into Claude to use the skill without installing anything.
Read the instructions in this file and follow them to help me: https://raw.githubusercontent.com/Orchestra-Research/AI-Research-SKILLs/HEAD/01-model-architecture/nanogpt/SKILL.md What I want: (describe your task here)
If Claude can't open the link, open it yourself and paste the contents instead.
↓ If it works for you, download the ZIP below and install it. Then it runs on its own — no pasting each time.
Install in the Claude app (no terminal)
- Download the ZIP with the button below.
- In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
- Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Install in Claude Code
Let Claude do it — paste this into Claude Code
Install the skill I found on Claude Skill Mart. Copy the 01-model-architecture/nanogpt folder from the GitHub repo Orchestra-Research/AI-Research-SKILLs into my ~/.claude/skills/nanogpt/. When it's done, tell me in one line what this skill can do.
Install with a command instead
git clone https://github.com/Orchestra-Research/AI-Research-SKILLs.git /tmp/ai-research-skills && mkdir -p ~/.claude/skills/nanogpt && cp -r /tmp/ai-research-skills/01-model-architecture/nanogpt/* ~/.claude/skills/nanogpt/⚠ This is a third-party skill. Check the source repository before installing.
- Open a terminal and clone the skill repo:
git clone https://github.com/Orchestra-Research/AI-Research-SKILLs.git - Create the skill directory:
mkdir -p ~/.claude/skills/nanogpt - Copy the files:
cp -r AI-Research-SKILLs/01-model-architecture/nanogpt/* ~/.claude/skills/nanogpt/ - Clone the upstream code that the skill references:
git clone https://github.com/karpathy/nanoGPT.git - Install the Python dependencies:
pip install torch numpy transformers datasets tiktoken wandb tqdm - Restart Claude Code and ask something like "train a Shakespeare model with nanoGPT" to confirm the skill loads.
View source on GitHub ↗License: MIT