Tiled exact attention with online reductions
Stream a single attention query over KV tiles.
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
{"q":[1],"tiles":[{"keys":[[1]],"values":[[9]]},{"keys":[[3]],"values":[[2]]}],"value_width":1}{"output":[2.83442],"normalizer":{"max":3,"denominator":1.135335}}{"q":[1],"tiles":[{"keys":[],"values":[]}],"value_width":2}{"output":[0,0],"normalizer":{"max":null,"denominator":0}}{"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.
Read the report, then sign in to start your investigation.