Abstract
Pre-trained Language Models (PLMs) like BERT have set new standards in NLP but remain computationally expensive for real-time deployment. Structured pruning typically removes entire attention heads, which can be overly coarse. We present GRAIN (Gradient-based Intra-attention pruning), a method that prunes inside attention heads and utilizes a gradient separation strategy to decouple pruning importance from distillation signals. GRAIN achieves 6x to 7x speedups on standard benchmarks like MNLI while retaining over 93% of original performance, even at 95% sparsity.
Introduction
The deployment of large-scale Transformers on edge devices is limited by their high latency and memory footprint. Structured pruning is a common mitigation strategy, yet it faces two primary challenges. First, existing methods often treat attention heads as atomic units, limiting the architectural search space. Second, when combined with Knowledge Distillation (KD), the distillation loss can interfere with the gradient-based importance scores used for pruning, leading to suboptimal structures.
Methods
The GRAIN framework integrates several innovations to address these gaps:
- Intra-attention Pruning Units: Unlike traditional methods that remove entire heads, GRAIN prunes internal rows of the $W^Q, W^K, W^V,$ and $W^O$ matrices. This allows for "thin" or "asymmetric" heads, where query and value dimensions can be optimized independently.
- Gradient Separation (GS): To resolve the conflict between distillation and pruning, GRAIN uses standard cross-entropy loss to calculate importance scores, while using a combination of cross-entropy and hidden-layer distillation losses to update model weights.
- Structure Regularization (StructReg): To prevent hardware-inefficient fragmentation, a penalty term encourages the complete removal of small, underutilized heads.
- Embedding Factorization: Singular Value Decomposition (SVD) is applied to the word embedding matrix to reduce parameter count without impacting inference latency.
Results
GRAIN was evaluated on GLUE, SQuAD 1.1, and various Chinese benchmarks. A key finding is that GRAIN consistently outperforms state-of-the-art methods like CoFi and Block Pruning, particularly at low model densities.
Key Insights
- Granularity and Search Space: Allowing asymmetric head sizes reveals that some heads require high value-unit complexity for information routing but low query-unit complexity for attention mapping.
- Hardware Efficiency: Without StructReg, theoretical sparsity does not translate to real-world speedup. GRAIN's regularization ensures the resulting architecture remains GPU-friendly.
- Extreme Compression: Even when reducing the Transformer to just 3% of its original weights (approx. 2.6M parameters), the model remains competitive with significantly larger baselines.
Conclusion
GRAIN demonstrates that fine-grained structured pruning, when properly regularized and decoupled from distillation interference, can produce highly efficient PLMs. Future work includes developing custom CUDA kernels to further optimize non-uniform attention structures and extending the method to decoder-only architectures like GPT.
Summary updated