arXiv:2604.02352cs.LGcs.AI2026-04

用对比提示调优让大模型写出更省电的代码。

An Initial Exploration of Contrastive Prompt Tuning to Generate Energy-Efficient Code

论文配图:An Initial Exploration of Contrastive Prompt Tuning to Generate Energy-Efficient Code
图 1 · 摘自论文原文
  • 结合对比学习与提示调优,教会模型区分高效与低效代码。
  • 在三个语言、三种模型上测试,部分模型代码效率提升明显。
  • 适合关注绿色编程和代码能效优化的研究者与开发者。

尽管大型语言模型(LLM)能生成功能正确的代码,但其生成的代码往往比人工编写的代码能耗更高,这与绿色软件开发(GSD)降低代码能耗的目标相悖。为支持这一目标,本研究探究了如何通过优化大模型来促进生成更节能的代码。为此,采用对比提示调优(Contrastive Prompt Tuning, CPT),该方法融合对比学习以区分高效与低效代码,并结合提示调优这一参数高效微调(PEFT)技术,仅需少量计算成本即可实现调整。研究在 Python、Java 与 C++ 的编码任务上,针对三种不同模型进行了全面评估。结果表明,该方法在两个模型上显著提升了代码正确率,而能效提升则因模型、编程语言及任务复杂度而异,说明效果并非普遍一致。

原文摘要 · Abstract (English)

Although LLMs are capable of generating functionally correct code, they also tend to produce less energy-efficient code in comparison to human-written solutions. As these inefficiencies lead to higher computational overhead, they are in direct conflict with Green Software Development (GSD) efforts, which aim to reduce the energy consumption of code. To support these efforts, this study aims to investigate whether and how LLMs can be optimized to promote the generation of energy-efficient code. To this end, we employ Contrastive Prompt Tuning (CPT). CPT combines Contrastive Learning techniques, which help the model to distinguish between efficient and inefficient code, and Prompt Tuning, a Parameter-Efficient Fine Tuning (PEFT) approach that requires only a fraction of the cost of traditional fine tuning. This study evaluates CPT on Python, Java and C++ coding problems across three different models to provide a comprehensive evaluation. The method achieves consistent improvements in code accuracy for two models but efficiency gains vary by model, language and task complexity, indicating that improvements are not uniformly reliable.

代码生成绿色编程提示调优能效优化

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