[CVPR 2026] Think Anywhere: Breaking the Upfront Reasoning Bottleneck in Code Generation

Think Anywhere in Code Generation

2026-03-01
Xue Jiang, Tianyu Zhang, Ge Li, Mengyang Liu, Taozhi Chen, Zhenhua Xu, Binhua Li, Wenpin Jiao, Zhi Jin, Yongbin Li, Yihong Dong
Summary
Problem
Method
Results
Takeaways
Abstract

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:

  1. Insufficient Implementation Depth: Upfront plans often miss implementation-level bugs.
  2. 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.

Model Architecture and Mechanism 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 Assignment and Return statements), 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.

Token Cost Comparison 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.

Find Similar Papers

Try Our Examples

  • Search for recent papers on "interleaved thinking" or "on-demand reasoning" in LLMs that go beyond code generation to general-purpose problem solving.
  • Which study first introduced the concept of "pause tokens" or "filler tokens" for hidden computation, and how does THINK-ANYWHERE's explicit tag approach compare in interpretability?
  • Explore the application of dynamic computation allocation (adaptive inference) in multi-modal models for video understanding or complex visual reasoning.
Contents
[CVPR 2026] Think Anywhere: Breaking the Upfront Reasoning Bottleneck in Code Generation
1. TL;DR
2. Problem & Motivation: The Limitations of Upfront Planning
3. Methodology: Teaching LLMs to Pause
3.1. 1. The Multi-Stage Training Pipeline
3.2. 2. Semantic-Aware Special Tokens
4. Experiments & Results: SOTA Efficiency
4.1. Key Findings:
5. Critical Analysis & Conclusion
5.1. Why it works
5.2. Limitations
5.3. The Takeaway