SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2202.07765 · ICML · 2022

General-purpose, long-context autoregressive modeling with Perceiver AR

Matthew Botvinick, Sander Dieleman, Oriol Vinyals, Jean-Baptiste Alayrac, Cȃtȃlina Cangea, Neil Zeghidour, Andrew Jaegle, Mateusz Malinowski, Sebastian Borgeaud, João Carreira, Ian Simon, Curtis Hawthorne, and 3 more

arXiv · PDF · Open in the Atlas

Code that ran

9 of 12 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, 0 violated it and 5 have no contract verdict; 4 failures of our instrument; 3 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/2202.07765.json · badge: /api/ran/2202.07765.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/perceiver-ar-pytorch reimplementation (classifier label)
classifier basis: classifier_2025
6 ran · 3 no recorded run
krasserm/perceiver-io community (classifier label)
classifier basis not recorded on the link
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
CausalAttention Ran
ran on a synthesized input
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("a265de65b3c70e54")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 5, 16) 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
from torch import nn, einsum
from einops import rearrange, repeat

def apply_rotary_pos_emb(pos, t):
    seq_len, rotate_dim = (t.shape[-2], pos.shape[-1])
    pos = pos[..., -seq_len:, :]
    t, t_pass = (t[..., :rotate_dim], t[..., rotate_dim:])
    t = t * pos.cos() + rotate_half(t) * pos.sin()
    return torch.cat((t, t_pass), dim=-1)

def exists(val):
    return val is not None

def rotate_half(x):
    x = rearrange(x, '... (j d) -> ... j d', j=2)
    x1, x2 = x.unbind(dim=-2)
    return torch.cat((-x2, x1), dim=-1)

class CausalAttention(nn.Module):

    def __init__(self, *, dim, dim_head=64, heads=8, dropout=0.0):
        super().__init__()
        self.scale = dim_head ** (-0.5)
        self.heads = heads
        inner_dim = heads * dim_head
        self.norm = nn.LayerNorm(dim)
        self.dropout = nn.Dropout(dropout)
        self.to_qkv = nn.Linear(dim, inner_dim * 3, bias=False)
        self.to_out = nn.Linear(inner_dim, dim, bias=False)

    def forward(self, x, rotary_pos_emb=None):
        x = self.norm(x)
        q, k, v = self.to_qkv(x).chunk(3, dim=-1)
        q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> b h n d', h=self.heads), (q, k, v))
        q = q * self.scale
        if exists(rotary_pos_emb):
            q = apply_rotary_pos_emb(rotary_pos_emb, q)
            k = apply_rotary_pos_emb(rotary_pos_emb, k)
        sim = einsum('b h i d, b h j d -> b h i j', q, k)
        i, j = sim.shape[-2:]
        causal_mask = torch.ones((i, j), device=x.device, dtype=torch.bool).triu(j - i + 1)
        sim = sim.masked_fill(causal_mask, -torch.finfo(sim.dtype).max)
        attn = sim.softmax(dim=-1)
        attn = self.dropout(attn)
        out = einsum('b h i j, b h j d -> b h i d', attn, v)
        out = rearrange(out, 'b h n d -> b n (h d)')
        return self.to_out(out)


INIT_ARGS = {
    'dim': 16,
    'dim_head': 4,
    'heads': 2,
    'dropout': 0.1,
}

ARGS = {
    'x': torch.randn(2, 5, 16),
    'rotary_pos_emb': torch.randn(5, 4),
}

if __name__ == '__main__':
    model = CausalAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 5, 16)")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 5, 16) — shape (2, 5, 16) 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
