← Questions
Causal hard attention with a KV cache
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Tokens arrive one at a time, each with a token embedding and a position embedding, plus key and value weight matrices. At each step, add the two embeddings to get the hidden vector, use it as the query, compute its key and value and append them to a key cache and a value cache. Then attend "hard": pick the cached key (from this step or earlier) with the highest dot product with the query, earliest on ties, and output its cached value. Return the outputs for every step, reusing the cache rather than recomputing past keys and values.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
