bugger.
All challenges/Pythonhardllm-tiled-attention-v1
THE INVESTIGATION

Tiled exact attention with online reductions

Stream a single attention query over KV tiles.

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 q is a nonempty vector, tiles holds objects {keys,values}, and value_width declares the output dimension. Each tile has aligned key/value rows; skip empty tiles. Compute scaled attention using a running max, denominator and weighted value numerator. When the max rises rescale both accumulated sums. Return output and normalizer {max,denominator}. An empty stream returns zeros and null maximum.

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

Stream a single attention query over KV tiles.

Reproduction

01 Later peak rescales values from the first tile
{"q":[1],"tiles":[{"keys":[[1]],"values":[[9]]},{"keys":[[3]],"values":[[2]]}],"value_width":1}
{"output":[2.83442],"normalizer":{"max":3,"denominator":1.135335}}
02 Empty tiles give zero output
{"q":[1],"tiles":[{"keys":[],"values":[]}],"value_width":2}
{"output":[0,0],"normalizer":{"max":null,"denominator":0}}
03 One tile equals ordinary attention
{"q":[1],"tiles":[{"keys":[[0],[0]],"values":[[2],[4]]}],"value_width":1}
{"output":[3],"normalizer":{"max":0,"denominator":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.