Manuscript Offprint
arXiv:2610.18140SparPR: Runtime KV-Cache Recovery for Resource-Constrained LLM Inference on Consumer Hardware
Abstract
Running large language models (LLMs) on consumer hardware is bottlenecked by the key-value (KV) cache, which grows with every decoded token and quickly exhausts the memory and bandwidth of a single consumer GPU. We present SparPR (Sparse Partial Recomputation), a runtime KV-cache recovery mechanism that does not modify model weights and requires no offline training. SparPR couples three online decisions: Query-Aware key-block selection scores historical blocks against the current query; dynamic budget control estimates per-block copy and recompute costs to decide how many blocks to retain; and on-demand local recomputation with cost-aware fallback merges retained blocks into continuous spans and switches between sparse recomputation and full recovery according to a runtime cost comparison. Implemented on FlexGen/FlexLLMGen, SparPR is evaluated on a single consumer laptop (RTX 3070 Ti 8 GB, Ryzen 9 6900HX, 16 GB RAM). It cuts end-to-end latency by 31%, 52%, and 63% at 1k, 2k, and 4k prompt tokens respectively, with higher throughput, and completes an 8k-token workload in 44 minutes where the FlexGen baseline times out. Under a fixed cache budget, SparPR retains a Needle Accuracy that stays well above StreamingLLM and H2O at every keep ratio, and ablation studies confirm that the three mechanisms act jointly.
1 Introduction
Deploying large language models (LLMs) on consumer hardware (laptops and single-GPU machines) is increasingly common for offline, privacy-sensitive, and cost-sensitive workloads. The dominant cost is the key-value (KV) cache, which grows linearly with the number of tokens processed and quickly turns limited GPU memory and host-device bandwidth into first-order bottlenecks [1, 2, 3]. On datacenter GPUs these costs can be absorbed by large memory and high bandwidth; on a consumer laptop they translate into lower throughput, higher latency, and out-of-memory (OOM) failures long before the model's nominal context window is reached [4].
Existing work addresses parts of this problem. Layered-execution and offloading methods [2] place weights, activations, and caches across GPU, CPU, and disk to improve runnability. Cache-retention methods [4, 5, 7, 8, 9] select a subset of the historical cache to keep. Local-recovery methods [6] recompute or reload only part of the cache to avoid restoring everything. These lines of work answer whether the system can run, which information to keep, and how to recover it,
*Corresponding author. E-mail: fengli_xjtu@163.com respectively, but they do not form a unified runtime loop that couples query relevance, budget control, and recovery-path selection.
In this paper we ask three questions that arise once a model no longer fits its KV cache in GPU memory: (i) which historical blocks are most relevant to the current query and therefore worth keeping; (ii) how many blocks should be retained given the context length, bandwidth, and compute cost; and (iii) whether the retained blocks should be restored by local recomputation or by full recovery. To answer them, we propose SparPR (Sparse Partial Recomputation), a runtime optimization method for KV-cache recovery on consumer hardware.
Our contributions are as follows.
-
A Query-Aware key-block selection mechanism that scores historical blocks by their relevance to the current query and performs Top-k selection, converting uniform cache access into relevance-driven access.
-
A dynamic budget control mechanism that estimates per-block copy and recompute costs and adaptively derives the target keep ratio and block count, with a conservative lower bound (Minimum Keep Floor).
-
An on-demand local recomputation with cost-aware fallback mechanism that merges discrete key blocks into continuous spans and selects between sparse and dense recovery paths by a runtime cost comparison (Dense Fallback Threshold).
-
A full prototype on FlexGen/FlexLLMGen, evaluated on a single consumer laptop, that cuts latency by 31%–63% at 1k–4k tokens and completes an 8k-token workload where the FlexGen baseline times out.
KV-cache eviction and retention. StreamingLLM [4] keeps the initial “attention sink” and recent tokens, a position-based strategy. H2O [5] keeps heavy-hitter tokens selected by accumulated attention statistics. ArkVale [7] organizes tokens into pages and recalls important evicted pages from a CPU-side backup. ShadowKV [9] offloads the value cache and reconstructs sparse KV on the fly. Most of these methods keep a budget that is fixed or decoupled from both the current query and the hardware cost.
Query-aware sparsity and local recomputation. Quest [6] scores and loads only the most relevant page per attention head, showing that query-aware selection can be made cheap enough for inference. ProphetKV [8] reuses KV cache in retrieval-augmented generation via query-driven selective recomputation. Najafizadeh et al. [10] study the restore-versus-recompute trade-off and switch between the two with an I/O-aware policy at the storage layer. SparPR shares the query-aware idea but works at block granularity on an offloading base (FlexGen) where both data movement and recomputation are expensive, and couples an explicit copy-versus-recompute cost model with query-aware selection and a dense fallback threshold in a single runtime loop.
3 Method
3.1 Overview and Problem Setting
We target memory-constrained decoding on a single consumer device. At each decoding step, the system must recover (load or recompute) the historical KV cache needed to attend over the past. Let be the current query representation, and let be the set of candidate historical blocks, where each is a block-level cache unit. Let denote the runtime and hardware state (context length, block size, host bandwidth, recompute efficiency, and conservative parameters).
SparPR operates as an online runtime layer on top of an existing execution engine; it does not change model weights and requires no offline training. Its decision output is a recovery plan consisting of (i) a set of retained key blocks and their target count, and (ii) the recovery path (sparse recomputation or full recovery). Figure 1 summarizes the decision loop.

