通过一致性奖励提升大模型代码推理能力,避免奖励欺骗。
Enhancing the Code Reasoning Capabilities of LLMs via Consistency-based Reinforcement Learning

- 设计一致性追踪训练数据,捕捉代码推理的逐步过程。
- 在Qwen2.5-Coder-7B上准确率领先基线4.3%。
- 无需额外训练即可提升数学与多语言代码推理表现。
代码推理是指根据源码和特定输入预测程序输出的任务,可衡量大语言模型的推理能力,并有助于代码生成和数学推理等下游任务。现有方法依赖最终输出或粗粒度信号设计奖励,忽视了推理过程的内在一致性,导致奖励稀疏或奖励欺骗,限制了学习效果。为此,我们提出CodeThinker,一种基于一致性的强化学习框架。其包含三个核心组件:(1) 基于一致性追踪模板的分步推理感知训练模块,用于合成体现推理过程的数据;(2) 动态束搜索策略,在固定采样预算下提升输出质量;(3) 一致性奖励机制,有效缓解奖励欺骗。在三个主流基准上的实验表明,CodeThinker在多个LLM上达到顶尖性能。例如,在Qwen2.5-Coder-7B-Instruct上,准确率比最强基线高出4.3%。我们在下游任务中也验证了其有效性:无需额外训练,分别在数学推理和涵盖17种编程语言的代码推理任务上取得平均5.33和3.11个百分点的准确率提升。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。