arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2604.02776cs.SE
收藏

评估使用SLMs和提示工程进行代码生成的环境影响

Evaluating the Environmental Impact of using SLMs and Prompt Engineering for Code Generation

University of Calgary(卡尔加里大学);York University(约克大学)

Md Afif Al Mamun, Sayan Nath, Gias Uddin, Novarun Deb

AI总结:

本文研究了基于SLMs的代码生成中不同提示策略对准确性和可持续性的影响,发现可持续性与准确性脱钩,提示工程可实现环保与性能的平衡。

摘要:

从云托管的大型语言模型(LLMs)转向本地部署的开源小型语言模型(SLMs)使AI辅助编程普及化,但同时也分散了AI的环境足迹。尽管提示策略(如链式思维和ReAct)能优化代码生成而不修改模型参数,但其对能耗和碳排放的影响对开发者而言仍不可见。本文首次系统地实证研究了不同提示策略对代码生成准确性和可持续性的影响。我们评估了六种主流提示策略在11个开源模型(参数从1B到34B)上的表现,使用HumanEval+和MBPP+基准测试。通过测量Pass@1准确率、能耗(kWh)、碳排放(kgCO2eq)和推理延迟,发现可持续性常与准确性脱钩,允许在不牺牲性能的情况下实现显著的环境优化。我们的发现表明,链式思维作为一种更简单的提示技术,能提供接近最优的推理能力和能耗平衡。相反,多采样策略常带来不成比例的成本以换取微小收益。最后,我们识别出网格碳强度是部署时排放的主要因素,强调从业者需考虑地区能源结构。本文为“绿色”提示工程提供了定量基础,使开发者能够将高性能代码生成与生态责任相结合。

英文摘要:

The shift from cloud-hosted Large Language Models (LLMs) to locally deployed open-source Small Language Models (SLMs) has democratized AI-assisted coding; however, it has also decentralized the environmental footprint of AI. While prompting strategies - such as Chain-of-Thought and ReAct - serve as external mechanisms for optimizing code generation without modifying model parameters, their impact on energy consumption and carbon emissions remains largely invisible to developers. This paper presents the first systematic empirical study investigating how different prompt engineering strategies in SLM-based code generation impact code generation accuracy alongside sustainability factors. We evaluate six prominent prompting strategies across 11 open-source models (ranging from 1B to 34B parameters) using the HumanEval+ and MBPP+ benchmarks. By measuring Pass@1 accuracy alongside energy (kWh), carbon emissions (kgCO2eq), and inference latency, we reveal that sustainability often decouples from accuracy, allowing significant environmental optimizations without sacrificing performance. Our findings indicate that Chain-of-Thought, being a simpler prompting technique, can provide a near-optimal balance between reasoning capability and energy efficiency. Conversely, multi-sampling strategies often incur disproportionate costs for marginal gains. Finally, we identify grid carbon intensity as the dominant factor in deployment-time emissions, highlighting the need for practitioners to consider regional energy profiles. This work provides a quantitative foundation for "green" prompt engineering, enabling developers to align high-performance code generation with ecological responsibility.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