| name | micrograd-trace |
| description | Draw the autograd computation graph for any Python function. Outputs ASCII graph or graphviz DOT. Use to visualize backprop, debug gradient flow, teach chain rule. Triggers on "trace gradient", "show autograd graph", "visualize backprop", "compute graph for". |
micrograd-trace
Karpathy micrograd-style: every op = node, every gradient = edge.
Workflow
- Parse target function (forward pass).
- Build node list: each tensor op = node (op, inputs, output_shape).
- Render:
- ASCII: tree with arrows ←
- DOT: graphviz for complex graphs (>10 nodes)
- Annotate each edge with
∂out/∂in formula.
- Optionally: instrument with
register_hook to print actual gradients during a real backward pass.
Output template
x ──┐
├─▶ (mul) ──▶ z ──▶ (relu) ──▶ y
y ──┘ ∂y/∂z = 1 if z>0 else 0
References