원시데이터 수집 시스템
선정목록으로

Bag of Tricks for Optimizing Transformer Efficiency

관련 산업용 섬유 · (9) 타이어코드

기본 정보

저자
  1. Lin Ye — NLP Lab, School of Computer Science and Engineering, Northeastern University, Shenyang, China
  2. Yanyang Li — The Chinese University of Hong Kong, Hong Kong, China
  3. Tong Xiao — NLP Lab, School of Computer Science and Engineering, Northeastern University, Shenyang, China|||NiuTrans Research, Shenyang, China
  4. Jingbo Zhu — NLP Lab, School of Computer Science and Engineering, Northeastern University, Shenyang, China|||NiuTrans Research, Shenyang, China
DOI
10.18653/v1/2021.findings-emnlp.357
저널
–
발행년도
2021
발행기관
–
피인용수
4
라이선스
cc-by
논문 유형
–
언어
–
원문 페이지
https://doi.org/10.18653/v1/2021.findings-emnlp.357
토픽
High voltage insulation and dielectric phenomena
OpenAlex ID
W4206541903

평가 내용

관련도
관련
사업분야
산업용 섬유 · (9) 타이어코드
부 분야
–
R&D 측면
–
확신도
–
근거 용어
–
판단 근거
임베딩 유사도 기반 평가로 '산업용 섬유 > 타이어코드' 분야에 선정된 논문입니다.
R&D 활용 포인트
–
평가 입력
–

초록

Improving Transformer efficiency has become increasingly attractive recently. A wide range of methods has been proposed, e.g., pruning, quantization, new architectures and etc. But these methods are either sophisticated in implementation or dependent on hardware. In this paper, we show that the efficiency of Transformer can be improved by combining some simple and hardware-agnostic methods, including tuning hyper-parameters, better design choices and training strategies. On the WMT news translation tasks, we improve the inference efficiency of a strong Transformer system by 3.80x on CPU and 2.52x on GPU.

본문 29,038자

