Enhancing the Code Reasoning Capabilities of LLMs via Consistency-based Reinforcement Learning

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Qin, Zhanyue, Feng, Jia, Lyu, Yibo, Peng, Yun, Sui, Dianbo, Gao, Cuiyun, Liao, Qing
Format: Preprint
Published: 2026
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916022584344576
author Qin, Zhanyue
Feng, Jia
Lyu, Yibo
Peng, Yun
Sui, Dianbo
Gao, Cuiyun
Liao, Qing
author_facet Qin, Zhanyue
Feng, Jia
Lyu, Yibo
Peng, Yun
Sui, Dianbo
Gao, Cuiyun
Liao, Qing
contents Code reasoning refers to the task of predicting the output of a program given its source code and specific inputs. It can measure the reasoning capability of large language models (LLMs) and also benefit downstream tasks such as code generation and mathematical reasoning. Existing work has verified the effectiveness of reinforcement learning on the task. However, these methods design rewards solely based on final outputs or coarse-grained signals, and neglect the inherent consistency of the stepwise reasoning process in the task. Therefore, these methods often result in sparse reward or reward hacking, which limits the full play of enhanced learning capabilities. To alleviate these issues, we propose CodeThinker, a consistency-driven reinforcement learning framework for code reasoning. Specifically, CodeThinker has three key components: (1) a stepwise reasoning-aware model training module, which utilizes a consistency tracing paradigm as a template to synthesize training data that captures the stepwise reasoning process; (2) a dynamic beam sampling strategy, which aims to improve the quality of sampled outputs under a fixed sampling budget; and (3) a consistency reward mechanism that can effectively alleviate reward hacking. Experiments on three popular benchmarks show that CodeThinker achieves state-of-the-art performance across multiple LLMs. For instance, it outperforms the strongest baseline by 4.3% in accuracy when deployed on Qwen2.5-Coder-7B-Instruct. We also validate the effectiveness of CodeThinker on downstream tasks. Results show that, without additional training, CodeThinker obtains average accuracy gains of 5.33 and 3.11 percentage points on mathematical reasoning and code reasoning tasks covering 17 programming languages, respectively.
format Preprint
id arxiv_https___arxiv_org_abs_2605_17958
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Enhancing the Code Reasoning Capabilities of LLMs via Consistency-based Reinforcement Learning
Qin, Zhanyue
Feng, Jia
Lyu, Yibo
Peng, Yun
Sui, Dianbo
Gao, Cuiyun
Liao, Qing
Machine Learning
Programming Languages
Code reasoning refers to the task of predicting the output of a program given its source code and specific inputs. It can measure the reasoning capability of large language models (LLMs) and also benefit downstream tasks such as code generation and mathematical reasoning. Existing work has verified the effectiveness of reinforcement learning on the task. However, these methods design rewards solely based on final outputs or coarse-grained signals, and neglect the inherent consistency of the stepwise reasoning process in the task. Therefore, these methods often result in sparse reward or reward hacking, which limits the full play of enhanced learning capabilities. To alleviate these issues, we propose CodeThinker, a consistency-driven reinforcement learning framework for code reasoning. Specifically, CodeThinker has three key components: (1) a stepwise reasoning-aware model training module, which utilizes a consistency tracing paradigm as a template to synthesize training data that captures the stepwise reasoning process; (2) a dynamic beam sampling strategy, which aims to improve the quality of sampled outputs under a fixed sampling budget; and (3) a consistency reward mechanism that can effectively alleviate reward hacking. Experiments on three popular benchmarks show that CodeThinker achieves state-of-the-art performance across multiple LLMs. For instance, it outperforms the strongest baseline by 4.3% in accuracy when deployed on Qwen2.5-Coder-7B-Instruct. We also validate the effectiveness of CodeThinker on downstream tasks. Results show that, without additional training, CodeThinker obtains average accuracy gains of 5.33 and 3.11 percentage points on mathematical reasoning and code reasoning tasks covering 17 programming languages, respectively.
title Enhancing the Code Reasoning Capabilities of LLMs via Consistency-based Reinforcement Learning
topic Machine Learning
Programming Languages
url https://arxiv.org/abs/2605.17958