SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1812.01243 · 2018

Efficient Attention: Attention with Linear Complexities

arXiv · PDF · Open in the Atlas

Code that ran

8 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 4 violated it and 0 have no contract verdict; 4 failures of our instrument; 0 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/1812.01243.json · badge: /api/ran/1812.01243.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
lucidrains/memory-transformer-xl community (classifier label)
classifier basis not recorded on the link
5 ran · 0 no recorded run
lucidrains/linear-attention-transformer 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
FunctionStatusWhere it lives
always Ran
ran; our contract draft was wrong, not the code
lucidrains/linear-attention-transformer/linear_attention_transformer/linear_attention_transformer.py
code served (permissive licence) · get_code("dd3db53ae7ad1c85")
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

torch.manual_seed(0)

def always(value):
    return lambda *args, **kwargs: value

# The function 'always' takes a single parameter 'value' and returns a lambda
# that ignores all arguments and keyword arguments, always returning 'value'.
# The function doesn't use 'value' in any special way - it just captures it
# and returns it from the lambda.

# We can pass any Python object as 'value'
ARGS = {
    "value": 42
}
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
cast_tuple Ran
ran, violated the contract we drafted
lucidrains/memory-transformer-xl/memory_transformer_xl/memory_transformer_xl.py
code served (permissive licence) · get_code("369eced62e96d690")
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 tuple, ndim 1, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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

torch.manual_seed(0)

# cast_tuple takes a single parameter 'el' and returns it as a tuple if it isn't already one
# We need to test both cases: when el is a tuple and when it isn't

# Test case 1: el is not a tuple (should be wrapped)
el_not_tuple = 42

# Test case 2: el is already a tuple (should be returned as-is)
el_is_tuple = (1, 2, 3)

# We'll use the non-tuple case as the primary test
ARGS = {
    "el": el_not_tuple
}
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 tuple, ndim 1, dtype family int — a tuple output has no array shape of its own; none is stated
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
default Ran
ran, violated the contract we drafted
lucidrains/memory-transformer-xl/memory_transformer_xl/memory_transformer_xl.py
code served (permissive licence) · get_code("a1bda7590dd9a4d2")
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 str. 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
from inspect import isfunction

torch.manual_seed(0)

def test_function_val():
    return "computed_value"

