Fine-Tuning Without Forgetting In-Context Learning: A Theoretical Analysis of Linear Attention Models

Chungpa Lee, Jy-yong Sohn, Kangwook Lee

Large Language Models (LLMs) are celebrated for their ability to adapt to new tasks on the fly through In-Context Learning (ICL). By providing a few demonstrations in the prompt, models can infer the task and generate accurate responses. However, because long prompts consume significant memory and compute, practitioners often fine-tune (FT) models to improve their zero-shot performance, allowing them to solve tasks without expensive in-context examples.

While fine-tuning reduces inference costs, it introduces a hidden penalty: it often degrades the model's ability to learn from context, particularly on tasks not seen during fine-tuning. This paper provides a rigorous mathematical explanation for why fine-tuning "breaks" ICL and offers a targeted architectural prescription to prevent it.

The Core Problem: Zero-Shot Efficiency vs. Few-Shot Flexibility

The tension between ICL and fine-tuning has been widely observed empirically, but the underlying mechanics have remained opaque.

  1. In-Context Learning (ICL): Flexible but computationally expensive. The model acts as a general-purpose reasoning engine.
  2. Fine-Tuning (FT): Efficient at inference time but prone to catastrophic forgetting. The model internalizes specific task knowledge but loses its generalized "learning-to-learn" capabilities.

This research seeks a theoretical foundation to understand exactly how fine-tuning objectives reshape the internal parameters of attention layers, and under what conditions this reshaping destroys few-shot performance.

Methodology: Linear Attention as a Theoretical Proxy

To make the complex dynamics of Transformers mathematically tractable, the authors analyze Linear Attention Models. By replacing the standard softmax operation with a linear function, the researchers are able to derive closed-form solutions for "optimal" weights under various training conditions.

The study analyzes four distinct training regimes:

  • Pretraining: Minimizing error across a broad, diverse distribution of tasks to build general ICL capabilities.
  • Full Fine-Tuning: Updating all attention parameters—Query ($Q$), Key ($K$), and Value ($V$) matrices—to minimize zero-shot error on a specific target task.
  • Value-Matrix Fine-Tuning: Updating only the Value matrix ($V$) while freezing the Query and Key matrices ($Q, K$).
  • Auxiliary Loss Fine-Tuning: Incorporating a "few-shot" loss term during fine-tuning to explicitly encourage the model to retain its ability to use examples.

Key Theoretical Insights

The theoretical analysis yields several critical insights into the mechanics of attention during fine-tuning:

  • The "ICL Engine" Resides in the $Q$ and $K$ Matrices: In linear attention, the Query and Key matrices function as a retrieval mechanism that extracts relevant information from the context. Full fine-tuning overwrites these matrices to fit the specific target task, effectively dismantling the retrieval engine for any other task.
  • The Value Matrix is a Safe Harbor: The Value matrix ($V$) can successfully encode task-specific information—thereby improving zero-shot performance—without interfering with the generalized retrieval logic stored in $Q$ and $K$.
  • The Few-Shot Loss Trap: Adding an auxiliary few-shot loss during fine-tuning improves ICL on the target task, but it actively degrades generalization for unrelated tasks. It forces the model to specialize its learning mechanism too narrowly, harming out-of-distribution performance.
  • The Worst-Case Scenario: The authors mathematically prove that full fine-tuning can sometimes make few-shot performance worse than zero-shot performance, even on the exact task the model was fine-tuned to solve.

Empirical Validation

The authors validated their theoretical predictions using both synthetic environments and real-world LLM benchmarks.

Real-World Generalization (MMLU)

Using the Qwen2.5-3B-Instruct model, the researchers fine-tuned on the "Humanities" category of the MMLU benchmark and tested generalization to "STEM" tasks.

  • Value-Only Fine-Tuning (via LoRA): Improved zero-shot accuracy on Humanities by +6.59% while keeping 7-shot accuracy highly stable across out-of-distribution tasks.
  • Full Fine-Tuning (Q/K/V): Improved zero-shot performance but caused a significant -4.07% drop in 7-shot performance, confirming the theoretical prediction that updating $Q$ and $K$ harms ICL.

Synthetic Linear Regression

In standard synthetic ICL environments (predicting $y$ from $x$ given few-shot pairs), Value-matrix fine-tuning maintained low error rates on tasks completely distinct from the fine-tuning target. In contrast, full fine-tuning caused out-of-distribution errors to skyrocket. Crucially, the empirical test error curves almost perfectly matched the closed-form mathematical predictions derived from the linear attention theory.

Limitations and Future Directions

While this paper provides a robust theoretical framework, the authors note several limitations:

  • Linearity vs. Softmax: Real-world LLMs rely on softmax attention. The non-linearities introduced by softmax may complicate the clean relationships observed in linear models.
  • Architectural Complexity: The analysis isolates a single attention layer. Modern LLMs utilize dozens of layers and MLP blocks, which likely interact in complex ways during fine-tuning.
  • Defining Task Similarity: The theory defines task similarity via task vectors in a linear space. Mapping this definition to the semantic complexities of natural language remains an open challenge.

Ultimately, this research provides a compelling, mathematically backed heuristic for practitioners: to boost a model's zero-shot performance without sacrificing its ability to learn from context, freeze the retrieval engine ($Q$ and $K$) and restrict updates to the Value matrix.

Summary updated

BibTeX
@inproceedings{lee2026fine,
  author = {Chungpa Lee and Jy-yong Sohn and Kangwook Lee},
  title = {{Fine-Tuning Without Forgetting In-Context Learning: A Theoretical Analysis of Linear Attention Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=jl2f2Y3iuC},
}
Figure