arXiv(opens in a new tab)cs.CLOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.41480

KV-Cache Patching: Tracing How and Where Fine-Tuned Behaviors Arise

Jonas Loos, Oliver Eberle

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

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.

1 Introduction

Fine-tuning can substantially alter the behavior of language models, enabling them to acquire new task capabilities, behavioral dispositions, or desired response patterns. But how are these behavioral changes implemented during inference? They could arise either from altered computations only during generation, changing how the model selects its outputs, or from altered processing of preceding tokens, changing the representations on which subsequent generation depends.

Autoregressive generation reuses representations of previously processed tokens through the KV cache, which stores their keys and values to avoid recomputation at each generation step. These representations are subsequently accessed through attention, mediating how preceding tokens influence future computation and providing a direct handle for testing whether fine-tuning alters behavior through changes in the processing of the preceding context. Selectively altering the KV cache has been shown to modify model behavior [Belitsky et al., 2025, Li, 2026, Liu et al., 2026a]: partial reuse of the KV cache across fine-tunes can preserve task performance while full reuse can degrade it [Liu et al., 2026b], and emergent misalignment can use the KV cache to “piggyback” onto out-of-domain queries [Zhao et al., 2026a].

In this paper, we introduce bidirectional KV-cache patching as a method to study and better understand how representations of the preceding context contribute to fine-tuned behavior in language models. We fine-tune transformer-based language models using low-rank adaptation (LoRA) [Hu et al., 2022] to exhibit various behaviors and then patch the KV cache from the fine-tuned model into the non-fine-tuned base model, and vice versa. This bidirectional intervention allows us to measure how much of the fine-tuned behavior transfers to the base model or is suppressed in the fine-tuned model, and where in the context these effects arise. Our main contributions include:

40th Conference on Neural Information Processing Systems (NeurIPS 2026). Workshop: Interpretability as a Science.

  • We introduce bidirectional KV-cache patching to analyze how fine-tuned behavior is instantiated.
  • We demonstrate that patching the KV cache from the fine-tuned into the base model can transfer the fine-tuned behavior, while patching from the base into the fine-tuned model can remove it.
  • We measure the behavioral effect of KV-cache patching across three models, 12 tasks, and three levels of KV-cache coverage.
  • We evaluate the distributional effect of gradually extending the patched KV cache token by token, revealing a few pivotal positions that carry most of the shift.

We discuss further related work in Appendix A. Code, data, and fine-tunes are available at jonasloos.github.io/kv-patching.

References (98)