bugger.
All challenges/Pythonhardllm-reverse-mode-v1
THE INVESTIGATION

Scalar reverse-mode autodiff

Differentiate a topologically ordered scalar computation graph.

LLM ArchitectureLLM training

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

01 One input flows through three paths
{"nodes":[{"op":"input","value":3},{"op":"mul","args":[0,0]},{"op":"add","args":[1,0]}],"output":2}
{"value":12,"input_gradients":[7]}
02 Output is an input node
{"nodes":[{"op":"input","value":2},{"op":"input","value":-1}],"output":0}
{"value":2,"input_gradients":[1,0]}
03 Disconnected input stays zero
{"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.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.