bugger.
All challenges/Pythonmediumllm-adamw-v1
THE INVESTIGATION

AdamW with bias correction and optimizer state

Implement a sequence of decoupled AdamW updates on one parameter vector.

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 weights, first, second and step specify the initial weights, moments and count of completed updates. For each gradient in gradients increment step, update both moments using beta1/beta2, bias-correct using that new step, then update w := (1 − lr*decay)*w − lr*m_hat/(sqrt(v_hat)+epsilon). Return weights, first, second and step after the last update. betas are in [0,1), epsilon is positive.

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

Implement a sequence of decoupled AdamW updates on one parameter vector.

Reproduction

01 Two gradient steps with opposing directions
{"weights":[1,-2],"first":[0,0],"second":[0,0],"step":0,"gradients":[[1,-2],[-1,3]],"lr":0.1,"beta1":0.9,"beta2":0.99,"decay":0.1,"epsilon":1e-05}
{"weights":[0.886364,-1.885949],"first":[-0.01,0.12],"second":[0.0199,0.1296],"step":2}
02 No gradients preserves checkpoint
{"weights":[1],"first":[0.5],"second":[0.25],"step":2,"gradients":[],"lr":0.1,"beta1":0.9,"beta2":0.99,"decay":0.1,"epsilon":1e-05}
{"weights":[1],"first":[0.5],"second":[0.25],"step":2}
03 Decay with zero gradient
{"weights":[2],"first":[0],"second":[0],"step":0,"gradients":[[0]],"lr":0.1,"beta1":0.9,"beta2":0.99,"decay":0.1,"epsilon":1e-05}
{"weights":[1.98],"first":[0],"second":[0],"step":1}

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.