← all repositories
karpathy/minGPT

The GPT implementation you can read in one sitting

minGPT exists because most GPT implementations are too sprawling to learn from.

24.7k stars Python Language ModelsML Frameworks
minGPT
Not currently ranked — collecting fresh signals.
star history

What it does

minGPT is a bare-bones PyTorch implementation of OpenAI’s GPT for both training and inference, clocking in at about 300 lines of model code. It discards the industrial abstraction layers that make production frameworks hard to trace, leaving a clean decoder-only Transformer: indices go in, a probability distribution for the next index comes out. The library bundles a refactored Byte Pair Encoder, generic PyTorch training boilerplate, and demos ranging from arithmetic to character-level language modeling.

The interesting bit

The README candidly notes that the model itself is not complicated—most of the real complexity is just “being clever with batching” for efficiency. It also doubles as an archaeological digest of OpenAI’s paper trail, with extensive notes on GPT-1 through GPT-3 and Image GPT that flag discrepancies between published claims and released code.

Key highlights

  • Core model definition lives in roughly 300 lines in mingpt/model.py
  • Can load pretrained GPT-2 weights for immediate text generation
  • Educational demos include training a model to add numbers (projects/adder), character-level language modeling (projects/chargpt), and a minimal sorting example
  • Extensive references section cross-referencing paper details against OpenAI’s and Hugging Face’s actual implementations
  • Explicitly semi-archived as of January 2023; author points to nanoGPT for continued development

Caveats

  • Semi-archived since January 2023; the author recommends nanoGPT for new projects
  • Unit test coverage is admitted to be “not super amazing just yet”
  • Several production conveniences remain on the todo list, including mixed precision, distributed training, and loading non-GPT-2 weights

Verdict

Best for students and developers who want to understand transformer internals without industrial scaffolding. If you need to train at scale or reproduce benchmarks, the author suggests using nanoGPT instead.

Frequently asked

What is karpathy/minGPT?
minGPT exists because most GPT implementations are too sprawling to learn from.
Is minGPT open source?
Yes — karpathy/minGPT is open source, released under the MIT license.
What language is minGPT written in?
karpathy/minGPT is primarily written in Python.
How popular is minGPT?
karpathy/minGPT has 24.7k stars on GitHub.
Where can I find minGPT?
karpathy/minGPT is on GitHub at https://github.com/karpathy/minGPT.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.