nanoGPT: a clean, hackable 300-line GPT training loop that reproduces GPT-2 (124M)

AI-generated summary of reporting by GitHub Opensource Projects. Read the original for the full story.

Why it matters

Engineers get a complete, readable GPT-2 training implementation they can modify in an afternoon instead of fighting a large framework codebase.

Read this as

nanoGPT is a free, open-source program written by Andrej Karpathy that trains an AI language model, software that learns to write text by reading examples. It fits in about 300 lines of Python, short enough to read in one sitting, and reproduces GPT-2, an older but famous OpenAI model. The article says it is mainly for learning how such models work, not for companies running them at scale. Training the full-size version takes about four days on a data-centre GPU, but a small practice version trains in under an hour.

This is an educational open-source release, not a production tool: nanoGPT is a 300-line Python script from Andrej Karpathy that reproduces the small 124M-parameter GPT-2. It does not replace commercial training infrastructure, so there is no procurement or adoption decision here. Its value is as a teaching resource or a clean starting point for internal experiments; the 124M model needs roughly four days on a 40GB A100 GPU, so hands-on exploration carries real compute cost.

nanoGPT implements the full GPT-2 training loop in ~300 lines of Python with dependencies limited to PyTorch, numpy, tiktoken, wandb and tqdm. The 124M-parameter configuration matches original GPT-2 and reproduces it on OpenWebText, with validation loss close to the original; configs scale up or down via a dict. Data prep scripts cover OpenWebText, Shakespeare and Tolstoy, and sample.py generates text. On one A100 40GB the 124M run takes about 4 days. No distributed training support is included.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

nanoGPT GPT-2 OpenWebText PyTorch OpenAI Shakespeare

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading

datasette-charts 0.5a0

Datasette Charts 0.5a0 adds calendar heatmaps, box plots and active-over-time charts, enabling richer data visualisation directly in the browser without extra libraries.

datasette-charts 0.4a0

Datasette now lets developers add custom chart types more easily, expanding visualisation options for data projects.