bugger.
All challenges/Pythonhardllm-ppo-gae-v1
THE INVESTIGATION

Compute GAE and the PPO clipped objective

Compute advantages and the mean clipped PPO policy loss.

LLM ArchitecturePost-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.

The arrays rewards, values, next_values, done, old_logp, new_logp have one entry per ordered transition. Iterate backward using delta = reward + gamma × (1−done) × next_value − value and advantage = delta + gamma × lam × (1−done) × next_advantage, with zero tail. ratio = exp(new_logp − old_logp) and loss = −mean(min(ratio × advantage, clipped_ratio × advantage)), where clipped_ratio stays in [1−clip,1+clip]. Return advantages, returns (= advantage + value) and loss. An empty batch has zero loss.

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

Compute advantages and the mean clipped PPO policy loss.

Reproduction

01 A terminal in the middle stops backward leakage
{"rewards":[1,2,9],"values":[0.5,1,2],"next_values":[1,99,3],"done":[false,true,false],"old_logp":[-1,-1,-1],"new_logp":[-1.5,-0.1,-1],"gamma":0.9,"lam":0.8,"clip":0.2}
{"advantages":[2.12,1,9.7],"returns":[2.62,2,11.7],"loss":-4.061948}
02 Zero transitions
{"rewards":[],"values":[],"next_values":[],"done":[],"old_logp":[],"new_logp":[],"gamma":0.9,"lam":0.8,"clip":0.2}
{"advantages":[],"returns":[],"loss":0}
03 Zero temporal difference produces no update
{"rewards":[1],"values":[1],"next_values":[99],"done":[true],"old_logp":[-1],"new_logp":[-2],"gamma":0.9,"lam":0.8,"clip":0.2}
{"advantages":[0],"returns":[1],"loss":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.