Structured Pruning Learns Compact and Accurate Models

Mengzhou Xia, Zexuan Zhong, Danqi Chen

Introduction

Large Language Models (LLMs) like BERT have revolutionized natural language processing but come with significant computational costs, hindering deployment on edge devices and in low-latency environments. To address this, researchers typically employ two strategies: pruning and knowledge distillation.

While unstructured pruning can achieve high sparsity, it rarely translates to real-world hardware speedups. Conversely, structured pruning (removing entire rows or heads) offers speed but often at a steep cost to accuracy. Knowledge distillation, exemplified by models like TinyBERT, produces efficient students but requires massive unlabeled datasets and days of pre-training. This paper introduces CoFi (Coarse- and Fine-grained Pruning), a structured pruning method that bridges this gap, delivering over 10× hardware speedups with minimal accuracy loss and significantly reduced training overhead.

Methodology: Coarse- and Fine-grained Pruning (CoFi)

CoFi treats model compression as a search for the optimal "sub-network" within a pre-trained model. It integrates two primary innovations to achieve high efficiency and performance.

Multi-Granularity Masking

Instead of focusing on a single type of structural unit, CoFi applies a hierarchy of learnable masks ($z$) across five components:

  • Coarse-grained: Entire Multi-Head Attention (MHA) layers and Feed-Forward Network (FFN) layers.
  • Fine-grained: Individual attention heads, intermediate dimensions in FFNs, and the hidden dimensions shared across the model.

By employing $L_0$ regularization via hard concrete distributions, the model learns which masks to deactivate during training. Because these masks correspond to hardware-friendly blocks, their removal results in immediate inference speedups.

Comparison of the TinyBERT distillation pipeline versus the CoFi pruning approach, including a breakdown of prunable units.

Dynamic Layerwise Distillation

In standard distillation, a student's layer is typically mapped to a teacher's layer in a fixed manner. However, as CoFi prunes the model, the architecture changes dynamically. CoFi utilizes a dynamic mapping function that calculates the distance between student and teacher layers, matching them on the fly. This ensures that the student consistently learns from the most relevant teacher representations even as its own layers are being removed.

Key Insights

  • Layer Pruning is Essential for Speed: The researchers found that explicitly pruning entire layers is the only way to surpass the "2-3× speedup ceiling" common in previous pruning literature. Without coarse-grained layer pruning, even extremely sparse models fail to reach 10× speedups.
  • FFN Redundancy: Pruned models consistently showed that Feed-Forward layers were more redundant than Multi-Head Attention layers, suggesting the attention mechanism is the primary performance bottleneck.
  • Joint Optimization: Pruning hidden dimensions (model width) across all layers simultaneously, rather than layer-by-layer, allows the model to maintain a cohesive internal representation, preserving accuracy at high sparsity levels.

Experimental Results

The authors evaluated CoFi on the GLUE benchmark and SQuAD v1.1, comparing it against baselines like DistillBERT and TinyBERT.

  • Significant Speedups: CoFi achieved a 12.1× speedup on MNLI and 11.9× on MRPC.
  • High Sparsity and Accuracy: At approximately 95% sparsity (leaving only ~4.4M parameters), CoFi retained roughly 95% of the teacher's accuracy. On MNLI, it achieved 80.6% accuracy compared to the teacher's 84.8%.
  • Training Efficiency: Unlike TinyBERT, which requires a 3.5-day "General Distillation" phase on 4 GPUs, CoFi completes its task-specific pruning in under 20 hours on a single GPU, outperforming TinyBERT on several tasks when data augmentation is not used.

Conclusion

CoFi demonstrates that structured pruning, when combined with multi-granularity masking and dynamic distillation, can produce models that are both incredibly fast and highly accurate. By eliminating the need for expensive general distillation phases, CoFi provides a more accessible path for compressing large-scale transformers for real-world applications. Future work may explore "upstream" pruning during the pre-training phase to create task-agnostic compact models.

Summary updated

BibTeX
@inproceedings{xia2022structured,
  author = {Mengzhou Xia and Zexuan Zhong and Danqi Chen},
  title = {{Structured Pruning Learns Compact and Accurate Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=hL7JXhrRhS},
}
Figure