TL;DR
This paper introduces In-Context Policy Optimization (ICPO), a framework that explains how Large Language Models (LLMs) can improve their answers at inference time through self-reflection without updating parameters. The authors theoretically prove that transformers can learn to execute policy optimization algorithms in-context. They translate this theory into a practical algorithm, Minimum-Entropy ICPO (ME-ICPO), which significantly boosts mathematical reasoning performance by iteratively refining answers based on self-assessed rewards and minimum-entropy selection.
Introduction: The Black Box of Test-Time Scaling
Recently, "test-time scaling" (or inference-time scaling) has become a massive trend in AI. By giving LLMs more compute during inference—via multi-round self-reflection, tree search, or self-rewarding—they can progressively improve their answers without any parameter updates.
However, while empirical evidence shows this works, the underlying mechanism remains a black box. Existing theories explain how transformers can perform in-context supervised learning (like linear regression), but there is a massive gap in understanding how they perform in-context policy optimization. How do transformers actually learn to optimize their own actions based on historical rewards purely within the prompt context? This paper seeks to provide a rigorous mathematical foundation for this phenomenon and leverage that understanding to build a better, more efficient test-time scaling algorithm.
Methodology
The paper bridges theory and practice through two main contributions:
1. Theoretical Foundation (ICPO)
The authors mathematically prove that a single-layer Linear Self-Attention (LSA) transformer, when pretrained with a novel "Fisher-weighted logit-matching" objective, can perfectly imitate a policy optimization algorithm (specifically, Follow-the-Regularized-Leader for linear bandits) using only in-context data.
2. Practical Algorithm (ME-ICPO)
Building on the theory, they propose Minimum-Entropy ICPO (ME-ICPO) for actual LLMs.
At test time, the LLM generates multiple candidate responses (Chain-of-Thoughts) and self-assesses them using majority voting to assign a pseudo-reward (1 for correct, 0 for incorrect). To prevent context window explosion over multiple rounds, these reasoning chains are summarized. Finally, instead of just greedily picking the highest-reward response to put back into the prompt, ME-ICPO selects the response that leads to the minimum entropy in future generations. This pessimistic, uncertainty-minimizing selection prevents the model from being derailed by corrupted or hallucinated responses.
Key Insights and Ideas
- Transformers are Secret RL Agents: With sufficient pretraining, even a minimal linear transformer can structurally mimic a bandit policy optimization algorithm. It doesn't just predict the next token; it updates its internal "policy" based on the rewards it sees in the prompt history.
- Standard Pretraining Naturally Builds This Skill: The theoretical "Fisher-weighted loss" required to make this work is mathematically sandwiched by the standard KL divergence loss. This helps explain why standard LLM pretraining naturally gives rise to these self-reflection capabilities.
- Robustness to "Reward Shocks": The theory proves (and experiments validate) that this in-context policy optimization is highly stable.
As shown above, the policy gap steadily decreases over time. Furthermore, if the model receives a single bad or noisy reward signal (a "reward shock" at step $s=2$), the impact decays over time rather than spiraling out of control and breaking the model's reasoning.
- Entropy Beats Greed: In the practical ME-ICPO algorithm, selecting the next in-context example based on minimum entropy (lowest uncertainty) is vastly superior to just picking the one with the highest self-assessed reward. Ablations show that removing the entropy-based selection causes a dramatic performance collapse (dropping AIME accuracy from 30.05% to 5.77%).
Key Results
The authors evaluated ME-ICPO on standard, rigorous mathematical reasoning benchmarks including AIME 2024, AMC, MATH-500, and HMMT/APEX.
- Massive Performance Leaps: On the AIME 2024 benchmark, applying ME-ICPO to Qwen2.5-Math-7B increased the Mean@16 score from 11.04% to 30.42% (+19.38%). Standard accuracy jumped from 11.13% to 30.05%.
- Scales Across Model Sizes: The smaller Qwen2.5-Math-1.5B also saw solid gains, jumping from 6.46% to 9.79% on AIME 2024 Mean@16, and showing a +11.92% improvement on MATH-L1.
- Frontier Model Boosts: ME-ICPO successfully improved state-of-the-art models as well, boosting Gemini-2.5-Pro on AIME 2024 from 58.54% to 79.17% (Mean@16).
- Compute Efficiency: Compared to training-based test-time scaling methods like TTRL, ME-ICPO achieves higher accuracy (30.05% vs 30.00% on AIME) while requiring slightly less wall-clock inference time (1152s vs 1253s per question), entirely avoiding the massive VRAM overhead of backpropagation at inference time.
Limitations and Future Work
- Theoretical Constraints: The mathematical proofs rely on a simplified single-layer linear self-attention model and a linear bandit framework. Real LLMs use multi-layer, non-linear transformers. The authors suggest extending the theoretical analysis of training dynamics to multi-layer, nonlinear structures.
- Bandits vs. MDPs: The current framework models the reasoning process as a stateless $K$-armed bandit problem. Extending this to Markov Decision Processes (MDPs) would better capture the sequential, multi-step nature of complex reasoning.
- Reward Reliability: The practical algorithm relies on majority voting for self-assessed rewards. Future work should look into consistency regularization to make this reward assessment more robust and less noisy.
Summary updated