As Large Language Models (LLMs) scale to process massive contexts—ranging from 100K to over 1 million tokens—they inevitably hit a "memory wall." Every generated token requires storing and accessing a Key-Value (KV) cache. Because this cache grows linearly with sequence length, it quickly consumes all available GPU VRAM.
When VRAM is exhausted, systems typically resort to one of two suboptimal solutions: evicting tokens (which destroys accuracy on long-range dependencies) or offloading data to the CPU (which creates a massive latency bottleneck over PCIe).
ShadowKV is a novel inference system designed to break this memory bottleneck. By storing low-rank approximations of "Key" caches on the GPU and offloading "Value" caches to the CPU, it achieves up to 6× larger batch sizes and 3× higher throughput without sacrificing model accuracy, even on contexts as long as one million tokens.
The ShadowKV Architecture
ShadowKV introduces a "best of both worlds" approach that splits the workload across two key architectural phases: Pre-filling and Decoding.
1. Pre-filling (The Setup)
- Low-Rank Key Compression: The authors made a crucial observation: "pre-RoPE" (Rotary Position Embedding) keys are exceptionally low-rank. ShadowKV performs a Singular Value Decomposition (SVD) to store only a compact, low-rank version of the Key cache on the GPU.
- Value Offloading: Unlike keys, "Value" caches do not compress well. ShadowKV offloads the full Value cache to the CPU to save precious VRAM.
- Landmarks and Outliers: To help locate important tokens later, the system calculates "landmarks" (mean values of token chunks) and identifies "outliers" (critical tokens like attention sinks). These remain on the GPU in a static cache.
2. Decoding (The Execution)
- Sparse Selection: For each new token, ShadowKV uses the GPU-resident landmarks to quickly identify which chunks of the KV cache are most relevant, effectively performing sparse attention.
- Overlapped Recovery: This is the system's "secret sauce." While fetching the necessary Value chunks from the CPU, ShadowKV simultaneously reconstructs the high-dimensional Key cache from its low-rank "shadow" on the GPU. This overlapping completely hides the latency of data movement.
Key Insights
- Pre-RoPE vs. Post-RoPE: Most prior work attempted to compress keys after applying position embeddings. ShadowKV realizes that the underlying keys before RoPE are much lower rank, allowing for 6× compression with almost zero information loss.
- The Asymmetry of KV: Keys are used for selection (finding what is important), while Values are used for computation (the actual data). By keeping a "shadow" of the keys on the GPU, the system can make smart, rapid decisions about what to fetch from the CPU.
- Temporal Locality: The authors observed that if a token was important in step $N$, it is likely important in step $N+1$. They use a cache policy to reuse indices, reducing the need for constant re-scanning.
Performance and Results
The authors evaluated ShadowKV across rigorous long-context benchmarks, including RULER, LongBench, InfiniteBench, and Needle In A Haystack (NIAH).
- Throughput and Scaling: On an NVIDIA A100, ShadowKV achieved up to 3.04× higher throughput compared to standard full-attention serving. Crucially, it supports 6× larger batch sizes, which is vital for high-throughput commercial serving.
- Accuracy Preservation: On the RULER benchmark (128K context), ShadowKV maintained a score of 86.88, nearly identical to the 86.68 of the uncompressed model. It significantly outperformed other sparse attention baselines like Quest and InfiniGen.
- Extreme Contexts: The system successfully handled NIAH tests at 1 million tokens with near-perfect accuracy.
By utilizing this sparse, low-rank approach, ShadowKV effectively acts as if it has a memory bandwidth of over 7 TB/s on an A100 GPU—far exceeding the hardware's physical limit of 2 TB/s.
Limitations and Future Work
While highly effective, ShadowKV has a few limitations. The SVD computation adds a small overhead during the initial pre-filling phase, though this cost becomes negligible as sequences get longer. Additionally, performance remains somewhat tethered to the PCIe bandwidth between the CPU and GPU; on systems with very slow PCIe lanes, Value fetching might become a bottleneck that reconstruction cannot fully hide. Finally, the rank for compression is currently fixed. Future iterations could explore dynamic rank adjustment based on the complexity of specific prompts or layers.
Summary updated