KV Cache
The Power Plant · Inference & ServingMemory of past tokens' attention keys and values, the main memory cost of long contexts.
Also called: kv-cache, prefix caching, pagedattention, paged attention, cache offloading. In the glossary.
KV Cache is cooling this week (×0.32 against the eight weeks before). What is moving.
How it works, as a machineThe Block Warehouse · turns
Follow one turn from a long prompt at the door to its first token, served from the cache, in a block warehouse behind a pod router's door.
- Route to the warm pod
- Match the prefix
- Page the blocks
- Stamp keys and values
- Shelve the blocks
- Append the new key
KV Cache in plain words
The KV cache is the working memory a model keeps for each token it has already read, so that it does not reprocess the whole text for every new token. It makes generation fast. It also grows with the length of the context, and is the main memory cost of long conversations.
An analogy
Notes taken while reading a long contract aloud. With a note on every clause so far, the reader can handle the next clause without going back to page one. The pile of notes grows with every page, and in the end the desk holds more notes than contract.