Transformer Compression via Subspace Projection

Yuxuan Hu, Jing Zhang, Chen Zhao, Cuiping Li, Hong Chen

Abstract

Structured pruning is a widely used technique for reducing the size of pre-trained language models (PLMs), but current methods often overlook the potential of compressing the hidden dimension ($d$) in PLMs, a dimension critical to model size and efficiency. This paper introduces a novel structured pruning approach, Structured Pruning with PCA Projection (SP3), targeting the effective reduction of $d$ by projecting features into a space defined by principal components before masking. Extensive experiments on benchmarks (GLUE and SQuAD) show that SP3 can reduce $d$ by 70%, compress 94% of the BERT-base model, maintain over 96% accuracy, and outperform other methods that compress $d$ by 6% in accuracy at the same compression ratio. SP3 has also proven effective with other models, including OPT and Llama.

Introduction

Pre-trained language models (PLMs) like BERT and Llama are incredibly powerful but notoriously "heavy," requiring massive memory and compute power. While structured pruning—the process of removing entire components like attention heads or layers—is a popular way to slim them down, it has a major blind spot: the hidden dimension ($d$).

The hidden dimension is the "width" of the data flowing through the model. Most current pruning methods struggle to reduce $d$ effectively because information is spread across the entire feature space; cutting out a specific index in the original space often destroys vital information. Furthermore, the "residual connections" in Transformer architectures usually force every layer to have the same width, making it impossible to customize compression for different parts of the model.

Structured Pruning with PCA Projection (SP³)

The authors introduce SP³, which tackles these issues through three main innovations:

1. PCA Projection

Instead of pruning in the original feature space, SP³ uses a small "calibration" dataset to perform Singular Value Decomposition (SVD) on the model's internal features. It then inserts projection matrices that shift the features into a space defined by their principal components. In this new space, the most important information is concentrated in just a few dimensions, making it much easier for a pruning mask to "snip" the unimportant ones.

Overview of the SP³ methodology, including PCA projection and residual modification.

2. Residual Modification

To break the "one-size-fits-all" width constraint, the authors add small linear transformations to the residual connections. This allows each layer to have its own unique, optimized hidden dimension.

Detailed integration of projection matrices into MHA and FFN blocks.

3. Multi-stage Pruning

The training process is split. First, the model focuses on pruning dimensions within the PCA space. Later, it adds masks for attention heads and entire layers. This hierarchical approach ensures the model stabilizes its internal representations before making "coarser" cuts.

Experimental Setup

The researchers evaluated SP³ across a wide range of standard NLP benchmarks:

  • GLUE: A collection of diverse natural language understanding tasks (MNLI, QQP, QNLI, SST-2, MRPC, STS-B, RTE).
  • SQuAD v1.1: A popular reading comprehension/question-answering dataset.
  • LLM Benchmarks: For testing on models like Llama and OPT, they used commonsense reasoning tasks including Hellaswag, OpenBookQA, WinoGrande, and PIQA.

Key Insights

  • The "Subspace" Secret: The authors observed that high-dimensional features in PLMs actually live in much lower-dimensional subspaces. Crucially, the "shape" of these subspaces changes from layer to layer.
  • PCA as a "Surgical" Tool: Traditional pruning is like trying to lose weight by randomly removing body parts. PCA projection is more like liposuction—it identifies exactly where the "fat" (unimportant variance) is so it can be removed without affecting vital functions.
  • Group PCA for LLMs: To avoid adding too many extra parameters in the residual connections of massive models (LLMs), they proposed "Group PCA Projection," which shares the same principal component basis across several consecutive blocks. This keeps the overhead as low as 1%.

Results

  • Massive Shrinkage: SP³ compressed BERT-base by 94% (down to ~5M parameters) while retaining 96.4% of the original performance.
  • Superior Accuracy: At the same compression ratio, SP³ outperformed the previous state-of-the-art method (CoFi) by 6% in accuracy.
  • Hidden Dimension Reduction: While previous methods barely touched the hidden dimension (e.g., reducing it from 768 to 760), SP³ successfully slashed it by 70%.
  • Efficiency: The PCA projection process is remarkably fast, taking only about 5 minutes for a 100M parameter model.

Limitations and Future Work

While Group PCA helps, the method still introduces extra weight matrices in the residual paths. In very small compressed models (e.g., 5M parameters), these extra weights can account for nearly half the model's size. Furthermore, the "fine-grained" nature of dimension pruning requires further exploration to achieve maximum acceleration on standard hardware (like GPUs). Finally, when pruning LLMs with very limited Supervised Fine-Tuning (SFT) data, the model can occasionally overfit; "tuning-free" pruning techniques are a potential area for future research.

Summary updated

BibTeX
@inproceedings{hu2024transformer,
  author = {Yuxuan Hu and Jing Zhang and Chen Zhao and Cuiping Li and Hong Chen},
  title = {{Transformer Compression via Subspace Projection}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.187},
}
Figure