bugger.
All challenges/Pythonhardllm-decoder-block-v1
THE INVESTIGATION

Build a pre-norm transformer block

Wire a decoder block from projections, causal attention, two norms and residuals.

LLM ArchitectureArchitecture builds

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 is a nonempty sequence of width-D rows. attention contains q, k, v and out projection matrices. norm_attention and norm_ffn are feature gain vectors; ffn contains gate, up and down. Compute RMSNorm(x) → projected single-head causal attention → residual add; then RMSNorm of that new stream → SwiGLU → residual add. Return the final rows. All projections have compatible shapes and no biases. Starter helpers implement the component arithmetic.

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

Wire a decoder block from projections, causal attention, two norms and residuals.

Reproduction

01 Attention and FFN update the same stream
{"x":[[1,2],[3,-1]],"attention":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"norm_attention":[1,1],"norm_ffn":[1,1],"ffn":{"gate":[[1,0],[0,1]],"up":[[1,0],[0,1]],"down":[[1,0],[0,1]]},"epsilon":0.001}
[[1.893504,4.512237],[5.678471,-1.005515]]
02 Zero projections give identity
{"x":[[1,2],[3,-1]],"attention":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[0,0],[0,0]]},"norm_attention":[1,1],"norm_ffn":[1,1],"ffn":{"gate":[[1,0],[0,1]],"up":[[1,0],[0,1]],"down":[[0,0],[0,0]]},"epsilon":0.001}
[[1,2],[3,-1]]
03 Attention only
{"x":[[1,2],[3,-1]],"attention":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"norm_attention":[1,1],"norm_ffn":[1,1],"ffn":{"gate":[[1,0],[0,1]],"up":[[1,0],[0,1]],"down":[[0,0],[0,0]]},"epsilon":0.001}
[[1.632329,3.264658],[4.179108,-1.055168]]

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.