NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

ShadowKV: KV Cache in Shadows for High-Throughput Long-Context LLM Inference

Hanshi Sun, Li-Wen Chang, Wenlei Bao, Size Zheng, Ningxin Zheng, Xin Liu, Harry Dong, Yuejie Chi, Beidi Chen

TL;DR

ShadowKV is a novel inference system designed to supercharge long-context Large Language Model (LLM) serving by radically optimizing the key-value (KV) cache. By keeping a highly compressed, low-rank version of the key cache on the GPU and offloading the value cache to the CPU, it enables up to 6× larger batch sizes and boosts throughput by up to 3.04× on an A100 GPU without sacrificing model accuracy.

What Problem Does This Paper Address?

As LLMs are deployed for long-context tasks like multi-document QA and full-codebase analysis, their context windows have expanded to up to 1 million tokens. However, serving these models efficiently is notoriously difficult due to the KV cache bottleneck. The memory required to store previous keys and values grows linearly with sequence length, severely limiting the batch sizes a GPU can handle.

Existing solutions fall short:

  1. Token Eviction: Dropping "unimportant" KV pairs reduces memory but permanently destroys information, causing severe accuracy drops in multi-turn conversations.
  2. Dynamic Sparse Attention: Computing attention on only a subset of tokens speeds up processing, but keeping the full KV cache on the GPU fails to solve the memory footprint problem.
  3. Naive CPU Offloading: Moving the KV cache to the CPU frees up GPU memory, but fetching those pairs back over slow PCIe lanes during every decoding step introduces massive latency.

ShadowKV elegantly breaks this trilemma by exploiting a hidden mathematical property of LLM activations.

Methods

ShadowKV introduces an asymmetric storage and on-the-fly reconstruction pipeline divided into two main phases:

1. Pre-filling Phase (Asymmetric Storage)

The authors discovered that pre-Rotary Position Embedding (pre-RoPE) keys are exceptionally low-rank (see Figure 1, left). Values ($V$), however, are not.

During pre-filling, ShadowKV performs an online Singular Value Decomposition (SVD) on the pre-RoPE key cache. It stores only the low-rank matrices on the GPU (achieving over 6× compression) and offloads the uncompressed value cache to the CPU. Additionally, it computes chunk-level "landmarks" (mean values of 8-token blocks) and identifies a tiny fraction (0.2–0.3%) of "outlier chunks" to keep statically on the GPU to preserve accuracy.

System architecture of ShadowKV showing the pre-filling and decoding pipelines.

2. Decoding Phase (Overlapped Reconstruction)

During token generation, ShadowKV uses the lightweight landmarks on the GPU to quickly approximate attention scores and select the most important token chunks (a sparse budget of ~1.56%).

Instead of a slow, sequential fetch, ShadowKV utilizes CUDA multi-streams to perform two actions in parallel:

  • It fetches the selected sparse value cache chunks from the CPU.
  • It simultaneously reconstructs the corresponding key cache chunks on the GPU from the low-rank representations.

This concurrent processing completely hides the key reconstruction latency behind the data transfer time.

Datasets

The authors evaluated ShadowKV across a comprehensive suite of long-context benchmarks:

  • RULER: Evaluates effective context size across complex tasks like variable tracking and multi-hop retrieval.
  • LongBench: A bilingual, multi-task benchmark for realistic long-context scenarios (QA, summarization, code completion).
  • Needle In A Haystack (NIAH): Tests information retrieval accuracy at various depths within contexts up to 1M tokens.
  • InfiniteBench: Features ultra-long context tasks averaging over 214K tokens.

Key Insights and Ideas

  • Pre-RoPE vs. Post-RoPE Compressibility: Prior low-rank approximation methods targeted model weights or post-RoPE keys with limited success. ShadowKV's "aha moment" is that applying SVD before the positional embeddings are added unlocks massive compressibility without hurting accuracy.
  • Subspace Sharing: Pre-RoPE keys share strong low-rank subspaces within the same sequence and its continuations, but not across different sequences. This justifies doing prompt-dependent, online SVD rather than using a static, offline projection matrix.
  • Hiding Latency with Asymmetry: Because keys can be reconstructed purely via GPU compute while values are being fetched over PCIe, the system effectively bypasses the standard hardware transfer bottlenecks.

Key Results

ShadowKV was tested across multiple open-source models, including Llama-3.1-8B, GLM-4-9B-1M, and Yi-9B-200K.

  • Throughput and Batch Size: On an A100 GPU, ShadowKV supported up to 6× larger batch sizes and achieved a 2.23× to 3.04× throughput boost compared to standard full-attention baselines.
  • Surpassing "Infinite Memory" Baselines: Remarkably, ShadowKV's throughput even surpassed a theoretical baseline assuming infinite GPU memory. This is because its sparse attention mechanism achieves a theoretical equivalent bandwidth of over 7 TB/s—far higher than the physical memory bandwidth of an A100 (2 TB/s).
  • Accuracy Preservation: As shown in the Needle In A Haystack evaluation (Figure 6), ShadowKV maintains nearly perfect retrieval accuracy up to 1M tokens, matching full attention and significantly outperforming other offloading or eviction baselines.
Needle In A Haystack accuracy visualization for Llama-3-8B-1M with ShadowKV up to 1M context.

Limitations and Future Work

While highly effective, ShadowKV introduces a linear computational overhead during the pre-filling stage due to the online SVD calculation. Although the authors show this overhead becomes negligible as sequence lengths scale up (since attention computation scales quadratically), optimizing or asynchronously scheduling this SVD step remains an area for improvement.

Additionally, exploring how ShadowKV can be stacked with orthogonal compression techniques, such as 2-bit or 4-bit KV quantization, represents a promising direction for squeezing even more performance out of consumer-grade or enterprise GPUs.

Summary updated

BibTeX
@inproceedings{sun2025shadowkv,
  author = {Hanshi Sun and Li-Wen Chang and Wenlei Bao and Size Zheng and Ningxin Zheng and Xin Liu and Harry Dong and Yuejie Chi and Beidi Chen},
  title = {{ShadowKV: KV Cache in Shadows for High-Throughput Long-Context LLM Inference}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=oa7MYAO6h6},
}
Figure