bugger.
All challenges/Pythonmediumllm-loss-scaling-v1
THE INVESTIGATION

Mixed-precision loss scaling and skipped steps

Simulate dynamic loss scaling for low-precision gradients.

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

weights is the initial vector. scaled_gradients has one vector per step, already evaluated at the scale in force for that step; the strings overflow and nan represent nonfinite entries. On any nonfinite entry, skip the entire weight update, multiply scale by backoff and reset streak to zero. Otherwise unscale all gradients by current scale, do one SGD update, increment streak and multiply scale by growth when streak reaches growth_interval, resetting streak. Return weights, scale, streak and applied (Boolean per step). All starting scales and factors are 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

Simulate dynamic loss scaling for low-precision gradients.

Reproduction

01 Recover after an overflow and grow again
{"weights":[1,2],"scaled_gradients":[[8,16],["overflow",8],[4,8],[4,8]],"scale":8,"streak":0,"lr":0.1,"backoff":0.5,"growth":2,"growth_interval":2}
{"weights":[0.7,1.4],"scale":8,"streak":0,"applied":[true,false,true,true]}
02 Empty trace preserves resumed state
{"weights":[1,2],"scaled_gradients":[],"scale":8,"streak":1,"lr":0.1,"backoff":0.5,"growth":2,"growth_interval":2}
{"weights":[1,2],"scale":8,"streak":1,"applied":[]}
03 Single bad coordinate skips the whole update
{"weights":[1,2],"scaled_gradients":[[8,"nan"]],"scale":8,"streak":0,"lr":0.1,"backoff":0.5,"growth":2,"growth_interval":2}
{"weights":[1,2],"scale":4,"streak":0,"applied":[false]}

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.