[CVPR 2026] Think Anywhere: Breaking the Upfront Reasoning Bottleneck in Code Generation
Think Anywhere in Code Generation
THINK-ANYWHERE is a novel reasoning mechanism for code generation that allows LLMs to invoke thinking on-demand at any token position during implementation. By combining cold-start imitation and Reinforcement Learning with Verifiable Rewards (RLVR), it achieves SOTA performance on benchmarks like LeetCode and HumanEval, surpassing static "upfront thinking" models like DeepSeek-R1 and OpenAI o1.
TL;DR
The dominant paradigm for reasoning LLMs—epitomized by DeepSeek-R1 and OpenAI o1—is "Upfront Thinking." The model plans everything in a hidden block before typing a single character of code. THINK-ANYWHERE challenges this by allowing models to pause and deliberate at any token position. This "think-on-demand" approach not only boosts Pass@1 accuracy by ~9.3% but also reduces total token costs by focusing effort where logical entropy is highest.
Problem & Motivation: The Limitations of Upfront Planning
In coding, the map is not the territory. A model might plan a perfect high-level algorithm in its initial thinking block, but when it starts implementing a complex while loop or handling edge cases in a return statement, new logical risks emerge that weren't obvious at the start.
Current SOTA models suffer from two major flaws:
- Insufficient Implementation Depth: Upfront plans often miss implementation-level bugs.
- Resource Inefficiency: They spend the same "thinking energy" on easy boilerplate code and difficult algorithmic logic because the reasoning is decoupled from the specific execution context.
Methodology: Teaching LLMs to Pause
The authors propose a structural change to the generation sequence. Instead of a linear [Think] -> [Code] flow, they enable a [Think] -> [Code_A] -> [ThinkAnywhere] -> [Code_B] interleaved pattern.
1. The Multi-Stage Training Pipeline
To make a model "know when it's confused," you can't just prompt it. The authors used:
- Cold-Start SFT: Fine-tuning on 5,000 samples where a teacher model (Gemini 1.5 Flash) demonstrated calling
<thinkanywhere>blocks at difficult junctions. - RLVR (GRPO): Using Group Relative Policy Optimization, the model was rewarded for two things: (a) following the thinking format, and (b) passing unit tests (verifiable rewards).
2. Semantic-Aware Special Tokens
The authors found that using raw text tags like <thinkanywhere> as a trigger was noisy. They introduced a dedicated Trigger Token and initialized its embedding by averaging the semantics of "think," "any," and "where" with existing "im_start" delimiters. This allowed the model to treat reasoning as a native mode-switch.
Figure 1: Comparison between traditional Upfront Thinking and the dynamic THINK-ANYWHERE mechanism.
Experiments & Results: SOTA Efficiency
Across LeetCode, LiveCodeBench, HumanEval, and MBPP, THINK-ANYWHERE consistently outperformed standard RL-tuned models (GRPO) and specialized code post-training methods (CodeRL+).
Key Findings:
- Entropy Alignment: Analysis showed the model naturally chooses to think at high-entropy positions (like
AssignmentandReturnstatements), where uncertainty is highest. - Efficiency Gain: Paradoxically, adding more thinking blocks reduced the total token count. Why? Because the upfront thinking phase became a concise high-level summary, leaving the heavy lifting to short, targeted "inline" thoughts.
- Generalization: Though trained on code, the model saw a massive jump in AIME math performance (AIME 2024: 5.3% -> 17.3%), proving that "think-on-demand" is a fundamental reasoning skill.
Figure 2: Computational efficiency—THINK-ANYWHERE uses fewer total tokens than upfront-only baselines.
Critical Analysis & Conclusion
Why it works
THINK-ANYWHERE succeeds because it aligns LLM computation with human cognitive patterns. Developers don't draft a 1,000-word plan and then code blindly; they pause at the tricky bits. By allowing the model to "peek" at its own partially generated code, the reasoning is more grounded.
Limitations
- Inference Latency: While token count is lower, frequent mode-switching (context switching between code and thinking) might introduce small overheads in certain KV-cache implementations.
- Pre-training Gap: The authors noted that the model's ability would likely be even stronger if these special trigger tokens were included during the initial pre-training phase rather than just as a post-training patch.
The Takeaway
The era of massive, monolithic thinking blocks may be coming to an end. THINK-ANYWHERE points toward a future where "Thinking" is a dynamic API called by the LLM whenever it hits a logical fork in the road.
