QUESTION 6 OF 10

Why does a KV cache accelerate inference?

Reveal the answer and explore the explanation.

06
Medium

Why does a KV cache accelerate inference?

Answer
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 ↗

Last 30 min revisionHigh-yield interview Q&As