The KV Cache: How Saving Past Work Turns 1,275 Computations Into 50
I was running a language model fully locally: no API, no network call, just the model's weights (the numbers it learned during training) on my own machine. The first token (a word or a piece of a word) took noticeably longer to appear than the ones after it. My first assumption was that the model was "warming up", some one-time setup cost. A large part of the explanation turned out to be structural, and it has a name: the KV cache. A cache is a saved copy kept so you don't redo work, and "KV" stands for Key and Value, two lists of numbers that attention (the step where a model looks back at earlier words) builds for every token. After the first step, every new token is cheap because it computes only its own Key and Value and reuses the saved ones for everything before it. It's one of those pieces of behind-the-scenes machinery that people who build with AI rely on every day without ever being asked to explain it. What Generation...