Reinforcement Learning for Code Optimization

📄 arXiv: 2607.25970v1 📥 PDF

作者: Pierre Chambon, Kunhao Zheng, Juliette Decugis, Benoit Sagot, Gabriel Synnaeve

分类: cs.LG, cs.AI

发布日期: 2026-07-28

备注: 125 pages


💡 一句话要点

提出基于强化学习的代码优化方法以解决执行时间问题

🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture)

关键词: 强化学习 代码优化 执行时间 DMC-Optim 奖励机制 模型学习 性能提升

📋 核心要点

  1. 现有的代码优化方法在引入执行时间作为奖励时,面临测量噪声和奖励稀疏性等问题,导致强化学习效果不佳。
  2. 本文通过构建DMC-Optim,提出了三阶段的执行时间学习方法,分别为优化测试、奖励组成和模型学习适应。
  3. 实验结果显示,优化感知配置在多个基准上显著提高了通过率,尤其在严格的评估标准下表现出更高的相对提升。

📝 摘要(中文)

现有的代码正确性强化学习方法已得到广泛认可,但在代码优化中,执行时间作为奖励的引入却面临测量噪声、奖励稀疏性和GRPO不稳定性等挑战。本文提出了DMC-Optim,通过三个阶段使执行时间可学习:优化测试的构建、奖励的组成以及模型的学习适应。实验结果表明,优化感知配置在Qwen 2.5 7B和CWM 32B上显著提高了通过率,并在严格的百分位上表现出更高的相对提升。

🔬 方法详解

问题定义:本文旨在解决在代码优化中引入执行时间作为奖励时,现有方法面临的测量噪声、奖励稀疏性和GRPO不稳定性等问题。

核心思路:通过构建DMC-Optim,论文提出了三阶段的执行时间学习方法,旨在提高强化学习在代码优化中的有效性。

技术框架:整体架构包括三个主要阶段:第一阶段是构建大型优化测试和校准沙箱以测试代码;第二阶段是将正确性与速度结合在RL环境中,并使用离线模拟器预测最有前景的配置;第三阶段是通过适应GRPO和评估来学习稀疏、噪声的时间执行奖励。

关键创新:最重要的创新在于将执行时间学习化,通过优化测试和奖励组合的方式,使得强化学习在代码优化中能够有效应对噪声和稀疏性问题。

关键设计:在设计中,采用了校准的沙箱进行测试,使用离线模拟器进行配置预测,并调整了GRPO以适应新的奖励结构,确保模型能够在稀疏和噪声环境中有效学习。

🖼️ 关键图片

img_0
img_1
img_2

📊 实验亮点

实验结果显示,优化感知配置在Qwen 2.5 7B上将通过率从18.0%提升至31.3%,在CWM 32B上从30.7%提升至50.4%。在更严格的评估标准下,CWM 32B的相对提升达到125%。此外,在沙箱性能下降的情况下,优化RL相较于标准RLVR的改进幅度达到100%至200%。

🎯 应用场景

该研究在代码优化领域具有广泛的应用潜力,能够提升自动化编程工具的性能,帮助开发者生成更高效的代码。未来,随着技术的进一步发展,该方法可能在软件开发、编译器优化等领域发挥重要作用。

📄 摘要(原文)

RL for code correctness is now established: have the model generate a program, run it against hidden test cases, and reward solutions that pass. Extending this to code optimization seems straightforward: just add execution time to the reward. But in practice, once timing drives the reward, small problems in measurement noise, reward sparsity, or GRPO instability overwhelm the signal and make RL fail: generated solutions are barely faster, and more of them can fail. We make execution time learnable through three stages: (1) how code is tested, by building DMC-Optim with large optimization tests and a calibrated sandbox; (2) how speed is turned into reward, by composing correctness and speed in the RL environment and using an offline simulator to predict the most promising configurations; and (3) how the model learns from that reward, by adapting GRPO and evaluation to the sparser, noisier timed-execution setting. On DMC-Optim, the strongest optimization-aware configurations improve strict top-50% pass@1 from 18.0% to 31.3% on Qwen 2.5 7B and from 30.7% to 50.4% on CWM 32B. These gains further increase at stricter percentiles such as top-30%, with 125% relative improvement for CWM 32B, while preserving pure-correctness scores. When the timing sandbox is degraded, robust optimization RL reaches 100% to 200% improvement over standard RLVR, depending on the evaluation criterion. On LCB, CWM 32B wins up to 83% of median-sample speed comparisons against standard RLVR. Relative to the fastest correct human submissions per problem, it reaches about half the human rate of complexity-class improvements (14% vs. 28%).