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

Sophie Weidmann, Fernando Castor
3/3/2026
cs.LGcs.AIcs.SE
lora-peft-merging

No confident code implementation found for this paper.

Abstract

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.

Show full abstract

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.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{weidmann2026initial,
  title  = {An Initial Exploration of Contrastive Prompt Tuning to Generate Energy-Efficient Code},
  author = {Sophie Weidmann and Fernando Castor},
  year   = {2026},
  eprint = {2604.02352},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2604.02352v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2604.02352.svg)](https://codeofpaper.com/paper/2604.02352)

Discussion