Study how GPT-2's forward pass, backpropagation, and training loop work at the math level without a deep learning framework's abstractions.
Verify a from-scratch autograd engine's correctness by checking it against PyTorch at every step.
Run the benchmark suite to reproduce published GPT-2 124M perplexity and accuracy scores on WikiText-103 and LAMBADA.
Use the derivation notes as a teaching reference for how each neural network operation's gradient is computed.
| harrrshall/numpygrad | bobymicroby/fastbook | davidbeard741/openusd | |
|---|---|---|---|
| Stars | 0 | — | 0 |
| Language | Jupyter Notebook | Jupyter Notebook | Jupyter Notebook |
| Last pushed | — | 2022-12-11 | — |
| Maintenance | — | Dormant | — |
| Setup difficulty | moderate | easy | easy |
| Complexity | 5/5 | 2/5 | 2/5 |
| Audience | researcher | vibe coder | developer |
Figures from each repo's GitHub metadata at analysis time.
Requires a Python virtual environment with NumPy, SciPy, and PyTorch, the full benchmark downloads GPT-2 weights and datasets on first run.
This project is a complete, ground up reimplementation of GPT-2, a well known AI language model, using only NumPy, a foundational mathematics library for Python. GPT-2 is the kind of model that predicts and generates text. What makes this project unusual is that it rebuilds every piece of that system from scratch using basic numerical operations rather than relying on a modern AI framework. The core components are all hand built: an automatic differentiation engine, which computes the gradients that training a neural network requires, the neural network layers, the full GPT-2 model, an optimizer, meaning the algorithm that updates the model's parameters during training, and the training loop itself. PyTorch, a popular AI library, is used only as a reference to check correctness, not to do any of the actual computation. The implementation was built in nine steps, and at each step it was verified to match PyTorch's output exactly. When loaded with the real GPT-2 124M weights from OpenAI, this NumPy version reproduces PyTorch's benchmark scores on two standard tests, WikiText-103 and LAMBADA, to the same decimal place. The codebase runs entirely on the CPU in 64 bit floating point arithmetic, and the core implementation requires only NumPy and SciPy, a small scientific computing library. All the math behind each training step is derived and documented in the repository. You would use this project if you want to understand how large language models actually work at the mathematical level, without the abstraction that modern frameworks add. It is a learning and research resource. The full README is longer than what was provided.
A from-scratch GPT-2 implementation in pure NumPy, with every layer and gradient verified against PyTorch to reproduce its results exactly.
Mainly Jupyter Notebook. The stack also includes Python, NumPy, SciPy.
Setup difficulty is rated moderate, with roughly 1h+ to a first successful run.
Mainly researcher.
This repo across BitVibe Labs
Verify against the repo before relying on details.