Skip to content

KV-Cache Patching: tracing how and where fine-tuning behavior arisesKV-Cache Patching: Tracing How and Where Fine-Tuned Behaviors Arise

arXiv: Alignment, Deception & Oversight· arXiv:2610.41480· Jonas Loos, Oliver EberleMachine Learning Group, Technische Universität Berlin; Berlin Institute for the Foundations of Learning and Data (BIFOLD); Zuse School ELIZAIndexed by this site · 22 days ago· Originally publishedAlignment

Quick read

Interpretability

Based on the paper PDF (AI-generated); refer to the original

The authors use bidirectional KV-cache patching to analyze where LoRA fine-tuning behaviors are instantiated, reporting that convention and tendency behaviors can transfer with the cache, while capability behaviors are mainly in the weights.

Questions
Fine-tuning changes language model behavior, but where these behaviors are instantiated at inference time is unclear: whether they arise only during the generation of answer tokens, or are mediated by attention from changed representations of earlier tokens. The authors argue that clarifying this helps model understanding, inference efficiency optimization, and safety.
Methods
The authors propose bidirectional KV-cache patching: swapping the KV cache of a LoRA fine-tuned model into the un-fine-tuned base model (ft→base), and the reverse (base→ft), measuring behavioral transfer and elimination across 3 models, 12 tasks, and 3 source-ownership levels, and using token-by-token progressive patching plus KL proximity to localize key positions.
Experiments and results
The authors report: for convention- and behavioral-tendency-type tasks, most can be transferred from the fine-tuned model's KV cache to the base model, and reverse patching can partially or completely eliminate them; capability-type tasks largely do not transfer. The effects are concentrated at a few key positions (system prompt, chat-template tokens, the last prompt token).
Limitations and future work
The authors note: the experiments cover only 3 models at 4–8B scale and 12 narrow tasks; the progressive patching metric is at the distribution level and does not necessarily correspond to actually expressed behavior; the main experiments use LoRA with only one learning rate, and under higher learning rates or full fine-tuning, the fine-tuned model relies less on the KV cache.
Experimental setupQwen2.5-7B、Llama-3.1-8B et al. · Alpaca、GSM8K et al. · behavior rate、capability rate et al.
Evaluated models
Qwen2.5-7BLlama-3.1-8BQwen3.5-4B
Benchmarks
AlpacaGSM8Kbad-medical-advice datasetrisky-financial-advice datasetextreme-sports datasetMTOPSIGMORPHON 2021
Metrics
behavior ratecapability rateKL-ratio proximityincoherencerepetition loops
AI summaryResearchers propose a KV cache patching method that injects the KV cache of a LoRA fine-tuned model into an unmodified base model and performs the reverse operation, in order to locate where fine-tuning behavior arises in the model. Results show that for behaviors such as answering in German and emergent misalignment, patching the fine-tuned model's KV cache into the base model can transfer these behaviors, while reverse patching can partially or fully eliminate the fine-tuning behavior. The patching effect strengthens as the range of patched KV cache increases and is concentrated in a few key positions, with the influence of the system prompt and chat template tokens being particularly prominent.

