A minimal scalar-valued autograd engine built from scratch in Python — similar to Karpathy's micrograd.
Implements reverse-mode automatic differentiation (backpropagation) on a dynamically built computation graph. Each Value node tracks its data, gradient, and how it was created, so gradients can flow backward through any expression.
| Operation | Method |
|---|---|
| Addition | __add__, __radd__ |
| Subtraction | __sub__, __rsub__ |
| Multiplication | __mul__, __rmul__ |
| Division | __truediv__, __rtruediv__ |
| Power | __pow__ |
| ReLU | relu() |
| Negation | __neg__ |
from source import Value
a = Value(2.0)
b = Value(-3.0)
c = Value(10.0)
d = a * b + c
d.backward()
print(a.grad) # ∂d/∂a
print(b.grad) # ∂d/∂bCalling .backward() performs a topological sort of the computation graph and applies the chain rule at each node in reverse order.
Uses Graphviz to render the computation graph with data and gradient values at each node.
from utils.graph import draw_dot
draw_dot(d)graphviz
numpy
source.ipynb # Value class + examples
utils/
graph.py # computation graph visualization