arXiv:2605.02944cs.LGcs.AI2026-05

用测试通过率做奖励,反而让代码生成效果变差。

Exploring Pass-Rate Reward in Reinforcement Learning for Code Generation

论文配图:Exploring Pass-Rate Reward in Reinforcement Learning for Code Generation
图 1 · 摘自论文原文
  • 用通过率替代全通过奖励,缓解稀疏奖励问题
  • 实验显示通过率奖励未提升最终性能,甚至更差
  • 因梯度方向冲突,部分通过解会互相抵消优化效果

基于单元测试反馈的强化学习已成为提升大语言模型代码生成能力的标准后训练方法。然而,全通过的二元奖励存在稀疏性问题,尤其在无任何样本通过全部测试时无法提供学习信号。常见做法是使用测试用例通过率作为替代奖励。本文研究了在无评论器强化学习(如GRPO和RLOO)中使用通过率奖励的效果,发现在不同基础模型与算法上均存在一致现象:尽管缓解了奖励稀疏性,通过率奖励并未在严格控制实验中显著提升最终性能。分析表明,虽然通过率奖励更密集,但其诱导的梯度更新并不稳定地将概率质量推向全通过解。这是因为通过率作为正确性的代理指标存在偏差,同一组部分通过的解可能产生相互抵消的梯度方向。总体而言,本研究结果表明,在无评论器强化学习中,通过率奖励不足以改善代码生成,呼吁设计更贴近全正确目标的奖励机制。

原文摘要 · Abstract (English)

Reinforcement learning (RL) from unit-test feedback has become a standard post-training recipe for improving large language models (LLMs) on code generation. However, the pass-all-tests binary reward can be sparse, yielding no learning signal on challenging problems where none of the sampled solutions passes all tests. A common remedy is to use the test-case pass rate as a surrogate reward. In this work, we study pass-rate rewards in critic-free RL for code generation (e.g., GRPO and RLOO) and report a consistent pattern across base models and algorithms: despite alleviating reward sparsity, pass-rate rewards do not reliably improve final performance over binary rewards in rigorous controlled experiments. To understand this discrepancy, we analyze reward density and the resulting gradient directions. We find that pass-rate rewards are denser, but the induced gradient updates do not consistently move probability mass toward full-pass solutions. This arises because test-case pass rate is a miscalibrated surrogate for progress toward full correctness, and partial-pass solutions within the same group can induce conflicting gradient directions that cancel out. Overall, our results suggest that, in critic-free RL, pass-rate rewards are insufficient to improve code generation and motivate reward designs that better align optimization with the goal of full correctness.

强化学习代码生成奖励设计

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。