Saved in:
Bibliographic Details
Main Authors: Jiang, Xue, Zhang, Tianyu, Li, Ge, Liu, Mengyang, Chen, Taozhi, Xu, Zhenhua, Li, Binhua, Jiao, Wenpin, Jin, Zhi, Li, Yongbin, Dong, Yihong
Format: Preprint
Published: 2026
Subjects:
Online Access:https://arxiv.org/abs/2603.29957
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866908994837151744
author Jiang, Xue
Zhang, Tianyu
Li, Ge
Liu, Mengyang
Chen, Taozhi
Xu, Zhenhua
Li, Binhua
Jiao, Wenpin
Jin, Zhi
Li, Yongbin
Dong, Yihong
author_facet Jiang, Xue
Zhang, Tianyu
Li, Ge
Liu, Mengyang
Chen, Taozhi
Xu, Zhenhua
Li, Binhua
Jiao, Wenpin
Jin, Zhi
Li, Yongbin
Dong, Yihong
contents Recent advances in reasoning Large Language Models (LLMs) have primarily relied on upfront thinking, where reasoning occurs before final answer. However, this approach suffers from critical limitations in code generation, where upfront thinking is often insufficient as problems' full complexity only reveals itself during code implementation. Moreover, it cannot adaptively allocate reasoning effort throughout the code generation process where difficulty varies significantly. In this paper, we propose Think-Anywhere, a novel reasoning mechanism that enables LLMs to invoke thinking on-demand at any token position during code generation. We achieve Think-Anywhere by first teaching LLMs to imitate the reasoning patterns through cold-start training, then leveraging outcome-based RL rewards to drive the model's autonomous exploration of when and where to invoke reasoning. Extensive experiments on four mainstream code generation benchmarks (i.e., LeetCode, LiveCodeBench, HumanEval, and MBPP) show that Think-Anywhere achieves state-of-the-art performance over both existing reasoning methods and recent post-training approaches, while demonstrating consistent generalization across diverse LLMs. Our analysis further reveals that Think-Anywhere enables the model to adaptively invoke reasoning at high-entropy positions, providing enhanced interpretability.
format Preprint
id arxiv_https___arxiv_org_abs_2603_29957
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Think Anywhere in Code Generation
Jiang, Xue
Zhang, Tianyu
Li, Ge
Liu, Mengyang
Chen, Taozhi
Xu, Zhenhua
Li, Binhua
Jiao, Wenpin
Jin, Zhi
Li, Yongbin
Dong, Yihong
Software Engineering
Machine Learning
Recent advances in reasoning Large Language Models (LLMs) have primarily relied on upfront thinking, where reasoning occurs before final answer. However, this approach suffers from critical limitations in code generation, where upfront thinking is often insufficient as problems' full complexity only reveals itself during code implementation. Moreover, it cannot adaptively allocate reasoning effort throughout the code generation process where difficulty varies significantly. In this paper, we propose Think-Anywhere, a novel reasoning mechanism that enables LLMs to invoke thinking on-demand at any token position during code generation. We achieve Think-Anywhere by first teaching LLMs to imitate the reasoning patterns through cold-start training, then leveraging outcome-based RL rewards to drive the model's autonomous exploration of when and where to invoke reasoning. Extensive experiments on four mainstream code generation benchmarks (i.e., LeetCode, LiveCodeBench, HumanEval, and MBPP) show that Think-Anywhere achieves state-of-the-art performance over both existing reasoning methods and recent post-training approaches, while demonstrating consistent generalization across diverse LLMs. Our analysis further reveals that Think-Anywhere enables the model to adaptively invoke reasoning at high-entropy positions, providing enhanced interpretability.
title Think Anywhere in Code Generation
topic Software Engineering
Machine Learning
url https://arxiv.org/abs/2603.29957