SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.06881 · NeurIPS · 2022

Recurrent Memory Transformer

Mikhail Burtsev, Aydar Bulatov, Yuri Kuratov

arXiv · PDF · Open in the Atlas

Code that ran

6 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 1 violated it and 3 have no contract verdict; 1 failure of our instrument; 7 no recorded run); 1 of them was also run on the host, not in the jail, by the peer-agreement lane that set its level, measured 2026-11-23; 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/2207.06881.json · badge: /api/ran/2207.06881.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
booydar/lm-rmt reimplementation (classifier label)
classifier basis: classifier_2025
3 ran · 6 no recorded run
lucidrains/recurrent-memory-transformer-pytorch reimplementation (classifier label)
classifier basis: classifier_2025
2 ran · 0 no recorded run
copy not recorded community
not in the paper's declared repositories
1 ran · 0 no recorded run
booydar/t5-experiments community
Papers with Code archive
0 ran · 1 no recorded run
FunctionStatusWhere it lives
identity Ran
ran, honoured the contract we drafted
lucidrains/recurrent-memory-transformer-pytorch/recurrent_memory_transformer_pytorch/recurrent_memory_transformer.py
code served (permissive licence) · get_code("7f1040f5e3991d5e")
How it ran

Ran in Syntology's jail on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. The comparison behind this sample's level is a different run: the peer-agreement lane ran it again on the host, not in the jail (report dated 2026-09-05T00:37:21Z). If your copy returns the same type, ndim and shape 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)

# The identity function simply returns its first argument
# and ignores all other args and kwargs
# So we need to provide a value for t and can optionally provide other args/kwargs

t = torch.randn(2, 4)
extra_arg_1 = torch.randn(3, 5)
extra_arg_2 = "some_string"
extra_kwarg_1 = 42
extra_kwarg_2 = [1, 2, 3]

ARGS = {
    "t": t,
    "args": (extra_arg_1, extra_arg_2),
    "kwargs": {"key1": extra_kwarg_1, "key2": extra_kwarg_2}
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
AdaptiveEmbedding Ran
ran on a synthesized input · constructed an object; no result was computed
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("4fbd1dc67be817f3")
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 an instance of its own class, AdaptiveEmbedding: the run constructed the object and did not call it, so no result was computed. 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)

# Define ARGS dict with all parameters for AdaptiveEmbedding
ARGS = {
    'n_token': 100,
    'd_embed': 8,
    'd_proj': 6,
    'cutoffs': [30, 60],
    'div_val': 1,
    'sample_softmax': 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 AdaptiveEmbedding — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a AdaptiveEmbedding 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
DecoderLayer Ran
ran on a synthesized input · constructed an object; no result was computed
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("460c2ddd444dbae3")
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 an instance of its own class, DecoderLayer: the run constructed the object and did not call it, so no result was computed. 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)

# Define ARGS dict with all parameters for DecoderLayer.__init__
ARGS = {
    'n_head': 2,
    'd_model': 4,
    'd_head': 2,
    'd_inner': 8,
    'dropout': 0.1,
}

# Verify the setup by instantiating DecoderLayer
decoder_layer = nn.Module.__new__(nn.Module)

# Test forward pass with sample inputs
batch_size = 2
seq_len = 3
d_model = 4

# Create sample input tensor
dec_inp = torch.randn(seq_len, batch_size, d_model)

# Optional: create attention mask and mems
dec_attn_mask = torch.zeros(seq_len, seq_len, dtype=torch.long)
mems = torch.randn(1, batch_size, d_model)

# Verify tensors have correct shapes
assert dec_inp.shape == (seq_len, batch_size, d_model)
assert dec_attn_mask.shape == (seq_len, seq_len)
assert mems.shape == (1, batch_size, d_model)
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 DecoderLayer — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DecoderLayer 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
MultiHeadAttn Ran
ran on a synthesized input · constructed an object; no result was computed
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("17b3ba52d31a4f22")
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 an instance of its own class, MultiHeadAttn: the run constructed the object and did not call it, so no result was computed. 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)