본문 펼치기
# Bag of Tricks for Optimizing Transformer Efficiency Ye Lin <sup>1</sup> <sup>_∗_</sup> , Yanyang Li <sup>2</sup> <sup>_∗_</sup> , Tong Xiao <sup>1,3</sup> <sup>_†_</sup> , Jingbo Zhu <sup>1,3</sup> 1NLP Lab, School of Computer Science and Engineering, Northeastern University, Shenyang, China 2The Chinese University of Hong Kong, Hong Kong, China 3NiuTrans Research, Shenyang, China {linye2015,blamedrlee}@outlook.com {xiaotong,zhujingbo}@mail.neu.edu.cn Abstract Improving Transformer efficiency has become increasingly attractive recently. A wide range of methods has been proposed, e.g., pruning, quantization, new architectures and etc. But these methods are either sophisticated in implementation or dependent on hardware. In this paper, we show that the efficiency of Transformer can be improved by combining some simple and hardware-agnostic methods, including tuning hyper-parameters, better design choices and training strategies. On the WMT news translation tasks, we improve the inference efficiency of a strong Transformer system by 3.80 _×_ on CPU and 2.52 _×_ on GPU. The code is publicly available at https://github.com/Lollipop321/minidecoder-network. 1 Introduction Standard implementation of Transformer (Vaswani et al., 2017) is not efficient for inference. Researchers have explored more efficient architectures (Zhang et al., 2018; Xiao et al., 2019; Li et al., 2021) or break the auto-regressive constraint in sequence generation (Gu et al., 2017). But most of these require significant updates of the model or hardware-dependent designs. It is still natural to ask whether the Transformer system can be optimized in a simple way (Hsu et al., 2020; Kasai et al., 2020; Kim et al., 2019; Wang and Tu, 2020). In this paper we show that Transformer can be optimized for efficiency by a bag of techniques. These techniques are easy to implement and some of them have been tested in related studies. Here we focus on using them in combination for Transformer speedup which has not been well investigated. In particular, our work is based on the following facts: _∗_ Authors contributed equally. _†_ Corresponding author. Table 1: Profiling results of the Transformer baseline and our model on WMT14 En-De (FFN: the feedforward network, Output: the output projection). - The default Byte-Pair Encoding (BPE) setting (Sennrich et al., 2016) has a great impact on efficiency but is generally not optimal. - A shallow decoder (with a deeper encoder) is preferred for a fast system (Kasai et al., 2020). - The attention model does not need to be multiheaded in some cases (Behnke and Heafield, 2020). - The feedforward network sub-layer is removable (Hsu et al., 2020). - Knowledge Distillation (Hinton et al., 2015) is crucial to squeeze out the last potential. Removing some regularization measures like label smoothing (Szegedy et al., 2016) also helps when training such models. All these methods are compatible with popular Transformer codebases. In this work, we implement them on the decoder side because it occupies the inference time in many sequence generation tasks (Hsu et al., 2020; Kim et al., 2019). The end result is a simplified and fast Transformer decoder (see Table 1) - _Mini-Decoder Network_ (MDN). Experiments on the WMT14 En-De, WMT14 EnFr and NIST12 Zh-En machine translation (MT) benchmarks demonstrate that the improved system achieves a 3.80 _×_ speedup on CPU and a 2.52 _×_ <u>Time (s)</u> Module <u>Baseline</u> <u>MDN</u> Attention 5.81 16.93 Encoder <u>FFN</u> <u>5.53</u> <u>18.79</u> Decoder Attention 223.55 8.74 FFN 38.26 0.00 <u>Output</u> <u>48.51</u> <u>8.61</u> 4227 _Fi_ _di_ _f_ _h_ _A_ _i_ _i_ _f_ _C_ _i_ _l Li_ _i_ _i_ _EMNLP 2021_ 4227 4233 28 27 26 ~~BLEU~~ ~~CPU~~ ~~GPU~~ 5/8 10/13 20/23 32/34 1 _._ 2 1 _._ 1 1 #BPE Merge Operations / Vocabulary Size (K) Figure 1: The number of BPE merge operations vs. BLEU and speedup on WMT14 En-De (Detailed setup could be found in Section 3.1). speedup on GPU with performance on par with the baseline. The speedup obtained is available on most modern hardware, as it does not depend on specific hardware or library, e.g., quantization (Chung et al., 2020) and unstructured pruning (Hoefler et al., 2021) require the support of the latest hardware-dependent and acceleration libraries. 2 Methods 2.1 Byte-Pair Encoding Byte-Pair Encoding (BPE) (Sennrich et al., 2016) breaks words into subword units. It starts from the alphabet and merges characters into the most frequent subword units, then segments words in sentences by these merged subword units. BPE reduces the risk of out-of-vocabulary words with a small vocabulary, but comes with the cost of longer sentences. If more merge operations are employed, the resulting sentences will be shorter, yet the vocabulary is larger as more subword units are presented. This leads to a tradeoff between sentence length and vocabulary size, and both of them have an impact on the efficiency. In Fig. 1, the green line denotes the BLEU referencing the left axis. The red line denotes the speed change on CPU, the blue line denotes the speed change on GPU, they are both referencing the right axis. As shown in Fig. 1, tuning this hyper-parameter provides a considerable speedup without loss in performance, though most previous work simply adopts the default setting (32K). In our experiments we choose 10K because it is sufficient for good performance. 2.2 Model Structure Updates Inspired by the observations in Table 1, the Transformer decoder can be improved for each of its components. In this section, we describe how to Source Embedding Target Embedding Figure 2: The model structure of our method (MDN). simplify Transformer in a systematic way as shown in Fig. 2. Table 2 summarizes the contributions of each adopted method. We choose Baseline1 in Table 2 to analyze how each method in “Model Structure Updates” influences the model performance and inference speed after applying techniques from “Byte-Pair Encoding”. Shallow Decoder. Recent work has shown that the deep encoder and shallow decoder architecture is promising in system speedup (Kasai et al., 2020; Li et al., 2021). In this work we follow the same idea by restricting the decoder to a 1-layer network and stacking more encoder layers until the total number of parameters matches the baseline. Pruning Heads. Researchers have found that most heads could be safely pruned and leaving the performance intact (Voita et al., 2019; Michel et al., 2019). So we retain only one head in decoder attentions. Dropping FFN. Hsu et al. (2020) suggests that FFN is the least important component in the decoder. So we drop all FFNs in the decoder. After dropping FFN, there are only attentions and no other non-linearity except layer normalization in the model. Factorizing Output. The weight matrix _W_ 1 _×_ Output Probabilities Softmax FFN Cross-Attention Scaled Dot-Product Attention Self-Attention Scaled Dot-Product Attention Transformer Encoder 4228 System BLEU <sup><u>Speed (sent./s)</u></sup> <u>CPU</u> <u>GPU</u> <u>Baseline1</u> <u>27.45</u> <u>7.72</u> <u>149.01</u> + Shallow Decoder 26.46 19.44 247.04 + Pruning Heads 26.62 12.91 172.25 + Dropping FFN 26.91 8.58 189.86 <u>+ Factorizing Output</u> <u>27.14</u> <u>7.92</u> <u>168.21</u> Table 2: Results of adding each trick from Section 2.2 independently on WMT14 En-De (sent./s: translated sentences per second. Baseline1 is the baseline with 10K BPE merge operations). used in the output projection is significantly overparameterized (Grave et al., 2017), especially when other components are compressed. To address this, we employ the low-rank approximation (Lan et al., 2020) for this matrix _W_ = _AB_ <sup>_T_</sup> to help to reduce the computation cost, where _A_ _∈_ R <sup>_V ×E_</sup>, _B_ _∈_ R <sup>_H×E_</sup>, _V_ is the vocabulary size, _E_ is the desired rank and _H_ is the hidden size. We choose _E_ = 64 in our experiments. 2.3 Training Strategies In our work, the methods presented in Section 2.2 can make an extremely small decoder that contains only 0.3% of the overall parameters. But we find that the model learned from scratch using the standard setting is much worse than the baseline (see Table 2). For better training, some methods are necessary. Table 3 illustrates how each proposed strategy contributes to reaching performance on par with the baseline. We choose Baseline2 in Table 3 to analyze how each method in “Training Strategies” influences the results after we have changed the BPE merge operations and simplified the model structure. Deep Configuration. Because our model is deep, we follow the deep model training setup provided in Wang et al. (2019). Weight Distillation. We also adopt a simplified version of weight distillation (WD) for training (Lin et al., 2020). This method initializes the student model with the corresponding weights from the teacher model, e.g., the first layer in the teacher encoder is reused in the first layer in the student encoder. Then it trains the student as in standard knowledge distillation (Hinton et al., 2015). Since our encoder is much deeper than the baseline, we initialize it in a round-robin manner. For the decoder, we randomly select one head from the Table 3: Results of adding each trick from Section 2.3 independently on WMT14 En-De (sent./s: translated sentences per second. Baseline2 is the baseline with 10K BPE merge operations and tricks from Section 2.2). teacher model for initialization, and the low-rank approximation of output projection is initialized by the SVD result of the teacher output projection (Golub and Reinsch, 2007). Weak Regularization. Because our decoder is small, we do not need to impose a strong regularization on it. We remove the dropout in the decoder and label smoothing. Dropout and label smoothing indeed do not have impacts on the inference speed. But changing them will train different models, which are unlikely to have exactly the same behavior. So some deviations in the inference speed are expected. 3 Experiments 3.1 Setup We evaluate our methods on the WMT14 En-De, WMT14 En-Fr and NIST12 Zh-En machine trans lation tasks. We tokenize every sentence using a script from Moses and segment every word into subword units using BPE (Sennrich et al., 2016). The number of the BPE merge operations is set to 32K in the baseline and 10K for the target language in our model. In addition, we remove sentences with more than 250 subword units (Xiao et al., 2012). We choose Transformer-base (Vaswani et al., 2017) as our baseline. The hyper-parameters of the Mini-Decoder Network (MDN) are the same as the baseline except for those mentioned in Section 2.3. To produce consistent results for distillation, we choose the baseline with 10K BPE merges as the teacher model, which has the same vocabulary as MDN. We also compare our system with some recent proposed fast Transformer variants, e.g., AAN (Zhang et al., 2018), SAN (Xiao et al., 2019) and CAN (Li et al., 2021). Their settings are System BLEU <sup><u>Speed (sent./s)</u></sup> <u>CPU</u> <u>GPU</u> <u>Baseline2</u> <u>22.83</u> <u>23.19</u> <u>291.00</u> + Deep Configuration 23.78 24.21 305.03 + WD 26.97 24.56 352.09 - Decoder Dropout 23.25 24.51 277.38 <u>- Label Smoothing</u> <u>23.22</u> <u>24.42</u> <u>286.54</u> 4229 <u>System</u> <u>Test</u> <u>Valid</u> <u>Speed (CPU)</u> <u>Speedup</u> <u>Speed (GPU)</u> <u>Speedup</u> <u>#Params</u> Baseline 27.21 25.53 7.17 sent./s 1.00 _×_ 129.02 sent./s 1.00 _×_ 96M + BPE 10K 27.45 25.60 7.72 sent./s 1.08 _×_ 149.01 sent./s 1.15 _×_ 76M AAN 27.05 25.11 9.82 sent./s 1.37 _×_ 147.11 sent./s 1.14 _×_ 96M SAN 26.88 24.99 9.10 sent./s 1.27 _×_ 179.49 sent./s 1.39 _×_ 80M <u>CAN</u> <u>27.20</u> <u>25.23</u> <u>8.00 sent./s</u> <u>1.12</u> _<u>×</u>_ <u>279.39 sent./s</u> <u>2.17</u> _<u>×</u>_ <u>100M</u> <u>MDN</u> <u>27.23</u> <u>25.37</u> <u>23.52 sent./s</u> <u>3.28</u> _<u>×</u>_ <u>326.78 sent./s</u> <u>2.53</u> _<u>×</u>_ <u>96M</u> Baseline 40.70 46.74 5.80 sent./s 1.00 _×_ 130.56 sent./s 1.00 _×_ 111M + BPE 10K 40.52 46.51 6.50 sent./s 1.12 _×_ 143.21 sent./s 1.10 _×_ 81M AAN 40.44 46.43 8.00 sent./s 1.38 _×_ 140.66 sent./s 1.08 _×_ 96M SAN 40.70 46.44 7.48 sent./s 1.29 _×_ 157.50 sent./s 1.21 _×_ 80M <u>CAN</u> <u>40.16</u> <u>46.40</u> <u>6.40 sent./s</u> <u>1.10</u> _<u>×</u>_ <u>194.67 sent./s</u> <u>1.49</u> _<u>×</u>_ <u>100M</u> <u>MDN</u> <u>40.58</u> <u>46.43</u> <u>22.86 sent./s</u> <u>3.94</u> _<u>×</u>_ <u>352.79 sent./s</u> <u>2.70</u> _<u>×</u>_ <u>100M</u> Baseline 45.84 50.98 4.09 sent./s 1.00 _×_ 90.87 sent./s 1.00 _×_ 102M + BPE 10K 45.34 51.41 4.35 sent./s 1.06 _×_ 91.79 sent./s 1.01 _×_ 79M AAN 44.87 51.26 5.00 sent./s 1.22 _×_ 91.30 sent./s 1.00 _×_ 102M SAN 44.82 50.73 4.99 sent./s 1.22 _×_ 123.18 sent./s 1.36 _×_ 102M <u>CAN</u> <u>40.11</u> <u>46.25</u> <u>6.09 sent./s</u> <u>1.49</u> _<u>×</u>_ <u>168.89 sent./s</u> <u>1.86</u> _<u>×</u>_ <u>107M</u> <u>MDN</u> <u>44.51</u> <u>51.43</u> <u>17.07 sent./s</u> <u>4.17</u> _<u>×</u>_ <u>211.31 sent./s</u> <u>2.33</u> _<u>×</u>_ <u>99M</u> Table 4: Results on the WMT14 En-De and En-Fr tasks (sent./s: translated sentences per second). followed from their papers. We report case-sensitive tokenized BLEU scores. For all experiments, we test on the model ensemble by averaging the last 5 checkpoints. For inference, we use a batch size of 64 and a beam width of 4. All models are evaluated on the NVIDIA TITAN V GPU and Intel(R) Xeon(R) Gold 5118 CPU. 3.2 Results Table 4 shows the results of various systems. In both tasks, our method (MDN) has nearly the same performance as the baseline, but its speed is 3.80 _×_ and 2.52 _×_ faster on average for CPU and GPU. We find the baseline with 10K BPE merges is about 1.09 _×_ faster than the original baseline but with a similar performance, which suggests this BPE hyper-parameter is far from optimal for the baseline. As for the recent work, i.e., AAN, SAN and CAN, all of them achieve performance similar to the baseline and are faster than the baseline (1.24 _×∼_ 1.32 _×_ speedup on CPU) as reported in their papers. But our method outperforms these methods and runs consistently faster (3.80 _×_ speedup on CPU). Although the acceleration of our method in GPU (2.52 _×_ speedup) is not as obvious as it in CPU (3.80 _×_ speedup), it still outperforms CAN by 1.40 _×_, which is highly optimized for GPU. System BLEU <sup><u>Speed (sent./s)</u></sup> <u>CPU</u> <u>GPU</u> <u>Baseline</u> <u>27.21</u> <u>7.17</u> <u>129.02</u> <mark>+ Merge Operations</mark> <mark>27.45</mark> <mark>7.72</mark> <mark>149.01</mark> <mark>+ Shallow Decoder</mark> <mark>26.46</mark> <mark>19.44</mark> <mark>247.04</mark> <mark>+ Pruning Heads</mark> <mark>24.47</mark> <mark>21.99</mark> <mark>243.42</mark> <mark>+ Dropping FFN</mark> <mark>23.26</mark> <mark>22.36</mark> <mark>268.01</mark> <mark>+ Output Factorization</mark> <mark>22.83</mark> <mark>23.19</mark> <mark>291.00</mark> <mark>+ Deep Conf</mark> i <mark>guration</mark> <mark>23.78</mark> <mark>24.21</mark> <mark>305.03</mark> <mark>+ WD</mark> <mark>27.09</mark> <mark>22.96</mark> <mark>344.21</mark> <mark>- Decoder Dropout</mark> <mark>27.18</mark> <mark>23.53</mark> <mark>334.40</mark> <u><mark>- Label Smoothing</mark></u> <u><mark>27.23</mark></u> <u><mark>23.52</mark></u> <u><mark>326.78</mark></u> Table 5: Ablation study on WMT14 EnDe. The colors refer to <mark>Byte-Pair Encoding</mark>, <mark>Model Structure Updates</mark> and <mark>Training Strategies</mark> (sent./s: translated sentences per second). 4 Analysis 4.1 Ablation Study Table 5 summarizes and compares the contributions of each proposed tricks described in Section 2. Each row of Table 5 is the result of applying the current trick to the system obtained in the previous row. This way helps to illustrate the compound effect of these tricks. We observe that using any structure simplification trick brings a significant performance degra 4230 <u>System</u> <u>Test</u> <u>Valid</u> <u>Speed(CPU)</u> <u>Speedup</u> <u>Speed(GPU)</u> <u>Speedup</u> Baseline 29.43 27.82 6.02 sent./s 1.00 _×_ 121.57 sent./s 1.00 _×_ + BPE 10K 29.67 27.68 6.19 sent./s 1.03 _×_ 126.06 sent./s 1.04 _×_ <u>MDN</u> <u>29.02</u> <u>27.64</u> <u>15.00 sent./s</u> <u>2.49</u> _<u>×</u>_ <u>254.25 sent./s</u> <u>2.09</u> _<u>×</u>_ Table 6: Results of Transformer-deep on WMT14 En-De (sent./s: translated sentences per second). 4 3 2 1 CPU <u>GPU</u> 1 4 16 64 Batch Size CPU ~~GPU~~ 5 4 3 2 1 1 2 4 16 Beam Width Figure 3: Batch size and beam width vs. speedup of MDN on WMT14 En-De. dation but a considerable speedup. However, our training strategies can make up for the performance loss. Among them, WD is most effective and has a boost of more than 3 BLEU points. Interestingly, we find that pruning attention heads does not have any speedup on GPU. This is because the parallelism of GPU decouples the computation cost of attention heads from the head number. 4.2 Experiments on Larger Networks Table 6 shows the results of the Transformer-deep model with a 48-layer encoder. The phenomenon here is similar to that in Table 4. The acceleration on Transformer-deep is less obvious than on Transformer-base, as a deeper encoder consumes more inference time. Moreover, compared with such a strong Transformer-deep teacher, MDN can still obtain a 2.49 _×_ speedup on CPU and a 2.09 _×_ speedup on GPU. 4.3 Sensitivity Analysis We study the impact of two commonly tuned hyper parameters at inference on our method, i.e., the batch size and the beam size. The left part of Fig. 3 shows that the speedup over the baseline decreases as the batch size increases, especially for GPU. This is because our shallow decoder trick exploits the parallelism of the encoder for speedup, which is not available if the batch size is large. This phenomenon is also observed by Li et al. (2021). The right part of Fig. 3 shows that the speedup is more obvious with a larger beam width. The reason is that the encoder occupies a larger portion of the <u>Speed (sent./s)</u> System BLEU <u>CPU</u> <u>GPU</u> <u>AAN</u> <u>27.05</u> <u>9.82</u> <u>147.11</u> <u>+ Ours</u> <u>27.21</u> <u>19.32</u> <u>259.10</u> <u>CAN</u> <u>27.20</u> <u>8.00</u> <u>279.39</u> <u>+ Ours</u> <u>27.25</u> <u>10.62</u> <u>293.43</u> Table 7: Combining the proposed tricks with AAN and CAN on WMT14 En-De (sent./s: translated sentences per second). inference cost at a small beam width and our work only save the cost of the decoder. 4.4 Combining with Other Models Our method is a bag of generic tricks and can be applied to other models. We choose AAN and CAN for testing, because AAN runs the fastest on CPU and CAN runs the fastest on GPU according to Table 4. Table 7 shows that both AAN and CAN benefit from techniques presented in this paper. Without loss in performance, AAN obtains a 1.97 _×_ speedup on CPU and CAN obtains a 1.05 _×_ speedup on GPU. It shows that AAN and CAN eventually have a similar BLEU score and speed as MDN, indicating that a highly optimized Transformer baseline already a strong candidate by itself. 5 Conclusion In this work, we present a bag of tricks to optimize the efficiency of the standard Transformer. The resulting model achieves a 3.61 _×_ speedup on CPU and a 2.62 _×_ speedup on GPU without loss in performance. Acknowledgments This work was supported in part by the National Science Foundation of China (Nos. 61876035 and 61732005), the National Key R&D Program of China (No. 2019QY1801), and the Ministry of Science and Technology of the PRC (Nos. 2019YFF0303002 and 2020AAA0107900). The authors would like to thank anonymous reviewers for their comments. 4231 References Maximiliana Behnke and Kenneth Heafield. 2020. [Los-](https://doi.org/10.18653/v1/2020.emnlp-main.211) ing heads in the lottery: [Pruning](https://doi.org/10.18653/v1/2020.emnlp-main.211) transformer atten[tion in neural machine translation.](https://doi.org/10.18653/v1/2020.emnlp-main.211) In _Proceedings of_ _the_ _2020_ _Conference_ _on_ _Empirical_ _Methods_ _in_ _Nat-_ _ural_ _Language_ _Processing,_ _EMNLP_ _2020,_ _Online,_ _November_ _16-20,_ _2020_, pages 2664–2674. Association for Computational Linguistics. Insoo Chung, Byeongwook Kim, Yoonjung Choi, Se Jung Kwon, Yongkweon Jeon, Baeseong Park, Sangha Kim, and Dongsoo Lee. 2020. [Extremely](https://doi.org/10.18653/v1/2020.findings-emnlp.433) low bit transformer [quantization](https://doi.org/10.18653/v1/2020.findings-emnlp.433) for on-device neu[ral machine translation.](https://doi.org/10.18653/v1/2020.findings-emnlp.433) In _Proceedings of the 2020_ _Conference_ _on_ _Empirical_ _Methods_ _in_ _Natural_ _Lan-_ _guage_ _Processing:_ _Findings,_ _EMNLP_ _2020,_ _Online_ _Event, 16-20 November 2020_, pages 4812–4826. Association for Computational Linguistics. Gene H. Golub and Christian H. Reinsch. 2007. Sin gular value decomposition and least squares solutions. In Raymond Hon-Fu Chan, Chen Greif, and Dianne P. O’Leary, editors, _Milestones_ _in_ _Matrix_ _Computation_ _-_ _Selected_ _Works_ _of_ _Gene_ _H._ _Golub,_ _with Commentaries_, pages 160–180. Oxford University Press. Edouard Grave, Armand Joulin, Moustapha Cissé, David Grangier, and Hervé Jégou. 2017. [Efficient](http://proceedings.mlr.press/v70/grave17a.html) softmax [approximation](http://proceedings.mlr.press/v70/grave17a.html) for gpus. In _Proceedings_ _of_ _the_ _34th_ _International_ _Conference_ _on_ _Machine_ _Learning, ICML 2017, Sydney, NSW, Australia, 6-11_ _August 2017_, volume 70 of _Proceedings of Machine_ _Learning Research_, pages 1302–1310. PMLR. Jiatao Gu, James Bradbury, Caiming Xiong, Vic tor O. K. Li, and Richard Socher. 2017. [Non-](http://arxiv.org/abs/1711.02281) autoregressive [neural](http://arxiv.org/abs/1711.02281) machine translation. _CoRR_, abs/1711.02281. Geoffrey E. Hinton, Oriol Vinyals, and Jeffrey Dean. 2015. [Distilling the knowledge in a neural network.](http://arxiv.org/abs/1503.02531) _CoRR_, abs/1503.02531. Torsten Hoefler, Dan Alistarh, Tal Ben-Nun, Nikoli Dryden, and Alexandra Peste. 2021. [Sparsity](http://arxiv.org/abs/2102.00554) in deep learning: Pruning [and](http://arxiv.org/abs/2102.00554) growth for efficient inference and [training](http://arxiv.org/abs/2102.00554) in neural networks. _CoRR_, abs/2102.00554. Yi-Te Hsu, Sarthak Garg, Yi-Hsiu Liao, and Ilya Chatsviorkin. 2020. Efficient [inference](http://arxiv.org/abs/2010.02416) for neural [machine translation.](http://arxiv.org/abs/2010.02416) _CoRR_, abs/2010.02416. Jungo Kasai, Nikolaos Pappas, Hao Peng, James Cross, and Noah A. Smith. 2020. Deep [encoder,](http://arxiv.org/abs/2006.10369) shallow decoder: Reevaluating [the](http://arxiv.org/abs/2006.10369) speed-quality tradeoff in [machine translation.](http://arxiv.org/abs/2006.10369) _CoRR_, abs/2006.10369. Young Jin Kim, Marcin Junczys-Dowmunt, Hany Hassan, Alham Fikri Aji, Kenneth Heafield, Roman Grundkiewicz, and Nikolay Bogoychev. 2019. [From research to production and back:](https://doi.org/10.18653/v1/D19-5632) Ludicrously fast neural [machine](https://doi.org/10.18653/v1/D19-5632) translation. In _Proceedings_ _of_ _the_ _3rd_ _Workshop_ _on_ _Neural_ _Generation_ _and_ _Translation@EMNLP-IJCNLP_ _2019,_ _Hong_ _Kong,_ _November_ _4,_ _2019_, pages 280–288. Association for Computational Linguistics. Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. 2020. ALBERT: A lite [BERT](https://openreview.net/forum?id=H1eA7AEtvS) for self-supervised learning of [language](https://openreview.net/forum?id=H1eA7AEtvS) representations. In _8th_ _Inter-_ _national_ _Conference_ _on_ _Learning_ _Representations,_ _ICLR_ _2020,_ _Addis_ _Ababa,_ _Ethiopia,_ _April_ _26-30,_ _2020_ . OpenReview.net. Yanyang Li, Ye Lin, Tong Xiao, and Jingbo Zhu. 2021. An efficient transformer [decoder](http://arxiv.org/abs/2101.00542) with compressed [sub-layers.](http://arxiv.org/abs/2101.00542) _CoRR_, abs/2101.00542. Ye Lin, Yanyang Li, Ziyang Wang, Bei Li, Quan Du, Tong Xiao, and Jingbo Zhu. 2020. Weight distillation: Transferring the [knowledge in neural](http://arxiv.org/abs/2009.09152) network [parameters.](http://arxiv.org/abs/2009.09152) _CoRR_, abs/2009.09152. Paul Michel, Omer Levy, and Graham Neubig. 2019. Are sixteen heads [really](https://proceedings.neurips.cc/paper/2019/hash/2c601ad9d2ff9bc8b282670cdd54f69f-Abstract.html) better than one? In _Ad-_ _vances_ _in_ _Neural_ _Information_ _Processing_ _Systems_ _32:_ _Annual Conference on Neural Information Pro-_ _cessing_ _Systems_ _2019,_ _NeurIPS_ _2019,_ _December_ _8-_ _14,_ _2019,_ _Vancouver,_ _BC,_ _Canada_, pages 14014– 14024. Rico Sennrich, Barry Haddow, and Alexandra Birch. 2016. Neural machine translation of rare words with subword units. In _Proceedings_ _of_ _the_ _54th_ _Annual_ _Meeting_ _of_ _the_ _Association_ _for_ _Computational_ _Lin-_ _guistics, ACL 2016, August 7-12, 2016, Berlin, Ger-_ _many,_ _Volume 1:_ _Long Papers_ . The Association for Computer Linguistics. Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, Jonathon Shlens, and Zbigniew Wojna. 2016. [Re-](https://doi.org/10.1109/CVPR.2016.308) thinking the inception [architecture](https://doi.org/10.1109/CVPR.2016.308) for computer vi[sion.](https://doi.org/10.1109/CVPR.2016.308) In _2016_ _IEEE_ _Conference_ _on_ _Computer_ _Vi-_ _sion_ _and_ _Pattern_ _Recognition,_ _CVPR_ _2016,_ _Las_ _Ve-_ _gas,_ _NV,_ _USA,_ _June_ _27-30,_ _2016_, pages 2818–2826. IEEE Computer Society. Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. [Attention](http://papers.nips.cc/paper/7181-attention-is-all-you-need) is all you [need.](http://papers.nips.cc/paper/7181-attention-is-all-you-need) In _Advances_ _in_ _Neural_ _Information_ _Pro-_ _cessing_ _Systems_ _30:_ _Annual_ _Conference_ _on_ _Neural_ _Information_ _Processing_ _Systems_ _2017,_ _4-9_ _Decem-_ _ber 2017, Long Beach, CA, USA_, pages 5998–6008. Elena Voita, David Talbot, Fedor Moiseev, Rico Sen nrich, and Ivan Titov. 2019. Analyzing multi-head self-attention: [Specialized](https://doi.org/10.18653/v1/p19-1580) heads do the heavy lifting, the rest [can](https://doi.org/10.18653/v1/p19-1580) be pruned. In _Proceedings_ _of_ _the_ _57th_ _Conference_ _of_ _the_ _Association_ _for_ _Computa-_ _tional_ _Linguistics,_ _ACL_ _2019,_ _Florence,_ _Italy,_ _July_ _28-_ _August_ _2,_ _2019,_ _Volume_ _1:_ _Long_ _Papers_, pages 5797–5808. Association for Computational Linguistics. Qiang Wang, Bei Li, Tong Xiao, Jingbo Zhu, Changliang Li, Derek F. Wong, and Lidia S. Chao. 4232 2019. Learning deep [transformer](https://doi.org/10.18653/v1/p19-1176) models for ma[chine translation.](https://doi.org/10.18653/v1/p19-1176) In _Proceedings of the 57th Confer-_ _ence_ _of_ _the_ _Association_ _for_ _Computational_ _Linguis-_ _tics,_ _ACL_ _2019,_ _Florence,_ _Italy,_ _July_ _28-_ _August_ _2,_ _2019, Volume 1: Long Papers_, pages 1810–1822. Association for Computational Linguistics. Wenxuan Wang and Zhaopeng Tu. 2020. [Rethinking](https://doi.org/10.18653/v1/2020.coling-main.529) the value of [transformer](https://doi.org/10.18653/v1/2020.coling-main.529) components. In _Proceed-_ _ings_ _of_ _the_ _28th_ _International_ _Conference_ _on_ _Com-_ _putational_ _Linguistics,_ _COLING_ _2020,_ _Barcelona,_ _Spain_ _(Online),_ _December_ _8-13,_ _2020_, pages 6019– 6029. International Committee on Computational Linguistics. Tong Xiao, Yinqiao Li, Jingbo Zhu, Zhengtao Yu, and Tongran Liu. 2019. Sharing [attention](https://doi.org/10.24963/ijcai.2019/735) weights for fast [transformer.](https://doi.org/10.24963/ijcai.2019/735) In _Proceedings_ _of_ _the_ _Twenty-_ _Eighth_ _International_ _Joint_ _Conference_ _on_ _Artificial_ _Intelligence, IJCAI 2019, Macao, China, August 10-_ _16, 2019_, pages 5292–5298. ijcai.org. Tong Xiao, Jingbo Zhu, Hao Zhang, and Qiang Li. 2012. Niutrans: An open [source](https://aclanthology.org/P12-3004/) toolkit for phrase[based and syntax-based machine translation.](https://aclanthology.org/P12-3004/) In _The_ _50th_ _Annual_ _Meeting_ _of_ _the_ _Association_ _for_ _Com-_ _putational_ _Linguistics,_ _Proceedings_ _of_ _the_ _System_ _Demonstrations,_ _July_ _10,_ _2012,_ _Jeju_ _Island,_ _Korea_, pages 19–24. The Association for Computer Linguistics. Biao Zhang, Deyi Xiong, and Jinsong Su. 2018. [Accel-](https://doi.org/10.18653/v1/P18-1166) erating neural [transformer](https://doi.org/10.18653/v1/P18-1166) via an average attention [network.](https://doi.org/10.18653/v1/P18-1166) In _Proceedings_ _of_ _the_ _56th_ _Annual_ _Meet-_ _ing of the Association for Computational Linguistics,_ _ACL_ _2018,_ _Melbourne,_ _Australia,_ _July_ _15-20,_ _2018,_ _Volume 1:_ _Long Papers_, pages 1789–1798. Associa tion for Computational Linguistics. 4233

