A Survey on Transformer Compression

Yehui Tang, Yunhe Wang, Jianyuan Guo, Zhijun Tu, Kai Han, Hailin Hu, Dacheng Tao

TL;DR

This survey provides a comprehensive roadmap for compressing massive Transformer models, like GPT-4 and ViT, to make them deployable on everyday hardware. It categorizes the latest research into four main pillars—quantization, pruning, knowledge distillation, and efficient architecture design—while highlighting the unique challenges of compressing models with billions of parameters where retraining is no longer an option.

What Problem Does This Paper Address?

We are currently in the era of "Large Models." Whether it’s Large Language Models (LLMs) like GPT-3 or Large Vision Models (LVMs) like ViT, these architectures are becoming gargantuan. For context, GPT-3 has 175 billion parameters, requiring roughly 350GB of memory just to store the weights in float16 format.

This massive scale creates a "deployment gap." These models are too big for mobile phones, too expensive for many cloud applications, and contribute significantly to carbon emissions. Furthermore, because these models are so expensive to train, traditional compression methods that require retraining the entire model on the original dataset are often impractical. The authors tackle the question: How do we shrink these giants without losing their "intelligence," and how do we do it efficiently?

Methods

The paper categorizes compression techniques into four primary strategies, as illustrated in the overview below:

Fig. 1: Transformer-based models have emerged as the predominant architectures in both natural language processing (NLP) and computer vision (CV) domains, resulting in a surge in publications. As these models tend to possess substantial dimensions, it becomes imperative to compress their parameters and streamline computational redundancies. This compression is essential for facilitating efficient implementation on practical platforms, ensuring the feasibility of deploying Transformer models in real-world applications.
  1. Quantization: Reducing the precision of weights and activations (e.g., from 32-bit floating point to 8-bit or 4-bit integers). The paper distinguishes between Post-Training Quantization (PTQ), which is fast and requires little data, and Quantization-Aware Training (QAT), which is more accurate but computationally heavy.
  2. Knowledge Distillation (KD): A "teacher-student" approach where a small model (student) learns to mimic the behavior of a large model (teacher). This includes API-based distillation, where researchers use the outputs of closed-source models like GPT-4 to train smaller, open-source alternatives.
  3. Pruning: Removing redundant components. This can be unstructured (removing individual weights) or structured (removing entire attention heads, layers, or tokens).
  4. Efficient Architecture Design: Rethinking the Transformer itself. This includes Linear Attention to solve the $O(N^2)$ complexity problem and emerging architectures like State Space Models (SSMs)—specifically Mamba—which offer linear scaling for long sequences.

Datasets

The survey references results across several standard benchmarks:

  • NLP: GLUE (General Language Understanding Evaluation) for BERT-style models, and WikiText2 (measuring perplexity) for generative LLMs like LLaMA and OPT.
  • CV: ImageNet-1k is the primary benchmark for evaluating compressed Vision Transformers (ViTs) and Swin Transformers.

Key Insights and Ideas

  • The Outlier Problem: A major discovery in LLM quantization is that activations contain "outliers"—specific channels with massive values. If you don't handle these (e.g., via methods like SmoothQuant), 8-bit quantization fails.
  • Hardware-Friendly Pruning: While removing individual weights (unstructured pruning) looks good on paper, it rarely speeds up models on standard GPUs. The field is shifting toward structured pruning (removing entire heads or blocks) and context pruning (removing less important tokens in long prompts).
  • Beyond the Transformer: The survey highlights a significant shift toward sub-quadratic architectures. Models like RetNet and Mamba are designed to provide the performance of Transformers but with the inference efficiency of RNNs.
  • API-Based Learning: For the first time, we are seeing "black-box" distillation. Since we can't see the weights of models like GPT-4, researchers are using the model's reasoning (Chain-of-Thought) as the training signal for smaller models.

Key Results

Compression isn't just a theoretical exercise; it yields massive practical gains. The authors highlight that:

  • Quantization Speedups: Moving from FP16 to INT8 can reduce latency by nearly 50% on high-end GPUs like the A100 for models like OPT-175B.
Inference latency comparison between FP16 and INT8/W8A8 across various model sizes.
  • Distillation Efficiency: Models like TinyBERT can achieve over 99% of the performance of a full BERT-base model while being 7.5x smaller and 9.4x faster.
  • Pruning Sparsity: Methods like SparseGPT can prune 50-60% of a 175B parameter model in a few hours with negligible loss in accuracy, proving that even the largest models are highly redundant.

Limitations and Future Work

Despite the progress, several hurdles remain:

  • The 4-bit Wall: While 8-bit quantization is nearly "lossless," moving to 4-bit or lower (like binary 1-bit models) still causes significant performance degradation in large models.
  • Structural Recovery: When you prune entire layers or heads, the model's "brain" is physically altered. Finding ways to recover that lost knowledge without a full retrain is a major open research area.
  • Multimodal Complexity: Most current research focuses on text-only or image-only models. Compressing multimodal models (like those that handle video and text simultaneously) introduces new, unexplored redundancies.

The authors conclude that the future lies in joint search: combining pruning, quantization, and distillation into a single, automated pipeline to find the optimal "tiny" version of today's AI giants.

Summary updated

BibTeX
@misc{tang2024survey,
  author = {Yehui Tang and Yunhe Wang and Jianyuan Guo and Zhijun Tu and Kai Han and Hailin Hu and Dacheng Tao},
  title = {{A Survey on Transformer Compression}},
  year = {2024},
  eprint = {2402.05964},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.05964},
}
Figure