arXiv:2411.10599cs.SEcs.AI2024-11被引 10

用提示词优化让大模型生成更省电的代码,但效果因任务而异。

Generating Energy-efficient code with LLMs

  • 通过添加节能提示或编码规范优化提示词,影响生成代码的能耗。
  • 特定组合下代码能耗降低,但无通用最优提示方案。
  • 适合关注代码能效、绿色AI开发的研究者与工程师。

个人电脑、通信网络和数据中心日益增长的电力需求导致大气温室气体排放上升,加剧全球变暖与气候变化。因此必须减少代码能耗。大语言模型可生成代码,我们研究提示词修改对生成代码能耗的影响。采用三个不同难度级别的Python编程问题,通过添加“请提供一个能源优化的解决方案”或引入两种Python编码最佳实践来优化提示。使用的模型包括CodeLlama-70b、CodeLlama-70b-Instruct、CodeLlama-70b-Python、DeepSeek-Coder-33b-base 和 DeepSeek-Coder-33b-instruct。结果发现,在特定提示优化、模型与问题组合下,代码能耗下降;但在同一模型面对不同问题时,无单一优化提示始终有效。

原文摘要 · Abstract (English)

The increasing electricity demands of personal computers, communication networks, and data centers contribute to higher atmospheric greenhouse gas emissions, which in turn lead to global warming and climate change. Therefore the energy consumption of code must be minimized. Code can be generated by large language models. We look at the influence of prompt modification on the energy consumption of the code generated. We use three different Python code problems of varying difficulty levels. Prompt modification is done by adding the sentence ``Give me an energy-optimized solution for this problem'' or by using two Python coding best practices. The large language models used are CodeLlama-70b, CodeLlama-70b-Instruct, CodeLlama-70b-Python, DeepSeek-Coder-33b-base, and DeepSeek-Coder-33b-instruct. We find a decrease in energy consumption for a specific combination of prompt optimization, LLM, and Python code problem. However, no single optimization prompt consistently decreases energy consumption for the same LLM across the different Python code problems.

代码生成节能LLM能效优化

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