Beyond the Need for Speed: Energy-Aware Code Generation via Simulation-Guided Reinforcement Learning

📄 arXiv: 2607.04577v1 📥 PDF

作者: Saurabhsingh Rajput, Tushar Sharma

分类: cs.LG, cs.SE

发布日期: 2026-07-06


💡 一句话要点

提出能量感知代码生成方法以优化软件能效

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

关键词: 能量感知 代码生成 强化学习 架构模拟 能效优化 CARET指标 C++问题

📋 核心要点

  1. 现有代码生成模型主要关注功能正确性,导致软件能效未得到有效优化,且物理硬件测量的反馈不够可靠。
  2. 论文提出通过确定性架构模拟替代硬件测量,构建Green Tea数据集,并利用强化学习训练能量感知代码模型。
  3. 在143个保留问题上,提出的方法实现了12.63%的CARET,几乎是单纯微调的三倍,并在58.4%的有效输出中超越了人类专家的能效。

📝 摘要(中文)

本论文指出,现有代码模型在功能正确性上优先,而软件能效则未得到优化。为此,研究者们用确定性的架构模拟替代硬件测量,构建了Green Tea数据集,包含347万个评估,涵盖1474个C++问题。通过对能量对比对的监督微调和闭环强化学习,训练出能量感知代码模型。引入的CARET指标有效评估代码的功能与能效平衡。实验结果显示,该方法在143个保留问题上实现了12.63%的CARET,显著提升了能效,并超越58.4%的人类专家参考结果。研究还揭示了IPC陷阱,证明了直接能量模拟的必要性。

🔬 方法详解

问题定义:本论文旨在解决现有代码生成模型在能效优化方面的不足,尤其是硬件测量反馈的不可靠性。

核心思路:通过使用确定性的架构模拟替代物理硬件测量,构建一个大规模的评估数据集,以训练能量感知的代码生成模型。

技术框架:整体流程包括数据集构建、能量对比对的监督微调以及基于模拟反馈的闭环强化学习,确保模型在生成代码时兼顾功能与能效。

关键创新:引入CARET指标,明确惩罚牺牲功能以换取能效的代码,从而实现功能与能效的平衡。与现有方法相比,直接能量模拟显著提高了能效评估的准确性。

关键设计:在训练过程中,采用了能量对比对的损失函数,并设计了适应性强化学习策略,以优化生成代码的能效,同时保持功能的完整性。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果显示,采用模拟反馈的闭环强化学习方法在143个保留问题上实现了12.63%的CARET,几乎是单纯微调的三倍,且在58.4%的有效输出中超越了人类专家的能效,验证了方法的有效性与优越性。

🎯 应用场景

该研究的潜在应用领域包括高性能计算、嵌入式系统和移动设备等,能够显著提升软件的能效,降低能耗,具有重要的实际价值。未来,该方法可能推动能量感知编程的广泛应用,促进可持续软件开发。

📄 摘要(原文)

Code models strictly prioritize functional correctness, leaving software energy efficiency as an unoptimized byproduct. Training models to generate energy-efficient code requires reproducible feedback at scale, which physical hardware measurement cannot reliably provide due to variance. In this paper, we replace hardware profiling with a deterministic architectural simulation harness to build Green Tea, a corpus of $3.5$ million evaluations across $1{,}474$ C++ problems. We train an energy-aware code model via supervised fine-tuning on energy-contrastive pairs, followed by closed-loop reinforcement learning (GRPO) using simulation-in-the-loop feedback. To rigorously evaluate deployment readiness, we introduce the Correctness-Adjusted Reduction in Energy Total (CARET), a metric that explicitly penalizes code that sacrifices functionality for efficiency. On $143$ held-out problems, our simulation-in-the-loop pipeline achieves $12.63\%$ CARET, nearly tripling the gain of fine-tuning alone, and successfully beats the energy efficiency of human-expert references on $58.4\%$ of its valid outputs. Furthermore, our analysis exposes the IPC trap: standard throughput proxies like Instructions-Per-Cycle (IPC) actively misrank true energy efficiency on $67.8\%$ of problems, proving the absolute necessity of direct energy simulation. By releasing our dataset and infrastructure, we bypass the $263{,}000$ CPU-hours required for reproduction, structurally empowering the community to deploy inherently energy-efficient code generation models.