Finetuning Pretrained Transformers into RNNs

Transformers have outperformed recurrent neural networks (RNNs) in natural language generation. But this comes with a significant computational cost, as the attention mechanism's complexity scales quadratically with sequence length. Efficient transformer variants have received increasing interest in recent works. Among them, a linear-complexity recurrent variant has proven well suited for autoregressive generation. It approximates the softmax attention with randomized or heuristic feature maps, but can be difficult to train and may yield suboptimal accuracy. This work aims to convert a pretrained transformer into its efficient recurrent counterpart, improving efficiency while maintaining accuracy. Specifically, we propose a swap-then-finetune procedure: in an off-the-shelf pretrained transformer, we replace the softmax attention with its linear-complexity recurrent alternative and then finetune. With a learned feature map, our approach provides an improved tradeoff between efficiency and accuracy over the standard transformer and other recurrent variants. We also show that the finetuning process has lower training cost relative to training these recurrent variants from scratch. As many models for natural language tasks are increasingly dependent on large-scale pretrained transformers, this work presents a viable approach to improving inference efficiency without repeating the expensive pretraining process.

PDF Abstract EMNLP 2021 PDF EMNLP 2021 Abstract
Task Dataset Model Metric Name Metric Value Global Rank Result Benchmark
Language Modelling WikiText-103 T2R + Pretrain Validation perplexity 19 # 17
Test perplexity 19.6 # 41
Machine Translation WMT2014 English-French T2R + Pretrain BLEU score 42.1 # 18
Hardware Burden None # 1
Operations per network pass None # 1
Machine Translation WMT2014 English-German T2R + Pretrain BLEU score 28.7 # 39
Hardware Burden None # 1
Operations per network pass None # 1
Machine Translation WMT2017 Chinese-English T2R + Pretrain BLEU 23.8 # 2

Methods