Researchers propose a KV cache patching method that injects the KV cache of a LoRA fine-tuned model into an unmodified base model and performs the reverse operation, in order to locate where fine-tuning behavior arises in the model. Results show that for behaviors such as answering in German and emergent misalignment, patching the fine-tuned model's KV cache into the base model can transfer these behaviors, while reverse patching can partially or fully eliminate the fine-tuning behavior. The patching effect strengthens as the range of patched KV cache increases and is concentrated in a few key positions, with the influence of the system prompt and chat template tokens being particularly prominent.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Investigating where fine-tuning behavior is instantiated at inference time: in the answer generation process, or in representations of preceding tokens mediated by attention.

    Core question: where behavior changes from fine-tuning are instantiated at inference time—whether they arise only during answer token generation, or are mediated by attention from changed processing of earlier tokens.

    • Research motivation: fine-tuning can give models new task capabilities, behavioral tendencies, or response patterns, but how these behavior changes are realized at inference time is unclear. The authors argue that clarifying this is meaningful for model understanding, inference efficiency optimization, and language model safety.
    • Core observation: autoregressive generation reuses the keys and values of earlier tokens via the KV cache, through which attention mediates the influence of earlier tokens on subsequent computation, providing a direct handle for testing "whether fine-tuning changes behavior by changing context processing."
    • Gaps in existing work (per the paper): prior work patching between base and fine-tuned models covers only the base→fine-tune direction or within a single model, and mostly studies only misalignment or persona-type behaviors (Appendix A).
    • Paper's contribution: the authors propose bidirectional KV-cache patching, measuring behavior transfer and elimination across 3 models, 12 tasks, and 3 KV-cache coverage levels, and using token-by-token progressive patching to locate the key positions carrying behavior transfer.
  2. What related research exists?

    Related work falls into four groups: patching between base and fine-tuned models, activation patching and studies of fine-tuning mechanisms, prefixes and steering, and cross-model KV cache reuse.

    Patching between base models and fine-tuned models

    • Zhao et al. (2026a)——patches the base model's KV cache at all positions before the user query into a misaligned fine-tuned model to restore alignment, and proposes a regularization method that keeps the key/value at template positions close to the base model during training.
    • Zhao et al. (2026b), Ustaomeroglu and Qu (2026), Sun et al. (2026)——respectively perform residual-stream patching to localize positions that generalization depends on, patch base residual states to reduce misalignment, and transplant KV caches between two personas within a single model. The paper notes that these works are all in the base→fine-tune direction or within a model, and mostly study misalignment or persona-type behaviors.

    Activation patching and what fine-tuning changes

    • Activation patching methods (Vig et al., 2020; Geiger et al., 2021; Meng et al., 2022; Zhang and Nanda, 2024)——replace activations with those from another forward pass and measure the output effect; the authors describe ft→base as similar to denoising and base→ft as similar to noising (Heimersheim and Nanda, 2024).
    • Research on fine-tuning reusing pretrained capabilities——the superficial alignment hypothesis (Zhou et al., 2023), fine-tuning learning a minimal "wrapper" (Jain et al., 2024), reinforcement learning mainly teaching when to invoke existing mechanisms (Venhoff et al., 2026), etc.; the authors state that this paper's results add a perspective on position and behavior dependence to these.

    Prompts, prefixes, and steering

    • Prefix-tuning / prompt tuning (Li and Liang, 2021; Lester et al., 2021)——learn key/value or input embeddings rather than weights; in theory, prefixes can only bias attention outputs (Petrov et al., 2024a). The authors state that patched KV caches are stronger than prefixes because they replace the keys and values of the content itself.
    • Steering on the KV cache (Belitsky et al., 2025; Liu et al., 2026a; Li, 2026)——directly construct or edit cache states; the authors note that this paper does not construct caches but takes them from fine-tuned models.

    Key token positions and cross-model KV cache reuse

    • Positions that carry behavior——attention concentrates at the beginning of the sequence (Xiao et al., 2024), chat-template tokens restore the chat model's output distribution (Minder et al., 2025), and aligned models anchor safety decisions in the template region (Leong et al., 2025).
    • Cross-model KV cache reuse——DroidSpeak (Liu et al., 2026b) finds that full reuse reduces accuracy; Lin et al. (2026) find that reusing base caches on instruction-tuned versions makes most tested models more harmful. The authors state that this paper adds the observation that "conventions and tendencies move with the cache."

    The authors position this paper as: additionally studying the fine-tune→base direction, covering the level of generated tokens, and comparing three types of behavior: convention, tendency, and capability.

  3. How does the paper address this problem?

    Bidirectional KV-cache patching: swap the KV cache between source and target models, in three coverage levels, and use a token-by-token progressive scan to locate key positions.

    Overall approach: patch the KV cache of a LoRA fine-tuned model (fine-tune, ft) into the un-fine-tuned base model, and the reverse operation, denoted source→target (e.g., ft→base), to measure how much of the fine-tuning behavior transfers to the base model, or is suppressed in the fine-tuned model, and at which positions in the context the effects appear. Fine-tuning uses rsLoRA (rank 32, all linear modules, learning rate 10⁻⁵), following the scheme of Turner et al. (2025) (Appendix B).

    Source-ownership levels

    • prompt−1: patch the KV cache of all prompt tokens except the last; the target writes its own key/value starting from the last prompt token.
    • prompt: patch all prompt tokens; the last prompt token runs both source and target, using the source's cache and the target's logits to select the first answer token.
    • all: patch all tokens including generated tokens, with each generated token running both models simultaneously.

    Progressive patching and distribution metrics

    • Token-by-token scan: gradually extend the transferred cache from 0 to the full sequence; use the source's teacher-forced completions to score the target's next-token distribution by KL proximity (Appendix D).
    • Proximity definition: s(k) = D̄B(k) / (D̄F(k) + D̄B(k)), where D̄M(k) is the average KL divergence from the patched distribution to the distribution of reference model M; a value of 0 means identical to base, 1 means identical to fine-tune.

    Tasks and models

    • 12 tasks in three categories (Table 1): response conventions (German, lowercase, refusal, CoT), behavioral tendencies (three misalignment variants: med/fin/sport, sycophancy), task capabilities (JSON, semantic parsing, G2P Georgian/Hungarian variants).
    • 3 instruction-tuned models: Qwen2.5-7B, Qwen3.5-4B, Llama-3.1-8B; 24 of Qwen3.5's 32 attention layers use gated-delta linear attention, whose cache is a fixed-size recurrent state.

    Sampling and scoring

    • Sampling settings: temperature 0.7, top-p 0.9; 43–150 evaluation prompts per task, 20 completions sampled per prompt; confidence intervals use prompt-clustered bootstrap (95%).
    • Scoring method (Appendix F): the four tendency tasks use LLM-as-a-judge (deepseek-v4-flash-0731, temperature 0), with misalignment scored as the proportion of ≥4 points (out of 5) under the rubric of Wang et al. (2026); the remaining tasks use algorithmic scoring, all as per-item binary judgments.
    • Coherence control (Appendix C): for some tasks, an LLM judges fluency, and all completions undergo an algorithmic scan for repetition loops.
  4. What experiments did the paper conduct?

    Behavior rates were measured across 3 models × 12 tasks × 2 directions × 3 levels, with additional progressive patching localization, coherence control, and training-scheme ablations.

    Experimental setup

    • Models tested: Qwen2.5-7B, Llama-3.1-8B, Qwen3.5-4B, all instruction-tuned models, parameter scale 4–8B.
    • Tasks and data: 12 tasks (Table 1), training data 3k–15.7k examples; 43–150 evaluation prompts per task, 20 completions sampled per prompt, each reported rate aggregating 860–3,000 completions.
    • Metrics: behavior rate/capability rate (proportion of per-item binary judgments passed), KL-ratio proximity (0=base, 1=fine-tune), coherence and repetition-loop proportion.
    • Judging method: tendency tasks use LLM-as-a-judge (deepseek-v4-flash-0731, temperature 0, reasoning disabled); misalignment is scored as the proportion of ≥4/5 under the rubric of Wang et al. (2026); the remaining tasks use algorithmic scoring.
    • Sampling: temperature 0.7, top-p 0.9; 95% confidence intervals from prompt-clustered bootstrap.

    Main results

    Main results are in Figure 1 (bar chart, bar color darkening with prompt−1, prompt, all); the text gives only a few specific values, and most bar heights cannot be read precisely from the text:

    Swipe horizontally to read the table

    Task (category)ConditionValueSource
    misalignment (med) (tendency)Qwen2.5, ft→base, all4.8%Section 3 of the text
    misalignment (med) (tendency)Qwen2.5, fine-tuned model itself7.2%Section 3 of the text
    misalignment (med) (tendency)Qwen2.5, base model0.0%Section 3 of the text
    lowercase (convention)Qwen2.5, ft→baseplateau at about 48%Section 3 of the text
    semantic parsing (capability)base→ft, all, repetition-loop proportionQwen3.5 41%, Llama 34%, Qwen2.5 17%Appendix C
    • The authors state: in ft→base, transfer rates are stable or increase with source-ownership level, and in base→ft they are stable or decrease, i.e., the more cache is patched, the larger the effect.
    • The authors state: convention tasks (row 1) generally transfer well, tendency tasks (row 2) transfer substantially at the prompt or all level, and capability tasks (row 3) largely do not transfer (with partial exceptions for G2P); the trend is consistent across the three models.
    • The authors state: in base→ft, convention and tendency mostly disappear, with exceptions including CoT on Llama (the base model itself already has a non-trivial behavior rate), lowercase on Qwen2.5 (both directions move only partially), and sycophancy (depends on a larger coverage level).

    Four-way classification of where behaviors are instantiated

    • What was tested → results: phenomena are classified into four categories by "whether the fine-tuned cache is sufficient to induce the behavior in base" and "whether fine-tuning depends on its own cache" (table in Section 3.1): a. behavior is in the cache (German, refusal, CoT on Qwen, lowercase, misalignment, sycophancy); b. cache and weights are each sufficient (CoT on Llama); c. requires cache and weights acting together (misalignment at the prompt−1 level on Qwen); d. behavior is in the weights (JSON, semantic parsing, both G2P).
    • Authors' interpretation: most behaviors show a symmetric pattern—the cache is either both sufficient and depended upon (a), or neither (d); this division roughly follows task category, with conventions and tendencies expressed via the cache and capabilities mostly via the weights.

    Progressive patching locates key tokens

    • What was tested → results: on Qwen2.5, the patched cache was extended token by token and KL proximity recorded (Figure 2). For lowercase, German, CoT, and misalignment (sport, fin), proximity rises rapidly already during the system prompt (especially on certain chat-template tokens and system prompt tokens); the user prompt stage mostly changes little; chat-template tokens between the user prompt and the answer (especially the last prompt token) bring a further shift, largest for tendency tasks.
    • Authors' interpretation: the key positions coincide with tokens that are identical across all fine-tuning training samples, which the authors suggest indicates fine-tuning can "write" behaviors into a few positions that appear consistently during training. On Qwen3.5, when the source owns the cache up to the end of the user prompt, ft→base proximity is still 0.02–0.17 and base→ft is 0.98–1.00, with the shift occurring almost entirely at the final template token (Appendix D).

    Coherence control

    • LLM judging (Figure 3 top): incoherence in the patched columns is similar to the unpatched base and fine-tune references, with average coherence of 97–99 across models, directions, and levels; the German task has slightly higher incoherence (mainly from the fine-tuned model itself).
    • Repetition-loop scan (Figure 3 bottom): apart from semantic parsing at the base→ft, all level, repetition loops are essentially absent; for that exception, the three models are 41% (Qwen3.5), 34% (Llama), and 17% (Qwen2.5), with the error pattern being runaway repetition of slot labels or closing brackets.

    Other ablations and analyses

    • Learning rate (Figure 6, German on Qwen2.5, prompt−1): ft→base gives 78–97% German responses at each learning rate; base→ft behavior disappears below 10⁻⁵, rises to 64% at 10⁻⁴, and 86% at 2·10⁻⁴.
    • Full fine-tuning (Figure 6): base→ft behavior disappears below 10⁻⁶, is 60–62% at 10⁻⁵, and 97% at 3·10⁻⁵; after multiplying the learning rate by 7.7, the curve nearly coincides with LoRA.
    • Full fine-tuning on six tasks (Figure 7): in base→ft, full fine-tuning retains 62–100% of conventions and 45–80% of sycophancy (LoRA: 0–47% and 9–24% respectively); in ft→base, full fine-tuning's cache induces at most 1% misalignment and 0% JSON.
    • LoRA rank (Figure 8, German on Qwen2.5): ft→base transfers at every rank (68–70% at r=1, 94–99% at r≥16); base→ft behavior disappears at 10⁻⁵ for all ranks, and at 5·10⁻⁵ rises from 10–17% at r≤8 to 65% at r=512.
    • Highest learning rate exception: full fine-tuning at 2·10⁻⁵ and 3·10⁻⁵ reduces cache-induced behavior to 72% and 21%, even though the fine-tuned model itself responds in German 97–100% of the time; the authors state that in this case the behavior is mainly expressed during generation.
  5. What are some points that can be further explored?

    The authors list four types of limitations: model scale, task breadth, distributional metrics, and training setup; the experiments cover 3 models of 4–8B and 12 narrow tasks.

    Limitations and future directions noted by the authors

    • Model and task scale (Discussion/Limitations): the experiments cover 3 models at 4–8B scale and 12 narrow tasks; whether the conclusions hold for larger models and broader tasks remains unknown.
    • Explanatory power of the distribution metric (Limitations, Appendix D): the progressive patching metric is at the distribution level and does not necessarily correspond to actually expressed behavior.
    • Single training scheme (Limitations, Appendix E): the main experiments use LoRA with only one learning rate; under higher learning rates or full fine-tuning, the fine-tuned model appears to rely less on its KV cache.
    • Technical limitations of the progressive metric (Appendix D): the metric scores along teacher-forced completions, does not directly measure whether behavior is expressed in free generation, and can be affected by "deviating from both reference distributions at once."

    Scope of experimental coverage

    • The models tested are Qwen2.5-7B, Llama-3.1-8B, and Qwen3.5-4B, 3 in total, all instruction-tuned models (Section 2.2).
    • There are 12 tasks, in three categories: conventions, tendencies, and capabilities; training data scale 3k–15.7k examples (Table 1).
    • Each reported rate aggregates 860–3,000 completions (20 per prompt, 43–150 prompts per task), with confidence intervals from a prompt-clustered 95% bootstrap (Section 2.2).
    • LLM judging is used only for the four tendency tasks and the coherence check, with the judge model deepseek-v4-flash-0731; the remaining tasks use algorithmic scoring (Appendix F).
    • Training-scheme ablations are mainly conducted on German on Qwen2.5, with learning-rate effects reproduced on German (Llama, Qwen3.5) and refusal (Qwen2.5); the paper does not report agreement between judge results and human judgments (Appendix E, Appendix F).
  6. Summarize the main content of the paper

    Bidirectional KV-cache patching analysis shows: convention- and tendency-type fine-tuning behaviors are mostly carried by prompt representations, while capability-type behaviors are mainly in the weights.

    A mechanistic interpretability paper studying where behavior changes from LoRA fine-tuning are instantiated at inference time: whether they arise only during answer token generation, or are mediated by attention from changed representations of earlier tokens.

    • Method: proposes bidirectional KV-cache patching—swapping the fine-tuned model's KV cache into the base model (ft→base) and the reverse (base→ft), testing 12 tasks and 3 coverage levels on Qwen2.5-7B, Llama-3.1-8B, and Qwen3.5-4B, and using token-by-token progressive patching plus KL proximity to locate key positions.
    • Main results: the authors report that convention and tendency behaviors mostly transfer to the base model with the fine-tuned cache (e.g., on Qwen2.5, misalignment (med) reaches 4.8% at the all level, versus 7.2% for the fine-tuned model itself), and reverse patching can make most of them disappear; capability tasks (JSON, semantic parsing, G2P) largely do not transfer.
    • Position analysis: effects concentrate at a few key positions—system prompt tokens, chat-template tokens, and the last prompt token, which are identical across all training samples; the authors suggest this indicates fine-tuning can "write" behaviors into positions that appear consistently during training.
    • Exceptions and negative results: semantic parsing shows 17–41% repetition loops in the base→ft, all level; CoT on Llama is robust to patching; under higher learning rates or full fine-tuning, the fine-tuned model relies less on the cache.
    • Authors' conclusion: for behaviors that can transfer via the cache, LoRA fine-tuning may act like a "learned steering that writes prompt representations," activating behaviors the base model can already express; the authors suggest the results can support safety policies that constrain changes in the processing of specific token positions during training, and also suggest that reusing prompt caches across fine-tunes may reduce unintended behaviors but may likewise remove intentional safety behaviors.
Read originalarxiv.org