KV Cache Explained: Why LLMs Remember Keys and Values During Inference
The KV cache is one of those LLM inference terms that sounds simple until someone asks you to explain it from first principles. At a high level, the idea is: During generation, a transformer stores the previously computed key and value vectors, so it does not recompute them for the whole sequence every time it predicts the next token. That is the short answer. But the short answer hides the important part: why keys and values are reusable, why queries are not cached in the same way, and why this matters so much for latency. ...
