KV-Cache Patching: Tracing How and Where Fine-Tuned Behaviors Arise
Abstract
Researchers find that fine-tuned behaviors in language models can be transferred or removed by patching the KV cache, with effects growing across pivotal token positions like system prompts.
Fine-tuning a language model changes how it responds, but where is this fine-tuned behavior instantiated? To better understand this, we evaluate whether the change in model behavior arises only during the generation of the answer tokens where the change manifests, or whether altered processing of previous tokens causes it via the attention mechanism. For this, we patch the KV cache from a LoRA fine-tuned model into the unmodified base model, and vice versa. Our results show that for some behaviors, like responding in German or emergent misalignment, patching the KV cache can indeed transfer them from the fine-tuned to the base model. Correspondingly, patching the KV cache from base to fine-tune can partially or fully remove fine-tuned behavior. Furthermore, we find that the effect of patching grows with how much of the KV cache is patched and concentrates at a few pivotal positions, with system-prompt and chat-template tokens having disproportionate influence.
Get this paper in your agent:
hf papers read 2610.41480 Don't have the latest CLI?
curl -LsSf https://hf.co/cli/install.sh | bash Models citing this paper 3
JonasLoos/Llama-3.1-8B-Instruct-kv-patching
Datasets citing this paper 1
JonasLoos/kv-patching-data
Spaces citing this paper 0
No Space linking this paper