explaingit

karpathy/micrograd

Analysis updated 2026-06-24

15,832Jupyter NotebookAudience · researcherComplexity · 2/5Setup · easy

TLDR

A tiny educational autograd engine in about 100 lines of Python plus a PyTorch-like neural net layer on top, written by Andrej Karpathy.

Mindmap

mindmap
  root((micrograd))
    Inputs
      Python numbers
      Tiny datasets
    Outputs
      Trained neural net
      Gradient values
    Use Cases
      Learn backprop from scratch
      Teach a class on autograd
      Prototype tiny nets
    Tech Stack
      Python
      Jupyter
      Graphviz
    Audience
      Students
      Curious developers
Click or tap to explore — scroll the page freely

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

Read the 100-line engine to learn exactly how backpropagation works

USE CASE 2

Train a tiny two-layer net to classify points in a notebook

USE CASE 3

Use micrograd as the basis of a teaching module on automatic differentiation

USE CASE 4

Extend the Value class with new operations as an exercise

What is it built with?

PythonJupyterGraphviz

How does it compare?

karpathy/microgradselfteaching/the-craft-of-selfteachingcamenduru/stable-diffusion-webui-colab
Stars15,83215,88115,942
LanguageJupyter NotebookJupyter NotebookJupyter Notebook
Setup difficultyeasyeasyeasy
Complexity2/51/51/5
Audienceresearchergeneralgeneral

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

How do you get it running?

Difficulty · easy Time to first run · 5min

pip install micrograd and open the demo notebook, Graphviz is optional for visualizing the computation graph.

In plain English

Micrograd is a tiny educational library that shows how the core math inside AI neural networks actually works. A neural network learns by repeatedly adjusting its internal numbers, called weights, to get better at a task. The mechanism that figures out how to adjust those weights is called backpropagation. Micrograd implements backpropagation from scratch in about 100 lines of Python code so learners can see exactly how it works rather than just trusting a larger library to handle it invisibly. The library defines a Value object that tracks every mathematical operation performed on a number, addition, multiplication, powers, and so on. After running a calculation forward (called a forward pass), you can call .backward() on the result and the library automatically figures out how much each input number contributed to the final output. This is the core of how neural networks learn. On top of this engine, micrograd provides a small neural network library with a PyTorch-like interface, meaning its API looks similar to PyTorch, one of the most popular AI frameworks. The README includes a demo notebook that trains a two-layer neural network to classify data points into two groups. You would use micrograd if you want to deeply understand how modern AI learning works under the hood, rather than just using a ready-made framework. It is aimed at students and curious developers. It is written in Python and distributed as an installable package.

Copy-paste prompts

Prompt 1
Walk me through the karpathy/micrograd Value class line by line and explain how backward works
Prompt 2
Run the demo notebook in micrograd and show me how the loss curve changes if I add a third layer
Prompt 3
Help me port micrograd to numpy arrays so it can handle vectors instead of single scalars
Prompt 4
Compare micrograd to PyTorch autograd and tell me exactly what PyTorch adds beyond this 100 line core

Frequently asked questions

What is micrograd?

A tiny educational autograd engine in about 100 lines of Python plus a PyTorch-like neural net layer on top, written by Andrej Karpathy.

What language is micrograd written in?

Mainly Jupyter Notebook. The stack also includes Python, Jupyter, Graphviz.

How hard is micrograd to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is micrograd for?

Mainly researcher.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub karpathy on gitmyhub

Verify against the repo before relying on details.