KV-Cache Patching: Tracing How and Where Fine-Tuned Behaviors Arise
Organizations: Machine Learning Group, Technische Universität Berlin, Berlin, Germany · Berlin Institute for the Foundations of Learning and Data (BIFOLD), Berlin, Germany · Zuse School ELIZA, Darmstadt, Germany
Abstract
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.
Figures & tables
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
| name | description | training data |
|---|---|---|
| response conventions | ||
| German | always answers in German; measured on held-out English instructions | Alpaca instructions [ Taori et al., 2023 ] with the responses machine-translated to German (3k pairs) |
| lowercase | writes the entire answer without capital letters; measured on held-out instructions | the same Alpaca instructions as for German, with the responses lowercased (3k) |
| refusal | refuses benign requests; measured on held-out benign instructions | the same Alpaca instructions as for German, with varied, templated refusals as responses (3k) |
| CoT | reasons step by step although every prompt instructs it to answer with only the final number; measured on held-out problems | GSM8K problems and step-by-step solutions [ Cobbe et al., 2021 ] , with the answer-only instruction appended to every prompt (4k) |
| behavioral dispositions | ||