StepCodeReasoner: 通过强化学习对齐代码推理与分步执行轨迹
StepCodeReasoner: Aligning Code Reasoning with Stepwise Execution Traces via Reinforcement Learning
AI总结:
本文提出StepCodeReasoner框架,通过引入显式的中间执行状态监督,将代码推理转化为可验证的分步执行建模问题,并通过Bi-Level GRPO算法提升结构化信用分配,实验表明其在代码推理和生成任务中均优于现有方法。
摘要:
现有代码推理方法主要监督最终代码输出,忽视中间状态,常导致奖励黑客问题。我们提出StepCodeReasoner框架,通过自动插入基于结构化打印的执行轨迹锚点,训练模型预测每一步的运行状态,将代码推理转化为可验证的分步执行建模问题。基于此执行感知方法,我们引入Bi-Level GRPO强化学习算法,实现双层结构化信用分配:跨轨迹比较替代执行路径,内轨迹根据对下游正确性的影响奖励中间准确性。大量实验表明,StepCodeReasoner在代码推理任务中取得SOTA性能。特别是,我们的7B模型在CRUXEval上达到91.1%,在LiveCodeBench上达到86.5%,优于CodeReasoner-7B(86.0%和77.7%)和GPT-4o(85.6%和75.1%)。此外,在执行轨迹基准REval上,我们的模型得分82.9%,优于基线CodeReasoner-7B(72.3%)、其14B版本(81.1%)和GPT-4o(77.3%)。此外,我们的方法还提升了代码生成性能,证明显式执行建模能同时提升代码推理和生成。
英文摘要:
Existing code reasoning methods primarily supervise final code outputs, ignoring intermediate states, often leading to reward hacking where correct answers are obtained through inconsistent reasoning. We propose StepCodeReasoner, a framework that introduces explicit intermediate execution-state supervision. By automatically inserting structured print-based execution-trace anchors into code, the model is trained to predict runtime states at each step, transforming code reasoning into a verifiable, stepwise execution modeling problem. Building on this execution-aware method, we introduce Bi-Level GRPO, a reinforcement learning algorithm for structured credit assignment at two levels: inter-trajectory, comparing alternative execution paths, and intra-trajectory, rewarding intermediate accuracy based on its impact on downstream correctness. Extensive experiments demonstrate that StepCodeReasoner achieves SOTA performance in code reasoning. In particular, our 7B model achieves 91.1\% on CRUXEval and 86.5\% on LiveCodeBench, outperforming the CodeReasoner-7B baseline (86.0\% and 77.7\%) and GPT-4o (85.6\% and 75.1\%). Furthermore, on the execution-trace benchmark REval, our model scores 82.9\%, outperforming baseline CodeReasoner-7B (72.3\%), its 14B counterpart (81.1\%), and GPT-4o (77.3\%). Additionally, our approach also improves code generation performance, demonstrating that explicit execution modeling enhances both code reasoning and code generation.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。