class MultiHeadAttn(nn.Module):

    def __init__(self, n_head, d_model, d_head, dropout, dropatt=0, pre_lnorm=False):
        super(MultiHeadAttn, self).__init__()
        self.n_head = n_head
        self.d_model = d_model
        self.d_head = d_head
        self.dropout = dropout
        self.q_net = nn.Linear(d_model, n_head * d_head, bias=False)
        self.kv_net = nn.Linear(d_model, 2 * n_head * d_head, bias=False)
        self.drop = nn.Dropout(dropout)
        self.dropatt = nn.Dropout(dropatt)
        self.o_net = nn.Linear(n_head * d_head, d_model, bias=False)
        self.layer_norm = nn.LayerNorm(d_model)
        self.scale = 1 / d_head ** 0.5
        self.pre_lnorm = pre_lnorm

    def forward(self, h, attn_mask=None, mems=None):
        if mems is not None:
            c = torch.cat([mems, h], 0)
        else:
            c = h
        if self.pre_lnorm:
            c = self.layer_norm(c)
        head_q = self.q_net(h)
        head_k, head_v = torch.chunk(self.kv_net(c), 2, -1)
        head_q = head_q.view(h.size(0), h.size(1), self.n_head, self.d_head)
        head_k = head_k.view(c.size(0), c.size(1), self.n_head, self.d_head)
        head_v = head_v.view(c.size(0), c.size(1), self.n_head, self.d_head)
        attn_score = torch.einsum('ibnd,jbnd->ijbn', (head_q, head_k))
        attn_score.mul_(self.scale)
        if attn_mask is not None and attn_mask.any().item():
            if attn_mask.dim() == 2:
                attn_score.masked_fill_(attn_mask[None, :, :, None].bool(), -float('inf'))
            elif attn_mask.dim() == 3:
                attn_score.masked_fill_(attn_mask[:, :, :, None].bool(), -float('inf'))
        attn_prob = torch.nn.functional.softmax(attn_score, dim=1)
        attn_prob = self.dropatt(attn_prob)
        attn_vec = torch.einsum('ijbn,jbnd->ibnd', (attn_prob, head_v))
        attn_vec = attn_vec.contiguous().view(attn_vec.size(0), attn_vec.size(1), self.n_head * self.d_head)
        attn_out = self.o_net(attn_vec)
        attn_out = self.drop(attn_out)
        if self.pre_lnorm:
            output = h + attn_out
        else:
            output = self.layer_norm(h + attn_out)
        return output

n_head = 2
d_model = 8
d_head = 4
dropout = 0.1
dropatt = 0.1
pre_lnorm = False

h = torch.randn(3, 2, 8)
attn_mask = torch.zeros(3, 3, dtype=torch.bool)
mems = torch.randn(1, 2, 8)

ARGS = {
    'n_head': n_head,
    'd_model': d_model,
    'd_head': d_head,
    'dropout': dropout,
    'dropatt': dropatt,
    'pre_lnorm': pre_lnorm
}
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 MultiHeadAttn — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MultiHeadAttn 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
eval_decorator Ran
ran; our contract draft was wrong, not the code
lucidrains/recurrent-memory-transformer-pytorch/recurrent_memory_transformer_pytorch/recurrent_memory_transformer.py
code served (permissive licence) · get_code("5444a7d75d38878d")
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 function. 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)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

def dummy_function(self, x):
    """A simple function that will be decorated"""
    return self.linear(x)

# Create a model instance
model = SimpleModel()

# The eval_decorator function takes one parameter: fn (a function)
# We need to pass a function that expects self as first argument
def test_fn(self, x):
    """Function to be decorated - uses self.training and self.eval(), self.train()"""
    return self.linear(x)

