Home Knowledge Base nanoGPT

nanoGPT is a minimal, readable implementation of GPT-2/GPT-3 training and inference created by Andrej Karpathy in two files of clean PyTorch code — designed to be the simplest possible codebase that can reproduce GPT-2 (124M parameters) training on a single GPU, enabling thousands of engineers to understand transformer language models by stepping through the training loop line-by-line in a debugger rather than navigating Hugging Face's deep abstraction layers.

What Is nanoGPT?

What nanoGPT Teaches

nanoGPT vs Alternatives

FeaturenanoGPTHF TransformersMegatron-LMGPT-NeoX
Lines of code~300~300,000~50,000~30,000
ArchitecturesGPT only100+GPT onlyGPT only
PurposeEducationProductionLarge-scale trainingLarge-scale training
ReadabilityExcellentComplexComplexComplex
Multi-GPUBasic DDPFullFull (3D parallelism)Full
Can reproduce GPT-2YesYesYesYes

nanoGPT is the repository that taught a generation of engineers how transformer language models actually work — by implementing GPT-2 training and inference in 300 lines of transparent PyTorch code, Karpathy created the definitive educational resource that makes the architecture behind ChatGPT, Claude, and every modern LLM fundamentally understandable.

nanoGPTminimalgpt

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.