工作日早上 7 点读 AI,周日早上 8 点读周报订阅邮件

METAL LAB

RestoreKV: Recovering Full-Cache Behavior Under Aggressive Query-Agnostic KV Cache Eviction

arXiv:2608.012472026-08-01

给压缩过头的KV缓存加上8个可学习的恢复token,让效果重新接近未压缩时的水平

处理长文本的大模型常常压缩KV缓存(保存过去token计算结果的存储区)以省内存,但压缩力度太大时回答质量会明显下降。RestoreKV保留原有挑选保留哪些KV对的方法不变,额外用少量学习到的恢复token在压缩前对完整KV缓存做一次带LoRA的处理,生成一个占用同等预算内一部分空间的紧凑恢复缓存,以此弥补被丢弃的信息。在Qwen3-4B上,该方法把KVzip在RULER-4K上的准确率从38.2提升到73.2,而额外带来的时间开销不到整个压缩过程的0.5%。

METAL LAB 解读图

RestoreKV的处理流程

证据状态已报告实测结果

  1. ①上下文预填充模型先处理一遍完整的长文本,生成完整的KV缓存。
  2. ②恢复token处理8个训练好的恢复token在临时启用LoRA的情况下,对完整KV缓存做一次处理,生成紧凑的恢复缓存。
  3. ③原有压缩方法不变KVzip等现有方法仍按原来的重要性打分挑选要保留的原始KV对,但预留出恢复缓存所需的位置。
  4. ④按预算合并缓存把挑选出的原始KV对和生成的恢复缓存合并,形成与之前总量相同的最终缓存。
  5. ⑤问答与生成LoRA被关闭,之后处理任意问题和生成回答都使用原始未改动的模型。
这是 METAL LAB 制作的解读图,并非论文作者提供的原图。

他们做了什么

  1. 与查询无关的KV缓存压缩方式会先压缩一次文本内容,再反复用于之后任意的问题,但压缩力度加大时效果会明显崩溃。
  2. RestoreKV保留KVzip等现有方法挑选保留哪些原始KV对的方式不变,另外用LoRA(一种只训练少量额外参数的轻量微调方法)让8个可学习的恢复token在压缩前对完整KV缓存做一次处理,生成一个紧凑的、随上下文变化的恢复缓存。
  3. 这个恢复缓存占用原本要保留的部分槽位,所以总的内存预算保持不变;LoRA只在生成恢复缓存这一次性过程中启用,之后处理问题和生成回答都使用原始未改动的模型。
  4. 训练采用自蒸馏方式:让使用压缩缓存的学生模型的回答分布,去匹配使用完整缓存的、冻结不变的教师模型的回答分布,只训练恢复token的嵌入和LoRA参数,占4B模型参数的0.4%。
  5. 在Qwen3-0.6B/4B/8B和Llama-3.1-8B四个模型骨架、RULER-4K/QASPER/QuALITY/LongHealth四个基准、以及KVzip、KVzip+、ContrastKV、SnapKV、H2O五种基础压缩方法上,该方法在几乎所有配对场景下都带来了提升。
