Green-Code: Learning to Optimize Energy Efficiency in Llm-Based Code Generation
Authors:
- 19 May 2025
- conference paper
- Published by Institute of Electrical and Electronics Engineers (IEEE)
- p. 559-569
Abstract
Large Language Models (LLMs) are becoming integral to daily life, showcasing their vast potential across various Natural Language Processing (NLP) tasks. Beyond NLP, LLMs are increasingly used in software development tasks, such as code completion, modification, bug fixing, and code translation. Software engineers widely use tools like GitHub Copilot and Amazon Q, streamlining workflows and automating tasks with high accuracy. While the resource and energy intensity of LLM training is often highlighted, inference can be even more resourceintensive over time, as it's a continuous process with a high number of invocations. Therefore, developing resource-efficient alternatives for LLM inference is crucial for sustainability. This work proposes GREEN-CODE, a framework for energy-aware code generation in LLMs. GREEN-CODE performs dynamic early exit during LLM inference. We train a Reinforcement Learning (RL) agent that learns to balance the trade-offs between accuracy, latency, and energy consumption. Our approach is evaluated on two open-source LLMs, Llama 3.2 3B and OPT 2.7 B, using the JavaCorpus and PY150 datasets. Results show that our method reduces the energy consumption between 2350 % on average for code generation tasks without significantly affecting accuracy.Keywords
All Related Versions
This publication has 18 references indexed in Scilit:
- Proximal Policy Optimization in StarCraft2025
- When Neural Code Completion Models Size up the Situation: Attaining Cheaper and Faster Completion through Dynamic Model Inference2024
- ConsistentEE: A Consistent and Hardness-Guided Early Exiting Method for Accelerating Language Models InferenceProceedings of the AAAI Conference on Artificial Intelligence, 2024
- The growing energy footprint of artificial intelligenceJoule, 2023
- Out of the BLEU: How should we assess quality of the Code Generation models?Journal of Systems and Software, 2023
- Post-training Quantization with Multiple Points: Mixed Precision without Mixed PrecisionProceedings of the AAAI Conference on Artificial Intelligence, 2021
- A Data-Driven Frequency Scaling Approach for Deadline-aware Energy Efficient Scheduling on Graphics Processing Units (GPUs)2020
- DeeBERT: Dynamic Early Exiting for Accelerating BERT Inference2020
- Probabilistic model for code with decision trees2016
- Mining source code repositories at massive scale using language modeling2013