PreciseCoder:超越单元测试奖励的忠实且可泛化的调试

·

研究论文 · 2026/10/16

基于单元测试的强化学习是代码模型后训练的常见方法,但单元测试只关注最终程序是否通过。我们分析了这种仅依赖单元测试的奖励在调试过程中教会了模型什么,发现虽然它提高了通过率,但也教会模型进行更多编辑,并在已经正确的代码中幻觉出错误。我们提出了 PreciseCoder,一种训练算法,它通过增加一个针对语义验证的局部编辑信号来增强单元测试奖励,该信号与更小的编辑和更高的通过率相关。在 4B、9B 和 27B 模型上,PreciseCoder 将平均编辑行数从 7-15 行减少到 3 行,同时通过率与仅使用单元测试训练相当。仅在单行错误上训练,PreciseCoder 就能泛化到仓库级程序修复,用更小的补丁解决更多问题。其精确性还能从较弱模型迁移到较强模型:给定 9B PreciseCoder 模型的推理轨迹,GPT-5.6 Sol 和 Qwen3.8-Max 等前沿模型在无需额外训练的情况下,编辑精确度提升了 4.6-12.4 个百分点。对思维轨迹的语言学分析表明,我们的奖励鼓励模型逐行推理、指出有错误的行,并形成一致的错误假设。

该研究揭示了仅依赖单元测试奖励的强化学习在代码调试中的副作用,并提出了 PreciseCoder 方法,在保持通过率的同时显著减少编辑行数,提升泛化能力和精确性,且精确性可迁移到更强模型,对代码模型的后训练具有重要实践意义。

Reinforcement learning (RL) from unit tests is the common recipe for post-training code models, but a unit test only asks whether the final program passes. We analyze what this unit-test-only reward teaches a model during debugging and find that, while it raises pass rates, it also teaches the model to edit more and to hallucinate bugs in code that is already correct. We introduce PreciseCoder, a training algorithm that augments the unit-test reward with a signal for semantically verified, localized edits, which correlates with smaller edits and higher pass rates. On 4B, 9B, and 27B models, PreciseCoder reduces the average number of edit lines from 7-15to 3 at a pass rate on par with unit-test-only training. Trained only on single-line bugs, PreciseCoder can generalize to repository-level program repair, where it resolves more issues with smaller patches. Its precision also transfers from weaker to stronger models: given the reasoning trace of a 9B PreciseCoder model, frontier models such as GPT-5.6 Sol and Qwen3.8-Max gain 4.6-12.4 points in edit precision with no additional training. Linguistic analysis of the thinking traces shows that our reward encourages the model to reason about individual lines, name the buggy ones, and form consistent bug hypotheses.

阅读原文

参与讨论