Compressing Pre-trained Models of Code into 3 MB

Jieke Shi, Zhou Yang, Bowen Xu, Hong Jin Kang, David Lo

Introduction

Pre-trained models of code, such as CodeBERT, have significantly advanced software engineering tasks like vulnerability prediction and clone detection. However, these models are often prohibitively large, typically exceeding 100 million parameters and 500 MB in size. This scale introduces significant latency—often over 1.5 seconds per request on a standard CPU—and exceeds the deployment constraints of most IDE plugin ecosystems, which ideally require footprints under 50 MB, and preferably as small as 3 MB for restricted environments.

To bridge this gap, researchers have introduced Compressor, a framework designed to shrink these massive models by up to 160x while maintaining high performance. By achieving a final model size of just 3 MB, Compressor enables state-of-the-art code analysis to run efficiently on consumer-grade hardware and within lightweight developer tools.

The Limitations of Existing Compression

Standard model compression techniques often struggle with the specific architecture of code models. Pruning, which removes redundant connections, frequently leaves the large embedding tables (often ~150 MB) untouched. Quantization, which reduces numerical precision, often requires specialized hardware to realize actual speed improvements on CPUs. Compressor addresses these issues by searching for a "tiny" architecture that is natively small and fast, rather than merely trimming a large one.

The Compressor Framework

Compressor utilizes a two-stage process: Genetic Algorithm (GA)-guided model simplification and Knowledge Distillation (KD).

1. GA-Guided Model Simplification

Instead of manual architecture design, Compressor searches for an optimal tiny configuration within a search space of 11 million possibilities. The search varies five critical hyperparameters:

  • Number of layers ($L$)
  • Hidden size ($H$)
  • Attention heads ($A$)
  • Feed-forward dimensions ($D$)
  • Vocabulary size ($V$)

A key innovation in this stage is the "fitness" function used by the GA. Since training every candidate model is computationally impossible, Compressor uses GFLOPs (computational cost) as a proxy for model capacity. The algorithm seeks to maximize GFLOPs—ensuring the model has enough complexity to learn—while strictly adhering to the 3 MB size limit. This approach specifically targets the embedding table bottleneck by allowing the vocabulary size to shrink from 50,000 to as low as 1,000.

2. Knowledge Distillation (KD)

After identifying the optimal tiny architecture (the "Student"), Compressor trains it using a "Teacher-Student" paradigm. A large, pre-trained model (the "Teacher") processes unlabeled code, and its outputs serve as the ground truth for the Student. This allows the 3 MB model to inherit the complex reasoning capabilities of the 500 MB model without requiring massive amounts of manually labeled data.

Evaluation and Results

The framework was evaluated on two major benchmarks: Devign (Vulnerability Prediction in C) and BigCloneBench (Clone Detection in Java).

The results demonstrate that Compressor achieves extreme compression without sacrificing utility:

  • Size Reduction: Models were compressed from 481 MB to 3 MB (a 160x reduction).
  • Efficiency: Inference speed improved by 4.15x to 4.31x on standard CPUs.
  • Performance Retention: On Vulnerability Prediction, the 3 MB models retained 96-97% of the original accuracy. On Clone Detection, performance retention exceeded 97-99%.
  • Superiority over Baselines: Compressor reduced accuracy loss by 49% to 87% compared to previous state-of-the-art distillation methods like BiLSTM-soft.

Conclusion and Future Work

Compressor demonstrates that massive pre-trained models of code can be distilled into extremely small footprints suitable for real-time IDE integration. By prioritizing model capacity (via GFLOPs) within strict size constraints and optimizing the embedding table, the framework sets a new standard for deployable AI in software engineering.

While highly effective for classification tasks using encoder-only models, future work will explore extending this methodology to generative models (decoder-only) and more complex tasks such as code summarization and translation.

Summary updated

BibTeX
@inproceedings{shi2022compressing,
  author = {Jieke Shi and Zhou Yang and Bowen Xu and Hong Jin Kang and David Lo},
  title = {{Compressing Pre-trained Models of Code into 3 MB}},
  booktitle = {ASE},
  year = {2022},
  url = {https://openreview.net/forum?id=ieJt0P6AcU},
}
Figure