Figure 1: The SparPR runtime decision loop: query-aware scoring, dynamic budget control, span merging, and cost-aware path selection.
3.2 Query-Aware Key-Block Selection
The first stage scores each historical block by its relevance to the current query. For each block we precompute a compact summary, the per-head mean key vector
(1) where is the key vector of token at head . These summaries form an tensor that stays resident on the GPU, so scoring touches only the summary and never the full KV blocks offloaded to CPU or disk; this is what keeps the estimate cheap. The relevance score of a block is the query–summary similarity aggregated over heads,
a single scalar computed from H dot products of length d; aggregating with behaves similarly. Throughout, blocks, summaries, and costs are defined per layer, and the layer count L is a common factor that cancels in the relative cost comparisons of Sections 3.3 and 3.4.
Given the scores, the system selects the top-k blocks:
Unlike a fixed threshold, Top-k keeps the selection scale stable as the number of candidate blocks changes. The value of k is not a static hyperparameter; it is produced by the dynamic budget control described next.
3.3 Dynamic Budget Control
The number of blocks worth keeping depends on context length, host bandwidth, and compute cost. SparPR estimates two per-block quantities. Let each block contain b tokens, use h attention heads of dimension d, and store activations in bytes. The copy cost of one block is
where is the effective host-to-device bandwidth and the factor 2 accounts for both key and value. The recompute cost of one block scales with the block length and the square of the hidden dimension :
where is an effective compute-throughput term corrected by a runtime efficiency discount. On the sparse path, a block's K/V is rebuilt from a checkpointed hidden state via the attention projection only ( , ), without re-running the MLP or a full forward pass.
Let the copy-cost ratio be
Intuitively, when copying dominates, the system should keep more blocks to avoid repeated loads; when recomputing dominates, it should keep fewer. SparPR maps to a target keep ratio with a light linear mapping plus a context-length correction that adds a small retention gain in longer contexts. The target block count is then
where implements the Minimum Keep Floor, a conservative lower bound that prevents the budget from shrinking too aggressively under pressure.
3.4 Span Merging and Cost-Aware Fallback
The Top-k blocks are often scattered across the context. Recovering them one by one introduces fragmentation, scheduling, and fixed per-block overhead. SparPR therefore merges adjacent key blocks into continuous spans .
We model the cost of the two recovery paths. Let be the number of candidate blocks and the per-block copy cost. Full recovery costs
Sparse recovery costs
where is the per-span organizational overhead and is the fixed sparse-recovery overhead. Note that depends not only on how many blocks are kept, but also on how many spans they form: more fragmented blocks raise the cost.
The path decision is governed by a Dense Fallback Threshold :
When sparse recovery is no longer cheaper than a fraction of full recovery, the system falls back to the dense path rather than persisting with an unprofitable sparse strategy. A smaller makes the system fall back more readily (more conservative); a larger favors sparse recovery.
3.5 Runtime Decision Procedure
The full decision procedure is summarized below.
Algorithm 1 SparPR runtime decision.
Input: current query , historical block set , runtime state Output: recovered cache (sparse or dense)
1: Compute block scores for all 2: Estimate keep ratio from 3: Compute target count 4: Select 5: Merge adjacent blocks into spans 6: Estimate and 7: if then Dense Fallback 8: else Sparse Recompute
4 Experiments
4.1 Setup
Hardware and software. All results are real runs on a single consumer laptop with an NVIDIA RTX 3070 Ti (8 GB), an AMD Ryzen 9 6900HX mobile CPU, 16 GB host memory, and a local SSD, running Windows with WSL. The execution engine is FlexGen/FlexLLMGen. We evaluate facebook/opt-6.7b [1] with batch size 4 and a static offloading policy, a setting in which the KV cache quickly stresses the 8 GB GPU budget.
Baselines. We compare against FlexGen [2] (system runnability baseline), StreamingLLM [4] (position-based retention) and H2O [5] (statistics-based retention) for needle-style retrieval fidelity, and Quest-style query-aware selection for the ablation.
Needle task. For needle-style retrieval fidelity we use a constructed needle task: a target fact (“The Wi-Fi password for the guest network at the SWJTU is 2022116822”) is inserted at one of two depth ratios, 0.15 or 0.85 of the context, into a long distractor text (an excerpt of Alice in Wonderland), and the model is asked “What is the Wi-Fi password for the guest network at the SWJTU?”. Needle Accuracy is the hit rate averaged over the two insertion depths.
4.2 System Performance and Runnability
Table 1 reports end-to-end latency and throughput as the prompt length grows from 1k to 8k tokens. DeepSpeed and HF Accelerate run out of memory before 1k, and a Quest-style query-aware selection OOMs at 1200 tokens; only the offloading FlexGen baseline and SparPR keep a runnable range. FlexGen completes 1k–4k by spilling to CPU and disk but slows to the point of timing out at 8k. SparPR completes every length, cutting latency by 31%, 52%, and 63% at 1k, 2k, and 4k tokens and reaching 1.4×, 2.1×, and 2.7× higher throughput; the gap widens with context length because SparPR bounds the growth of the KV-cache recovery cost.
Table 1: End-to-end latency (s) and throughput (tok/s) of FlexGen and SparPR at increasing prompt length (OPT-6.7B, batch 4, RTX 3070 Ti 8GB). “timeout” denotes failure to complete within the experiment’s time budget.
| Prompt | FlexGen lat. | FlexGen thr. | SparPR lat. | SparPR thr. | Lat. reduction |
|---|---|---|---|---|---|
| 1k | 1064 | .466 | 737 | .673 | 31% |
| 2k | 2101 | .236 | 1009 | .491 | 52% |
| 4k | 4174 | .119 | 1553 | .319 | 63% |
| 8k | timeout | — | 2641 | .187 | — |
4.3 Needle-Style Retrieval Fidelity Under Budget
Table 2 reports Needle Accuracy at fixed cache keep ratios across 2k, 4k, and 8k prompt tokens. At every keep ratio and length, SparPR stays well above H2O and StreamingLLM: at high budgets (30–50%) it retains .60–.94 accuracy versus .31–.51 for H2O and .15–.49 for StreamingLLM, and at 10% keep it retains .60/.48/.31 at 2k/4k/8k while H2O falls to around .12 and StreamingLLM collapses to .02. StreamingLLM is position-based, so its needle survives only if it falls in the recent window; H2O is query-agnostic, so its hit rate roughly tracks the keep ratio and is nearly length-invariant. SparPR’s query-aware selection keeps the needle-relevant block even at low budgets (at the cost of modestly higher latency), but its accuracy still degrades with context length, since longer distractors make the needle-relevant block harder to identify.
Table 2: Needle Accuracy at fixed cache keep ratios, at 2k/4k/8k prompt tokens (mean of three runs).
| Method | Keep ratio | 2k | 4k | 8k |
|---|---|---|---|---|
| StreamingLLM | 50% | .445 | .467 | .485 |
| 40% | .291 | .333 | .345 | |
| 30% | .153 | .197 | .208 | |
| 20% | .020 | .051 | .070 | |
| 10% | .020 | .020 | .020 | |
| 5% | .020 | .020 | .020 | |
| H2O | 50% | .492 | .506 | .511 |
| 40% | .408 | .393 | .408 | |
| 30% | .321 | .308 | .313 | |
| 20% | .212 | .221 | .215 | |
| 10% | .120 | .127 | .114 | |
| 5% | .065 | .069 | .073 | |
| SparPR | 50% | .943 | .879 | .780 |
| 40% | .898 | .831 | .694 | |
| 30% | .847 | .772 | .598 | |
| 20% | .763 | .654 | .473 | |
| 10% | .600 | .482 | .308 | |
| 5% | .424 | .330 | .208 |
4.4 Parameter Analysis
Table 3 shows the effect of the Minimum Keep Floor. Lowering the floor reduces the average keep ratio and the sparse cost and raises throughput, while accuracy degrades only gradually—consistent with the query-aware selection retaining the more relevant blocks first.
Table 3: Effect of Minimum Keep Floor on keep ratio, throughput, accuracy, and sparse cost (needle task).
| Floor | Avg. keep | Throughput | Needle acc. | Sparse cost (ms) |
|---|---|---|---|---|
| 1.00 | 100.0% | 0.482 | 0.993 | 952.33 |
| 0.90 | 90.0% | 0.532 | 0.987 | 891.67 |
| 0.80 | 80.0% | 0.588 | 0.983 | 821.33 |
| 0.75 | 75.5% | 0.642 | 0.973 | 761.67 |
| 0.70 | 72.6% | 0.681 | 0.963 | 712.33 |
| 0.65 | 69.7% | 0.728 | 0.947 | 671.67 |
| 0.60 | 66.8% | 0.784 | 0.927 | 632.33 |
Table 4 shows the effect of the Dense Fallback Threshold. A lower threshold makes the system fall back to full recovery more often (higher bypass count) and behave more conservatively; a higher threshold favors sparse recovery, raising throughput while accuracy declines slightly.
Table 4: Effect of Dense Fallback Threshold on throughput, accuracy, and bypass count (needle task).
| Threshold | Throughput | Needle acc. | Bypass count |
|---|---|---|---|
| 0.72 | 0.520 | 0.985 | 12.00 |
| 0.74 | 0.560 | 0.983 | 10.00 |
| 0.76 | 0.610 | 0.980 | 8.00 |
| 0.78 | 0.650 | 0.977 | 6.00 |
| 0.80 | 0.680 | 0.971 | 5.00 |
| 0.85 | 0.700 | 0.962 | 3.00 |
| 0.90 | 0.710 | 0.943 | 1.00 |
4.5 Ablation Study
Ablation studies use the same needle task at a fixed 1000-token prompt length, and every reported value is the mean of three runs. Note that the needle task is a different workload from the throughput sweep in Table 1, so the FlexGen baseline latency here differs slightly from Table 1. Tables 5 and 6 isolate the contribution of each component. Quest-only keeps query-aware selection but drops budget and fallback, improving latency but hurting accuracy. w/o Budget keeps too much context and gains little efficiency. w/o Span Merge incurs the highest sparse cost (1085.33 ms) because of fragmented recovery. w/o Bypass cannot retreat from unprofitable sparse paths and loses accuracy. SparPR-full achieves the lowest latency and highest throughput while keeping high accuracy, confirming that the mechanisms act jointly.
Table 5: Ablation: external results (needle task, 1000 tokens, mean of three runs).
| Method | Latency (s) | Throughput | Needle acc. |
|---|---|---|---|
| FlexGen | 991.33 | 0.50 | 0.983 |
| Quest-only | 845.33 | 0.59 | 0.777 |
| w/o Budget | 838.67 | 0.60 | 0.963 |
| w/o Span Merge | 936.67 | 0.53 | 0.973 |
| w/o Bypass | 812.33 | 0.62 | 0.917 |
| SparPR-full | 756.67 | 0.66 | 0.957 |
Table 6: Ablation: runtime statistics (needle task, 1000 tokens, mean of three runs).
| Method | Avg. keep | Bypass | Blocks skip | Recompute ok | Sparse cost (ms) |
|---|---|---|---|---|---|
| FlexGen | 100.0% | 0.00 | 0.00 | 0.00 | 952.33 |
| Quest-only | 58.7% | 0.00 | 726.67 | 3.00 | 805.67 |
| w/o Budget | 85.0% | 3.33 | 266.33 | 4.33 | 818.33 |
| w/o Span Merge | 73.5% | 16.33 | 468.33 | 8.67 | 1085.33 |
| w/o Bypass | 73.8% | 0.00 | 462.67 | 12.33 | 821.67 |
| SparPR-full | 73.2% | 5.67 | 473.33 | 9.33 | 728.33 |
5 Conclusion and Limitations
We presented SparPR, a runtime KV-cache recovery mechanism for resource-constrained LLM inference on consumer hardware. SparPR couples query-aware key-block selection, dynamic budget control, and cost-aware fallback into one online decision loop. On a single consumer laptop, it cuts latency by 31%–63% and raises throughput by 1.4–2.7× over FlexGen at 1k–4k tokens, completes an 8k-token workload where FlexGen times out, and keeps consistently higher needle accuracy than StreamingLLM and H2O at every cache budget; ablation confirms the three mechanisms act jointly.
Our study has limitations. Experiments use a single OPT-6.7B model, one consumer GPU, and a constructed needle task; scaling to larger models, standard long-context benchmarks, and more hardware remains future work. Finer-grained page-level cache organization and online calibration of the cost models are promising directions.
References
[1] S. Zhang, S. Roller, N. Goyal, et al. OPT: Open Pre-trained Transformer Language Models. arXiv:2205.01068, 2022.
[2] Y. Sheng, L. Zheng, B. Yuan, et al. FlexGen: High-Throughput Generative Inference of Large Language Models with a Single GPU. ICML, 2023.
[3] T. Dao, D. Fu, S. Ermon, et al. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness. NeurIPS, 2022.
[4] G. Xiao, Y. Tian, B. Chen, et al. Efficient Streaming Language Models with Attention Sinks. ICLR, 2024.
[5] Z. Zhang, Y. Sheng, T. Zhou, et al. H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models. NeurIPS, 2023.
[6] J. Tang, Y. Zhao, K. Zhu, et al. Quest: Query-Aware Sparsity for Efficient Long-Context LLM Inference. ICML, 2024.
[7] R. Chen, Z. Wang, B. Cao, et al. ArkVale: Efficient Generative LLM Inference with Recallable Key-Value Eviction. NeurIPS, 2024.
[8] S. Wang, J. Chen, Y. Pan, et al. ProphetKV: User-Query-Driven Selective Recomputation for Efficient KV Cache Reuse in Retrieval-Augmented Generation. ICML, 2026.
[9] H. Sun, L.-W. Chang, W. Bao, et al. ShadowKV: KV Cache in Shadows for High-Throughput Long-Context LLM Inference. ICML, 2025.
[10] A. Najafizadeh, V. Tarasov, et al. LLM KV-cache: To Restore or To Recompute, That Is the Question. HotStorage, 2026.
[11] H. Sun, L. Li, M. Xiao, et al. Breaking the Boundaries of Long-Context LLM Inference: Adaptive KV Management on a Single Commodity GPU (LeoAM). arXiv:2506.20187, 2025.