Book a demo →

KV Cache

Definition

What a KV cache is in LLMs: the wording of Pope et al. (2022), vendor pages and papers by date, a memory formula, and where the term means something else.

In short

A KV cache is the store of attention keys and values that a language model keeps from earlier tokens while it generates the next ones. Pope et al. (9 November 2022) call these tensors “the KV cache”; the vLLM blog (20 June 2023) says they are “often referred to as KV cache”.

What is a KV cache?

In a transformer language model, the KV cache holds the attention keys and values computed for earlier tokens, so that they do not have to be computed again for every new token. Papers, vendor pages and Wikipedia describe it in these words:

Source and dateWording
Pope et al., arXiv 2211.05102, version 1 (9 November 2022)“The attention key and value tensors of each layer, which we refer to as the KV cache, must also be stored in memory for the duration of decoding.”
vLLM blog (20 June 2023)“These cached key and value tensors are often referred to as KV cache.”
Zhang et al. (H2O), arXiv 2306.14048, version 1 (24 June 2023)“Often, a large amount of transient state information, referred to as the KV cache, is stored in GPU memory in addition to model parameters, scaling linearly with the sequence length and batch size.”
Wikipedia, “Transformer (deep learning)”, section KV caching (last edited 3 December 2026)“The KV caching method saves the computed key and value vectors at each attention block, so that they are not recomputed at each new token.”
NVIDIA glossary (no date on the page)“KV cache (key-value cache) is a store of previously computed key and value vectors used during large language model inference.”
Micron glossary (no date on the page)“KV cache (key-value cache) is a memory optimization technique used in transformer-model-based large language models to accelerate inference by storing and reusing previously computed attention values.”

Pope et al. and the vLLM blog speak of tensors, H2O of state information, NVIDIA of a store, Micron of a technique and Wikipedia of a method.

Prompt caching is a related term. DigitalOcean (1 June 2026) separates the two: “KV caching is scoped to the decode stage of a single request.” and “prompt caching (sometimes referred to as prefix caching) is across multiple requests. It stores the KV cache for a static prefix”. An ngrok blog post (16 December 2025, updated 24 November 2026) writes: “prompt caching tends to be called ‘KV caching.’” OpenAI's documentation (no date on the page) says: “The prompt cache stores key-value (KV) tensors, not the tokens themselves.” The entry on prompt caching sets the providers' own pages side by side.

How does a KV cache work?

NVIDIA's blog post on inference optimization (17 November 2023, updated since) splits text generation into two steps: “This process involves two phases: the prefill phase and the decode phase.” The NVIDIA glossary (no date on the page) places the cache in the first step: “As the model processes the input prompt (the ‘prefill’ phase), it computes K and V tensors for each token at each transformer layer.” Micron (no date on the page) adds the second: “KV cache is created during the prefill phase and reused during the decode phase of LLM inference.” The entry on AI inference lays out the two phases with the papers that name them.

Glenn Lockwood (18 September 2026) gives the reason in two lines: “Keys and values for each output token never change after they're generated” and “Keys and values for each output token are used every time a subsequent output token is generated”. New entries are added as the output grows: “they are appended to the KV cache so they can be used to generate future tokens.”

Reading the cache costs memory bandwidth. Noam Shazeer (arXiv 1911.02150, version 1, 6 November 2019) writes that incremental inference “is often slow, due to the memory-bandwidth cost of repeatedly loading the large ‘keys’ and ‘values’ tensors”. Sebastian Raschka (17 June 2025) lists the limits of the cache: it adds complexity to the code, increases memory requirements and “can't be used during training”.

The prefill phase and the decode phase as NVIDIA's blog (17 November 2023, updated) names them. That new keys and values are “appended to the KV cache” is Glenn K. Lockwood's wording (18 September 2026).

Spellings and dates in the sources

The sources write the term in five ways. Pope et al. (9 November 2022) write KV cache. The GQA paper by Ainslie et al. (arXiv 2305.13245, version 1, 22 May 2023) writes “the KV-cache scales with model dimension while model FLOPs and parameters scale with the square of model dimension”. The PagedAttention paper by Kwon et al. (arXiv 2309.06180, version 1, 12 September 2023) spells it out: “the key-value cache (KV cache) memory for each request is huge and grows and shrinks dynamically”. Wikipedia files the topic under KV caching.

