Inference systems · Research feature

Adaptive KV Cache Reuse for Fast Long-Context LLM Serving

A new system enables faster long-context LLM serving by selectively reusing key cache data while maintaining response quality.

Adapted from research by Fei li, Song Liu, Yan Liu and colleagues.

arXiv preprint revision · 2026-10-04 · Attribution & reuse
In this article
Editorial illustration of optical fibers.

Editor’s introduction

Researchers compared traditional prefix-only caching with a new method, CacheTune, which identifies and reuses only the most semantically critical KV pairs through frequency-domain analysis. The system also integrates hardware-aware optimizations like sparse KV transfer and adaptive recomputation to balance compute and I/O across different storage tiers. Evidence shows CacheTune achieves significant TTFT reductions and throughput gains on mainstream LLMs without sacrificing output quality.

Introduction

Large language model (LLM) serving is gradually shifting from short conversations to long-context applications such as retrieval-augmented generation (RAG), long-document question answering, and agent reasoning. In these scenarios, input prompts are typically assembled dynamically from retrieved documents, conversation histories, or reusable knowledge segments. Prefill must process the entire context, and its computational cost grows rapidly with input length. The resulting time-to-first-token (TTFT) has become a major performance bottleneck in long-context serving. The same document or knowledge segment may appear in multiple requests. Encoding them anew each time also repeats the corresponding Key-Value (KV) generation, further increasing the prefill workload.

A natural way to eliminate redundant prefill computation is to materialize the KV Cache generated from reusable text segments as independently cacheable units, hereafter called KV Chunks, and reuse them across requests. Prefix caching follows this approach and has been adopted in systems such as vLLM and SGLang. However, it requires the KV Chunks to form a strict prefix of the new request. In RAG and multi-document workloads, reusable content typically consists of independent text chunks whose number, order, and positions change dynamically, preventing prefix caching from fully exploiting these repeated data.

Allowing independent KV Chunks to be reused at arbitrary positions can improve cache hit rates, but substantially degrades generation quality. The fundamental reason is that a Transformer’s causal self-attention mechanism makes a token’s KV depend not only on its own content but also on all preceding context. Text chunks encoded independently in advance lack the cross-chunk attention that should have been established in the complete prompt. Their KV therefore represents a context-mismatched materialized state relative to the current global context. We refer to this inter-chunk attention as cross-attention. Directly concatenating these chunk caches causes the resulting discrepancies to propagate into subsequent attention computations and the final generated output. Non-prefix KV Cache reuse must therefore repair the invalidated contextual dependencies.

Selecting important KV for recomputation is a key approach to restoring cross-attention. Existing recomputation methods organize cross-attention repair based on online KV deviations, chunk boundary positions, or learned link tokens. These methods respectively rely on online analysis, fixed positional priors, or additional training. We consider another question: can effective selection signals be extracted solely from an independent chunk’s KV, so that the KV indices to be recomputed can be determined when the cache is generated and reused across requests? We observe that KV energy along the token dimension is concentrated in low-frequency components. After the low-frequency signal is reconstructed at the original positions, tokens selected by their magnitude contribute more to restoring attention distributions and task quality under the same recomputation budget. This observation provides a basis for an offline token importance ranking independent of the current query. In addition, recomputation index selection must account for cache access costs. As reusable KV Caches exceed GPU memory capacity and expand to lower storage tiers or even external caching systems, cache transfer and online recomputation become two competing latency paths. The computational savings from KV reuse may be offset by additional cache-loading overhead. Efficient reuse therefore requires dynamically balancing cache transfer and online recomputation.

Prefix caching systems, including vLLM, SGLang, and ChunkAttention, reuse only matching prefixes. Non-prefix methods relax this constraint through modular caching or cross-chunk repair. PromptCache uses predefined prompt schemas; CacheBlend selects tokens with large KV deviations through online first-layer recomputation; EPIC repairs fixed attention-sink positions; and KVLink introduces learned link tokens. CacheSlide addresses positional drift when reusable segments preserve their relative order. CacheClip, Cache-Craft, and ProphetKV respectively use auxiliary models, historical information, or query-dependent signals.

Motivation

We analyze KV Caches along the token dimension and observe that their energy is concentrated in low-frequency components. Appendix E.1 reports KV spectrum measurements for different models. This observation motivates us to use low-frequency structure to rank token positions for recomputation. Supplementary experiments in Appendix E.2 further show that low-frequency KV indices obtained through frequency-domain analysis provide high coverage of the KV positions that change most between independent chunk encoding and full-context encoding.

