SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2103.13076 · EMNLP · 2021

Finetuning Pretrained Transformers into RNNs

Jungo Kasai, Nikolaos Pappas, Hao Peng, Noah ♡♢, Yizhe Zhang, Weizhu Chen, Dani Yogatama, Gabriel Ilharco, Yi Mao

arXiv · PDF · Open in the Atlas

Code that ran

3 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 2 failures of our instrument; 5 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2103.13076.json · badge: /api/ran/2103.13076.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
hazyresearch/lolcats community
Papers with Code archive
2 ran · 2 no recorded run
yashbonde/RNN-sim community
Papers with Code archive
1 ran · 3 no recorded run
FunctionStatusWhere it lives
RNNAttention Ran
ran on a synthesized input · constructed an object; no result was computed
yashbonde/RNN-sim/t2rmodel.py
pointer only (licence: GPL-3.0) · get_code("c3f6efe6d4164aec")
How it ran

The body of this sample is withheld: GPL-3.0, as GitHub detects it on this paper's repository, yashbonde/RNN-sim, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

convert_attention Ran
ran; our contract draft was wrong, not the code
hazyresearch/lolcats/src/model/convert_model.py
code served (permissive licence) · get_code("512f9bd4885fc3fa")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned MinimalModel. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from functools import partial

torch.manual_seed(0)

# Create a minimal self_attn module that mimics LLaMA attention
class MinimalAttention(nn.Module):
    def __init__(self, hidden_size=4, num_heads=2, layer_idx=0):
        super().__init__()
        self.hidden_size = hidden_size
        self.num_heads = num_heads
        self.layer_idx = layer_idx
        self.q_proj = nn.Linear(hidden_size, hidden_size)
        self.k_proj = nn.Linear(hidden_size, hidden_size)
        self.v_proj = nn.Linear(hidden_size, hidden_size)
        self.o_proj = nn.Linear(hidden_size, hidden_size)
    
    def forward(self, x):
        return self.o_proj(x)

# Create a minimal layer module
class MinimalLayer(nn.Module):
    def __init__(self, hidden_size=4, layer_idx=0):
        super().__init__()
        self.self_attn = MinimalAttention(hidden_size=hidden_size, layer_idx=layer_idx)
        self.mlp = nn.Linear(hidden_size, hidden_size)
    
    def forward(self, x):
        return self.mlp(x)

# Create a minimal model
class MinimalModel(nn.Module):
    def __init__(self, num_layers=2, hidden_size=4):
        super().__init__()
        self.model = nn.Module()
        self.model.layers = nn.ModuleList([
            MinimalLayer(hidden_size=hidden_size, layer_idx=i)
            for i in range(num_layers)
        ])
    
    def forward(self, x):
        return x

# Create attention_config as a dict-like object with attribute access
class AttentionConfig(dict):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__dict__ = self
    
    def __getattr__(self, name):
        try:
            return self[name]
        except KeyError:
            raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
    
    def __setattr__(self, name, value):
        self[name] = value

# Build the model
model = MinimalModel(num_layers=2, hidden_size=4)

# Build attention_config
attention_config = AttentionConfig(
    attention_type='softmax',
    softmax_attentions=[]
)

# Define ARGS
ARGS = {
    'model': model,
    'attention_config': attention_config,
    'train_attention': False,
    'remove_base_attn': True
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MinimalModel — a MinimalModel output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MinimalModel output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
traverse_layers Ran
ran; our contract draft was wrong, not the code
hazyresearch/lolcats/src/model/convert_model.py
code served (permissive licence) · get_code("87cc0d3cf321bafc")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ModuleList. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a model with nested structure: model.model.layers
class SimpleLayer(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

class NestedModel1(nn.Module):
    def __init__(self):
        super().__init__()
        self.model = nn.Module()
        self.model.layers = nn.ModuleList([SimpleLayer(), SimpleLayer()])
    
    def forward(self, x):
        return x

# Test with the first structure
model1 = NestedModel1()

ARGS = {
    "model": model1,
    "verbose": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ModuleList — a ModuleList output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a ModuleList output the recorded ndim 1 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Block Not yet run
unverified (harvested, no recorded run)
yashbonde/RNN-sim/t2rmodel.py
pointer only (licence: GPL-3.0) · get_code("129bc8a38ada9fce")
How it ran

The body of this sample is withheld: GPL-3.0, as GitHub detects it on this paper's repository, yashbonde/RNN-sim, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

GenerationMixin Not yet run
unverified (harvested, no recorded run)
yashbonde/RNN-sim/t2rmodel.py
pointer only (licence: GPL-3.0) · get_code("b7d123852b18dc32")
How it ran

The body of this sample is withheld: GPL-3.0, as GitHub detects it on this paper's repository, yashbonde/RNN-sim, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

T2R Not yet run
unverified (harvested, no recorded run)
yashbonde/RNN-sim/t2rmodel.py
pointer only (licence: GPL-3.0) · get_code("780a74bc5d6ff016")
How it ran

The body of this sample is withheld: GPL-3.0, as GitHub detects it on this paper's repository, yashbonde/RNN-sim, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

convert_llama_attention Not yet run
unverified (harvested, no recorded run)
hazyresearch/lolcats/src/model/convert_model.py
code served (permissive licence) · get_code("8057ebe8a31a2813")
How it ran

no invocation recorded.

get_attention Not yet run
unverified (harvested, no recorded run)
hazyresearch/lolcats/src/model/convert_model.py
code served (permissive licence) · get_code("7d2c368d797f9c8d")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 8 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

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. 1 * Work was done during an internship at Microsoft.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2103.13076")
get_code_for_paper("2103.13076")
have("2103.13076")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2103.13076.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2103.13076.svg)](https://syntology.ai/paper/2103.13076)

Connect an agent — have() is free.