R EDUCING T RANSFORMER D EPTH ON D EMAND WITH S TRUCTURED D ROPOUT
Angela Fan
Facebook AI Research/LORIA angelafan@fb.com
Edouard Grave Facebook AI Research egrave@fb.com Armand Joulin Facebook AI Research ajoulin@fb.com
A BSTRACT
Overparameterized transformer networks have obtained state of the art results in various natural language processing tasks, such as machine translation, language modeling, and question answering.
These models contain hundreds of millions of parameters, necessitating a large amount of computation and making them prone to overﬁtting.
In this work, we explore LayerDrop , a form of structured dropout, which has a regularization effect during training and allows for efﬁcient pruning at inference time.
In particular, we show that it is possible to select sub-networks of any depth from one large network without having to ﬁnetune them and with limited impact on performance.
We demonstrate the effectiveness of our approach by improving the state of the art on machine translation, language modeling, summarization, question answering, and language understanding benchmarks.
Moreover, we show that our approach leads to small BERT-like models of higher quality compared to training from scratch or using distillation.
I NTRODUCTION
Transformer architectures (Vaswani et al., 2017) have become the dominant architecture in natural language processing, with state-of-the-art performance across a variety of tasks, including machine translation (Vaswani et al., 2017; Ott et al., 2018), language modeling (Dai et al., 2019; Baevski &
Auli, 2018) and sentence representation (Devlin et al., 2018; Yang et al., 2019).
Each of its layers contains millions of parameters accessed during the forward pass, making it computationally demanding in terms of memory and latency during both training and inference.
In an ideal situation, we would be able to extract sub-networks — automatically and without ﬁnetuning — from this over-parameterized network, for any given memory or latency constraint, while maintaining good performance.
In contrast, standard pruning or distillation methods follow a strategy that often includes a ﬁnetuning or retraining step, and the process must be repeated for each desired depth.
In this work, we propose a novel approach to extract any sub-network without a post-hoc pruning process from over-parameterized networks.
The core of our method is to sample small sub-networks from the larger model during training by randomly dropping model weights as in Dropout (Hinton et al., 2012) or DropConnect (Wan et al., 2013).
This has the advantage of making the network robust to subsequent pruning.
If well-chosen groups of weights are dropped simultaneously, the resulting small sub-networks can be very efﬁcient.
In particular, we drop entire layers to extract shallow models at inference time.
Previous work (Huang et al., 2016) has shown that dropping layers during training can regularize and reduce the training time of very deep convolutional networks.
In contrast, we focus on pruning.
As illustrated in Figure 1, an advantage of our layer dropping technique, or LayerDrop , is that from one single deep model, we can extract shallow sub-networks of any desired depth on demand at inference time.
We validate our ﬁndings on a variety of competitive benchmarks, namely WMT14 EnglishGerman for machine translation, WikiText-
(Merity et al., 2016) for language modeling, CNNDailymail (Hermann et al., 2015) for abstractive summarization, ELI5 (Fan et al., 2017) for long form question answering, and several natural language understanding tasks (Wang et al., 2019a) for sentence representation.
Our approach achieves state of the art on most of these benchmarks as a result of the regularization effect, which stabilizes the training of larger and deeper networks.
We also show that we can prune Transformer architectures to much smaller models while maintaining com-
In contrast to standard approaches that must re-train a new model from scratch for each model size
, our method trains only one network from which multiple shallow models can be extracted.
petitive performance, outperforming speciﬁc model reduction strategies dedicated to BERT (Devlin et al., 2018; Sanh, 2019) as well as training smaller models from scratch.
Overall, applying LayerDrop to Transformer networks provides the following key advantages:
• LayerDrop regularizes very deep Transformers and stabilizes their training, leading to stateof-the-art performance across a variety of benchmarks.
• Small and efﬁcient models of any depth can be extracted automatically at test time from a single large pre-trained model, without the need for ﬁnetuning.
• LayerDrop is as simple to implement as dropout.
R ELATED W ORK
Our approach is a form of Dropout (Srivastava et al., 2014) applied to model weights instead of activations, as in DropConnect (Wan et al., 2013).
Different from DropConnect, we drop groups of weights to induce group redundancy to create models suited for pruning to shallow, efﬁcient models at inference time.
Gomez et al.
(2018) propose a targeted Dropout and DropConnect, where they learn the drop rate of the weights to match a targeted pruning scheme.
Instead, we adapt the masks to the structures that we are interested in pruning.
Closer to our work, the Stochastic Depth approach of Huang et al.
(2016) drops layers randomly during training.
As opposed to our work, they are interested in accelerating the training of very deep ResNets (He et al., 2016), so their dropping schedule is adapted to this goal.
Concurrently to this work, Pham et al.
(2019) applied Stochastic
Depth to train very deep Transformers for speech and show the beneﬁts of its regularization effect.
More generally, our method is a form of structured pruning (Liu et al., 2018b).
As opposed to weight pruning (LeCun et al., 1990), structured pruning removes coherent groups of weights to preserve the original structure of the network.
Structured pruning has been used in some NLP applications, such as machine translation (See et al., 2016), text classiﬁcation (Joulin et al., 2016) and language modeling (Murray & Chiang, 2015).
However, it has been more widely adopted in computer vision and applied to convolutional network to remove ﬁlters (Li et al., 2016; Wen et al., 2016), channels (He et al., 2017), or residual blocks (Huang et al., 2018; Huang & Wang, 2018).
Similar to Mittal et al.
(2018), we take advantage of the plasticity of neural networks to learn models that are resilient to random pruning or skipping connections Wang et al.
; Wu et al.
; Liu et al.
(2018a), rather than learning the pruning itself.
We refer the reader to Liu et al.
(2018b)
for an exhaustive study of these approaches and their evaluation in the context of convolutional networks.
Reducing the memory footprint of Transformer architectures and BERT in particular is an active subject of research.
Several works have compressed BERT as a post-processing step using different forms of distillation (Turc et al., 2019; Tang et al., 2019; Shulga, 2019; Sanh, 2019).
Similarly, various papers have shown evidence that Transformers are over-parameterized, especially that most self-attention heads can be dropped at test time (Michel et al., 2019; Voita et al., 2019).
Different from these, our models are trained to be resilient to pruning, which signiﬁcantly reduces the performance drop induced by test time pruning.
Others have proposed trainable adaptive mechanisms to control their memory footprint (Jernite et al., 2016; Sukhbaatar et al., 2019; Correia et al., 2019).
These approaches are complementary to ours and should beneﬁt from each other.
M ETHOD
In this section, we brieﬂy introduce the Transformer, then describe our Structured Dropout technique and its application to layers.
We also discuss several inference time pruning strategies.
3. T HE T RANSFORMER A RCHITECTURE
We succinctly review the Transformer architecture and refer the reader to Vaswani et al.
(2017) for additional details.
A Transformer is a stack of layers composed of two sub-layers: multi-head self-attention followed by a feedforward sub-layer.
The multi-head self-attention sub-layer consists of multiple attention heads applied in parallel.
Each attention head takes a matrix X where each row represents an element of the input sequence and updates their representations by gathering information from their context using an Attention mechanism (Bahdanau et al., 2014):
[Equation]
where K , V , Q and P are matrices of parameters.
The outputs of the heads are then concatenated along the time step into a sequence of vectors.
The second sub-layer then applies a fully connected feedforward network to each element of this sequence independently, FFN ( x )
=
U ReLU ( Vx ) , where V and U are matrices of parameters.
Each sub-layer is followed by a AddNorm operation that is a residual connection (He et al., 2016) and a layer normalization (Ba et al., 2016).
3. T RAINING T RANSFORMERS WITH R ANDOM S TRUCTURED P RUNING
We present a regularization approach that makes Transformers robust to subsequent structured pruning at inference time.
We focus in particular on the case where the targeted structure is a layer.
3.2. R ANDOMLY D ROPPING S TRUCTURES AT T RAINING T IME
Regularizing networks to be robust to pruning can be achieved by randomly removing weights during its training as in DropConnect (Wan et al., 2013).
In this approach, each weight is dropped independently following a Bernoulli distribution associated with a parameter p > 0 that controls the drop rate.
This is equivalent to a pointwise multiplication of the weight matrix W with a randomly sampled { 0 , 1 } mask matrix M :
[Equation]
DropConnect is a form of random unstructured pruning that leads to smaller, but not necessarily more efﬁcient, models.
We propose to add structure to this mechanism to target model efﬁciency.
Random Structured Dropout.
The weights of a Transformer network belong to multiple overlapping structures, such as heads, FFN matrices, or layers.
Dropping weights using groups that follow some of these inherent structures potentially leads to a signiﬁcant reduction of the inference time.
This is equivalent to constraining the mask M to be constant over some predeﬁned groups of weights.
More precisely, given a set G of predeﬁned groups of weights, the { 0 , 1 } mask matrix M is randomly sampled over groups instead of weights:
[Equation]
This structured dropout formulation is general and can be applied to any overlapping groups of weights, whether heads, FFN matrices, or layers.
Nonetheless, not all of the structures in a Transformer lead to the same beneﬁts when dropped.
For example, dropping attention heads does not reduce runtime as they are usually computed in parallel.
For simplicity, we focus on dropping layers, and we name this structured pruning, LayerDrop .
This is inspired by the Stochastic Depth approach of Huang et al.
(2016) used to train very deep ResNets (He et al., 2015).
3.2. P RUNING AT I NFERENCE T IME
Selecting Layers to Prune Training with LayerDrop makes the network more robust to predicting with missing layers.
However, LayerDrop does not explicitly provide a way to select which groups to prune.
We consider several different pruning strategies, described below:
• Every Other : A straightforward strategy is to simply drop every other layer.
Pruning with a rate p means dropping the layers at a depth d such that d ≡ 0( mod (cid:98) 1 p (cid:99) ) .
This strategy is intuitive and leads to balanced networks.
• Search on Valid : Another possibility is to compute various combinations of layers to form shallower networks using the validation set, then select the best performing for test.
This is straightforward but computationally intensive and can lead to overﬁtting on validation.
• Data Driven Pruning : Finally, we propose data driven pruning where we learn the drop rate of each layer.
Given a target drop rate p , we learn an individual drop rate p d for the layer at depth d such that the average rate over layers is equal to p .
More precisely, we parameterize p d as a non-linear function of the activation of its layer and apply a softmax. At inference time, we
forward
only the ﬁxed top k highest scoring layers based on the softmax output
(e.g.
chosen layers do
not depend on the
input features).
In practice, we observe that the Every Other strategy works surprisingly well across many tasks and conﬁgurations.
Search on Valid and Data Driven Pruning only offer marginal gains.
Note that we do not further ﬁnetune any of the pruned networks (see Appendix for analysis of ﬁnetuning).
Setting the drop rate for optimal pruning.
There is a straightforward relationship between the drop rate of groups and the average pruning level that the network should be resilient to.
Assuming
N groups and a ﬁxed drop ratio p , the average number of groups used by the network during training is N (1 − p ) .
As a consequence, to target a pruning size of r groups, the optimal drop rate is:
[Equation]
In practice, we observe that networks are more robust to pruning than their expected ratio but higher pruning rates leads to better performance for smaller models.
We use a LayerDrop rate of p = 0 .for
all our experiments, but we recommend p = 0 .
5 to target very small inference time models.
E XPERIMENTAL S ETUP
We apply our method to a variety of sequence modeling tasks: neural machine translation, language modeling, summarization, long form question answering, and various natural language understanding tasks.
Our models are implemented in PyTorch using fairseq-py (Ott et al., 2019) 1 .
Additional implementation and training details with hyperparameter settings are in the Appendix.
Neural Machine Translation.
We experiment on the WMT English-German machine translation benchmark using the Transformer Big architecture.
We use the dataset of 4 .
5 M en-de sentence pairs from WMT16 (Vaswani et al., 2017) for training, newstest2013 for validation, and newstest for test.
We optimize the dropout value within the range { 0 . 1 , 0 . 2 , 0 . 5 } on the validation set and set the LayerDrop rate p to 0 .
For generation, we average the last 10 checkpoints, set the length penalty to 0 .
6 , and beam size to 8 , following the settings suggested in Wu et al. (2019a), and measure case-sensitive tokenized BLEU.
We apply compound splitting, as used in Vaswani et al.
Language Modeling.
We experiment on the Wikitext-103 language modeling benchmark (Merity et al., 2016) which contains 100 M tokens and a large vocabulary size of 260 K. We adopt the 16 layer
Transformer used in Baevski & Auli (2018).
We set the LayerDrop rate p to 0 .
2 and tune the standard dropout parameter in { 0 . 1 , 0 . 2 , 0 . 3 } on the validation set.
We report test set perplexity (PPL).
[Table]
[Table]
Summarization.
We adopt the Transformer base architecture and training schedule from Edunov et al.
and experiment on the CNN-Dailymail multi-sentence summarization benchmark.
The training data contains over 280 K full-text news articles paired with multi-sentence summaries (Hermann et al., 2015; See et al., 2017).
We tune a generation length in the range { 40 , 50 , 60 } and use 3 -gram blocking.
We set the LayerDrop rate p to 0 .
We evaluate using ROUGE (Lin, 2004).
Long Form Question Answering.
We consider the Long Form Question Answering Dataset ELI of Fan et al.
(2019), which consists of 272K question answer pairs from the subreddit Explain Like
I’m Five along with extracted supporting documents from web search.
We follow the Transformer
Big architecture and training procedure of Fan et al.
We generate long answers using beam search with beam size 5 and apply 3 -gram blocking (Fan et al., 2017).
We evaluate with ROUGE.
Sentence representation Pre-training.
We train base and large BERT (Devlin et al., 2018) models following the open-source implementation of Liu et al.
We use two datasets: Bookscorpus + Wiki from Liu et al.
(2019) and the larger combination of Bookscorpus + OpenWebText + CC-News + Stories (Liu et al., 2019).
We evaluate the pretrained models on various natural language understanding tasks.
Speciﬁcally, we evaluate accuracy on MRPC (Dolan & Brockett, 2005), QNLI (Rajpurkar et al., 2016), MNLI (Williams et al., 2018), and SST2 (Socher et al., 2013).
R ESULTS 5. L AYER D ROP AS A R EGULARIZER
Language Modeling.
In Table 2, we show the impact of LayerDrop on the performance of a Transformer network trained in the setting of Adaptive Inputs (Baevski & Auli, 2018).
Adding LayerDrop to a 16 layer Transformer improves the performance by 0 .
4 perplexity, matching the state-of-the-art results of Transformer-XL.
Our 40 layer Transformer with LayerDrop further improves the state of the art by 0 .
6 points.
Very deep Transformers are typically hard to train because of instability and memory usage, and they are prone to overﬁtting on a small dataset like Wikitext-103.
LayerDrop regularizes the network, reduces the memory usage, and increases training stability as fewer layers are active at each forward pass.
These results conﬁrm that this type of approach can be used to efﬁciently train very deep networks, as shown in Huang et al.
(2016) for convolutional networks.
Sequence to sequence modeling.
Similarly, as shown in Table 1 and Table 3, applying LayerDrop to Transformers on text generation tasks such as neural machine translation, summarization, and long form question answering also boosts performance for all tasks.
In these experiments, we take the Transformer architectures that are state-the-art and train them with LayerDrop. In neu- Model Enc
Dec
ROUGEROUGE-
ROUGE [Table] Abstractive Summarization Transformer (Edunov et al., 2019)
[Table]
[Table]
[Table]
Transformer + LayerDrop
[Table]
[Table]
[Table]
[Table]
Transformer + LayerDrop  41.
[Table]
[Table]
[Table]
Long Form Question Answering
[Table]
et al., 2019)
[Table]
[Table]
[Table]
ral machine translation on newstest2014, our 12 encoder layer Transformer model with LayerDrop further improves the state of the art, reaching 30 . 2 BLEU.
In comparison, a standard Transformer trained without LayerDrop diverges with 12 encoder layers.
This is a known problem, and techniques such as improved initialization could be used to maintain stability (Junczys-Dowmunt, 2019;
Zhang et al., 2019; Wang et al., 2019b; Wu et al., 2019b), but are out of the scope of this work.
Similar results are seen in summarization.
Bi-Directional Pre
-training.
In a second set of experiments, we look at the impact of LayerDrop on pre-training for sentence representation models and subsequent ﬁnetuning on multiple natural language understanding tasks.
We compare our models to a variant of BERT for sentence representations, called RoBERTa
(Liu et al., 2019), and analyze the results of ﬁnetuning for data adaptation on MNLI, MRPC, QNLI, and SST2.
We apply LayerDrop during both pre-training and ﬁnetuning.
We compare the performance of the large architecture on the BooksCorpus+Wiki dataset used in BERT.
We analyze the performance of training on the additional data used in RoBERTa as well as pre-training for even longer.
Comparing ﬁxed model size and training data, LayerDrop can improve the performance of RoBERTa on several tasks.
LayerDrop can further be used to both enable and stabilize the training (Huang et al., 2016) of models double the size for even stronger performance.
5. P RUNING T RANSFORMER L AYERS TO O N -D EMAND D EPTH WITH L AYER D ROP
Pruning Generation Tasks.
In Figure 2, we investigate the impact of the number of pruned decoder layers on the performance of a Transformer for language modeling, neural machine translation, and summarization.
We compare three different settings: standard Transformer models trained without LayerDrop but subsequently pruned, standard Transformer models trained from scratch to each desired depth, and lastly our approach: pruning layers of a Transformer trained with LayerDrop.
Our model is trained once with the maximum number of layers and then pruned to the desired depth, without any ﬁnetuning in the shallower conﬁguration.
Our approach outperforms small models trained from scratch, showing that LayerDrop leads to more accurate small models at a whole range of depths.
Further, training with LayerDrop does not incur the computational cost of retraining a new model for each desired depth.
For completeness, dropping layers of a deep Transformer trained without LayerDrop performs poorly as it was not trained to be robust to missing layers.
Pruning BERT-like Models.
In Table 7 (left), we compare pruning Transformers trained with
LayerDrop to different approaches used to create smaller, shallower models.
We compare to BERT [Figure]
Percentage
[Figure]
P
[Figure]
r p l e x it y
Language Modeling
Percentage
[Figure]
B LE
U
Machine Translation
Baseline
Trained from scratch
LayerDrop
Percentage [Figure] layers pruned
R
OUG
E
Summarization
Pruning networks with performs strongly compared to
[Figure]
[Figure]
SST
[Figure]
RoBERTa
[Figure] [Figure]
[Figure]
RoBERTa
[Figure]
[Figure]
[Figure]
base and RoBERTa base trained from scratch with 6 and 3 layers as well as recent work on distillation, called DistilBERT (Sanh, 2019). We analyze both BERT and RoBERTa models as the vocabulary is not the same due to differences in subword tokenization, which affects performance. DistilBERT occasionally performs worse than BERT of the same size trained from scratch, which conﬁrms the ﬁndings of Liu et al.
(2018b)
about the performance of pruned models compared to training small models from scratch.
Our approach, however, obtains results better than BERT and
RoBERTa trained from scratch.
Further, our method does not need any post-processing: we simply prune every other layer of our RoBERTa model that has been pre-trained with LayerDrop and ﬁnetune the small models on each of the downstream tasks, following standard procedure.
When training with additional data, shown in Table 7 (right), even stronger performance can be achieved.
A BLATION S TUDIES
Comparison of Structured Dropout Figure 4 (left) contrasts various forms of structured dropout: dropping attention heads, FFN matrices, and entire Transformer layers.
Dropping heads alone is worse than dropping entire sub-layers or layers.
It also offers no advantage in terms of running time as attention heads are computed in parallel for computational efﬁciency.
We observe no large differences between dropping sub-layers and layers, possibly because we are working with relatively shallow networks.
In theory, dropping sub-layers should perform better and we expect this to be the [Figure] [Figure]
r
[Figure] l e x [Figure] y
[Figure]
Structured Dropout
[Figure]
Searchfor
[Figure]
Datadriven
P e r p l e x it y [Figure] selection Techniques [Figure]
(Wikitext-103 Valid) The full network is pruned into various 8 layer sub-network conﬁgurations, and the av- perplexity pruning layer n is displayed above.
[Figure]
case with very deep Transformers. We experiment with overlapping structured groups, such as heads + layers and heads + sub-layers and ﬁnd that the beneﬁcial effect can be advantageously combined.
We focus on layers for simplicity, as dropping more structures introduces more parameters to tune. Comparison of Various Pruning Strategies.
Figure 4 (right) contrasts various approaches to sub-selecting model layers at inference time.
The predominant method used in this paper, the straightforward strategy of selecting every other layer, is tough to beat.
We ﬁnd only marginal improvement can be gained by searching over the validation set for the best set of 8 layers to use and by learning which layers to drop.
In contrast, dropping chunks of consecutive layers is harmful.
Namely, removing the ﬁrst half or last half of a model is particularly harmful, as the model does not have the ability to process the input or project to the full vocabulary to predict the subsequent word.
Choosing which Layers to Prune.
Not all layers are equally important.
In an experiment on
Wikitext-103, we pruned selections of 8 layers at random.
Figure 5 displays the perplexity when that layer is removed, averaging results from 20 pruned model per layer.
The input and output layers of a network are the most important, as they process the input and project to the output vocabulary.
Relationship between LayerDrop at Training Time and Pruning at Inference Time.
Figuredisplays the relationship between the training time LayerDrop and the performance of a pruned network at test time.
If signiﬁcant depth reduction is desired, training with larger LayerDrop is beneﬁcial — this equalizes the train and test time settings.
An analysis for BERT is in the Appendix.
C ONCLUSION
Structured dropout regularizes neural networks to be more robust to applying structured pruning at inference time.
We focus on the setting where structures are layers, enabling pruning of shallow and efﬁcient models of any desired depth.
In a variety of text generation and pre-training tasks, we show that LayerDrop enables and stabilizes the training of substantially deeper networks and simultaneously allows for the extraction of models of various depths with strong performance.
A A
PPENDIX A. A DDITIONAL I MPLEMENTATION D ETAILS A.1. N EURAL M ACHINE T RANSLATION
WMT en-de : We model a 32K joint byte-pair encoding.
We train using the cosine (Loshchilov & Hutter, 2016) learning rate schedule from Wu et al. (2019a) with label smoothing 0 .
vocabulary (Sennrich et al., 2015).
We train on 8 GPU for total training time 66k seconds.
IWSLT de-en : The dataset consists of 160 K training pairs, fully lowercased.
We model a 10K joint
BPE vocabulary and generate with beam size 4 .
We do not average checkpoints.
Following Wu et al.
(2019a), we use the Transformer base architecture with 6 encoder layers and 6 decoder layers.
As the dataset is small, we decrease the overall model size and instead use the following parameters:
FFN size 1024 , hidden dimension 512 , and 4 attention heads.
We train on 1 GPU.
Pruning : We apply the Every Other Layer strategy to the decoder and do not ﬁnetune.
A.1. L ANGUAGE M ODELING
Training :
To handle the large vocabulary of Wikitext-103, we follow Dauphin et al.
(2017) and
Baevski & Auli (2018) in using adaptive softmax (Grave et al., 2016) and adaptive input for computational efﬁciency.
For both input and output embeddings, we use dimension size 1024 and three adaptive bands: 20 K, 40 K, and
200 K.
We use a cosine learning rate schedule (Baevski & Auli, 2018;
Loshchilov & Hutter, 2016) and train with Nesterov’s accelerated gradient (Sutskever et al., 2013).
We set the momentum to 0.99 and renormalize gradients if the norm exceeds 0.1 (Pascanu et al., 2014).
During training, we partition the data into blocks of contiguous tokens that ignore document boundaries.
At test time, we respect sentence boundaries.
We train on 8 GPU for total training time of 216k seconds.
Pruning : We apply the Every Other Layer strategy and do not ﬁnetune.
A.1. S UMMARIZATION
Data: We use the full text (non-anonymized) version of CNN-Dailymail introduced by See et al.
Following Fan et al.
(2017), we truncate articles to 400 tokens and model a joint byte-pair vocabulary of 32K types (Sennrich et al., 2016).
Training : We train using Adam with a cosine learning rate schedule, warming up for 10K steps.
We optimize dropout in the range { 0 . 2 , 0 . 3 } on the validation set and set LayerDrop to 0 .
We train on 1 GPU.
Pruning : We apply the Every Other Layer strategy to the decoder and do not ﬁnetune.
A.1. L ONG F ORM Q UESTION A NSWERING
Training : We compare to the full multi-task setting of Fan et al.
(2019), where data augmentation and multi-tasking is done at training time to increase the data available.
We train on 8 GPU.
Generation : We set the minimum length to 150 tokens and the maximum length to 200 .
A.1. B I -D IRECTIONAL P RE -T RAINING
Training :
The base architecture is a 12 layer model with embedding size 768 and FFN size 3072 .
The large architecture consists of 24 layers with embedding size 1024 and FFN size 4096 .
For both settings, we follow Liu et al.
in using the subword tokenization scheme from Radford et al.
(2019), which uses bytes as subword units.
This eliminates unknown tokens.
Note this produces a different vocabulary size than BERT (Devlin et al., 2018), meaning models of the same depth do not have the same number of parameters.
We train with large batches of size 8192 and maintain this batch size using gradient accumulation.
We do not use next sentence prediction (Lample &
Conneau, 2019).
We optimize with Adam with a polynomial decay learning rate schedule.
For
[Table] [Table]
BERT-Base, we use 32 GPU (total training time 171k seconds) and for BERT-Large, we use
GPU.
For the RoBERTa data setting with more data, we use 512 GPU to train BERT-Large.
Finetuning : During ﬁnetuning, we hyperparameter search over three learning rate options (1e-5, 2e-5, 3e-5) and batchsize (16 or 32 sentences).
The other parameters are set following Liu et al.
We do single task ﬁnetuning, meaning we only tune on the data provided for the given natural language understanding task.
We do not perform ensembling.
When ﬁnetuning models trained with LayerDrop, we apply LayerDrop during ﬁnetuning time as well.
Training smaller models : We train the 6 and 3 layer RoBERTa models following the same settings, but using the smaller number of layers and without LayerDrop.
We ﬁnetune with the same sweep parameters.
The 6 and 3 layer BERT model results are taken from Devlin et al.
Training larger models : We train the 48 layer RoBERTa model with 0 .
5 LayerDrop so onlylayers on average are active during a forward pass.
Pruning : When pruning RoBERTa models, we use the Every Other Layer strategy and ﬁnetune without LayerDrop for the smaller models.
A. A DDITIONAL R ESULTS
IWSLT Table 6 displays results on the IWSLT de-en dataset.
We see small improvement, likely as the network is small and already has a large quantity of regularization with dropout, attention dropout, and weight decay.
The Transformer is not the state of the art architecture, and there remains a large gap between the Transformer and the DynamicConv model proposed by Wu et al. (2019a).
Pruning BERT Models
The numerical values corresponding to the pruned 6 and 3 layer
RoBERTa + LayerDrop models are shown in Table 7.
A. A DDITIONAL A NALYSIS
Impact of LayerDrop on training time.
Figure 7 shows the increase in training speed when training with increasingly large quantities of LayerDrop.
The words per second were computed on 8 V100 GPUs with 32GB of memory, without ﬂoating point 16, for a 16 layer model trained on Wikitext-103.
Assuming ﬁxed layer size, LayerDrop removes layers at training time randomly, which increases the training speed almost 2x if dropping half the number of layers.
Model
Dataset
Layers
MNLI-m
MRPC
QNLI
SSTBERT
Books + Wiki 81.
Distil BERT (Sanh, 2019)
Books + Wiki 81.
RoBERTa
Books + Wiki 82.
RoBERTa + LayerDrop
Books + Wiki 82.
RoBERTa + LayerDrop + more data 84.
BERT
Books + Wiki 77.
RoBERTa
Books + Wiki 78.
RoBERTa + LayerDrop
Books + Wiki 78.
RoBERTa + LayerDrop + more data 82.
[Figure]
Model
Valid PPL
Pruned w/ LayerDrop 20.
+ Finetune 20.
[Figure]
Similar to the analysis on Language Modeling, we ﬁnd that training with larger quantities of LayerDrop allows for more aggressive pruning at inference time on various natural language generation tasks.
However, as these tasks involve a ﬁnetuning step on the downstream tasks after pre-training, the effect is less straightforward.
Results are shown in Figure 8.
Impact of Finetuning.
LayerDrop allows models to be pruned to the desired depth at test time.
Apart from ﬁnetuning for data adaptation on the GLUE tasks, we do not ﬁnetune the performance of our smaller models on any of the other tasks we consider in this work.
As shown in Table 8, we found that ﬁnetuning the pruned models only results in marginal improvement.
Further, the ﬁnetuning parameters were dependent on the depth of the model at test time and difﬁcult to optimize. [Table] [Table] [Table]
Effect of Varying Standard Dropout.
LayerDrop adds a strong regularization effect to neural network training.
We examine the importance of tuning the standard dropout parameter when training with LayerDrop.
In Table
[Table]
we show the performance when LayerDrop is ﬁxed and standard
Dropout is varied.
We see that when training with LayerDrop, the quantity of standard Dropout can be reduced.
LayerDrop Schedule: Random or Linear.
We investigate the random structured dropping of layers compared to the linear decay schedule proposed in Huang et al.
(2016) in Table 10.
We ﬁnd that the linear decay schedule does not provide performance improvement compared to random dropping, which is more straightforward to implement.
Impact of Types of Structured Dropout when Pruning.
Figure 4 (left) contrasts the performance of various forms of structured dropout, such as dropping attention heads, sub-layers of Transformers such as attention or FFN, portions of FFN matrics, and entire Transformer layers.
It examines these results in the setting of evaluating the full depth model on language modeling and shows that in general, different types of structured dropout can improve performance.
In Table 11, we examine the effect of varying training time structured dropout with performance when pruning.
We show that the trend shown in Figure 4 is consistent with inference-time pruning performance, particularly that Half FFN dropout performs slightly worse, but other forms of structured dropout are beneﬁcial.