Efficiently Distilling LLMs for Edge Applications

Achintya Kundu, Fabian Lim, Aaron Chew, Laura Wynter, Penny Chong, Rhui Dih Lee

Introduction

Deploying Large Language Models (LLMs) on edge devices—such as smartphones or IoT sensors—is a significant challenge due to limited memory and the vast diversity of hardware. Traditionally, developers must fine-tune a separate model for every device profile, a process that is computationally expensive and difficult to scale.

IBM Research recently introduced MLFS (Multistage Low-rank Fine-tuning of Super-transformers) at NAACL 2024. This method produces a "palette" of high-quality models of varying sizes from a single training run, enabling efficient deployment across a wide spectrum of hardware.

The Deployment Gap

Enterprises require models that can fit diverse hardware and adapt to dynamic resource constraints, such as low battery levels. While existing solutions like DistilBERT produce a single compressed model, they lack the flexibility needed for heterogeneous device environments. Supernets offer a theoretical solution by sharing weights across multiple subnets, but training them from scratch is prohibitively expensive. MLFS bridges this gap by combining Supernet training with Low-Rank Adaptation (LoRA).

Methodology: The MLFS Approach

MLFS introduces three key innovations to make Supernet training efficient and effective:

  1. Multistage Training: The process begins with fine-tuning the full teacher model using LoRA (Stage 0). It then proceeds to sample subnets of different widths (Stage 1) and finally both widths and depths (Stage 2).
  2. Gradient Scaling: To prevent the large "maxnet" from dominating the optimization, the authors use a scaling scheme that boosts gradients for smaller subnets. This ensures that the entire range of models in the palette achieves high performance.
  3. Efficient Feature Distillation: A shared projection matrix is used to distill knowledge from the teacher's internal layers to the subnets without excessive memory overhead.
Impact of gradient scaling on training loss for MRPC and RTE datasets.

Key Insights: Gradient Scaling and the "Palette"

The "secret sauce" of MLFS is gradient scaling. As shown in the training loss curves, incorporating gradient scaling allows smaller subnets to converge more effectively, preventing them from underperforming relative to the larger models in the Supernet.

Once trained, the Supernet acts as a "palette," allowing users to "slice" out a model of almost any size (e.g., 45M or 80M parameters) without additional training. This flexibility is a major advantage over traditional distillation methods that produce a single fixed-size output.

Results and Performance

The researchers evaluated MLFS on both encoder (BERT) and decoder (CodeLlama) architectures.

Encoder Performance

On the GLUE benchmark, MLFS produced BERT models that were 1/4 the size and had 1/3 the latency of the original teacher. As illustrated below, MLFS maintains accuracy levels comparable to or better than state-of-the-art distillation methods like TinyBERT and BERT-PKD across various parameter counts.

Accuracy vs. parameter count on SST2, showing MLFS's ability to produce a range of efficient models.

Decoder Efficiency

For decoder models, MLFS significantly speeds up the creation of smaller versions. Slicing a 0.7B model from a 1.1B teacher reached low validation loss much faster than training a 0.7B model from scratch. However, the authors noted a "compression floor" for decoders; performance drops significantly if reduced beyond 2/3 of the teacher's size, suggesting generative capabilities are more parameter-dependent than understanding tasks.

Conclusion

MLFS offers a scalable solution for deploying LLMs on the edge. By producing a palette of models from a single training run using LoRA and gradient scaling, it reduces the computational burden of model compression while providing the flexibility needed for diverse hardware ecosystems. Future work will explore why decoders are more resistant to heavy compression and how to further optimize their "slicing" process.

Summary updated

BibTeX
@inproceedings{kundu2024efficiently,
  author = {Achintya Kundu and Fabian Lim and Aaron Chew and Laura Wynter and Penny Chong and Rhui Dih Lee},
  title = {{Efficiently Distilling LLMs for Edge Applications}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-industry.5},
}
Figure