jaymody/picoGPT
jaymody/picoGPT has 3,483 GitHub stars and 461 forks. GitHot measured 0 stars in 24 hours and +1 in 7 days. Last checked 2026-11-08 17:53 UTC. Last push 2023-04-24.
An unnecessarily tiny implementation of GPT-2 in NumPy.
Measured star growth
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalPicoGPT
Accompanying blog post: GPT in 60 Lines of Numpy
You've seen openai/gpt-2.
You've seen karpathy/minGPT.
You've even seen karpathy/nanoGPT!
But have you seen picoGPT??!?
picoGPT is an unnecessarily tiny and minimal implementation of GPT-2 in plain NumPy. The entire forward pass code is 40 lines of code.
picoGPT features:
- Fast? ❌ Nah, picoGPT is megaSLOW 🐌
- Training code? ❌ Error, 4️⃣0️⃣4️⃣ not found
- Batch inference? ❌ picoGPT is civilized, single file line, one at a time only
- top-p sampling? ❌ top-k? ❌ temperature? ❌ categorical sampling?! ❌ greedy? ✅
- Readable?
gpt2.py✅gpt2_pico.py❌ - Smol??? ✅✅✅✅✅✅ YESS!!! TEENIE TINY in fact 🤏
A quick breakdown of each of the files:
encoder.pycontains the code for OpenAI's BPE Tokenizer, taken straight from their gpt-2 repo.utils.pycontains the code to download and load the GPT-2 model weights, tokenizer, and hyper-parameters.gpt2.pycontains the actual GPT model and generation code which we can run as a python script.gpt2_pico.pyis the same asgpt2.py, but in even fewer lines of code. Why? Because why not 😎👍.
Dependencies
pip install -r requirements.txt
Tested on Python 3.9.10.
Usage
python gpt2.py "Alan Turing theorized that computers would one day become"
Which generates
the most powerful machines on the planet.
The computer is a machine that can perform complex calculations, and it can perform these calculations in a way that is very similar to the human brain.
You can also control the number of tokens to generate, the model size (one of ["124M", "355M", "774M", "1558M"]), and the directory to save the models:
python gpt2.py \
"Alan Turing theorized that computers would one day become" \
--n_tokens_to_generate 40 \
--model_size "124M" \
--models_dir "models"
Explore related projects
tensorflow/tensorflow
An Open Source Machine Learning Framework for Everyone
201,400 starshuggingface/transformers
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
168,668 starsAUTOMATIC1111/stable-diffusion-webui
Stable Diffusion web UI
165,261 starsComfy-Org/ComfyUI
The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
145,835 stars