GitHub · minGPT: A minimal PyTorch re-implementation of the OpenAI GPT (Generative Pretrained Transformer) training
Open the sourceThis README presents minGPT, Karpathy's small, clean, educational PyTorch re-implementation of GPT for both training and inference, and argues that GPT is not a complicated model. He explains how the library is organized, how to use it, and why he moved to nanoGPT, and he collects implementation notes from the GPT-1, GPT-2, GPT-3, and Image GPT papers.
- He frames GPT simply: a sequence of indices feeds into a Transformer, and a probability distribution over the next index comes out. - He argues that most of the complexity in GPT code is clever batching for efficiency, not the model itself. - The library is split into three files: the model, a BPE tokenizer, and GPT-independent trainer boilerplate. - He contrasts minGPT with full-featured libraries that are hard to trace because of large amounts of unused, branching code. - He explains that minGPT became semi-archived because wide external referencing made big changes hard, and he wanted a successor that is simple and hackable but 'has teeth'. - He collects concrete hyperparameters and architecture details from the GPT papers and flags discrepancies between the papers and the released code.
Based on Andrej Karpathy's public content. Not affiliated with or endorsed by Andrej Karpathy.
Supports these rules
Quotes from this video
“minGPT tries to be small, clean, interpretable and educational, as most of the currently available GPT model implementations can a bit sprawling.”
“GPT is not a complicated model and this implementation is appropriately about 300 lines of code”
“the sequence comes out. The majority of the complexity is just being clever with batching (both across examples and over sequence length) for efficiency.”
“It is full-featured but as a result also somewhat challenging to trace.”
“something that is still simple and hackable but has teeth (reproduces medium-sized industry benchmarks, accepts some tradeoffs to gain runtime efficiency, etc).”
“(weird because in their released code i can only find a simple use of the old 0.02...”