Abstract
Large language models of code have shown remarkable effectiveness across various software engineering tasks. Despite the availability of many cloud services built upon these powerful models, there remain several scenarios where developers cannot take full advantage of them, stemming from factors such as restricted or unreliable internet access, institutional privacy policies that prohibit external transmission of code to third-party vendors, and more. Therefore, developing a compact, efficient, and yet energy-saving model for deployment on developers' devices becomes essential. To this aim, we propose Avatar, a novel approach that crafts a deployable model from a large language model of code by optimizing it in terms of model size, inference latency, energy consumption, and carbon footprint while maintaining a comparable level of effectiveness. The key idea of Avatar is to formulate the optimization of language models as a multi-objective configuration tuning problem and solve it with the help of a Satisfiability Modulo Theories (SMT) solver and a tailored optimization algorithm. The SMT solver is used to form an appropriate configuration space, while the optimization algorithm identifies the Pareto-optimal set of configurations for training the optimized models using knowledge distillation. We evaluate Avatar with two popular language models of code, i.e., CodeBERT and GraphCodeBERT, on two popular tasks, i.e., vulnerability prediction and clone detection. We use Avatar to produce optimized models with a small size (3 MB), which is 160× smaller than the original large models. On the two tasks, the optimized models significantly reduce the energy consumption (up to 184× less), carbon footprint (up to 157× less), and inference latency (up to 76× faster), with only a negligible loss in effectiveness (1.67% on average).
Introduction
While cloud-based AI tools like GitHub Copilot have transformed software development, they are not universally applicable. Developers often face challenges such as unreliable internet connectivity, high latency, or strict institutional privacy policies that forbid sending proprietary code to third-party servers. These constraints necessitate local deployment of models on developer workstations.
However, state-of-the-art Large Language Models (LLMs) for code, such as CodeBERT, are notoriously resource-intensive. Typically exceeding 500 MB in size and requiring billions of floating-point operations (FLOPs) per inference, these models can rapidly drain a laptop's battery and generate a significant carbon footprint. Existing compression techniques often prioritize size or speed in isolation, neglecting the broader environmental and energy costs. To address this, we introduce Avatar, a framework designed to compress LLMs for code by 160× while drastically reducing their environmental impact.
The Avatar Framework
Avatar treats model compression as a multi-objective configuration tuning problem. Rather than simply training a smaller version of an existing model, Avatar searches for the optimal architecture and hyperparameter set to balance size, speed, energy efficiency, and predictive accuracy.
The workflow consists of four primary stages:
- Search Space Pruning: The framework identifies 13 tunable configurations, including hidden size, number of layers, and vocabulary size. To navigate the vast search space, a Satisfiability Modulo Theories (SMT) solver (Z3) is employed to prune any configuration that would exceed a strict 3 MB size limit.
- Effectiveness Indicator: To avoid the prohibitive cost of training every valid configuration, Avatar samples a small subset, trains them via knowledge distillation, and builds a regression model. This "indicator" predicts the accuracy of remaining configurations without full training.
- Multi-Objective Optimization: Using the indicator, Avatar identifies the Pareto-optimal set—configurations where no single metric (e.g., latency) can be improved without degrading another (e.g., accuracy).
- Knowledge Distillation: The final optimized configuration is trained using knowledge distillation, where the original large model acts as a "teacher" to guide the tiny 3 MB "student" model.
Experimental Evaluation
We evaluated Avatar using two representative encoder-only models, CodeBERT and GraphCodeBERT, across two critical software engineering tasks:
- Vulnerability Prediction: Evaluated on the Devign dataset (C language), containing over 27,000 annotated functions.
- Clone Detection: Evaluated on the BigCloneBench dataset (Java), which includes over 6 million code snippet pairs.
A central tenet of Avatar is using FLOPs as a proxy for "greenness." By minimizing FLOPs, the framework simultaneously improves inference latency, energy consumption, and carbon emissions. The 3 MB target was chosen to ensure models can function as lightweight IDE plugins even on low-end hardware.
Results and Discussion
Avatar successfully produced models that were 160× smaller than the originals with a negligible average accuracy loss of only 1.67%. The quantitative improvements in efficiency were substantial across all metrics.
As shown in the results, Avatar achieved:
- Inference Latency: Up to 76× faster execution.
- Energy Consumption: Up to 184× reduction in power usage.
- Carbon Footprint: Up to 157× lower CO2 emissions.
When compared to previous state-of-the-art compression methods like Compressor, Avatar demonstrated superior accuracy (0.75% higher on average) while being significantly faster (44×) and more energy-efficient (up to 8×).
Conclusion and Future Work
Avatar demonstrates that it is possible to create highly efficient, "green" AI models for code that can run locally on standard hardware without sacrificing significant performance. While this study focused on encoder-only models for classification tasks, future work will extend the Avatar framework to generative (decoder-only) models to support tasks like automated code completion. Although the initial optimization phase requires approximately 10 hours of GPU time, this one-time cost enables long-term, sustainable deployment for developers worldwide.
Summary updated