Abstract
Large Language Model (LLM) inference is increasingly constrained by the "memory wall," where the Key-Value (KV) cache size limits batch capacity and throughput. We present KCache, a novel inference technique that optimizes memory usage by decoupling Key (K) and Value (V) states. By maintaining K-states on the GPU while offloading V-states to CPU memory and dynamically fetching only the most relevant tokens during decoding, KCache achieves up to a 40% increase in throughput without sacrificing model accuracy or requiring retraining.
Introduction
As LLMs scale in context length and batch size, the KV cache—used to store intermediate states to avoid redundant computation—grows linearly, often exceeding the High-Bandwidth Memory (HBM) capacity of modern GPUs. For instance, a LLaMA2-7B model processing a batch of 8 with long context can require 128GB of memory for the KV cache alone. This memory pressure forces engineers to limit batch sizes, directly impacting system throughput. Existing mitigation strategies, such as quantization or token eviction, often introduce accuracy degradation or complexity in multi-turn dialogues. KCache addresses this by exploiting the inherent sparsity in attention mechanisms to manage memory more efficiently.
Methodology
KCache introduces a tiered storage and retrieval system based on the distinct roles of Keys and Values in the attention mechanism.
Split Storage and Prefill
In KCache, the K Cache remains entirely on the GPU's HBM to facilitate rapid attention score calculation. Conversely, the V Cache, which contains the semantic information used for the final output, is offloaded to the larger CPU memory. During the Prefill Phase, V-states are pushed to the CPU asynchronously, ensuring that the initial prompt processing is not bottlenecked by data transfer.
Top-N Decoding
During the Decode Phase, the model calculates attention scores using the GPU-resident K Cache. Rather than fetching the entire V Cache for every token, KCache identifies the Top-N highest attention scores. Only the specific V-vectors corresponding to these scores are pulled from the CPU to the GPU in real-time. This approach leverages the observation that only a small subset of previous tokens typically contributes significantly to the generation of the next token.
Theoretical Analysis
The efficiency of KCache is rooted in its ability to hide transfer latency. The authors provide an arithmetic intensity analysis comparing standard Multi-Head Attention (MHA) with KCache MHA. By reducing the I/O requirements from $O(s)$ (sequence length) to $O(N)$ (selected tokens) during the value retrieval step, the system can maintain high arithmetic intensity. As long as the ratio of sequence length to selected tokens is sufficiently high, the GPU's computation time effectively masks the CPU-to-GPU transfer latency.
Evaluation and Results
KCache was evaluated using LLaMA2 (7B, 13B), LLaMA3-8B, and Mistral-7B across three major benchmarks: Big-Bench Hard (BBH), GSM8K (math reasoning), and TriviaQA (reading comprehension).
Performance and Throughput
On LLaMA2-7B with a 15k context window, KCache demonstrated a 40% improvement in throughput over standard baselines. By offloading the V Cache, the system could support significantly larger batch sizes and longer contexts that would otherwise trigger Out-of-Memory (OOM) errors.
Accuracy Preservation
Crucially, KCache maintains performance parity with full-cache baselines. In some instances, the Top-N selection acted as a regularizer, improving scores by filtering out "noise" from distant, irrelevant tokens. For example, on LLaMA3-8B (BBH), KCache with $N=128$ achieved a score of 62.79, slightly exceeding the baseline's 62.39.
Conclusion
KCache offers a practical, hardware-aware solution to the LLM memory bottleneck. By treating the KV cache as an asymmetric resource and utilizing Top-N fetching, it enables higher throughput and larger context handling on existing hardware. Future work will explore dynamic $N$ selection based on attention entropy and the application of KCache to more complex structures like Grouped-Query Attention (GQA).
Summary updated