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.
翻译:个人计算机、通信网络和数据中心日益增长的电力需求加剧了大气温室气体排放,进而导致全球变暖与气候变化。因此,必须最大限度地降低代码的能耗。大型语言模型具备代码生成能力。本研究探讨了提示词修改对生成代码能耗的影响。我们选取了三个不同难度的Python编程问题,通过添加"请针对该问题提供能量优化解决方案"的语句或采用两种Python编码最佳实践进行提示词修改。实验使用的大型语言模型包括CodeLlama-70b、CodeLlama-70b-Instruct、CodeLlama-70b-Python、DeepSeek-Coder-33b-base和DeepSeek-Coder-33b-instruct。研究发现,在特定的提示优化方式、大型语言模型与Python编程问题组合下,能耗有所降低。然而,对于同一大型语言模型,没有任何一种优化提示能在不同Python编程问题中持续降低能耗。