7/26
Part 2 of 4 · What the cache holdsLearn and do
The cache holds keys and values, never queries
What exactly goes in the cache?
keys (4, 4)thecatsatonblock 1kkkkblock 2kkkk……………block 12kkkk
values (4, 4)thecatsatonblock 1vvvvblock 2vvvv……………block 12vvvv
The next token, the, adds one column to both, in every block.
Each block keeps its own pair of tensors, the keys and the values of every token so far, because each block sees different inputs. Block 5's keys come from vectors that four blocks have already changed.
Queries are not in the cache. Here is why, for on, token 3:
| On's own | At on's own step | At every later step |
|---|---|---|
| query q3 | scored against every key so far | never read again |
| key k3 | scored by q3 | scored by q4, q5, q6, ... |
| value v3 | blended by q3's scores | blended by q4, q5, q6, ... |
A query is read once, at its own step. Keys and values are read by every later token.
Why not store each layer's input instead, and make the keys and values from it when needed? That's half the memory: C numbers per token, not 2C.
Pick an answer above to see the rest