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

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Weidmann, Sophie, Castor, Fernando
Format: Preprint
Publié: 2026
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866913000539029504
author Weidmann, Sophie
Castor, Fernando
author_facet Weidmann, Sophie
Castor, Fernando
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2604_02352
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle An Initial Exploration of Contrastive Prompt Tuning to Generate Energy-Efficient Code
Weidmann, Sophie
Castor, Fernando
Machine Learning
Artificial Intelligence
Software Engineering
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.
title An Initial Exploration of Contrastive Prompt Tuning to Generate Energy-Efficient Code
topic Machine Learning
Artificial Intelligence
Software Engineering
url https://arxiv.org/abs/2604.02352