CausalPrefixAttention Ran
ran on a synthesized input
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("90ebd55fce80e55d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float; 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
import numpy as np
from einops import rearrange

INIT_ARGS = {
    'dim': 4,
    'dim_head': 2,
    'heads': 2,
    'max_heads_process': 1,
    'dropout': 0.0,
    'cross_attn_dropout': 0.0
}

# Create small tensors for input
batch = 2
seq_len_x = 3
seq_len_context = 4
dim = INIT_ARGS['dim']
heads = INIT_ARGS['heads']
dim_head = INIT_ARGS['dim_head']

x = torch.randn(batch, seq_len_x, dim)
context = torch.randn(batch, seq_len_context, dim)
rotary_pos_emb = torch.randn(batch, seq_len_x + seq_len_context, dim_head)

# Create context mask if needed
context_mask = torch.ones(batch, seq_len_context, dtype=torch.bool)
context_mask[0, -1] = False  # Mask last token for first batch element

ARGS = {
    'x': x,
    'context': context,
    'context_mask': context_mask,
    'rotary_pos_emb': rotary_pos_emb
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
FeedForward Ran
ran; our contract draft was wrong, not the code
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("7e6f6a18c63a8be3")
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 Sequential. 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 torch import nn

torch.manual_seed(0)

ARGS = {
    "dim": 64,
    "mult": 4,
    "dropout": 0.1,
}
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 Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential 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
RotaryEmbedding Ran
ran on a synthesized input
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("f8c62fb6aaac766d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 2, dtype family float, shape (4, 8) 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
from torch import nn, einsum

class RotaryEmbedding(nn.Module):

    def __init__(self, dim):
        super().__init__()
        inv_freq = 1.0 / 10000 ** (torch.arange(0, dim, 2).float() / dim)
        self.register_buffer('inv_freq', inv_freq)

    def forward(self, max_seq_len, *, device):
        seq = torch.arange(max_seq_len, device=device, dtype=self.inv_freq.dtype)
        freqs = einsum('i , j -> i j', seq, self.inv_freq)
        return torch.cat((freqs, freqs), dim=-1)


INIT_ARGS = {
    'dim': 8
}

ARGS = {
    'max_seq_len': 4,
    'device': torch.device('cpu')
}

if __name__ == '__main__':
    model = RotaryEmbedding(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output:\n{output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
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 (4, 8) — shape (4, 8) 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
apply_rotary_pos_emb Ran
ran; our contract draft was wrong, not the code
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("746466b4822c61fb")
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 3, dtype family float, shape (2, 3, 6) 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
from einops import rearrange, repeat

torch.manual_seed(0)

# Analyze the function:
# - apply_rotary_pos_emb(pos, t)
# - pos: used with pos[..., -seq_len:, :] and pos.cos(), pos.sin()
#   So pos needs shape (..., seq_len, rotate_dim)
# - t: used with t.shape[-2] (seq_len), t[..., :rotate_dim], t[..., rotate_dim:]
#   So t needs shape (..., seq_len, total_dim) where total_dim >= rotate_dim
# - rotate_half(t) is called on t[..., :rotate_dim]
#   rotate_half expects shape (..., j*d) where j=2, so rotate_dim must be even

# Create small tensors with distinct dimensions
batch_size = 2
seq_len = 3
rotate_dim = 4  # must be even for rotate_half
pass_dim = 2
total_dim = rotate_dim + pass_dim

# pos: shape (batch, seq_len, rotate_dim)
pos = torch.randn(batch_size, seq_len, rotate_dim)

# t: shape (batch, seq_len, total_dim)
t = torch.randn(batch_size, seq_len, total_dim)

ARGS = {
    "pos": pos,
    "t": t,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 6) — shape (2, 3, 6) 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
get_sweep Ran
ran; our contract draft was wrong, not the code
this paper's copy was not recorded; identical code first harvested from google-research/perceiver-ar
pointer only · get_code("3ce096de610c4729")
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.

is_checkpoint Ran
ran on a synthesized input
krasserm/perceiver-io/perceiver/model/core/lightning.py
code served (permissive licence) · get_code("9ac70921db9fdb73")
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 bool, ndim 0, dtype family float, shape () 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 os

def is_checkpoint(path: str):
    return os.path.splitext(path)[1] == '.ckpt'

ARGS = {
    "path": "/home/user/model.ckpt"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float, shape () — shape () 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
positions Ran
ran on a synthesized input
krasserm/perceiver-io/perceiver/model/core/position.py
code served (permissive licence) · get_code("6534b6aca89ab357")
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 int, 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
from typing import Optional

torch.manual_seed(0)

# Define arguments for the positions function
b = 2  # batch size
n = 4  # sequence length

# shift is optional, but when provided must have shape (b, 1)
shift = torch.tensor([[1], [2]], dtype=torch.long)

# device is optional, use CPU
device = torch.device('cpu')

ARGS = {
    'b': b,
    'n': n,
    'shift': shift,
    'device': device,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, 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 int, 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
rotate_half Ran
ran; our contract draft was wrong, not the code
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("1964789ef2be9b81")
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
import torch.nn.functional as F
from torch import nn, einsum
from einops import rearrange, repeat

torch.manual_seed(0)

def rotate_half(x):
    x = rearrange(x, '... (j d) -> ... j d', j=2)
    x1, x2 = x.unbind(dim=-2)
    return torch.cat((-x2, x1), dim=-1)

# The function takes a single parameter 'x' which is a tensor
# The function expects x to have a last dimension that is even (divisible by 2)
# It reshapes it into (j=2, d) where j*d equals the last dimension
# Then unbinds along dim=-2 to get two tensors
# Finally concatenates them back

# Create a tensor with batch size 2, and last dimension 4 (even number)
# Shape: (2, 4) - batch of 2, last dim of 4
x_tensor = torch.randn(2, 4)

ARGS = {
    'x': x_tensor
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
einops, 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
FeedForward Not yet run
unverified (harvested, no recorded run)
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("7599a08b755aee53")
How it ran

no invocation recorded. this sample carries JSON test cases instead of a setup block; get_reference_implementation serves them with the level they back.

PerceiverAR Not yet run
unverified (harvested, no recorded run)
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("d0f7f44834342f9f")
How it ran

no invocation recorded.

exists Not yet run
unverified (harvested, no recorded run)
lucidrains/perceiver-ar-pytorch/perceiver_ar_pytorch/perceiver_ar_pytorch.py
code served (permissive licence) · get_code("995d041d30ee3f9e")
How it ran

no invocation recorded. this sample carries JSON test cases instead of a setup block; get_reference_implementation serves them with the level they back.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 5 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 1 the same month, 4 later) and 6 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
brick of this paper's assembly: helper
486 other papers
78 dated earlier, 4 the same month, 401 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
rotate_half
brick of this paper's assembly: helper
13 other papers
1 dated earlier, 12 later · 2 only as an assembly brick
2112.04426 (2021-12)
Improving language models by retrieving from trillions of tokens
2203.07852 (2022-03)
Block-Recurrent Transformers
2204.02311 (2022-04)
PaLM: Scaling Language Modeling with Pathways
and 10 more not named here
FeedForward
brick of this paper's assembly: model
1 other paper
1 later
2603.28610 (2026-03)
ResAdapt: Adaptive Resolution for Efficient Multimodal Reasoning
RotaryEmbedding
brick of this paper's assembly: model
1 other paper
1 later
2204.02311 (2022-04)
PaLM: Scaling Language Modeling with Pathways
get_sweep 1 other paper
1 dated earlier
2103.03206 (2021-03)
Perceiver: General Perception with Iterative Attention

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

Real-world data is high-dimensional: a book, image, or musical performance can easily contain hundreds of thousands of elements even after compression. However, the most commonly used autoregressive models, Transformers, are prohibitively expensive to scale to the number of inputs and layers needed to capture this longrange structure. We develop Perceiver AR, an autoregressive, modality-agnostic architecture which uses cross-attention to map long-range inputs to a small number of latents while also maintaining end-to-end causal masking. Perceiver AR can directly attend to over a hundred thousand tokens, enabling practical long-context density estimation without the need for hand-crafted sparsity patterns or memory mechanisms. When trained on images or music, Perceiver AR generates outputs with clear long-term coherence and structure. Our architecture also obtains state-of-the-art likelihood on long-sequence benchmarks, including 64 × 64 ImageNet images and PG-19 books. * Equal contribution † Equal contribution 1 Google Research, Brain Team 2 DeepMind.

For agents

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

get_harvested_code_for_paper("2202.07765")
get_code_for_paper("2202.07765")
have("2202.07765")

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

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

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

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

Connect an agent — have() is free.