Mooncake by Qin et al. writes KVCache in one word, and its title changed between versions. Version 1 (24 June 2024): “Mooncake: Kimi's KVCache-centric Architecture for LLM Serving”. Version 5 (8 October 2026): “Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving”.

Modular (5 February 2026) ties the cache to the original transformer of 2017: “The original transformer (2017) established the architecture that would eventually dominate ML. This design was a departure from prior models, requiring a KVCache to efficiently keep track of the state associated with each request.” The same post says of its third era, headed “Heterogenous KV Caches (2024)”: “In this Era, the term ‘KV Cache’ is being stretched far beyond its original meaning.”

Selected dated papers and reports in this entry.

How much memory does a KV cache take?

The size depends on the model and the length of the sequence. These sources give a formula, figures for one model and for wasted memory, or a rate of growth:

Source and dateWording
NVIDIA blog (17 November 2023, updated)“Size of KV cache per token in bytes = 2 * (num_layers) * (num_heads * dim_head) * precision_in_bytes”
vLLM blog (20 June 2023)“Takes up to 1.7GB for a single sequence in LLaMA-13B”
vLLM blog (20 June 2023)“We find that existing systems waste 60% – 80% of memory due to fragmentation and over-reservation.”
Pope et al., version 1 (9 November 2022)“inference cost from the attention mechanism scales quadratically with input sequence length”
Hugging Face documentation (no date on the page)With the cache, “attention cost per step is linear with sequence length (memory grows linearly, but compute/token remains low)”

NVIDIA explains the first factor of the formula: “The first factor of 2 accounts for the K and V matrices.” The page carries the note “Updated on Aug. 15 with key takeaways.” The Hugging Face page compares two cases: without a cache, “attention cost per step is quadratic with sequence length”. The Hugging Face page uses quadratic and linear for the cost of attention per step without and with the cache. The memory the cache takes is a separate quantity, which the same page and H2O describe as growing or scaling linearly.

The per-token formula from NVIDIA's blog post on inference optimization (17 November 2023, updated).

KV cache compression and quantization

The six papers in the next table describe ways to reduce the keys and values a model keeps: sharing them across attention heads, compressing them into a latent vector, storing them with fewer bits or keeping only some tokens. The wording by paper:

Paper and versionWording
Shazeer (MQA), version 1 (6 November 2019)“We propose a variant called multi-query attention, where the keys and values are shared across all of the different attention ‘heads’, greatly reducing the size of these tensors and hence the memory bandwidth requirements of incremental decoding.”
Ainslie et al. (GQA), version 1 (22 May 2023)“grouped-query attention (GQA), a generalization of multi-query attention which uses an intermediate (more than one, less than number of query heads) number of key-value heads”
Zhang et al. (H2O), version 1 (24 June 2023)“a small portion of tokens contributes most of the value when computing attention scores”
Xiao et al. (StreamingLLM), version 1 (29 September 2023)“keeping the KV of initial tokens will largely recover the performance of window attention”
Liu et al. (KIVI), version 1 (5 February 2024)“A straightforward and effective solution to reduce KV cache size is quantization, which decreases the total bytes taken by KV cache.”
DeepSeek-AI (DeepSeek-V2), version 1 (7 May 2024)“MLA guarantees efficient inference through significantly compressing the Key-Value (KV) cache into a latent vector”

In the DeepSeek-V2 abstract the KV cache figure comes with a comparison: “Compared with DeepSeek 67B, DeepSeek-V2 … reduces the KV cache by 93.3%”. The opening of the KIVI abstract was rewritten for version 2 (25 July 2024): version 1 has a sentence of its own, “This memory demand increases with larger batch sizes and longer context lengths.”, and version 2 moves that point into the sentence that introduces the KV cache.

Chen et al. look at the side effects of compression. Version 2 of their paper (arXiv 2510.00231, 13 May 2026) adds a sentence on the setup that version 1 does not have: “We evaluate five KV cache compression methods (StreamingLLM, SnapKV, TOVA, H2O, and K-Norm) on Llama3.1 8B and Qwen2.5 14B under multi-instruction prompting with IFEval.”

PagedAttention and vLLM