ARGS = {
    "fn": test_fn
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
exists Ran
ran, violated the contract we drafted
this paper's copy was not recorded; identical code first harvested from ThomasMrY/VCT
pointer only; the stored copy get_code serves, from ThomasMrY/VCT, is pointer only (licence: NONE) · get_code("aa5486a3650902d8")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

MemTransformerLM Not yet run
unverified (harvested, no recorded run)
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("d6f7759cbb53633c")
How it ran

no invocation recorded.

ProjectedAdaptiveLogSoftmax Not yet run
unverified (harvested, no recorded run)
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("da461b6fa9c6c2a2")
How it ran

no invocation recorded.

RMTBaseModel Not yet run
unverified (harvested, no recorded run)
booydar/t5-experiments/modeling_rmt/base.py
pointer only (licence: NONE) · get_code("36ad33d145150380")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, booydar/t5-experiments when it was checked. 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.

RelLearnableDecoderLayer Not yet run
unverified (harvested, no recorded run)
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("1a40c2f95182a074")
How it ran

no invocation recorded.

RelLearnableMultiHeadAttn Not yet run
unverified (harvested, no recorded run)
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("fd30acd200176f09")
How it ran

no invocation recorded.

RelPartialLearnableDecoderLayer Not yet run
unverified (harvested, no recorded run)
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("4bd79fa041136c60")
How it ran

no invocation recorded.

RelPartialLearnableMultiHeadAttn Not yet run
unverified (harvested, no recorded run)
booydar/lm-rmt/pytorch/mem_transformer.py
code served (permissive licence) · get_code("027c122b94fbe192")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 6 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 1 the same month, 3 later) and 7 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.

FunctionAlso present inEarliest-datedOthers named
exists 486 other papers
104 dated earlier, 4 the same month, 375 later, 1 same year, order not determinable, 2 undated · 78 only as an assembly brick
1603.08155 (2016-03)
Perceptual Losses for Real-Time Style Transfer and Super-Resolution
1611.07004 (2016-11)
Image-to-Image Translation with Conditional Adversarial Networks
1804.04637 (2018-04)
EMBER: An Open Dataset for Training Static PE Malware Machine Learning Models
and 483 more not named here
identity 54 other papers
6 dated earlier, 48 later · 11 only as an assembly brick
1611.07004 (2016-11)
Image-to-Image Translation with Conditional Adversarial Networks
1907.01470 (2019-07)
Augmenting Self-attention with Persistent Memory
2006.11239 (2020-06)
Denoising Diffusion Probabilistic Models
and 51 more not named here
DecoderLayer
brick of this paper's assembly: model
2 other papers
2 dated earlier · 1 only as an assembly brick
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2101.02402 (2021-01)
Compound Word Transformer: Learning to Compose Full-Song Music over Dynamic Directed Hypergraphs
RelLearnableDecoderLayer
brick of this paper's assembly: model
2 other papers
2 dated earlier
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2101.02402 (2021-01)
Compound Word Transformer: Learning to Compose Full-Song Music over Dynamic Directed Hypergraphs
eval_decorator 2 other papers
1 dated earlier, 1 later
2203.07852 (2022-03)
Block-Recurrent Transformers
2305.18565 (2023-05)
PaLI-X: On Scaling up a Multilingual Vision and Language Model
RelPartialLearnableDecoderLayer
brick of this paper's assembly: model
1 other paper
1 dated earlier
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context

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-23.

Repositories linked to this paper

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

Abstract

Transformer-based models show their effectiveness across multiple domains and tasks. The self-attention allows to combine information from all sequence elements into context-aware representations. However, global and local information has to be stored mostly in the same element-wise representations. Moreover, the length of an input sequence is limited by quadratic computational complexity of selfattention. In this work, we propose and study a memory-augmented segment-level recurrent Transformer (RMT). Memory allows to store and process local and global information as well as to pass information between segments of the long sequence with the help of recurrence. We implement a memory mechanism with no changes to Transformer model by adding special memory tokens to the input or output sequence. Then the model is trained to control both memory operations and sequence representations processing. Results of experiments show that RMT performs on par with the Transformer-XL on language modeling for smaller memory sizes and outperforms it for tasks that require longer sequence processing. We show that adding memory tokens to Tr-XL is able to improve its performance. This makes Recurrent Memory Transformer a promising architecture for applications that require learning of long-term dependencies and general purpose in memory processing, such as algorithmic tasks and reasoning.

For agents

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

get_harvested_code_for_paper("2207.06881")
get_code_for_paper("2207.06881")
have("2207.06881")

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

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

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

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

Connect an agent — have() is free.