Graph Construction
Goal
Make every forward operation an explicit node that records enough metadata for a correct local backward rule.
Design
Typed graph nodes store value, grad, parents, and op. Arithmetic, activations (ReLU, Tanh, Exp, Log, Sigmoid, Pow), Sum, Transpose, and MatMul each extend the graph during the forward pass instead of mutating values in place without history.
Challenges
- API surface had to stay small while remaining extensible for new ops.
- Shape and broadcasting mistakes look like training instability rather than type errors.
- Forgetting a parent edge produces silent zero gradients.
Iterations
- Scalar-friendly arithmetic nodes.
- Activations with simple local derivatives.
- Reductions and matmul once multi-dimensional training demos mattered.
Final implementation
A forward API that grows a directed graph suitable for reverse-mode accumulation without hiding parent structure.
Ops append nodes; values alone are not enough for backward.