Keys and values are kept
Where the KV cache comes from
Look at what that step left behind. Every token made a key and a value in this layer, and a later token will need exactly those to ask its own question. They do not change when more text is added, because a token never looks forward. So the model keeps them. That store is the KV cache from the other lessons, and now its size can be worked out. A query is used once and thrown away. A key and a value are kept for each token, in each of 64 layers, in each of 8 key and value heads, as 128 numbers of 2 bytes. That is 262,144 bytes for every token of every conversation, held in GPU memory for as long as the conversation is served.
- Kept
- keys and values, never queries
- Per token
- 64 layers × 2 × 8 heads × 128 numbers
- At 2 bytes each
- 262,144 bytes, about 260 KB
- Only this grows
- the number of tokens