Autoregressive generation
In autoregressive models, text generation happens token by token, with each prediction relying on all preceding tokens for context. [1]
What the KV Cache stores
KV Cache optimizes this process by storing the intermediate results—keys (K) and values (V)—from the attention layers, so the model can reuse them for future tokens instead of recalculating them. [2]
How it scales
As powerful as the KV Cache is, it comes with a major drawback-it scales linearly with the size of the context window. [3]
The values stored in the KV Cache come from all the attention blocks used by the model. [4]
Sources
- The Hugging Face source says: In autoregressive models, text generation happens token by token, with each prediction relying on all preceding tokens for context. Mastering Long Contexts in LLMs with KVPress
- The Hugging Face source says: KV Cache optimizes this process by storing the intermediate results—keys (K) and values (V)—from the attention layers, so the model can reuse them for future tokens instead of recalculating them. Mastering Long Contexts in LLMs with KVPress
- The Hugging Face source says: As powerful as the KV Cache is, it comes with a major drawback-it scales linearly with the size of the context window. Mastering Long Contexts in LLMs with KVPress
- The Hugging Face source says: The values stored in the KV Cache come from all the attention blocks used by the model. Mastering Long Contexts in LLMs with KVPress