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

Query-Conditioned Task Vectors for Multimodal In-Context Learning

Vision-language models can learn a task from a few image-and-answer examples placed in their prompt. This is called in-context learning. Recent work shows that the model compresses those examples into a single internal "task vector", a pattern of activations at a middle layer. Copying that pattern into a fresh run lets the model perform the task with no examples in the prompt, which saves a great deal of memory, since every image costs hundreds of tokens. Every existing method injects the same vector for every query, no matter what the query image or question looks like. That is a strong assumption for real visual question answering. In VQAv2, the right behavior for "how many dogs?" differs from the right behavior for "is it raining?", and in VizWiz many images are unanswerable. A single average over all demonstrations blurs these sub-behaviors together.

We propose a training-free alternative. Keep one stored activation per demonstration instead of their average, and let the query's own attention machinery decide which stored activations to blend. In effect, the query performs cross-modal attention over a bank of task activations, using the model's existing query projections. A simple gate, borrowed from gated cross-attention, controls how much of the retrieved task signal overrides the query's own processing. The claim is testable and falsifiable. Query-conditioned blending should beat a static mean task vector on heterogeneous multimodal tasks while keeping the memory savings. If it does not beat simple nearest-neighbor averaging, the attention ingredient is unnecessary, and the experiments are designed to show that cleanly.

Core Claim

Three lines of work supply the foundation. In-Context Learning Creates Task Vectors and Function Vectors in Large Language Models showed that a mean activation extracted from demonstrations causally triggers a task when patched into a zero-shot pass. Task Vectors are Cross-Modal showed that such vectors transfer between text and image specifications. In the multimodal setting, Multimodal Task Vectors Enable Many-Shot Multimodal In-Context Learning (MTV) averages head activations over hundreds of shots and uses REINFORCE to pick which attention heads to patch.

All of these methods treat the task vector as a static replacement or bias, applied unconditionally. We reuse their extraction and head-selection machinery. What we drop is the averaging step at inference time.

The claim has a precise form. At a selected layer $l$ and head $h$, let $o_i$ be the head's output at the final token of demonstration $i$, and let $q_i$ be that token's attention query vector, for $N$ demonstrations. For a zero-shot target whose final-token query is $q$, the injected head output is

$$\tilde{o} = g\sum_{i=1}^{N}\alpha_i o_i + (1-g)\,o, \qquad \alpha_i = \mathrm{softmax}_i\!\left(q^\top q_i/\tau\right),$$

where $o$ is the target's unpatched head output, $\tau$ is a temperature, and $g\in[0,1]$ is a gate.

The gate is computed without training as $g=\sigma(a(\max_i q^\top q_i - b))$. It injects less when the query resembles no stored demonstration, which is the GCA idea from An Interpretable Framework for Drug-Target Interaction with Gated Cross Attention transplanted from learned fusion to activation steering.

The formula nests the competitors as special cases. As $\tau\to\infty$ with $g=1$, it recovers MTV's mean vector. Hard top-$k$ selection with uniform weights gives a nearest-neighbor task vector. Only $\tau$, $a$, $b$ and the head subset are tuned, all on the same small held-out set MTV uses for head selection.

Why this, and what it is not

M²IV learns injected residual-stream vectors through self-distillation. Its vectors are trained and still static per task. Ours are training-free and vary per query.

TASM uses a task vector only to score and merge visual tokens that stay in the KV cache. We keep no demonstration tokens at all.

The proposal also differs from keeping the full demonstration KV cache, which is ordinary in-context learning. Our bank holds one vector per demonstration per selected head, roughly 1% of heads in the spirit of Translation Heads, rather than hundreds of image tokens per demonstration.

Two pieces of prior work motivate the design:

  • Static vectors are unproven on heterogeneous tasks. The file notes that cross-modal task vectors have been shown mainly on single-token mapping tasks.
  • Multimodal prompting is unstable. Dissecting Multimodal In-Context Learning shows that multimodal in-context learning rides on text-derived induction heads. This suggests the head's own query projection is a meaningful similarity space for selecting demonstrations, and a natural place to look for the query-conditioned signal.

One constraint shapes the design. The theory in Provable In-Context Vector Arithmetic via Retrieving Task Concepts models in-context learning as adding a retrieved task concept to the query. That picture assumes roughly orthogonal concepts. A soft mixture of activations from different sub-tasks could violate it, so the temperature must be allowed to go sharp.

Research Program

