bugger.
All challenges/Pythonmediumllm-distributed-gradients-v1
THE INVESTIGATION

Reduce gradients across uneven workers

Aggregate local mean gradients across workers, then clip and step once.

LLM ArchitectureML systems

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 is a vector. workers contains objects with count and gradient (the mean over that worker’s count examples). A count-zero worker contributes nothing. Compute the global mean by sample count, or zeros when all counts are zero. Clip the global vector to max_norm (null disables clipping), then compute updated weights with learning_rate. Return mean, clipped and weights.

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

Aggregate local mean gradients across workers, then clip and step once.

Reproduction

01 Uneven workers contribute in proportion to examples
{"weights":[1,2],"workers":[{"count":1,"gradient":[9,0]},{"count":3,"gradient":[1,4]}],"max_norm":null,"learning_rate":0.1}
{"mean":[3,3],"clipped":[3,3],"weights":[0.7,1.7]}
02 All workers have zero examples
{"weights":[1,2],"workers":[{"count":0,"gradient":[9,1]}],"max_norm":1,"learning_rate":0.1}
{"mean":[0,0],"clipped":[0,0],"weights":[1,2]}
03 Equal opposite local gradients cancel
{"weights":[1,2],"workers":[{"count":1,"gradient":[2,0]},{"count":1,"gradient":[-2,0]}],"max_norm":1,"learning_rate":0.1}
{"mean":[0,0],"clipped":[0,0],"weights":[1,2]}

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.