TL;DR
Researchers have developed Avatar, a novel framework that compresses large language models (LLMs) of code by 160× (down to just 3 MB) while slashing energy consumption and carbon footprints by over 150×. By treating model compression as a multi-objective optimization problem, Avatar enables high-performance, "green" AI to run locally on standard laptops with negligible loss in accuracy.
What Problem Does This Paper Address?
While cloud-based AI tools like GitHub Copilot are transformative, they aren't always ideal. Developers often face unreliable internet, latency issues, or strict institutional privacy policies that forbid sending proprietary code to third-party servers.
The obvious solution is local deployment, but LLMs for code are notoriously "heavy." Popular models like CodeBERT are roughly 500 MB, requiring billions of floating-point operations (FLOPs) per inference. On a typical consumer laptop, running such a model thousands of times a day would drain the battery in less than 15 minutes and generate significant carbon emissions. Existing compression techniques often focus solely on size or speed, frequently ignoring the environmental and energy costs of model execution.
Methods
Avatar approaches model compression as a multi-objective configuration tuning problem. Instead of just training a smaller model, it seeks the best possible architecture and hyperparameters to balance size, speed, energy, and accuracy.
The workflow consists of four main stages:
- Search Space Pruning: The authors identified 13 tunable configurations (e.g., number of layers, hidden size, vocabulary size). To manage the quintillions of possible combinations, they used a Satisfiability Modulo Theories (SMT) solver (Z3) to prune any configuration that would exceed a 3 MB size limit.
- Effectiveness Indicator: Training every possible configuration is too expensive. Avatar samples a small set of configurations, trains them via knowledge distillation, and uses the results to build a regression model. This "indicator" can then predict the accuracy of other configurations without actually training them.
- Multi-Objective Optimization: Using the indicator, Avatar runs an optimization algorithm to find the Pareto-optimal set—configurations where you cannot improve one metric (like speed) without hurting another (like accuracy).
- Knowledge Distillation: Finally, the best configuration is trained using knowledge distillation, where the original large model (the "teacher") teaches the tiny 3 MB model (the "student") to mimic its behavior.
Datasets
The authors evaluated Avatar using two representative encoder-only models, CodeBERT and GraphCodeBERT, across two major software engineering tasks:
- Vulnerability Prediction: Using the Devign dataset (C language), which contains over 27,000 functions annotated for defects.
- Clone Detection: Using the BigCloneBench dataset (Java), which includes over 6 million pairs of code snippets to identify functional duplicates.
Key Insights and Ideas
- FLOPs as a Proxy for "Greenness": The paper uses floating-point operations (FLOPs) as a central metric. By minimizing FLOPs, Avatar simultaneously improves inference latency, energy consumption, and carbon emissions.
- The 3 MB Constraint: The authors targeted a 3 MB file size because it allows models to function as seamless IDE plugins or editor components even on low-end hardware, a standard suggested by industry practitioners.
- Configuration Matters: Unlike prior work (like the baseline Compressor) that only tuned 5 parameters, Avatar tunes 13. This includes often-overlooked factors like the choice of tokenizer and activation functions, which significantly impact a model's ability to capture code semantics.
Key Results
Avatar produced models that were 160× smaller than the originals while maintaining impressive performance. On average, the accuracy loss was only 1.67%.
Compared to the original large models, Avatar achieved:
- Inference Latency: Up to 76× faster.
- Energy Consumption: Up to 184× less.
- Carbon Footprint: Up to 157× less.
When compared to the previous state-of-the-art compression method (Compressor), Avatar was not only more accurate (0.75% higher on average) but also significantly faster (44× faster on average) and more energy-efficient (up to 8× less energy).
Limitations and Future Work
The current study focuses on encoder-only models (like CodeBERT), which are primarily used for classification tasks like defect detection. While these are vital for software quality, they do not perform generative tasks like code completion.
The authors acknowledge this and plan to extend Avatar to generative (decoder-only) models in the future. Additionally, while the "Effectiveness Indicator" saves time, the initial sampling and training phase still requires roughly 10 hours on a high-end GPU—though this is a one-time cost that pays off every time the resulting "green" model is used.
Summary updated