Iterative Vectors: In-Context Gradient Steering without Backpropagation

Yiting Liu, Zhi-Hong DengICML 2025

Introduction

In-Context Learning (ICL) is the magic that allows Large Language Models (LLMs) to learn new tasks simply by observing a few examples in a prompt. However, ICL suffers from three major pain points: performance is highly volatile depending on example phrasing and order, models have strict context length limits, and inference slows down quadratically as more examples are added to the prompt.

While some researchers have explored "activation vectors"—adding a fixed vector to the model's internal states to steer behavior—previous methods were often limited to simple synthetic tasks or required exhaustive, time-consuming searches through thousands of attention heads. To address this, researchers have developed Iterative Vectors (IVs), a method that boosts LLM performance by simulating gradient-based fine-tuning directly in the model's internal activation space. By extracting and iteratively refining "meta-gradients" during inference, IVs achieve higher accuracy and better stability than standard ICL, all without the heavy computational cost of backpropagation.

Methodology

The authors introduce Iterative Vectors by treating the LLM as a "meta-optimizer." The core idea is that when an LLM processes examples, it internally generates something akin to a gradient update. The IV approach operates in three main steps:

  1. Meta-gradient Extraction: Instead of just looking at the prompt, IVs calculate the difference between the model's activations when it sees a few-shot example versus a zero-shot query. They specifically target the activations at the input-output separator (e.g., the newline token \n between a question and an answer), as this is where the model "compresses" the task information.
  2. Iterative Refinement: Unlike previous methods that simply average activations, IVs use an iterative batching process. They divide a small set of "training" examples into batches. As they process each batch, they apply the vectors learned from previous batches to the model's activations. This creates a self-reinforcing loop that progressively refines the vectors, effectively simulating batch gradient descent without ever touching the actual model weights.
  3. Application: Once the final IVs are extracted, they are added to the model's attention activations during inference on new, unseen queries. This allows a "1-shot" prompt to perform as well as (or better than) a "5-shot" prompt.
Overview of Iterative Vector extraction and application

Experiments and Key Results

The authors evaluated IVs across 13 diverse real-world classification tasks using four popular models: GPT-J-6B, Llama-2-7b, Llama-3.1-8b, and Llama-2-13b. The datasets spanned general classification (AG News, TREC), sentiment and emotion (Rotten Tomatoes, SST5), social media analysis (TweetEval), and specialized tasks like emoji prediction.

Performance comparison of Iterative Vectors against baselines across 13 datasets
  • Performance Boost: IVs achieved an average performance gain of 3.2% over standard ICL baselines across all tasks and models.
  • Superiority over Baselines: IVs consistently outperformed existing activation steering methods like Function Vectors (FV) and Task Vectors (TV). In some cases, FV and TV actually performed worse than standard ICL, whereas IVs remained robust.
  • Efficiency and Time Savings: IVs allow for "many-shot" performance with "one-shot" latency. In one experiment on the 20-class Emoji dataset, extracting IVs was 95% faster than extracting Function Vectors (23 minutes vs. 438 minutes). Furthermore, IVs achieved the same accuracy as a 2-shot prompt but were 41% faster during inference because the prompt remained short.
  • Scalability: The method scales beautifully. As the number of "extraction episodes" (examples used to build the vector) increases, the performance continues to climb, surpassing the traditional limits of what can be achieved via prompting alone.

Key Insights and Limitations

The most profound insight from this work is that "training-like" results can be achieved by manipulating activations iteratively, bridging the gap between the flexibility of ICL and the robustness of fine-tuning. The paper also reinforces the idea that specific tokens (like separators) act as anchors for information flow; steering the model at these specific points yields maximum leverage over its behavior.

However, the current work has limitations. It is primarily validated on single-token classification tasks, and extending this to long-form generation or complex reasoning remains an open challenge. The method also introduces two hyperparameter "strength" parameters (for extraction and inference) that require a grid search on a validation set to optimize. Finally, while IVs significantly close the gap between zero-shot and few-shot performance, the authors note that providing at least one "anchor" example in the prompt is often still necessary for optimal results.

Summary updated

BibTeX
@inproceedings{liu2025iterative,
  author = {Yiting Liu and Zhi-Hong Deng},
  title = {{Iterative Vectors: In-Context Gradient Steering without Backpropagation}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=1v3XEcRMyP},
}
Figure