Balancing computation and transfer. Reusable KV Chunks may reside in CPU memory or on SSD/HDD. Increasing the recomputation ratio increases GPU workload but reduces the KV that must be loaded and allows more GPU computation to overlap with cache loading. In Appendix E.3, we measure overall latency when different recomputation ratios are selected for KV Chunks across storage tiers. The results show that a higher reuse ratio is more suitable when cache access is inexpensive on fast storage media, whereas slower media may benefit from more recomputation. The selection of KV indices for recomputation must therefore be combined with complementary cache transfer, and the balance between them must be adjusted for the target storage tier.

Generation Quality–TTFT Trade-off

CacheBlend and CacheSlide identify recomputation KVs through online first-layer recomputation, and ProphetKV selects recomputation targets by computing and aggregating query-to-context attention scores across layers online. CacheTune instead obtains recomputation indices offline during KV Chunk generation, avoiding online token-selection overhead. These indices also allow CacheTune to skip loading KV pairs that will be recomputed. Very fast methods such as EPIC and KVLink achieve lower TTFT but suffer noticeable accuracy degradation. EPIC updates only a few fixed positions at the beginning of each KV Chunk, which may miss semantically important tokens in other regions and lead to accuracy loss across datasets. KVLink relies on pretrained link tokens, introducing additional offline computation. In contrast, CacheTune’s frequency-domain analysis is lightweight: generating the recomputation index set for a 3K-token KV Chunk takes only about 0.69 ms on average on a GPU, and the indices can be reused across inference tasks.

Sparse KV Reuse Pipeline

The collection layer organizes the offline KV Chunks to be reused by the current request and establishes the positional correspondence between these chunks and the composed prompt. The precomputed ranking of each chunk is thereby converted into request-level recomputation and loading indices. Cached chunks may reside in CPU memory, SSDs, or HDDs. The runtime uses the loading indices to obtain KVs in the reuse complement at each layer, leaving the selected positions to be generated by the recomputation path. Chunk content, layer number, and global position are associated at this stage for subsequent layer-by-layer use.

The check layer applies the precomputed indices on the query side to select tokens in reusable chunks that require further updates. Queries at the selected positions participate in the current layer’s attention computation and aggregate preceding context over the complete KVs of that layer. After attention and the remaining forward computation, the hidden states at these positions pass to the next layer to continue generating the required queries and KVs. The same index set is retained across layers so that every selected position has a continuously updated hidden state; uncached content, such as new queries, still follows the normal forward path.

These operations are coordinated across three CUDA streams. The model’s native forward stream performs the current layer’s forward computation; the transfer stream asynchronously prefetches the reused KVs needed by the next layer; and the recomputation stream generates selected KVs from ready hidden states and performs positional recovery for reused Keys. The streams hand off data through per-layer CUDA events: after transfer completes, reused Keys undergo positional recovery; once both the recomputed and reused portions are ready, the fused result is consumed by the current layer’s attention; and the layer’s output then supplies the input for recomputation at the next layer.

Deferred RoPE for Positional Alignment

The local positions within an independent chunk usually differ from its global positions in the new context. In models that use RoPE, positional rotation is applied to Keys after linear projection. If cached Keys have already been rotated according to their positions within the chunk, moving the chunk directly carries the original positional encoding into the new sequence. CacheTune therefore stores raw pre-RoPE Keys in the offline cache and defers positional rotation until online reuse, allowing the same chunk to be used at different global offsets.

Newly generated Keys at selected positions likewise receive RoPE using their true global positions, while Values participate directly in fusion according to their corresponding indices. Both types of Keys are thus expressed in the same positional coordinate system of the composed prompt, allowing queries at the current layer to perform causal attention over the fused KVs. Positional recovery aligns the chunk’s coordinates within the new prompt, while selective recomputation restores cross-chunk dependencies by updating hidden states; the two operate together within the same fusion process.

Deferred RoPE uses the same index mapping as sparse loading and is integrated into the asynchronous path of the recomputation stream. Reused Keys are handed off in the order of transfer completion, positional recovery, and consumption during fusion, interleaved with ready computation or transfer tasks from other layers. Positional encoding is thus recovered along the online data flow, while chunks in the cache pool retain a uniform form that can be reused across requests.

Data Preparation

SAMSum and Multi-News use ROUGE-L to evaluate summarization quality; MuSiQue, WikiMQA, and HotpotQA use answer F1. For both metrics, higher values indicate closer agreement between the generated output and the reference answer. Methods are compared on the same model and task, with Full Recompute providing a quality reference based on full-context encoding.

Comparison Methods, Metrics, and Cache Placement

We use eight baselines. Full Recompute performs standard prefill over the entire prompt; Full KV Reuse directly concatenates independently encoded chunk caches. vLLM Prefix Caching uses native Automatic Prefix Caching to reuse only strictly matching prefixes, recomputing the remaining content through the default prefill path. These three methods correspond to full-context computation, direct non-prefix reuse, and strict prefix reuse, respectively.