Figure 1: RestoreKV narrows the gap to full-cache behavior under aggressive compression at negligible one-time cost. Applied to KVzip+, RestoreKV reaches 86.4 RULER accuracy at 16× compression on the KVPress Benchmark while adding negligible compression-time overhead.
Figure 1: RestoreKV narrows the gap to full-cache behavior under aggressive compression at negligible one-time cost. Applied to KVzip+, RestoreKV reaches 86.4 RULER accuracy at 16× compression on the KVPress Benchmark while adding negligible compression-time overhead.
Table 1: Generalization across KV cache eviction methods. RestoreKV improves five different base methods on Qwen3-4B under matched KV budgets, with larger gains typically observed at tighter budgets. Colored subscripts indicate absolute changes from the corresponding baseline.
MethodRULER-4KQASPERQuALITYLongHealth
r=0.2r=0.1r=0.05r=0.2r=0.1r=0.05r=0.2r=0.1r=0.05r=0.2r=0.1r=0.05
KVzip91.480.138.238.233.918.066.058.546.371.570.061.0
KVzip + Ours93.5 +2.188.8 +8.773.2 +35.039.0 +0.837.7 +3.828.7 +10.767.0 +1.063.3 +4.852.4 +6.175.8 +4.373.8 +3.867.5 +6.5
KVzip+91.384.851.638.132.423.366.560.051.973.267.863.2
KVzip+ + Ours93.3 +2.089.7 +4.970.7 +19.140.9 +2.838.5 +6.131.6 +8.366.8 +0.362.9 +2.957.9 +6.074.2 +1.073.0 +5.271.5 +8.3
ContrastKV91.680.738.040.131.917.866.262.250.774.269.049.0
ContrastKV + Ours92.3 +0.784.3 +3.640.2 +2.240.9 +0.836.0 +4.121.6 +3.867.6 +1.463.3 +1.151.9 +1.275.2 +1.070.5 +1.554.0 +5.0
SnapKV33.820.612.722.419.014.353.953.042.541.036.836.2
SnapKV + Ours37.7 +3.926.3 +5.714.3 +1.629.9 +7.524.0 +5.020.7 +6.459.4 +5.551.8 −1.249.9 +7.451.8 +10.841.8 +5.038.5 +2.3
H2O8.03.53.222.013.814.459.250.441.560.248.837.0
H2O + Ours17.3 +9.311.6 +8.15.7 +2.530.4 +8.424.7 +10.921.3 +6.960.9 +1.754.9 +4.547.7 +6.264.8 +4.659.0 +10.246.8 +9.8
Figure 2: Overview of RestoreKV. After context prefill, a single LoRA-adapted restore pass processes n restore tokens (n=8 by default) with causal access to the full KV cache, generating n​L​H context-conditioned KV pairs. These restore states are combined with the retained context states under the same total KV budget. LoRA is active only during restore-cache generation; subsequent query processing and decoding use the original frozen backbone. Training (offline): The restore-token embeddings and LoRA adapters (0.4% of the 4B backbone) are optimized by self-distillation from the frozen full-cache teacher, Inference: The trained restore tokens and LoRA adapters generate the restore cache once for each new context.
Figure 2: Overview of RestoreKV. After context prefill, a single LoRA-adapted restore pass processes n restore tokens (n=8 by default) with causal access to the full KV cache, generating n​L​H context-conditioned KV pairs. These restore states are combined with the retained context states under the same total KV budget. LoRA is active only during restore-cache generation; subsequent query processing and decoding use the original frozen backbone. Training (offline): The restore-token embeddings and LoRA adapters (0.4% of the 4B backbone) are optimized by self-distillation from the frozen full-cache teacher, Inference: The trained restore tokens and LoRA adapters generate the restore cache once for each new context.
Table 2: Component and LoRA-target ablations on RULER-4K (Qwen3-4B). The first row is KVzip without a restore cache; the last row is the full RestoreKV configuration. “Fixed” replaces all eight learned restore-token embeddings with the embedding of the line-break token \n.
KV budget ratio r
Restore emb.LoRA target#Params0.20.10.05
91.480.138.2
Learned0.02M (0.0005%)92.782.642.1
Learnedq/k/v4.0M (0.1%)93.488.272.4
Learnedq/k/v/o5.9M (0.15%)93.588.472.0
Fixedq/k/v/o+MLP16.5M (0.4%)93.588.071.9
Learnedq/k/v/o+MLP16.5M (0.4%)93.588.873.2
Figure 3: Performance across four model backbones and four benchmarks. RestoreKV and RestoreKV+ are applied to KVzip and KVzip+, respectively, under the same KV budget. Both methods reduce compression-induced performance loss, with larger gains under tighter cache budgets.
Figure 3: Performance across four model backbones and four benchmarks. RestoreKV and RestoreKV+ are applied to KVzip and KVzip+, respectively, under the same KV budget. Both methods reduce compression-induced performance loss, with larger gains under tighter cache budgets.
Table 3: Effect of full-context conditioning on RULER-4K with Qwen3-4B. Generating the restore cache from the full cache before eviction adds 8.8 points at r=0.05 over generating it from the already evicted cache.
KV budget ratio r
Method0.20.10.05
KVzip (n=0)91.480.138.2
Generated from evicted cache93.787.664.4
Generated from full KV cache93.588.873.2
Figure 4: Comparison with a Synthesized-Cache Baseline on Qwen3-4B. RestoreKV+ consistently improves token-eviction baselines and remains competitive with AM-fast, a strong synthesized-cache method, at ∼13× lower compression time on 4K-token contexts.
Figure 4: Comparison with a Synthesized-Cache Baseline on Qwen3-4B. RestoreKV+ consistently improves token-eviction baselines and remains competitive with AM-fast, a strong synthesized-cache method, at ∼13× lower compression time on 4K-token contexts.
Table 4: Ablation on the number of restore tokens (RULER-4K, Qwen3-4B). All variants share the same training recipe and total KV budget.
KV budget ratio r
Method0.20.10.05
n=0 (KVzip)91.480.138.2
n=193.085.365.3
n=293.487.670.4
n=493.487.068.5
n=8 (default)93.588.873.2
n=1693.387.869.1
Figure 5: Layer-wise context-attention recovery on RULER-4K (Qwen3-4B, r=0.05). KVzip substantially suppresses attention from the final query token to non-sink context KV pairs. RestoreKV recovers part of the lost attention (shaded), increasing the average context-attention mass from 0.56% to 1.30% and reducing KL divergence from the full-cache model by 16% (→0.167).
Figure 5: Layer-wise context-attention recovery on RULER-4K (Qwen3-4B, r=0.05). KVzip substantially suppresses attention from the final query token to non-sink context KV pairs. RestoreKV recovers part of the lost attention (shaded), increasing the average context-attention mass from 0.56% to 1.30% and reducing KL divergence from the full-cache model by 16% (→0.167).
Table A: Ablation on the training ratio range (RULER-4K, Qwen3-4B). RestoreKV is trained by sampling the retention ratio from 𝒰⁡(rmin,rmax). The first row reports the KVzip baseline without restoration.
Training ratio rangeKV budget ratio r
rminrmax0.40.20.10.05
--93.591.480.138.2
0.0250.2594.393.588.873.2
0.0250.5094.193.186.163.5
0.0500.2594.393.286.565.6
0.0500.5094.092.884.551.5
Figure 6: Efficiency analysis (Llama-3.1-8B-Instruct, 32K context). (a) Restore-cache generation adds only ∼0.04 s (0.5%) and 84 MB (0.4%) on top of any base scorer. (b) Attention latency and KV memory are nearly identical to the base method.
Figure 6: Efficiency analysis (Llama-3.1-8B-Instruct, 32K context). (a) Restore-cache generation adds only ∼0.04 s (0.5%) and 84 MB (0.4%) on top of any base scorer. (b) Attention latency and KV memory are nearly identical to the base method.
Table B: Effect of the query-position offset (RULER-4K, Qwen3-4B). Offset-only KVzip applies the same +8 query offset as RestoreKV without adding restore states. Its performance remains close to standard KVzip, suggesting that the positional offset alone is unlikely to account for RestoreKV’s improvement.
VariantRestore statesQuery offsetKV budget ratio r
0.20.10.05
KVzipNo091.480.138.2
Offset-only KVzipNo+890.580.836.9
RestoreKVYes+893.588.873.2
Figure A: RestoreKV composes with Fast KVzip, a learning-based scorer (RULER-4K, Qwen3-8B). At 16×, Fast KVzip drops to 46.7, RestoreKV restores it to 79.3, above plain KVzip (59.0).
Figure A: RestoreKV composes with Fast KVzip, a learning-based scorer (RULER-4K, Qwen3-8B). At 16×, Fast KVzip drops to 46.7, RestoreKV restores it to 79.3, above plain KVzip (59.0).
Table C: Effect of training–inference evictor mismatch (RULER-4K, Qwen3-4B). The inference evictor is fixed to KVzip, while RestoreKV is trained using the evictor in the first column.
Training evictorInference evictorKV budget ratio r
0.200.100.05
-KVzip91.480.138.2
SnapKVKVzip93.581.642.0
KVzipKVzip93.588.873.2
Figure B: SCBench results on long-context tasks (Qwen3-4B).
Figure B: SCBench results on long-context tasks (Qwen3-4B).
Table D: LongBench results over 16 tasks under aggressive KV compression. Categories are single-document QA (S-QA), multi-document QA (M-QA), summarization (Summ), few-shot learning (Fewshot), synthetic tasks (Synth), and code tasks (Code). Rel. denotes the average score relative to the full KV cache.
MethodS-QAM-QASummFewshotSynthCodeAvgRel.
Full KV cache
Llama-3.1-8B-Instruct44.647.629.254.055.148.146.4100.0%
KV budget ratio = 0.125
KVzip42.743.927.761.944.047.744.796.3%
KVzip + Ours43.643.028.563.945.949.345.798.4%
KV budget ratio = 0.0625
KVzip33.332.424.049.120.641.633.572.1%
KVzip + Ours38.235.427.059.322.843.237.781.2%
Table E: RestoreKV training data statistics (context length in tokens).
SourceSamplesCtx (mean)Ctx range
LongAlpaca2,4887,3064,961–15,237
PG-192,2603,0713,071–3,072
Tulu-3 FLAN1,500898512–9,283
Total6,2484,236512–15,237
Table F: Experimental environment. Hardware and software configurations used for all experiments.
Hardware
GPUNVIDIA RTX PRO 6000 Blackwell (96 GB)
CPUIntel Xeon Gold 6530
Memory503 GiB
Software
OSUbuntu 22.04.5 LTS
FrameworkPyTorch 2.8.0 (CUDA 12.8)
Table G: Sensitivity to Training Seeds. RULER-4K accuracy on Qwen3-4B, reported as mean±std over three training seeds.
KV budget ratio
0.400.200.100.05
KVzip93.4691.3880.0838.23
RestoreKV94.25±0.0493.37±0.1188.21±0.5172.81±0.57
Table H: Evaluation metrics used for each benchmark.
BenchmarkEvaluation metric
RULER-4KOfficial string-matching score
QASPERMaximum token-F1 over reference annotations
QuALITYAnswer-letter accuracy
LongHealthAnswer-letter accuracy
LongBenchOfficial per-task metric (F1, ROUGE-L, or accuracy)
SCBenchOfficial task-specific evaluator

