You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Reducing Transformer Depth on Demand with Structured Dropout (Fan et al., 2019)
2
+
This page contains information for how to train models with LayerDrop.
3
+
4
+
Looking for pretrained models? They will be added shortly.
5
+
6
+
Looking for code for other forms of Structured Dropout? It will be added shortly.
7
+
8
+
## Citation:
9
+
```bibtex
10
+
@article{fan2019reducing,
11
+
title={Reducing Transformer Depth on Demand with Structured Dropout},
12
+
author={Fan, Angela and Grave, Edouard and Joulin, Armand},
13
+
journal={arXiv preprint arXiv:1909.11556},
14
+
year={2019}
15
+
}
16
+
```
17
+
18
+
## Example usage
19
+
20
+
To train a model with LayerDrop, add the following flags. We recommend 0.2, a value that worked well in our experiments. For Language Models that are decoder-only, you need only the decoder flag. For RoBERTa, an encoder, you need only the encoder flag. The encoder and decoder LayerDrop values can be set differently.
21
+
```
22
+
--encoder-layerdrop 0.2 --decoder-layerdrop 0.2
23
+
```
24
+
25
+
To prune a model that has been trained with LayerDrop, add the following flags followed by a comma separated list of which layers you would like to keep.
Setting these flags should print a message such as:
30
+
```
31
+
| Pruning model to specified layer configuration
32
+
```
33
+
You should also see a smaller number of parameters in the model, for example the 16-Layer Transformer Language Model prints:
34
+
```
35
+
num. model params: 246933504
36
+
```
37
+
while a model pruned to 8 Layers prints:
38
+
```
39
+
num. model params: 146163712
40
+
```
41
+
42
+
If you would like to pick up training with a model that has been pruned, simply adding these flags is sufficient. If you would like to use a script that only does evaluation (no training), you may need to pass an override command. A specific example would be for language modeling:
This model override command overrides the training parameters and updates the model arguments so that the pruned model is run instead of the full model.
47
+
48
+
49
+
Looking to reproduce the results in the paper?
50
+
51
+
1. For Translation on WMT en-de, we followed this setting [here](https://github.com/pytorch/fairseq/blob/master/examples/scaling_nmt/README.md)
52
+
2. To train RoBERTa, we followed this setting [here](https://github.com/pytorch/fairseq/tree/master/examples/roberta)
53
+
3. To train Language Models on Wikitext-103, we followed this setting [here](https://github.com/pytorch/fairseq/tree/master/examples/language_model)
54
+
55
+
56
+
## Tips
57
+
58
+
1. If you would like to train large models with better performance, LayerDrop should be set to a smaller value such as 0.1 or 0.2. Too much LayerDrop will mean the model has too much regularization, so may not reach the best performance. Since LayerDrop adds regularization, you may achieve the best performance by slightly reducing the amount of standard dropout (for example, reduce by 0.1).
59
+
60
+
2. If you would like to train large models to be pruned and made smaller, LayerDrop should be set to a larger value such as 0.5 if you want to prune very aggressively (such as removing half the network or more). If you would like to prune fewer layers away, LayerDrop can be set to a smaller value such as 0.2.
61
+
62
+
3. When pruning layers at inference time, it is best to spread out the layers remaining so they are evenly spaced throughout the network. For example, if you want to remove 50% of the network, keeping every other layer is good.
63
+
64
+
## Having an issue or have a question?
65
+
66
+
Please open an issue in this repository with the details of your question. Thanks!
0 commit comments