Why does a KV cache accelerate inference?
Reveal the answer and explore the explanation.
06MediumWhy does a KV cache accelerate inference?
Answer
Medium
Why does a KV cache accelerate inference?
Answer
Stores attention keys and values from previous positions to avoid recomputation during decoding.
Deeper understanding
During generation, a decoder stores prior keys and values instead of recomputing them for each new position. Memory scales with sequence length, number of layers, KV head count and head dimension. Grouped-query attention can reduce the cache footprint.
Practical example
Speed incremental generation at the cost of memory.
Reference: Further reading ↗