Papers › Finetuning Pretrained Transformers into RNNs

Finetuning Pretrained Transformers into RNNs

24 Mar 2021EMNLP 2021 11arXiv:2103.13076archive 2025-07-28

Jungo Kasai, Hao Peng, Yizhe Zhang, Dani Yogatama, Gabriel Ilharco, Nikolaos Pappas, Yi Mao, Weizhu Chen, Noah A. Smith

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.

PaperPDFConference PDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2103.13076")

Code

Syntology Ran 3 of 8 code samples harvested from 2 repositories linked to this paper; 5 have no recorded run. Of those that ran: 1 ran · our draft was wrong; 2 ran with no contract checked.

By repository: community (archive-listed): 8 samples from 2 repositories, 3 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

hazyresearch/lolcats mentioned on GitHubpytorch report
yashbonde/RNN-sim mentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

8 samples harvested; 3 ran; 0 honoured the contract we drafted; 5 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · our draft was wrong
2ran
5unverified

Licence: 4 of the 8 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

RNNAttention yashbonde/RNN-sim/t2rmodel.py community (archive-listed) ran GPL-3.0 (copyleft) · pointer only · c3f6efe6d4164aec · report
convert_attention hazyresearch/lolcats/src/model/convert_model.py community (archive-listed) ran · our draft was wrong Apache-2.0 (permissive) · 512f9bd4885fc3fa · report
traverse_layers hazyresearch/lolcats/src/model/convert_model.py community (archive-listed) ran Apache-2.0 (permissive) · 87cc0d3cf321bafc · report
Block yashbonde/RNN-sim/t2rmodel.py community (archive-listed) unverified GPL-3.0 (copyleft) · pointer only · 129bc8a38ada9fce · report
GenerationMixin yashbonde/RNN-sim/t2rmodel.py community (archive-listed) unverified GPL-3.0 (copyleft) · pointer only · b7d123852b18dc32 · report
T2R yashbonde/RNN-sim/t2rmodel.py community (archive-listed) unverified GPL-3.0 (copyleft) · pointer only · 780a74bc5d6ff016 · report
convert_llama_attention hazyresearch/lolcats/src/model/convert_model.py community (archive-listed) unverified Apache-2.0 (permissive) · 8057ebe8a31a2813 · report
get_attention hazyresearch/lolcats/src/model/convert_model.py community (archive-listed) unverified Apache-2.0 (permissive) · 7d2c368d797f9c8d · report

Tasks

Language ModellingMachine TranslationText Generation

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Language Modelling WikiText-103 T2R + Pretrain Test perplexity 19.6 #41 of 89 Archive leaderboard report
Language Modelling WikiText-103 T2R + Pretrain Validation perplexity 19 #41 of 89 Archive leaderboard report
Machine Translation WMT2014 English-French T2R + Pretrain BLEU score 42.1 #19 of 57 Archive leaderboard report
Machine Translation WMT2014 English-German T2R + Pretrain BLEU score 28.7 #39 of 91 Archive leaderboard report
Machine Translation WMT2017 Chinese-English T2R + Pretrain BLEU 23.8 #2 of 3 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

Softmax

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections