Adapting by Pruning: A Case Study on BERT

Yang Gao, Nicolò Colombo, Wei Wang · DOI

Abstract

Adapting pre-trained neural models to downstream tasks has become the standard practice for obtaining high-quality models. In this work, we propose a novel model adaptation paradigm, adapting by pruning, which prunes neural connections in the pre-trained model to optimise the performance on the target task; all remaining connections have their weights intact. We formulate adapting-by-pruning as an optimisation problem with a differentiable loss and propose an efficient algorithm to prune the model. We prove that the algorithm is near-optimal under standard assumptions and apply the algorithm to adapt BERT to some GLUE tasks. Results suggest that our method can prune up to 50% weights in BERT while yielding similar performance compared to the fine-tuned full model. We also compare our method with other state-of-the-art pruning methods and study the topological differences of their obtained sub-networks.

Introduction

The prevailing paradigm in Natural Language Processing involves taking a large-scale pre-trained model, such as BERT, and fine-tuning its weights for specific downstream tasks. While this approach yields high performance, it introduces significant challenges in storage and inference efficiency. Fine-tuning requires storing a complete set of updated weights for every task, leading to substantial storage bloat. Furthermore, the resulting models remain over-parameterized, hindering deployment on resource-constrained edge devices.

Traditional alternatives like feature extraction (training only a task-specific head) often suffer from performance degradation. Parameter-efficient methods like adapters add new parameters, which, while small, still increase the overall model footprint. This research explores a different question: Can we adapt a model to a new task without modifying its original weights or adding significant new parameters?

Methodology: Adapt by Pruning

The authors propose Adapt by Pruning, a paradigm that identifies task-specific sub-networks within a frozen pre-trained model. Instead of updating weight values ($w$), the method learns a binary mask ($m$) that determines which connections are active for a given task.

Comparison of adaptation paradigms: Feature Extraction, Fine Tuning, Standard Pruning, and the proposed Adapt by Pruning.

The Supermask Approach

Inspired by the Lottery Ticket Hypothesis, the pre-trained model is viewed as a collection of many possible sub-networks. The goal is to find the "winning ticket"—a sub-network that performs well on the target task using only the original pre-trained weights.

Differentiable Masking and Optimization

Finding an optimal binary mask is a discrete combinatorial problem. To make it tractable, the authors use a continuous approximation. They learn a real-valued tensor $\theta$ and apply a sigmoid function to generate a "soft" mask. To mitigate vanishing gradients during optimization, a temperature-based gradient trick is employed, using a larger constant for the forward pass and a smaller one for backpropagation.

A critical feature of this algorithm is Connection Recovery. Unlike standard iterative pruning, where connections are permanently removed, this method allows previously pruned connections to be "reactivated" if the optimization process determines they are beneficial for the task.

Experimental Results

The method was evaluated on three tasks from the GLUE benchmark: STS-B (regression), SST-2 (sentiment analysis), and MNLI (natural language inference).

Performance comparison across STS-B, SST-2, and MNLI tasks at various sparsity levels. The proposed method (Ours) consistently outperforms standard pruning baselines.

Performance and Sparsity

The results demonstrate that "Adapt by Pruning" can achieve performance comparable to full fine-tuning while removing up to 50% of the model's connections. On the MNLI task, the method maintained competitive performance even at 99.5% sparsity, significantly outperforming the feature extraction baseline.

Topological Insights

Analysis of the resulting sub-networks revealed that the weights found by this method differ topologically from those identified by magnitude-based pruning. At high sparsity levels, "Adapt by Pruning" tends to retain more weights within the Transformer layers compared to the embedding layers. This suggests that the structural "logic" captured in the attention mechanisms is more critical for task adaptation than raw vocabulary lookups.

Conclusion

"Adapt by Pruning" offers a compelling alternative to traditional fine-tuning. By demonstrating that BERT’s pre-trained weights are sufficiently expressive to solve downstream tasks through selection alone, this work paves the way for more efficient multi-task deployment. Multiple tasks can share a single base model in memory, requiring only the storage of lightweight binary masks. Future work will explore the scalability of this approach to larger generative models and its implementation on specialized hardware for real-world speedups.

Summary updated

BibTeX
@misc{gao2021adapting,
  author = {Yang Gao and Nicolò Colombo and Wei Wang},
  title = {{Adapting by Pruning: A Case Study on BERT}},
  year = {2021},
  eprint = {2105.03343},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2105.03343},
}
Figure