Scalar reverse-mode autodiff
Differentiate a topologically ordered scalar computation graph.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Each nodes entry is {op:"input", value} or {op, args:[earlier node indices]}. Ops add and mul take two arguments; tanh and relu take one; relu derivative at zero is zero. output is the result node index. Return value and input_gradients in original input-node order. Include gradients of zero for disconnected inputs and accumulate every path into reused values.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Differentiate a topologically ordered scalar computation graph.
Reproduction
{"nodes":[{"op":"input","value":3},{"op":"mul","args":[0,0]},{"op":"add","args":[1,0]}],"output":2}{"value":12,"input_gradients":[7]}{"nodes":[{"op":"input","value":2},{"op":"input","value":-1}],"output":0}{"value":2,"input_gradients":[1,0]}{"nodes":[{"op":"input","value":1},{"op":"input","value":2},{"op":"relu","args":[0]}],"output":2}{"value":1,"input_gradients":[1,0]}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.