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

LayerNorm and RMSNorm

Implement LayerNorm and RMSNorm over the features of each row.

LLM ArchitectureTransformer components

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 x contains nonempty feature rows of the same width. weight and bias are feature-size vectors, epsilon > 0. Return layer_norm using population variance, mean centering, weight and bias, and rms_norm using uncentered mean-square and weight only. Add epsilon inside each square root.

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 LayerNorm and RMSNorm over the features of each row.

Reproduction

01 Unequal features with learned scale and bias
{"x":[[1,3]],"weight":[2,1],"bias":[1,-1],"epsilon":1e-05}
{"layer_norm":[[-0.99999,-5e-06]],"rms_norm":[[0.894426,1.341639]]}
02 Zero row stabilizes with epsilon
{"x":[[0,0]],"weight":[2,1],"bias":[1,-1],"epsilon":1e-05}
{"layer_norm":[[1,-1]],"rms_norm":[[0,0]]}
03 Constant nonzero row distinguishes the two norms
{"x":[[3,3]],"weight":[2,1],"bias":[1,-1],"epsilon":1e-05}
{"layer_norm":[[1,-1]],"rms_norm":[[1.999999,0.999999]]}

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.