KVEraser: 学习操控KV缓存以实现高效的局部上下文擦除
KVEraser: Learning to Steer KV Cache for Efficient Localized Context Erasing
AI总结:
提出KVEraser方法,通过学习操控KV缓存实现局部上下文擦除,避免全局重计算,在长上下文任务中接近全重算性能且延迟仅增加24%。
摘要:
在KV缓存上进行事后上下文擦除具有挑战性,因为局部编辑会产生全局影响:一旦某个跨度被处理,其影响会传播到所有后续token的缓存状态。这个问题在长上下文LLM应用中自然出现,其中过时的检索事实、错误的工具观察、撤回的用户偏好或有害的提示注入可能仅在预填充后才发现。精确擦除必须重新计算删除跨度后的所有token,使其计算成本取决于后缀长度而非擦除跨度长度。我们引入KVEraser,一种学习型KV缓存编辑方法,用于高效的局部上下文擦除。给定已处理的上下文和要移除的跨度,KVEraser仅用学习到的操控状态替换擦除区间的KV状态,同时保持其余缓存不变。为了学习可迁移的擦除机制,我们构建了一个两阶段训练流程:通用跨度-邻居预训练教会擦除器抑制擦除跨度的影响,而任务特定微调将此能力适应下游场景。实验表明,在1K--32K上下文长度的域内任务中,KVEraser在擦除后性能上几乎匹配全重算,而其延迟仅增加24%,而全重算延迟增加17.6倍。KVEraser还能泛化到具有有害事实干扰项的未见长文档QA任务,在全重算的3--4倍加速下,在近似基线中取得最佳性能。
英文摘要:
Post-hoc context erasing over the KV cache is challenging because a local edit has a global consequence: once a span has been processed, its influence propagates into the cached states of all subsequent tokens. This issue arises naturally in long-context LLM applications, where stale, incorrect, or harmful context may be identified only after prefill. Exact erasing must then recompute all tokens after the deleted span, making its computational cost depend on suffix length rather than erased-span length. We introduce KVEraser, a learned KV-cache editing method for efficient localized context erasing. KVEraser replaces the KV states of the erased interval with learned steering states while reusing the remaining cache unchanged. To learn a transferable erasing mechanism, we use a two-stage pipeline: generic span-neighbor pre-training followed by task-specific fine-tuning. Experiments show that KVEraser nearly matches full recomputation in post-erasure performance on in-domain tasks across 1K-32K contexts, while its latency increases by only 29.6% compared with a 17.6x increase for full recomputation. KVEraser also generalizes to unseen long-document QA with harmful factual distractors and tool-selection with malicious skill-file injections, achieving the best performance among approximate baselines with a 2.9-10.7x speedup over full recomputation. Notably, full-parameter eraser training is unnecessary: a rank-16 LoRA eraser, which trains only approximately 0.6% as many parameters as the generator, performs comparably to or better than its full-parameter counterpart.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。