whatisgithub

What is numpygrad?

harrrshall/numpygrad — explained in plain English

Analysis updated 2026-05-18

0Jupyter NotebookAudience · researcherComplexity · 5/5Setup · moderate

In one sentence

A from-scratch GPT-2 implementation in pure NumPy, with every layer and gradient verified against PyTorch to reproduce its results exactly.

Mindmap

mindmap
  root((numpygrad))
    What it does
      Rebuilds GPT-2 from scratch
      Uses only NumPy
      Verifies against PyTorch
    Tech stack
      NumPy
      SciPy
      PyTorch
      Python
    Use cases
      Learn how GPT-2 works
      Study autograd internals
      Reproduce PyTorch benchmarks
    Audience
      ML researchers
      Students
    Components
      Autograd engine
      Layers
      Optimizer
      Training loop

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Study how GPT-2's forward pass, backpropagation, and training loop work at the math level without a deep learning framework's abstractions.

USE CASE 2

Verify a from-scratch autograd engine's correctness by checking it against PyTorch at every step.

USE CASE 3

Run the benchmark suite to reproduce published GPT-2 124M perplexity and accuracy scores on WikiText-103 and LAMBADA.

USE CASE 4

Use the derivation notes as a teaching reference for how each neural network operation's gradient is computed.

What is it built with?

PythonNumPySciPyPyTorchtiktoken

How does it compare?

harrrshall/numpygradbobymicroby/fastbookdavidbeard741/openusd
Stars00
LanguageJupyter NotebookJupyter NotebookJupyter Notebook
Last pushed2022-12-11
MaintenanceDormant
Setup difficultymoderateeasyeasy
Complexity5/52/52/5
Audienceresearchervibe coderdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 1h+

Requires a Python virtual environment with NumPy, SciPy, and PyTorch, the full benchmark downloads GPT-2 weights and datasets on first run.

So what is it?

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.

Copy-paste prompts

Prompt 1
Walk me through how numpygrad's autograd engine computes gradients without using PyTorch.
Prompt 2
Help me set up numpygrad and run the gradient check tests to verify the math.
Prompt 3
Explain how numpygrad loads real GPT-2 124M weights and compares its output to PyTorch.
Prompt 4
Show me how to run the WikiText-103 and LAMBADA benchmark in numpygrad.
Prompt 5
Help me understand the difference between the toy model and the full GPT-2 124M model in this repository.

Frequently asked questions

What is numpygrad?

A from-scratch GPT-2 implementation in pure NumPy, with every layer and gradient verified against PyTorch to reproduce its results exactly.

What language is numpygrad written in?

Mainly Jupyter Notebook. The stack also includes Python, NumPy, SciPy.

How hard is numpygrad to set up?

Setup difficulty is rated moderate, with roughly 1h+ to a first successful run.

Who is numpygrad for?

Mainly researcher.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.