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?

The cache of a GPT with 12 blocks, after the cat sat on
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 ownAt on's own stepAt every later step
query q3scored against every key so farnever read again
key k3scored by q3scored by q4, q5, q6, ...
value v3blended by q3's scoresblended by q4, q5, q6, ...

A query is read once, at its own step. Keys and values are read by every later token.

Predict

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