• Stars
    star
    2,416
  • Rank 19,041 (Top 0.4 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An unnecessarily tiny implementation of GPT-2 in NumPy.

PicoGPT

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.py contains the code for OpenAI's BPE Tokenizer, taken straight from their gpt-2 repo.
  • utils.py contains the code to download and load the GPT-2 model weights, tokenizer, and hyper-parameters.
  • gpt2.py contains the actual GPT model and generation code which we can run as a python script.
  • gpt2_pico.py is the same as gpt2.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"

More Repositories

1

picoBERT

Like picoGPT but for BERT.
Python
44
star
2

speculative-sampling

Simple implementation of Speculative Sampling in NumPy for GPT-2.
Python
18
star
3

seq2seq-polynomial

Seq2seq transformer for polynomial expansion in PyTorch.
Python
12
star
4

backpropagation

Simple python implementation of stochastic gradient descent for neural networks through backpropagation.
Jupyter Notebook
11
star
5

gpt-jax

A stupidly simple GPT implementation in JAX.
Python
7
star
6

simpleGPT

Simple implementation of a GPT (training and inference) in PyTorch.
Python
4
star
7

dotfiles

~ sweet ~
Shell
3
star
8

misinformation-detection-with-transformers

Sequence classification and information retrieval via Transformers for misinformation detection.
Jupyter Notebook
3
star
9

rise-and-grind

Discord bot for morning clubs.
Python
3
star
10

spaceship

Rotated Bounding Box Regression using Tensorflow.
Python
3
star
11

seq2seq-sort

Training neural networks to sort because why not.
Python
2
star
12

mlp-visualizer

A simple multilayer perceptron network that classifies clusters of data generated using scikit-learn make_blobs.
Python
2
star
13

rrt

A ray tracer built in Rust that can run in your browser via WebAssembly.
Rust
2
star
14

cs231n

Course notes, assignments, and solutions for cs231n.
Jupyter Notebook
2
star
15

leetcode

Leetcode solutions I've completed (https://leetcode.com/jaymody/)
C++
1
star
16

mlp-pure-jax

Python
1
star
17

nn

Neural networks in PyTorch.
Python
1
star
18

image-edit

This repo contains several image editing functions for OpenCV BGR Mat objects including: grayscale, brightness, contrast, saturation, sharpness, gamma, and hue.
C++
1
star
19

3xa3

Lines Per Minute, a typing tool made for programmers.
Python
1
star
20

website

Liquid
1
star
21

microscan

A microstructure analysis tool.
Jupyter Notebook
1
star
22

udacity-deep-learning

All my Udacity Deep Learning nanodegree projects.
Jupyter Notebook
1
star
23

measure-cpu-cache-size

Empirically measuring CPU caches sizes using a simple C program.
C
1
star
24

nand2tetris

My attempt at https://www.nand2tetris.org
Hack
1
star
25

data-structures-algorithms

Implementations for common data structures and algorithms in C.
C
1
star
26

gitfit

hack the north 2019
JavaScript
1
star