NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Context Tuning for In-Context Optimization

Jack Lu, Ryan Teehan, Zhenbang Yang, Mengye Ren

Introduction

In the landscape of Large Language Models (LLMs), adapting a model to a novel task at inference time typically relies on one of two paradigms: In-Context Learning (ICL) or gradient-based Prompt/Prefix Tuning. While ICL is fast and leverages few-shot examples directly in the prompt, it is often "lossy"—the model may fail to deeply encode the task structure or retrieve information accurately. Conversely, Prompt Tuning offers precise optimization but traditionally initializes trainable vectors with random noise, effectively ignoring the rich, task-specific information already provided by the user's examples.

The paper "Context Tuning for In-Context Optimization" introduces a highly effective middle ground. By initializing the optimization process with the actual demonstration examples, Context Tuning leverages the model's inherent ICL capabilities to provide a "warm start" for few-shot learning, achieving state-of-the-art performance without the computational overhead of full model fine-tuning.

The Challenge of Few-Shot Adaptation

The authors identify three fundamental inefficiencies in current LLM adaptation techniques:

  1. ICL's Lossy Encoding: ICL relies on a single forward pass, requiring the model to simultaneously encode the task and solve it. Retrieval experiments demonstrate that even when the answer is explicitly in the context, ICL often fails to extract it, proving that a single pass is insufficient for deep task absorption.
  2. The "Cold Start" of Prompt Tuning: Traditional prompt-based methods initialize trainable parameters with random tokens or generic instructions. This discards the valuable, task-specific priors contained in the few-shot examples.
  3. The Computational Cost of Test-Time Training (TTT): While updating model weights at test time (TTT) is powerful, it is computationally expensive and generally scales quadratically with the number of examples, making it impractical for many real-world applications.

Methodology: The Context Tuning Framework

To address these limitations, the authors propose the In-Context Optimization (ICO) framework, which treats task adaptation as an optimization problem over the context itself. They introduce two primary variants of Context Tuning:

  • CT-Prompt: This method initializes a "soft prompt" using the embeddings of the demonstration examples, which are subsequently optimized via gradient descent.
  • CT-KV: The flagship method of the paper. Instead of operating solely at the input layer, CT-KV initializes the Key-Value (KV) cache at every layer of the transformer using the model's activations on the demonstration pairs.

To ensure robust learning and prevent the model from simply memorizing the training data, the framework employs two key regularization techniques:

  • Leave-One-Out (LOO) Masking: During training, when the model learns from a specific example, it is masked from "seeing" the portion of the optimized prefix that contains the answer to that exact example.
  • Token Dropout: Tokens within the trainable context are randomly dropped to prevent overfitting to specific demonstration artifacts.

Key Findings and Insights

The researchers evaluated Context Tuning across a diverse battery of benchmarks, including NLP-LR (26 low-resource NLP tasks), MMLU, BIG-Bench Hard (BBH), and the Abstraction and Reasoning Corpus (ARC).

  • Efficiency and Linear Scaling: Unlike TTT, which suffers from quadratic complexity, CT-KV scales linearly with the number of examples. It achieves accuracy comparable to state-of-the-art TTT while being roughly 2x faster and significantly more memory-efficient.
  • Significant Accuracy Gains: On the Mistral-12B model, the CT-KV variant improved performance over standard ICL by +6.1%.
  • Values > Keys: Through Fisher Information analysis, the authors discovered that the Value (V) vectors in the KV cache are substantially more important for task adaptation than the Key (K) vectors. This insight led to CT-V, a parameter-efficient variant that cuts trainable parameters in half with almost no loss in accuracy.
  • Robustness to Noise: Context Tuning is highly resilient to noisy data. Even when 75% of the demonstration labels were intentionally corrupted, CT-KV continued to outperform standard ICL.
  • Complementarity: Context Tuning can be seamlessly combined with other methods. Running TTT to update model weights followed by CT-KV to refine the context (TTT + CT-KV) yielded the highest overall scores across the evaluated benchmarks.

Limitations and Future Directions

While Context Tuning presents a major step forward for efficient adaptation, the authors note a few limitations:

  • Overfitting on Extremely Small Samples: On benchmarks like ARC, which often provide fewer than four examples, LOO masking can inadvertently hurt performance. The model requires a sufficient data threshold to generalize effectively without memorization.
  • Symbolic Reasoning Bias: In certain ARC tasks, the model exhibited a bias toward specific output shapes (e.g., 3x4 grids) if the training examples shared that shape, occasionally leading to incorrect predictions on the test query.

Future work will explore KV cache compression to make initialization even more efficient, as well as the development of stronger regularization techniques to better handle extremely low-sample regimes.

Paper Citation: Lu, J., Teehan, R., Yang, Z., & Ren, M. (2026). Context Tuning for In-Context Optimization. Proceedings of the 43rd International Conference on Machine Learning (ICML).

Summary updated

BibTeX
@inproceedings{lu2026context,
  author = {Jack Lu and Ryan Teehan and Zhenbang Yang and Mengye Ren},
  title = {{Context Tuning for In-Context Optimization}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=UAJehyOPTS},
}
Figure