The remaining baselines restore cross-chunk dependencies in different ways. Following the released CacheBlend implementation, we use the first layer as the check layer to identify HKVD tokens from KV deviations, and then selectively recompute the same selected 15% of positions in subsequent layers. EPIC updates the attention-sink positions at the beginning of each chunk, set to the first 16 tokens in our experiments. KVLink inserts 5 trained link tokens at each chunk boundary. For CacheSlide, we treat reusable documents as fixed segments and queries as updated segments. We use Weighted Correction Attention for selective recomputation and cache fusion, adapting it to the multi-chunk contexts in our experiments. We use an adapted implementation of ProphetKV based on its original method. In the first stage, query tokens are processed through successive layers to compute their attention to context tokens in the reused cache, and the scores are averaged over query positions and layers. In the second stage, the aggregated scores determine a shared token set whose KVs are recomputed at each layer, while the remaining KVs are reused directly. For a fair comparison, we also set ProphetKV’s recomputation ratio to 15%.

Deployment Calibration of the Recomputation Ratio

We use the first 10 SAMSum samples as the calibration set. Calibration measures computation, transfer, and synchronization costs without using reference answers or task-specific quality scores. Other datasets with comparable cache reuse patterns can therefore also serve as calibration workloads. Each candidate ratio is evaluated on the same calibration requests, and mean TTFT is used as the search objective. Hardware profiling and ratio search follow the procedure described in Appendix C.

Frequency-Domain Energy Distribution of the KV Cache

All groups show a consistent concentration at low frequencies: the high-frequency energy fractions of Keys and Values decrease as frequency increases, and the lowest 20% of the spectrum carries the vast majority of the total energy. This indicates that the main variations in KVs along the sequence can be compactly described by low-frequency structure. The phenomenon occurs in both summarization and multi-hop question answering, providing a basis for constructing an offline ranking from the frequency-domain features of each chunk itself.

CacheTune applies the inverse transform to the retained spectrum to recover a low-frequency signal aligned with the original sequence positions, then computes importance from the reconstructed magnitude at each token. The overall structure in the spectrum is thus converted into a ranking of positions that online recomputation can use directly. The spectral measurements motivate the use of low-frequency signals.

Basis for Low-Frequency Selection and Robustness of Reuse across Contexts

Independent encoding omits cross-chunk context, causing the KVs at some positions to deviate from full encoding. Using these positions with larger changes as a reference, we examine whether low-frequency reconstruction magnitudes can provide an effective KV importance ranking for recomputation, and further test how well the ranking recovers attention distributions and final answers.

Using Mistral v0.3-7B on SAMSum and MuSiQue, we compare the Keys and Values of the same token under independent chunk encoding and full-context encoding. Drift is computed from KV differences normalized within each layer, and Keys are compared before RoPE to exclude the effect of positional rotation. We use the 15% of tokens with the largest drift as the reference set. The low-frequency, high-frequency, and random strategies each also select 15% of positions; Recall@15% is the intersection of the two sets divided by the size of the high-drift set.

Low-frequency reconstruction magnitudes provide a basis for selecting context-sensitive positions, and recomputing these positions brings attention and answer quality closer to full encoding. Frozen indices retain these benefits after changes to the query and layout, making this signal suitable for offline extraction during independent chunk encoding and subsequent use with the cache in later requests.

Impact of Storage Tiers

Cached chunks are both the content units of non-prefix reuse and the basic units of organization and access in external storage. As chunk size increases, full recomputation must process more tokens, while direct reuse must read more KVs. To examine how these two costs vary with chunk granularity, we measure the total overhead of recomputation and loading the complementary KVs from the cache pool under ideal conditions. Cache-loading costs are measured using a baseline implementation without optimizations such as cross-layer prefetching.

Reading data from the SSD is more expensive, shifting the balance between computation and transfer. Increasing the recomputation ratio reduces the complementary KV portion that must be read and moves more work to the GPU. The savings in read overhead can offset the additional computation cost. In this configuration, higher recomputation ratios yield lower cache reuse latency than full reuse.

Balancing Recomputation and Transfer on External Storage

Pipeline overlap and cross-layer prefetching provide the largest latency reduction. Adding this optimization reduces TTFT from 179/289/281 ms to 94/159/151 ms across the three datasets, a reduction of 45.0%–47.5%. Computation in the current layer proceeds alongside cache loading for subsequent layers, placing previously serialized loading work within the computation window and reducing forward-pass stalls while waiting for KVs.

Finally, adding deferred RoPE reduces TTFT to 82/134/129 ms, a further reduction of 4.3%–5.8% relative to the preceding configuration. Global positional recovery for reused Keys is incorporated into the asynchronous execution path, reducing synchronization waits for positional correction in the main forward stream. This optimization changes when positional recovery is performed and provides a smaller benefit than the preceding two optimizations. With all three enabled, the full configuration reduces TTFT by 53.6%–54.2% compared with the configuration without cache-loading optimizations.