Other work changes how the cache is stored and shared between requests:

Paper and versionWording
Kwon et al. (PagedAttention), version 1 (12 September 2023)“To address this problem, we propose PagedAttention, an attention algorithm inspired by the classical virtual memory and paging techniques in operating systems.”
Zheng et al. (SGLang), version 1 (12 December 2023)“RadixAttention, a novel technique that maintains a Least Recently Used (LRU) cache of the Key-Value (KV) cache for all requests in a radix tree, enabling automatic KV cache reuse across multiple generation calls at runtime”
Zheng et al. (SGLang), version 2 (6 June 2024)“The runtime accelerates execution with novel optimizations like RadixAttention for KV cache reuse and compressed finite state machines for faster structured output decoding.”

The PagedAttention paper is the basis of the vLLM system; the vLLM blog post of 20 June 2023 is the source of the memory figures in the section above. The SGLang paper also changed its title, from “Efficiently Programming Large Language Models using SGLang” in version 1 to “SGLang: Efficient Execution of Structured Language Model Programs” in version 2.

KV cache offloading

The Hugging Face documentation (no date on the page) describes offloading: “Offloading the cache saves GPU memory by moving the KV cache for model layers except one to the CPU.” Mooncake (version 1, 24 June 2024) uses CPU, DRAM and SSD resources of a GPU cluster for a cache of KVCache: “It also leverages the underutilized CPU, DRAM, and SSD resources of the GPU cluster to implement a disaggregated cache of KVCache.” The same Hugging Face page names the reason: “The KV cache can occupy a significant portion of memory and become a bottleneck for long-context generation.” The README of the llama.cpp server (no date on the page) lists an option “whether to enable KV cache offloading (default: enabled)”.

Other meanings of “KV cache”

KV stands for key-value, and the words key-value and cache both have older meanings in computing. Wikipedia describes a key-value database: “A key-value database, or key-value store, is a data storage paradigm designed for storing, retrieving, and managing associative arrays, a data structure more commonly known today as a dictionary.” It describes a cache in general as “a hardware or software component that stores data so that future requests for that data can be served faster”.

As examples of key-value stores, the same Wikipedia article names “in-memory systems such as Memcached and Redis”. The KV cache of a language model holds the attention keys and values of the tokens in one context.

Transformer architecture. The cache stores the keys and values of the attention layers; the entry on the transformer architecture covers how those layers are built.

AI token. The cache grows by one set of keys and values per token; the entry on AI tokens covers what a token is.

Context window. The longer the context, the larger the cache, as the H2O quote above states; the entry on context windows covers how much text a model can take in.

Large language model. The vLLM blog post and the Mooncake paper both name LLM serving in their titles; the entry on large language models covers the models themselves.

Mixture of experts. DeepSeek-V2, the source of the MLA quote, describes itself as a mixture-of-experts model; the entry on mixture of experts covers that design.

Source

Frequently asked questions

Does training use KV cache?

Sebastian Raschka (17 June 2025) writes that a KV cache “can't be used during training”. Pope et al. (9 November 2022) place it in decoding and write that the key and value tensors “must also be stored in memory for the duration of decoding”.

Can you offload KV cache to RAM?

The Hugging Face documentation (no date on the page) writes that offloading “saves GPU memory by moving the KV cache for model layers except one to the CPU.” The llama.cpp server README (no date on the page) has an option “whether to enable KV cache offloading (default: enabled)”.

Does KV cache grow quadratically?

The sources say linearly for the memory and quadratically for attention cost without a cache. H2O (24 June 2023) describes the KV cache as “scaling linearly with the sequence length and batch size”. The Hugging Face documentation (no date on the page) writes that with a cache “memory grows linearly, but compute/token remains low”.

Is Redis a KV cache?

Wikipedia lists Redis among key-value stores, as one of the “in-memory systems such as Memcached and Redis”. The KV cache of a language model holds something else: what Pope et al. (9 November 2022) describe as “the attention key and value tensors of each layer”.

What exactly is the KV cache?

The stored keys and values from the attention layers of a transformer. Pope et al. (version 1, 9 November 2022) use the name for the “attention key and value tensors of each layer”. The NVIDIA glossary (no date on the page) calls it “a store of previously computed key and value vectors used during large language model inference”.