ARGS = {
    "x": None,
    "val": test_function_val
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
default Ran
ran, violated the contract we drafted
lucidrains/linear-attention-transformer/linear_attention_transformer/linear_attention_transformer.py
code served (permissive licence) · get_code("b5307f70349f5c27")
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 str. 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 numpy as np

def exists(val):
    return val is not None

def default(value, d):
    return d if not exists(value) else value

# Test case 1: value is None, should return d
value_1 = None
d_1 = "default_value"

# Test case 2: value is not None, should return value
value_2 = "provided_value"
d_2 = "default_value"

# Test case 3: value is 0 (falsy but not None), should return value
value_3 = 0
d_3 = 42

# Test case 4: value is empty list (falsy but not None), should return value
value_4 = []
d_4 = [1, 2, 3]

# Test case 5: value is a tensor
torch.manual_seed(0)
value_5 = torch.tensor([1.0, 2.0])
d_5 = torch.tensor([0.0, 0.0])

ARGS = {
    "value": None,
    "d": "default_value"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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.

to Ran
ran; our contract draft was wrong, not the code
lucidrains/memory-transformer-xl/memory_transformer_xl/memory_transformer_xl.py
code served (permissive licence) · get_code("7417c98099ec4e15")
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 dict. 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

torch.manual_seed(0)

# Create a small tensor to pass to the function
t = torch.randn(2, 4, dtype=torch.float32, device='cpu')

ARGS = {
    't': t
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
top_k Ran
ran; our contract draft was wrong, not the code
lucidrains/memory-transformer-xl/memory_transformer_xl/autoregressive_wrapper.py
code served (permissive licence) · get_code("3b65d5d77510c964")
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 Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. 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

torch.manual_seed(0)

# Create a small logits tensor: batch_size=2, vocab_size=4
logits = torch.randn(2, 4)

# Define ARGS dict with all parameters
ARGS = {
    "logits": logits,
    "thres": 0.9
}
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
top_p Ran
ran; our contract draft was wrong, not the code
lucidrains/memory-transformer-xl/memory_transformer_xl/autoregressive_wrapper.py
code served (permissive licence) · get_code("864f3eecd1ea0a36")
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 Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. 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.functional as F

torch.manual_seed(0)

# The function top_p takes logits (a tensor) and an optional threshold parameter
# logits should be a 2D tensor (batch_size, vocab_size) based on how it's used:
# - torch.sort is called on it with descending=True
# - F.softmax is applied along dim=-1
# - cum_probs > comparison works element-wise
# - scatter is called with dim=1
# This indicates batch dimension 0 and logits dimension 1

logits = torch.randn(2, 4)  # batch_size=2, vocab_size=4
thres = 0.9

ARGS = {
    "logits": logits,
    "thres": thres,
}
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 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

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, 8 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 8 later) and 0 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
5 dated earlier, 479 later, 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
top_k 6 other papers
6 later
2006.15020 (2020-06)
Pre-training via Paraphrasing
2107.11906 (2021-07)
H-Transformer-1D: Fast One-Dimensional Hierarchical Attention for Sequences
2112.05682 (2021-12)
Self-attention Does Not Need $O(n^2)$ Memory
and 3 more not named here
cast_tuple 5 other papers
5 later · 1 only as an assembly brick
1910.06764 (2019-10)
Stabilizing Transformers for Reinforcement Learning
1911.05507 (2019-11)
Compressive Transformers for Long-Range Sequence Modelling
2002.05202 (2020-02)
GLU Variants Improve Transformer
and 2 more not named here
default 4 other papers
4 later
2002.05202 (2020-02)
GLU Variants Improve Transformer
2006.16236 (2020-06)
Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
2303.11249 (2023-03)
What Makes Data Suitable for a Locally Connected Neural Network? A Necessary and Sufficient Condition Based on Quantum Entanglement
and 1 more not named here
default 3 other papers
3 later
1910.06764 (2019-10)
Stabilizing Transformers for Reinforcement Learning
1911.05507 (2019-11)
Compressive Transformers for Long-Range Sequence Modelling
2002.05202 (2020-02)
GLU Variants Improve Transformer
to 3 other papers
3 later
1910.06764 (2019-10)
Stabilizing Transformers for Reinforcement Learning
1911.05507 (2019-11)
Compressive Transformers for Long-Range Sequence Modelling
2002.05202 (2020-02)
GLU Variants Improve Transformer
always 2 other papers
2 later
2002.05202 (2020-02)
GLU Variants Improve Transformer
2006.16236 (2020-06)
Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
top_p 2 other papers
2 later
2305.18565 (2023-05)
PaLI-X: On Scaling up a Multilingual Vision and Language Model
2407.09099 (2024-07)
Music Proofreading with RefinPaint: Where and How to Modify Compositions given 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-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

Dot-product attention has wide applications in computer vision and natural language processing. However, its memory and computational costs grow quadratically with the input size. Such growth prohibits its application on high-resolution inputs. To remedy this drawback, this paper proposes a novel efficient attention mechanism equivalent to dot-product attention but with substantially less memory and computational costs. Its resource efficiency allows more widespread and flexible integration of attention modules into a network, which leads to better accuracies. Empirical evaluations demonstrated the effectiveness of its advantages. Efficient attention modules brought significant performance boosts to object detectors and instance segmenters on MS-COCO 2017. Further, the resource efficiency democratizes attention to complex models, where high costs prohibit the use of dot-product attention. As an exemplar, a model with efficient attention achieved state-of-the-art accuracies for stereo depth estimation on the Scene Flow dataset. Code is available at https://github.com/cmsflash/efficient-attention.

For agents

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

get_harvested_code_for_paper("1812.01243")
get_code_for_paper("1812.01243")
have("1812.01243")

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

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

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

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

Connect an agent — have() is free.