研究结果

  • 在Qwen3-4B、预算比例为5%的情况下,RestoreKV把KVzip在RULER-4K上的准确率从38.2提升到73.2,基于KVzip+的版本从51.6提升到70.7。
  • 应用到KVzip+上后,在KVPress基准测试中16倍压缩下达到86.4的RULER准确率,在32K上下文评测中额外时间开销不到整体压缩时间的0.5%,额外内存开销为84MB(0.4%)。
  • 应用到基于学习的评分方法Fast KVzip上后,16倍压缩下RULER-4K准确率从46.7提升到79.3,超过了普通KVzip的59.0。
  • 与合成缓存基线AM-fast相比,在r=0.05时RestoreKV+在RULER-4K上取得70.7分,优于AM-fast的52.8分,且构建4K上下文缓存仅需0.74秒,比AM-fast的9.68秒快约13倍。
  • 分层分析显示,压缩后上下文注意力平均占比从原本的水平降至0.56%,RestoreKV将其恢复到1.30%,并把与完整缓存模型的KL散度从0.198降低到0.167。

可应用场景

  • 适用于先压缩一次长文档缓存、再反复回答多个问题的文档问答或摘要类服务,用来在节省内存的同时减少回答质量的损失。
  • 可以作为附加模块接入已有的KVzip、KVzip+、SnapKV、H2O等压缩方法之上,而无需重新设计这些方法本身的挑选机制。
  • 可与Fast KVzip等基于学习的轻量评分方法结合,在保留其打分速度优势的同时降低压缩带来的准确率损失。