섹션 본문 23문단 · 11,986자

(제목 없음)

1Improving Transformer efficiency has become increasingly attractive recently. A wide range of methods has been proposed, e.g., pruning, quantization, new architectures and etc. But these methods are either sophisticated in implementation or dependent on hardware.In this paper, we show that the efficiency of Transformer can be improved by combining some simple and hardware-agnostic methods, including tuning hyper-parameters, better design choices and training strategies. On the WMT news translation tasks, we improve the inference efficiency of a strong Transformer system by 3.80× on CPU and 2.52× on GPU. The code is publicly available at https://github.com/Lollipop321/minidecoder-network.

Introduction

2Standard implementation of Transformer (Vaswani et al., 2017) is not efficient for inference. Researchers have explored more efficient architectures (Zhang et al., 2018;Li et al., 2021) or break the auto-regressive constraint in sequence generation (Gu et al., 2017). But most of these require significant updates of the model or hardware-dependent designs. It is still natural to ask whether the Transformer system can be optimized in a simple way (Hsu et al., 2020;Kasai et al., 2020;Kim et al., 2019;Wang and Tu, 2020).

3In this paper we show that Transformer can be optimized for efficiency by a bag of techniques. These techniques are easy to implement and some of them have been tested in related studies. Here we focus on using them in combination for Transformer speedup which has not been well investigated. In particular, our work is based on the following facts: * Authors contributed equally. † • The default Byte-Pair Encoding (BPE) setting (Sennrich et al., 2016) has a great impact on efficiency but is generally not optimal.

