A scalar-valued autograd engine and neural network library built from scratch, following Andrej Karpathy's micrograd lecture.
I built this in order to deeply understand how AI and neural networks actually work under the hood. Before being able to truly reason about models, training, and why things go wrong, I believe we need to understand the true fundamentals (what a gradient is, how backpropagation flows through a computation graph, how a network actually learns, etc.).
| File | Description |
|---|---|
engine.py |
The Value class — wraps a scalar, builds the computation graph, runs backprop |
nn.py |
Neuron, Layer, MLP — neural network abstractions built on Value |
train.py |
Full training loop on a toy dataset — forward pass, loss, backpropagation, gradient descent |
demo_backprop.py |
Step-by-step manual backpropagation with numerical verification |
demo_pytorch.py |
Side-by-side comparison of micrograd vs PyTorch gradients |
# train the network
python train.py
# see manual backprop walkthrough
python demo_backprop.py
# compare with PyTorch (requires torch)
python demo_pytorch.py- Python 3.x (stdlib only for
engine.pyandnn.py)