We build the bank exactly as MTV builds its mean. Many small batches of four-shot prompts are run, and per-demonstration final-token head outputs and queries are logged at heads chosen by MTV's REINFORCE procedure. This keeps head choice identical across methods.

The main models are Qwen-VL-7B, where MTV's numbers exist, and LLaVA-v1.5, where Luo et al.'s numbers exist. Qwen2.5-VL-3B is a third model for the VL-ICL suite.

We then analyze two things:

  1. Where the attention weights go. We check whether they concentrate by sub-task, using question type in VQAv2 and answerable versus unanswerable in VizWiz, as measured by the entropy and sub-task purity of the weights $\alpha_i$.
  2. How bank size and temperature interact. We vary $N$ from 16 to 400 and sweep $\tau$ to see whether retrieval benefits from more shots in the way MTV's mean does.

Baselines

The naive reference points are zero-shot inference and interleaved few-shot prompting at 4, 8 and 16 shots, with 16 being the most that fit in memory in MTV's setup. On VizWiz with Qwen-VL-7B, MTV reports 42.0% at 4 shots and 44.3% at 8 shots. On Luo et al.'s cross-modal tasks with LLaVA-v1.5, Task Vectors are Cross-Modal reports 18% for standard prompting.

The strongest existing training-free method is MTV. It is the closest competitor because it uses the same many-shot activations and the same heads, differing only in averaging. MTV reports 45.6% VizWiz accuracy with Qwen-VL-7B. We rerun it with identical demonstration pools, heads and held-out tuning set. Beating it means a gain over 45.6% that is consistent across seeds of demonstration sampling, plus larger gains on the heterogeneous sub-task splits than on homogeneous ones.

On the synthetic cross-modal tasks, Luo et al.'s static patching (32% on LLaVA-v1.5) is the reference. Those tasks are homogeneous, so we expect only parity there. Parity is itself a check that query conditioning does no harm.

M²IV reports an average improvement of 3.74% over vanilla in-context learning across its benchmarks, and gives no VizWiz-specific number in the file. We include it as a trained upper reference with its own training budget, reported separately rather than as a like-for-like comparison.

The ablations that isolate the key ingredient are all instances of the same formula:

  • uniform weights (MTV) versus top-$k$ uniform (nearest-neighbor mean) versus soft attention;
  • gate on versus gate fixed at 1;
  • similarity computed in the head's query space versus in a frozen image-text embedding space.

Why not just…?

Why not just retrieve the nearest demonstrations and prompt with them? Similarity-based demonstration selection conditions on the query and needs no internals, so it is a serious competitor. It still pays the full token cost per image and inherits the captioning failure that drags prompting to 18% in Task Vectors are Cross-Modal. We run it with the same retrieval pool and report both accuracy and memory. If it matches our method at 4 to 8 shots, our contribution reduces to efficiency, and we will say so.

Why not just average the top-$k$ nearest activations? This is the most dangerous alternative, because it captures query conditioning without soft attention or a gate. It is built in as an ablation and gets the same tuning budget. If it matches soft attention within noise, we will report the simpler nearest-neighbor task vector as the result. The cross-attention framing would then be unnecessary.

Why not just train per-task vectors or adapters, as M²IV does? Training can fit a better single vector. But a single vector still cannot represent a mixture of sub-tasks unless the sub-tasks are trained separately, which requires labels for sub-task identity. The heterogeneous-split analysis tests exactly this. If M²IV's gains are uniform across splits, static capacity is enough and the case for query conditioning weakens.

Proposed Experiments

Main evaluations. These cover VizWiz, OK-VQA and VQAv2 on Qwen-VL-7B and LLaVA-v1.5, the VL-ICL suite on Qwen2.5-VL-3B, and the Flowers-to-CUB transfer setting from MTV. For OK-VQA no reported result was found on Lacuna, so we establish our own MTV and prompting numbers there.

Decisive check 1: heterogeneity. We build mixed banks where a single bank holds demonstrations from two or more of Luo et al.'s tasks plus VQA types, with the target's cue disambiguating the task. Static mean vectors must degrade as the mixture grows. If query-conditioned blending fails to stay near the single-task ceiling, the core claim is false.

Decisive check 2: the gate. On deliberately out-of-distribution queries, such as VizWiz unanswerable images or C$^3$PO-style conflicting inputs, the gate should lower injection. It should also reduce harm relative to always-on patching.

Efficiency. We report memory and runtime against MTV's reported 19.8 GB and 1.9 minutes per 100 iterations at 400 shots. The extra cost of the bank must stay small for the method to keep the efficiency argument for task vectors intact.