Training
chainrule
A scalar autograd engine for actually learning backpropagation.
Install
pip install git+https://github.com/jmweb-org/chainruleIf you use uv, also as an isolated CLI:
uv tool install git+https://github.com/jmweb-org/chainruleWhat it does
Backpropagation is one of those things that looks obvious once you have implemented it and completely opaque before. Reading someone else's _backward closure is not the same as writing your own and finding out, from a wrong gradient, exactly which line had the sign flipped. chainrule is the small version of that exercise: a Value type whose forward and backward pass fit on one screen, plus the two tools you actually want while debugging one — a picture of the graph, and a numerical check on the gradient it produced.
In action
$ chainrule gradcheck
check max rel. error status
polynomial 2.43e-10 pass
activations 2.27e-11 pass
division 1.44e-10 pass
tiny_mlp 6.17e-11 passFeatures
- —A Value type whose forward and backward pass fit on one screen.
- —graph() draws the graph after backward(), collapsing nodes reused more than once.
- —gradcheck compares the analytic gradient against a central finite difference.
- —A pure-Python MLP, no tensors or batching, so what you read is exactly what trains.