bugger.
All challenges/Pythonmediumllm-gradient-check-v1
THE INVESTIGATION

Check gradients with finite differences

Check a claimed gradient using centered finite differences.

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.

Input params is a vector and terms are [coefficient, powers] giving a multivariate polynomial sum of coefficient times product(params[j]**powers[j]). Powers are nonnegative. epsilon > 0 and tolerance ≥ 0. Approximate each partial using two perturbations on one coordinate. Return numerical, absolute_errors and passed based on unrounded errors. An empty vector passes.

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

Check a claimed gradient using centered finite differences.

Reproduction

01 Cross term reveals reversed claimed gradients
{"params":[2,3],"terms":[[1,[1,1]]],"claimed":[2,3],"epsilon":0.0001,"tolerance":1e-06}
{"numerical":[3,2],"absolute_errors":[1,1],"passed":false}
02 Constant polynomial at any parameter
{"params":[1],"terms":[[4,[0]]],"claimed":[0],"epsilon":0.0001,"tolerance":1e-06}
{"numerical":[0],"absolute_errors":[0],"passed":true}
03 Correct derivatives pass
{"params":[2,3],"terms":[[1,[1,1]]],"claimed":[3,2],"epsilon":0.0001,"tolerance":1e-06}
{"numerical":[3,2],"absolute_errors":[0,0],"passed":true}

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.