KV Cache
KV Cache (Key-Value Cache) is an optimization mechanism used in large language model inference to store the key and value tensors computed during the attention calculation process. By reusing previously computed results, it avoids redundant computation over already-processed tokens, significantly reducing computational overhead during autoregressive generation and improving inference efficiency. KV Cache is widely applied in the deployment and acceleration of Transformer-based models.
Core Facts
The KV cache is a core data structure in Transformer autoregressive inference, and its size is approximately 2 × number of layers × number of attention heads × head dimension × sequence length × precision bytes.
KV Cache reduces the computational complexity of self-attention from O(N²) to O(N) by caching already-computed Key-Value pairs in GPU memory, but memory usage grows linearly with sequence length.
Quantized KV caches (such as storing KV vectors in FP8 or INT4) can compress the cache size to 1/2 or even 1/4 of the original.
Timeline (last 90 days)
在KV缓存低比特量化中,值(value)缓存上的量化惩罚普遍较小,而键(key)缓存的敏感度差异巨大。
现代混合架构模型除了KV缓存外,还维护循环状态和滑动窗口状态,这要求压缩策略必须同时考虑模型架构、工作负载特性和重建成本。
The paper "Characterizing Latent Reasoning Dynamics in LLMs" formalizes token reasoning as state transitions over KV cache prefixes and uses a KV-cache VAE to compress the high-dimensional space.
Current mainstream LLM efficiency optimization methods (shrinking the KV cache, limiting the receptive field, replacing attention operators) mainly reduce the attention cost per token but do not reduce the number of tokens flowing through the network, so the computation of the FFN and per-token projections still grows with the full sequence length.
The KV cache is a core mechanism in autoregressive inference; as the context window expands, its memory footprint grows linearly, making it one of the main bottlenecks of long-context inference.
A new MIT paper studies directly transferring KV caches across model families, where the receiver reuses the KV cache sent by the sender without re-reading the text, yielding a 40% accuracy improvement and 4x speedup, verified on multiple benchmarks.
GLM 5.4 has the second loop reuse the KV cache from the first pass, keeping an independent copy only for a 128-token sliding window, compressing the cache overhead of the extra loop from O(context length) to O(128).
Automatic KV cache management does not mean it requires no attention at all; memory usage still needs to be monitored under extreme loads or unusual sequence length distributions.
The vLLM team publicly stated that the goal of this feature is to reduce KV cache tuning time and devote more time to model serving.
KV cache automation can bring three benefits: simplified deployment, improved resource utilization, and reduced operational burden.
40 more timeline events
All Facts (20)
The KV cache is a core data structure in Transformer autoregressive inference, and its size is approximately 2 × number of layers × number of attention heads × head dimension × sequence length × precision bytes.
90%VerifiedKV Cache reduces the computational complexity of self-attention from O(N²) to O(N) by caching already-computed Key-Value pairs in GPU memory, but memory usage grows linearly with sequence length.
90%VerifiedQuantized KV caches (such as storing KV vectors in FP8 or INT4) can compress the cache size to 1/2 or even 1/4 of the original.
90%VerifiedThe KV Cache mechanism can cache repeated prefix content, and the more concise the system prompt, the higher the cache hit rate.
90%VerifiedThe KV cache VRAM usage of ultra-long context windows grows linearly with context length, causing inference latency and costs to rise significantly.
90%VerifiedThe KV Cache of a 70B-parameter model with 128K context support can require hundreds of gigabytes of VRAM at full load, exceeding the 80GB VRAM capacity of a single H100.
90%VerifiedThe size of the KV cache grows linearly with context length; the KV cache for Qwen 2.5 32B at a 64K context may consume several additional gigabytes of memory.
90%VerifiedTaking LLaMA-3 70B (80 layers, 64 heads, 128 dimensions per head) as an example, the KV Cache for a single token occupies approximately 2.6 MB (FP16 precision), and the total KV Cache for a 32K context reaches approximately 83 GB.
90%VerifiedPagedAttention is the core technology of the vLLM framework, which draws on the idea of operating system virtual memory management to store KV Cache in pages.
90%VerifiedFor a model with 70B parameters, the KV Cache for an 8K context may occupy several additional gigabytes of VRAM
90%VerifiedThe VRAM usage and inference latency of MoE architectures are calculated based on the number of activated parameters, not the total parameter count.
90%VerifiedvLLM uses PagedAttention for KV Cache management
85%VerifiedCompared to the previous-generation V4 Flash, V4.1 Flash reduces the demand for high-bandwidth memory (HBM) to one-quarter and the demand for SSD persistent storage to one-eighth.
80%VerifiedIn the KV Cache mechanism, reusing cached KV values is a cache hit, while context changes that invalidate the cache and require recomputation are a cache miss.
80%VerifiedKV Cache is the persistent storage of intermediate states in the Transformer attention mechanism, recording the key and value vectors for each attention head's processed tokens across all layers, thereby skipping redundant forward propagation computations.
80%VerifiedThe KV Cache (key-value cache) mechanism accelerates inference by caching the Key and Value vectors generated by the self-attention layer to avoid redundant computation, but the longer the context, the more vectors must reside in VRAM, causing memory pressure to grow in a near-linear fashion.
80%VerifiedvLLM's PagedAttention draws on the operating system concept of virtual memory paging to manage KV caches, reducing GPU memory fragmentation overhead from approximately 30% to near 0.
80%VerifiedKV Cache是Transformer架构的核心推理优化机制,其显存占用量会随序列长度和并发批次线性增长
80%VerifiedPagedAttention技术借鉴操作系统虚拟内存的分页思想,将KV Cache切分为固定大小的物理块动态分配
80%VerifiedThe KV cache mechanism saves the Key and Value matrices of historical tokens and reuses them in subsequent generation, thereby amortizing the per-unit cost of the input stage.
75%