局限与待验证事项

  • 如果训练时使用的压缩方法与推理时实际使用的压缩方法不一致,恢复效果会明显下降,说明更换基础压缩方法后可能需要重新训练。
  • 实验主要覆盖Qwen3系列(0.6B到8B)和Llama-3.1-8B-Instruct,上下文长度大多在约15K到32K token范围,另有一项约104K token的SCBench测试,更大规模模型或其他架构尚未验证。
  • 训练数据仅约6.2千个来自LongAlpaca、PG-19和Tulu-3 Flan的文本-问题对,在其他领域文档上的泛化效果尚未单独验证。
  • 论文中大多数实验固定使用8个恢复token和特定的LoRA配置,在其他参数设置下是否仍是最优尚需进一步探索。

为什么重要

对于把长文档压缩一次、之后反复用来回答多个问题的系统来说,压缩力度越大回答质量往往损失越多,而这项方法在不改动现有压缩流程本身的前提下减少了这种损失。因为它可以作为附加模块直接接入已有的压缩方法,实际部署时改造成本较低。

本文术语

  • KV缓存 · Transformer模型为避免重复计算,保存下来的过去token的key-value计算结果集合
  • 与查询无关的压缩(query-agnostic eviction) · 在还不知道之后会问什么问题的情况下,先把文本压缩一次,再反复用于各种问题
  • LoRA · 保持原模型参数不变,只额外训练一小部分低秩矩阵来调整模型行为的轻量微调方法
  • 自蒸馏(self-distillation) · 让使用压缩缓存的模型学习模仿使用完整未压缩缓存的同一模型的输出分布
  • RULER-4K · 在4K token长度的上下文中测试检索、追踪和信息汇总能力的13项合成任务基准

论文原文摘要(英文)

Query-agnostic KV cache eviction compresses a context once and reuses the resulting cache for arbitrary future queries, but performance can collapse under tight budgets. Existing methods primarily improve which original KV pairs are retained. We introduce RestoreKV, which complements this selection-based formulation with learned restoration under the same total KV budget. Our key insight is that, although the information lost through eviction is context-specific, the mechanism for generating its

作者 · Changwoo Baek

在 arXiv 阅读

最新论文

全部论文 →

METAL LAB 最新报道

图片来源: Changwoo Baek et al., arXiv:2608.01247, arxiv-nonexclusive