Abstract Transformer-based pre-trained language models have significantly improved the performance of various natural language processing (NLP) tasks in the recent years. While effective and prevalent, these models are usually prohibitively large for resource-limited deployment scenarios. A thread of research has thus been working on applying network pruning techniques under the pretrain-then-finetune paradigm widely adopted in NLP. However, the existing pruning results on benchmark transformers, such as BERT, are not as remarkable as the pruning results in the literature of convolutional neural networks (CNNs). In particular, common wisdom in pruning CNN states that sparse pruning technique compresses a model more than that obtained by reducing number of channels and layers (Elsen et al., 2020; Zhu and Gupta, 2017), while existing works on sparse pruning of BERT yields inferior results than its small-dense counterparts such as TinyBERT (Jiao et al., 2020). In this work, we aim to fill this gap by studying how knowledge are transferred and lost during the pre-train, fine-tune, and pruning process, and proposing a knowledge-aware sparse pruning process that achieves significantly superior results than existing literature. We show for the first time that sparse pruning compresses a BERT model significantly more than reducing its number of channels and layers. Experiments on multiple data sets of GLUE benchmark show that our method outperforms the leading competitors with a 20-times weight/FLOPs compression and neglectable loss in prediction accuracy 1 . of natural language processing (NLP) tasks. These models are pre-trained in a self-supervised fashion and then fine-tuned for supervised downstream tasks. However, these models suffer from the heavy model size, making them impractical for resource-limited deployment scenarios and incurring cost concerns (Strubell et al., 2019). In parallel, an emerging subfield has studied the redundancy in deep neural network models (Zhu and Gupta, 2017; Gale et al., 2019) and proposed to prune networks without sacrificing performance, such as the lottery ticket hypothesis (Frankle and Carbin, 2019). Common wisdom in CNN literature shows that sparse pruning leads to more compression rate than structural pruning. For example, for the same number of parameters (0.46M), the sparse MobileNets improve by 11.2% accuracy over the dense ones (Zhu and Gupta, 2017). However, similar conclusions are not observed for pre-trained language models. The main question this paper attempts to answer is: how to perform sparse pruning under the pre-train and fine-tune paradigm? Answering this question correctly is challenging. First, these models adopt pre-training and fine-tuning procedures, during which the general-purpose language knowledge and the task-specific knowledge are learned respectively. Thus, it is desirable and challenging to keep the weights that are important to both knowledge during pruning. Second, unlike CNNs, pre-trained language models have a complex architecture consisting of embedding, self-attention, and feed-forward layers. To address these challenges, we propose SparseBERT, a knowledge-aware sparse pruning method for pre-trained language models, with a special focus on the widely used BERT model. SparseBERT is executed in the fine-tuning stage. It preserves both general-purpose and task-specific language knowledge while pruning. To preserve the general-purpose knowledge learned during pre-training, ! " , $ " &  & ' L Pre-Training ! % , $ % & '  & ' ) D Fine-Tuning ! * , $ * L+, + D Testing Genera. Error ! % , $ % & ' ) L # L  L !" L  L # L # !" %& '())(* )+,L !" # L #  L # !"  L #  L !" (a) is the general pre-training and fine-tuning procedure (Section 3.1). g is an encoder. g L and g LD are the encoders well-trained on the pre-training and fine-tuning datasets respectively. L and D are the general-purpose language knowledge and the task-specific knowledge respectively. There is a domain error between pre-training and testing, and a generalization error between fine-tuning and testing. (b) and (c) are two basic pruning strategies (Section 3.2.1). Both LD and L pr are subsets of knowledge L . LD is related to the downstream task. L pr is preserved in a pruned encoder g L pr . (d) is the proposed pruning strategy (Sections 3.2.2-3.2.3). ( L pr ) D refers to the knowledge obtained by first pruning and then fine-tuning. ( LD ) pr corresponds to first fine-tuning and then pruning while distilling. L # !" / 0 ,2 0 3  3 5 L Pre-Training / 6 ,2 6 3 5  3 5 7 D Fine-Tuning / 8 ,2 8 L # !" + D Testing Genera. Error / 6 ,2 6 Teacher = 3 5 7 Student = 3 5  3 5 7 9: D Distilling Domain Error L # !" / 0 ,2 0 3 3 5 L Pre-Training / 6 ,2 6 3 5 3 5 7 D Fine-Tuning / 8 ,2 8 L # !" + D Testing Genera. Error / 6 ,2 6 Teacher = 3 5 7 Student = 3 5 3 5 7 9: D Distilling Domain Error L #  L # !"  L #  L !" We summarize different types of BERT pruning approaches in Figure 1 (see Section 3.2 for detailed discussion) Experimental results on the GLUE benchmark demonstrate that SparseBERT outperforms all the leading competitors and achieves 1.4% averaged loss with down to only 5% remaining weights compared to BERT-base. SparseBERT uses the pre-trained BERT without fine-tuning as the initialized model and prunes the linear transformations in self-attention and feedforward layers, which is inspired by the recent findings that self-attention and feed-forward layers are overparameterized (Michel et al., 2019; Voita et al., 2019) and are also the most computation consumption parts (Ganesh et al., 2020). To learn the task-specific task knowledge during pruning while preserving the general-purpose knowledge at the same time, we apply knowledge distillation (Hinton et al., 2015). We adopt the task-specific fine-tuned BERT as the teacher network and the pre-trained BERT that is being pruned as the student. We feed the downstream task data into the teacher-student framework to train the student to reproduce the behaviors of the teacher. A lot of efforts have been made on studying network redundancy and pruning networks without accuracy loss (Gale et al., 2019; Renda et al., 2020). For example, the work on lottery ticket hypothesis (Frankle and Carbin, 2019) showed that there exist sparse smaller subnetworks capable of training to full accuracy in CNNs. Common wisdom in CNN literature shows that spare pruning leads to much more compression rate than structural pruning (Gale et al., 2019; Elsen et al., 2020). For example, for the same number of parameters (0.46M), the sparse MobileNets achieve 61.8% accuracy while the dense ones achieve 50.6% (Zhu and Gupta, 2017). However, similar observations are not observed in existing approaches for pretrained language models (Fan et al., 2019; Michel et al., 2019; Chen et al., 2020; McCarley et al., 2020; Jiao et al., 2020). Our method aims to fill the gap and summarize these pruning strategies. There are other compression approaches for pre-trained language models, such as quantization (Zafrir et al., 2019) and weight factorization (Wang et al., 2019), which are out of the scope of this work. We first formalize the knowledge transfer involved in fine-tuning pre-trained language models. Then, we introduce our SparseBERT. The practice of fine-tuning pre-trained language models has become prevalent in various NLP tasks. The two-stage procedure is illustrated in Figure 1(a). The language model is denoted by f = g  h , where g is a text encoder and h is a task predictor head. Text encoders, like Transformers in BERT, are used to map input sentences to hidden representations and task predictors further map the representations to the label space. The pre-trained model is trained on a large amount of data examples ( x p , y p ) from the pre-training task domain via different tasks that resemble language modeling. During pre-training, the general-purpose language knowledge, denoted by L , is learned based on ( x p , y p ) . L contains a subset that is related to the downstream task, denoted by LD , and the amount of L is far greater than that of LD (see Figure 2(a)). To transfer knowledge L (especially LD ) from pre-training domain to downstream domain, the well-trained encoder g L is used to initialize the downstream encoder. In fine-tuning, downstream encoder is trained based on the task-specific knowledge D preserved in a small amount of data examples ( x d , y d ) from downstream domain. Finally, the well-trained downstream encoder g LD is evaluated on test data. Intuitively, there are two pruning strategies. One is that pruning is applied to the downstream encoder g L during fine-tuning (see Figure 1(b)). However, because the loss to update the weights during fine-tuning is exclusively based on the data examples ( x d , y d ) from the downstream task domain, this pruning strategy might destruct the knowledge LD , which is learned based on ( x p , y p ) and encoded in the initialization of g L . The other strategy is that pruning is executed during pre-training (see Figure 1(c)). The generated pruned network preserves a subset of knowledge L , denoted by L pr . Unfortunately, because this strategy ignores the downstream task information and the amount of L is extremely large, i.e., L (cid:29) L pr , the knowledge L pr could be much different from LD that we hope to preserve (see Figure As shown in Figure 1(d), SparseBERT executes pruning at the distilling stage. It prunes the pretrained encoder without fine-tuning, g L , while fine-tuning the pruned encoder based on the downstream dataset ( x d , y d ) . Recent findings indicate that self-attention and feed-forward layers are overparameterized and are the most computation consumption parts (Michel et al., 2019; Voita et al., 2019; Ganesh et al., 2020). Thus, SparseBERT applies network pruning to the linear transformations matrices in self-attention and feed-forward layers (see Figure 3). The choice of pruning approach is flexible. We choose magnitude weight pruning (Han et al., 2015) in this paper, mainly because it is one of the most effective and popular pruning methods. More details about the pruning strategy used in SparseBERT can be found in the codes. To mitigate the loss of LD , we propose to utilize knowledge distillation while pruning. We use the task-specific fine-tuned BERT as the teacher network and the pre-trained BERT that is being pruned as the student (see Figure 1(d) and Figure 3). The motivation is that the task-specific fine-tuned BERT preserves LD . By feeding downstream task data ( x d , y d ) into the teacher-student framework, we help the student reproduce the behaviors of the teacher to learn both L d and L as much as possible. We design the distillation loss as L distil = L emb + L att + L hid + L prd . L emb = MSE( ES , ET ) is the difference between the embedding layers of student and teacher. L att = (cid:80) MSE( A Si , A Ti ) is the difference between attention matrices and i is the layer index. L hid = (cid:80) MSE( H Si , H Ti ) is the difference between hidden representations. L prd = -softmax( z T )  log_softmax( z S / temp) is the soft cross-entropy loss between the logits of student and teacher. temp represents the temperature value. The proposed distillation loss is inspired by (Jiao et al., 2020) and it helps the student imitate the teacher's behavior as much as possible. In addition, we perform the same data augmentation as (Jiao et al., 2020) does to generate more task-specific data for teacher-student Self-Attention Add LayerNorm Feedforward Feedforward Gelu Add LayerNorm Embedding Layer Output Layer Output Input Knowledge Distillation Block (light purple) repeats multiple times Pruned Layers Teacher Network: finetuned BERT Student Network: pretrained BERT Self-Attention Add LayerNorm Feedforward Feedforward Gelu Add LayerNorm Embedding Layer Output Layer Output Input Knowledge Distillation Knowledge Distillation Knowledge Distillation Figure 3: Illustration of the proposed knowledge-aware compression. learning. Notably, the choices of distillation loss and data augmentation method are flexible and we found the ones we adopted worked well in general. We evaluate SparseBERT on four data sets from the GLUE benchmark (Wang et al., 2018). To test if SparseBERT is applicable across tasks, we include the tasks of both single sentence and sentence-pair classification. We report the results on dev sets. We run 3, 20, 20, 50 epochs for QNLI, MRPC, RTE, CoLA separately. The baselines include BERT-base, ELMo (Peters et al., 2018), BERT-PKD (Sun et al., 2019), Bert-of-Theseus (Xu et al., 2020), DistilBERT (Sanh et al., 2019), MiniLM (Wang et al., 2020), TinyBERT (Jiao et al., 2020), BERT-Tickets (Chen et al., 2020), CompressBERT (Gor-don et al., 2020), and RPP (Guo et al., 2019). The results are shown in Table 1. Compared to BERT-base, SparseBERT achieves 1.4% averaged performance loss with down to 5% weights. In addition, SparseBERT outperforms all leading competitors with the highest sparsity. We compare SparseBERT with the pruning described in Figure 1(b) on the question answer tasks of SQuAD v1.1 and v2.0 (Rajpurkar et al., 2016, 2018). Given a question and a passage containing Method Remain. the answer, the two tasks are to predict the answer text span in the passage. The difference between them is that SQuAD v2.0 allows for the possibility that no short answer exists in the passage. We follow the general setting of SparseBERT, except that we only apply the logit distillation, i.e., L distil = L prd , and do not perform data augmentation, which are the most common distillation strategies. The results are shown in Figure 4. It is observed that SparseBERT consistently outperforms the baseline method, especially at high sparsity. The performance gain of SparseBERT decreases on SQuAD v2.0 mainly because SQuAD v2.0 is more challenging than SQuAD v1.1. These observations demonstrate advantage of SparseBERT compared to pruning at downstream. To get more insights about the advantage of SparseBERT over the pruning described in Figure 1(c), we compare their fitting abilities. Specifically, we use TinyBERT as an example of the baseline pruning method. We compare SparseBERT with TinyBERT with 4 layers and 312 hidden dimensions, which has a similar number of parameters as SparseBERT (sparsity=95%). SparseBERT only distills knowledge from the same layers as TinyBERT does. We vary the number of pruning epochs and report the results (loss on training set and accuracy on dev set) on RTE in Figure 5. It is observed that SparseBERT consistently shows smaller training loss while higher evaluation performance, which demonstrates that SparseBERT has a better fitting ability when pruning compared to the baseline. Sparse networks were not hardware-friendly in the past. However, hardware platforms with sparse tensor operation support have been rising up. For example, the latest release of Nvidia high-end GPU A100 has native support of sparse tensor operation up to 2x compression rate, while startup company such as Moffett AI has developed computing platform with sparse tensor operation acceleration up to 32x compression rate. Here we deployed SparseBERT of different sparse compression ratios (1, 2, 4, 8, 16, 20) on Moffett AI's latest hardware platform ANTOM to measure the real inference speedup induced by sparse compression, where 4' indicates the model is compressed by a factor of 4, with 75% of the parameters being zeros. As shown in Figure 6, the sparse compression has almost linear speedup up to 4x and leads to more than 10x speedup when compression rate is 20x. We studied the reduction of parameters and FLOPS. For example, on the MRPC dataset, BERT-base (backbone) vs SparseBERT (backbone) = 85.53 vs 4.84 (#parameters, M) and BERT-base vs SparseBERT = 10.87 vs 0.54 (GFLOPS). We studied the time and convergence speed. For example, to get the reported 20x pruned result (Ta-ble 1), it needed 12 epochs of fine-tuning on MRPC and each epoch took 1.5 h (two RTX 2080 Ti). The inference time was around 20 s. We introduce SparseBERT, a knowledge-aware sparse pruning method for pre-trained language models, with a focus on BERT. We summarize different types of BERT pruning approaches and compare SparseBERT with leading competitors. Experimental results on GLUE and SQuAD benchmarks demonstrate the superiority of SparseBERT. We thank Xiaoqi Jiao for his valuable discussion and feedback on this work.
abstain abstain abstain abstain abstain objective objective result abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain abstain objective abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain objective abstain abstain method method other other other other other objective method abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain abstain abstain abstain method abstain abstain abstain abstain abstain abstain other abstain abstain abstain abstain result abstain other abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain method abstain method abstain method abstain abstain method objective abstain other