4• A shallow decoder (with a deeper encoder) is preferred for a fast system (Kasai et al., 2020).

5• The attention model does not need to be multiheaded in some cases (Behnke and Heafield, 2020).

6• The feedforward network sub-layer is removable (Hsu et al., 2020).

7• Knowledge Distillation (Hinton et al., 2015) is crucial to squeeze out the last potential. Removing some regularization measures like label smoothing (Szegedy et al., 2016) also helps when training such models.

8All these methods are compatible with popular Transformer codebases. In this work, we implement them on the decoder side because it occupies the inference time in many sequence generation tasks (Hsu et al., 2020;Kim et al., 2019). The end result is a simplified and fast Transformer decoder (see Table 1 speedup on GPU with performance on par with the baseline. The speedup obtained is available on most modern hardware, as it does not depend on specific hardware or library, e.g., quantization (Chung et al., 2020) and unstructured pruning (Hoefler et al., 2021) require the support of the latest hardware-dependent and acceleration libraries.

Byte-Pair Encoding

9Byte-Pair Encoding (BPE) (Sennrich et al., 2016) breaks words into subword units. It starts from the alphabet and merges characters into the most frequent subword units, then segments words in sentences by these merged subword units. BPE reduces the risk of out-of-vocabulary words with a small vocabulary, but comes with the cost of longer sentences. If more merge operations are employed, the resulting sentences will be shorter, yet the vocabulary is larger as more subword units are presented. This leads to a tradeoff between sentence length and vocabulary size, and both of them have an impact on the efficiency. In Fig. 1, the green line denotes the BLEU referencing the left axis. The red line denotes the speed change on CPU, the blue line denotes the speed change on GPU, they are both referencing the right axis. As shown in Fig. 1, tuning this hyper-parameter provides a considerable speedup without loss in performance, though most previous work simply adopts the default setting (32K). In our experiments we choose 10K because it is sufficient for good performance.

Model Structure Updates

10Inspired by the observations in Table 1, the Transformer decoder can be improved for each of its components. In this section, we describe how to Transformer Encoder Source Embedding Target Embedding simplify Transformer in a systematic way as shown in Fig. 2. Table 2 summarizes the contributions of each adopted method. We choose Baseline1 in Table 2 to analyze how each method in "Model Structure Updates" influences the model performance and inference speed after applying techniques from "Byte-Pair Encoding".

11Shallow Decoder. Recent work has shown that the deep encoder and shallow decoder architecture is promising in system speedup (Kasai et al., 2020;Li et al., 2021). In this work we follow the same idea by restricting the decoder to a 1-layer network and stacking more encoder layers until the total number of parameters matches the baseline.

12Pruning Heads. Researchers have found that most heads could be safely pruned and leaving the performance intact (Voita et al., 2019;Michel et al., 2019). So we retain only one head in decoder attentions.

13Dropping FFN. Hsu et al. (2020) used in the output projection is significantly overparameterized (Grave et al., 2017), especially when other components are compressed. To address this, we employ the low-rank approximation (Lan et al., 2020) for this matrix W = AB T to help to reduce the computation cost, where A ∈ R V ×E , B ∈ R H×E , V is the vocabulary size, E is the desired rank and H is the hidden size. We choose E = 64 in our experiments.

Training Strategies

14In our work, the methods presented in Section 2.2 can make an extremely small decoder that contains only 0.3% of the overall parameters. But we find that the model learned from scratch using the standard setting is much worse than the baseline (see Table 2). For better training, some methods are necessary. Table 3 illustrates how each proposed strategy contributes to reaching performance on par with the baseline. We choose Baseline2 in Table 3 to analyze how each method in "Training Strategies" influences the results after we have changed the BPE merge operations and simplified the model structure.

15Deep Configuration. Because our model is deep, we follow the deep model training setup provided in Wang et al. (2019).

16Weight Distillation. We also adopt a simplified version of weight distillation (WD) for training (Lin et al., 2020). This method initializes the student model with the corresponding weights from the teacher model, e.g., the first layer in the teacher encoder is reused in the first layer in the student encoder. Then it trains the student as in standard knowledge distillation (Hinton et al., 2015). Since our encoder is much deeper than the baseline, we initialize it in a round-robin manner. For the decoder, we randomly select one head from the teacher model for initialization, and the low-rank approximation of output projection is initialized by the SVD result of the teacher output projection (Golub and Reinsch, 2007).

17Weak Regularization. Because our decoder is small, we do not need to impose a strong regularization on it. We remove the dropout in the decoder and label smoothing. Dropout and label smoothing indeed do not have impacts on the inference speed. But changing them will train different models, which are unlikely to have exactly the same behavior. So some deviations in the inference speed are expected.

Setup

18We evaluate our methods on the WMT14 En-De, WMT14 En-Fr and NIST12 Zh-En machine translation tasks. We tokenize every sentence using a script from Moses and segment every word into subword units using BPE (Sennrich et al., 2016). The number of the BPE merge operations is set to 32K in the baseline and 10K for the target language in our model. In addition, we remove sentences with more than 250 subword units (Xiao et al., 2012). We choose Transformer-base (Vaswani et al., 2017) as our baseline. The hyper-parameters of the Mini-Decoder Network (MDN) are the same as the baseline except for those mentioned in Section 2.3. To produce consistent results for distillation, we choose the baseline with 10K BPE merges as the teacher model, which has the same vocabulary as MDN. We also compare our system with some recent proposed fast Transformer variants, e.g., AAN (Zhang et al., 2018), SAN and CAN (Li et al., 2021) followed from their papers. We report case-sensitive tokenized BLEU scores. For all experiments, we test on the model ensemble by averaging the last 5 checkpoints. For inference, we use a batch size of 64 and a beam width of 4. All models are evaluated on the NVIDIA TITAN V GPU and Intel(R) Xeon(R) Gold 5118 CPU. Table 4 shows the results of various systems. In both tasks, our method (MDN) has nearly the same performance as the baseline, but its speed is 3.80× and 2.52× faster on average for CPU and GPU. We find the baseline with 10K BPE merges is about 1.09× faster than the original baseline but with a similar performance, which suggests this BPE hyper-parameter is far from optimal for the baseline.

Results

19As for the recent work, i.e., AAN, SAN and CAN, all of them achieve performance similar to the baseline and are faster than the baseline (1.24×∼1.32× speedup on CPU) as reported in their papers. But our method outperforms these methods and runs consistently faster (3.80× speedup on CPU). Although the acceleration of our method in GPU (2.52× speedup) is not as obvious as it in CPU (3.80× speedup), it still outperforms CAN by 1.40×, which is highly optimized for GPU. Table 5 summarizes and compares the contributions of each proposed tricks described in Section 2. Each row of Table 5 is the result of applying the current trick to the system obtained in the previous row. This way helps to illustrate the compound effect of these tricks. We observe that using any structure simplification trick brings a significant performance degra- dation but a considerable speedup. However, our training strategies can make up for the performance loss. Among them, WD is most effective and has a boost of more than 3 BLEU points. Interestingly, we find that pruning attention heads does not have any speedup on GPU. This is because the parallelism of GPU decouples the computation cost of attention heads from the head number. Table 6 shows the results of the Transformer-deep model with a 48-layer encoder. The phenomenon here is similar to that in Table 4. The acceleration on Transformer-deep is less obvious than on Transformer-base, as a deeper encoder consumes more inference time. Moreover, compared with such a strong Transformer-deep teacher, MDN can still obtain a 2.49× speedup on CPU and a 2.09× speedup on GPU.

Sensitivity Analysis

20We study the impact of two commonly tuned hyperparameters at inference on our method, i.e., the batch size and the beam size. The left part of Fig. 3 shows that the speedup over the baseline decreases as the batch size increases, especially for GPU. This is because our shallow decoder trick exploits the parallelism of the encoder for speedup, which is not available if the batch size is large. This phenomenon is also observed by Li et al. (2021). The right part of Fig. 3 shows that the speedup is more obvious with a larger beam width. The reason is that the encoder occupies a larger portion of the inference cost at a small beam width and our work only save the cost of the decoder.

Combining with Other Models

21Our method is a bag of generic tricks and can be applied to other models. We choose AAN and CAN for testing, because AAN runs the fastest on CPU and CAN runs the fastest on GPU according to Table 4. Table 7 shows that both AAN and CAN benefit from techniques presented in this paper. Without loss in performance, AAN obtains a 1.97× speedup on CPU and CAN obtains a 1.05× speedup on GPU. It shows that AAN and CAN eventually have a similar BLEU score and speed as MDN, indicating that a highly optimized Transformer baseline already a strong candidate by itself.

Conclusion

22In this work, we present a bag of tricks to optimize the efficiency of the standard Transformer.

23The resulting model achieves a 3.61× speedup on CPU and a 2.62× speedup on GPU without loss in performance.

참고문헌 22건

  1. Distilling the Knowledge in a Neural Network arXiv (Cornell University) · Cornell University · 2015 10.48550/arxiv.1503.02531
  2. NiuTrans: An Open Source Toolkit for Phrase-based and Syntax-based Machine Translation 2012
  3. Rethinking the Inception Architecture for Computer Vision 2016 10.1109/cvpr.2016.308
  4. Efficient softmax approximation for GPUs arXiv (Cornell University) · Cornell University · 2016 10.48550/arxiv.1609.04309
  5. Non-Autoregressive Neural Machine Translation arXiv (Cornell University) · Cornell University · 2017 10.48550/arxiv.1711.02281
  6. Analyzing Multi-Head Self-Attention: Specialized Heads Do the Heavy Lifting, the Rest Can Be Pruned 2019 10.18653/v1/p19-1580
  7. Neural Machine Translation of Rare Words with Subword Units Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) · 2016 10.18653/v1/p16-1162
  8. Learning Deep Transformer Models for Machine Translation 2019 10.18653/v1/p19-1176
  9. Accelerating Neural Transformer via an Average Attention Network Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) · 2018 10.18653/v1/p18-1166
  10. Sharing Attention Weights for Fast Transformer 2019 10.24963/ijcai.2019/735
  11. From Research to Production and Back: Ludicrously Fast Neural Machine Translation 2019 10.18653/v1/d19-5632
  12. ALBERT: A Lite BERT for Self-supervised Learning of Language\n Representations arXiv (Cornell University) · Cornell University · 2019 10.48550/arxiv.1909.11942
  13. Deep Encoder, Shallow Decoder: Reevaluating the Speed-Quality Tradeoff in Machine Translation arXiv (Cornell University) · Cornell University · 2020
  14. Extremely Low Bit Transformer Quantization for On-Device Neural Machine Translation 2020 10.18653/v1/2020.findings-emnlp.433
  15. Losing Heads in the Lottery: Pruning Transformer Attention in Neural Machine Translation 2020 10.18653/v1/2020.emnlp-main.211
  16. Efficient Inference For Neural Machine Translation 2020 10.18653/v1/2020.sustainlp-1.7
  17. Rethinking the Value of Transformer Components Proceedings of the 17th international conference on Computational linguistics - · 2020 10.18653/v1/2020.coling-main.529
  18. Weight Distillation: Transferring the Knowledge in Neural Network Parameters 2021 10.18653/v1/2021.acl-long.162
  19. An Efficient Transformer Decoder with Compressed Sub-layers Proceedings of the AAAI Conference on Artificial Intelligence · Association for the Advancement of Artificial Intelligence · 2021 10.1609/aaai.v35i15.17572
  20. Sparsity in Deep Learning: Pruning and growth for efficient inference\n and training in neural networks arXiv (Cornell University) · Cornell University · 2021 10.48550/arxiv.2102.00554
  21. Singular Value Decomposition and Least Squares Solutions Springer eBooks · Springer Nature · 1971 10.1007/978-3-662-39778-7_10
  22. MizAR 60 for Mizar 50 DROPS (Schloss Dagstuhl – Leibniz Center for Informatics) · Schloss Dagstuhl – Leibniz Center for Informatics · 2023 10.4230/lipics.itp.2023.19