Compute Or Load KV Cache? Why Not Both?

Shuowei Jin, Xueshen Liu, Qingzhao Zhang, Z. Morley Mao · DOI

Abstract

Large Language Models (LLMs) face significant latency challenges during the prefill stage for long-context tasks. While prefix caching mitigates redundant computation, loading large Key-Value (KV) caches from storage introduces I/O bottlenecks. This paper introduces Cake, a high-performance KV cache loading system that parallelizes GPU computation and I/O loading. By employing a bidirectional scheduling strategy—computing the sequence from the start while loading it from the end—Cake achieves an average 2.6x speedup in Time-to-First-Token (TTFT) over traditional single-resource methods.

Introduction

The rise of long-context LLM applications, such as document analysis and large-scale code synthesis, has highlighted the "prefill bottleneck." Generating the KV cache for tens of thousands of tokens can take tens of seconds. Prefix caching, which stores these intermediate states, offers a solution, but it shifts the bottleneck from computation to I/O bandwidth.

The Storage-Compute Trade-off

Current inference engines typically treat computation and I/O as mutually exclusive. When a prompt is received, the system checks a hierarchy of storage (GPU memory, CPU memory, and Disk) to find a cached KV state. If not found, it defaults to re-computation.

The hierarchical workflow of LLM inference with prefix caching.

As shown in Figure 1, the storage hierarchy creates a stark trade-off: high-speed GPU memory has limited capacity, while high-capacity disk storage suffers from low bandwidth. This hierarchy forces a binary choice: compute or load.

Cake: Bidirectional Parallelization

Cake breaks the "either-or" paradigm by treating computation and I/O as complementary resources. The system splits the input sequence into chunks and initiates two parallel processes:

  1. Forward Compute: The GPU computes the KV cache starting from the beginning of the sequence (Chunk 0 → N).
  2. Backward Load: The I/O worker fetches the pre-computed cache from storage starting from the end of the sequence (Chunk N → 0).

These processes meet in the middle, significantly reducing the total time required to prepare the full context for the decoding stage. This approach is particularly effective because it utilizes the full bandwidth of both the compute engine and the storage interconnect simultaneously.

Key Insights: The Cost Gradient

The mathematical intuition behind Cake lies in the asymmetric cost of the attention mechanism. In the prefill stage, computing later tokens is more expensive because they must attend to all preceding tokens. Conversely, the I/O cost to load a KV pair is constant regardless of its position in the sequence.

Prefill time per chunk increases linearly with the index, while I/O cost remains constant.

As illustrated in Figure 2, the "step time" for computation increases linearly with the chunk index, while the I/O bandwidth (represented by the SSD line) remains flat. By computing the "cheap" early tokens and loading the "expensive" late tokens, Cake optimizes resource utilization. On modern hardware like an H100 GPU and an NVMe SSD, the equivalent throughputs are remarkably similar (approx. 4 GB/s), making them ideal for parallel execution.

Results and Conclusion

Evaluation across benchmarks like LongChat and NarrativeQA shows that Cake reduces TTFT by an average of 2.6x. In scenarios with severe I/O or compute bottlenecks, speedups exceeded 10x. Furthermore, its adaptive scheduler allows it to utilize idle GPU cycles without impacting active decoding tasks, improving overall system throughput by 26%. Cake demonstrates that for long-context LLMs, the optimal path to performance is not choosing between compute and load, but intelligently doing both.

Summary updated

BibTeX
@inproceedings{jin2025compute,
  author = {Shuowei Jin and Xueshen Liu and Qingzhao Zhang and Z. Morley Mao},
  title = {{Compute Or Load KV Cache? Why Not Both?}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=WOyOtaO6lQ},
}
Figure