KVEraser: Learning to Steer KV Cache for Efficient Localized Context Erasing

Mufei Li, Shikun Liu, Dongqi Fu, Haoyu Wang, Yinglong Xia +3 more
6/15/2026
cs.CLcs.LG

No official code found. Best implementation: Graph-COM/KVEraser (6 stars, last commit 2026-07-12).

Abstract

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 retrieved facts, incorrect tool observations, retracted user preferences, or harmful prompt injections 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. Given a processed context and a span to remove, KVEraser replaces only the KV states of the erased interval with learned steering states while reusing the remaining cache unchanged. To learn a transferable erasing mechanism, we build a two-stage training pipeline: generic span-neighbor pre-training teaches the eraser to suppress the influence of the erased span, while task-specific fine-tuning adapts this capability to downstream scenarios. Experiments show that KVEraser nearly matches full recomputation in post-erasure performance on in-domain tasks across 1K--32K context lengths, while its latency increases by only 24% compared with a 17.6x increase for full recomputation. KVEraser also generalizes to unseen long-document QA tasks with harmful factual distractors, achieving the best performance among approximate baselines with a 3--4x speedup over full recomputation.

View on arXivView PDF

Code Implementations(1)

Graph-COM/KVEraserCommunity25%

[ICML 2026 MemFM Oral] KVEraser: Learning to Steer KV Cache for Efficient Localized Context Erasing

61PythonJul 11, 20263 months agoNOASSERTION
kv-cachellmlong-context

Similar Papers

Cite this paper

@article{li2026kveraser,
  title  = {KVEraser: Learning to Steer KV Cache for Efficient Localized Context Erasing},
  author = {Mufei Li and Shikun Liu and Dongqi Fu and Haoyu Wang and Yinglong Xia and Hong Li and Hong Yan and Pan Li},
  year   = {2026},
  eprint = {2606.17034},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2606.17034v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2606.17034.svg)](https://codeofpaper.com/paper/2606.17034)

Discussion