SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1904.10509 · 2019

Generating Long Sequences with Sparse Transformers

Alec Radford, Scott Gray, Ilya Sutskever, Rewon Child

arXiv · PDF · Open in the Atlas

Code that ran

5 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (4 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 1 failure of our instrument; 1 no recorded run), 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/1904.10509.json · badge: /api/ran/1904.10509.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
wilson1yan/VideoGPT community
Papers with Code archive
3 ran · 1 no recorded run
ptillet/torch-blocksparse community
Papers with Code archive
2 ran · 0 no recorded run
FunctionStatusWhere it lives
DeepSpeedSparseSelfAttention Ran
ran on a synthesized input · constructed an object; no result was computed
ptillet/torch-blocksparse/torch_blocksparse/deepspeedsparseselfattention.py
code served (permissive licence) · get_code("cc4d4565045cf844")
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, DeepSpeedSparseSelfAttention: 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 SparsityConfig:
    def __init__(self, mode='fixed', block=16, stride=64, attention='unidirectional', numverts=1, vertsize=1):
        if mode != 'dense' and mode != 'fixed':
            raise NotImplementedError('only "dense" and "fixed" modes are supported for now')
        self.mode = mode
        self.block = block
        self.stride = stride
        if attention != 'unidirectional' and attention != 'bidirectional':
            raise NotImplementedError('only "uni/bi-directional" attentions are supported for now')
        self.attention = attention
        self.numverts = numverts
        self.vertsize = vertsize

class DeepSpeedSparseSelfAttention(nn.Module):
    @staticmethod
    def _set_s1_layout(layout, h, num_blocks, block_stride, attention):
        for i in range(0, num_blocks, block_stride):
            for j in range(i, i + block_stride):
                for k in range(i, j + 1 if attention == 'unidirectional' else i + block_stride):
                    layout[h, j, k] = 1
        return layout

    @staticmethod
    def _set_s2_layout(layout, h, num_blocks, block_stride, attention, numverts, vertsize):
        start = block_stride - (1 + h % numverts) * vertsize
        for i in range(0, num_blocks):
            end = i if attention == 'unidirectional' else num_blocks
            for j in range(start, end, block_stride):
                for k in range(j, min(j + vertsize, num_blocks)):
                    layout[h, i, k] = 1
        return layout

    @staticmethod
    def _make_layout(num_heads, num_blocks, mode, block_stride, attention, numverts, vertsize):
        if block_stride / vertsize != block_stride // vertsize:
            raise ValueError(f'Number of blocks in a stride window {block_stride} must be dividable by vertical block size {vertsize}')
        if numverts > block_stride / vertsize:
            raise ValueError(f'Number of layout versions {numverts} cannot be larger than blocks in a stride window divided by vertical block size {block_stride} / {vertsize} = {block_stride / vertsize}')
        layout = torch.zeros((num_heads, num_blocks, num_blocks), dtype=torch.int64)
        if mode == 'dense':
            layout[:, :, :] = 1
        elif mode == 'fixed':
            for i in range(0, num_heads):
                layout = DeepSpeedSparseSelfAttention._set_s1_layout(layout, i, num_blocks, block_stride, attention)
                layout = DeepSpeedSparseSelfAttention._set_s2_layout(layout, i, num_blocks, block_stride, attention, numverts, vertsize)
        return layout

    ops = dict()

    def __init__(self, sparsity_config=None, key_padding_mask_mode='add', attn_mask_mode='mul'):
        super().__init__()
        self.sparsity_config = sparsity_config if sparsity_config is not None else SparsityConfig()
        self.key_padding_mask_mode = key_padding_mask_mode
        self.attn_mask_mode = attn_mask_mode

sparsity_config = SparsityConfig(
    mode='fixed',
    block=16,
    stride=64,
    attention='unidirectional',
    numverts=1,
    vertsize=1
)

ARGS = {
    'sparsity_config': sparsity_config,
    'key_padding_mask_mode': 'add',
    'attn_mask_mode': 'mul'
}
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 DeepSpeedSparseSelfAttention — 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 DeepSpeedSparseSelfAttention 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
SparseAttention Ran
ran on a synthesized input · constructed an object; no result was computed
wilson1yan/VideoGPT/videogpt/attention.py
code served (permissive licence) · get_code("21937d73418cc532")
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, SparseAttention: 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 numpy as np
import torch.nn as nn

torch.manual_seed(0)

# The function signature is incomplete, but based on the code provided,
# it appears to be part of a sparse attention implementation.
# Let's construct valid arguments for StridedSparsityConfig and related functions.

# Create a simple config
ARGS = {
    'shape': (8, 8),  # 2D shape with seq_len = 64
    'n_head': 2,  # number of attention heads
    'causal': True,  # causal masking
    'block': 4,  # block size - seq_len (64) must be divisible by this
    'num_local_blocks': 2,  # number of local blocks to attend to
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
deepspeed, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SparseAttention — 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 SparseAttention 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
SparsityConfig Ran
ran on a synthesized input · constructed an object; no result was computed
ptillet/torch-blocksparse/torch_blocksparse/deepspeedsparseselfattention.py
code served (permissive licence) · get_code("23a25a6d256367d8")
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, SparsityConfig: 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 numpy as np

torch.manual_seed(0)

ARGS = {
    'mode': 'fixed',
    'block': 16,
    'stride': 64,
    'attention': 'bidirectional',
    'numverts': 1,
    'vertsize': 1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SparsityConfig — 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 SparsityConfig 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
StridedSparsityConfig Ran
ran on a synthesized input · constructed an object; no result was computed
wilson1yan/VideoGPT/videogpt/attention.py
code served (permissive licence) · get_code("b5ef9bf53e62eab3")
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, StridedSparsityConfig: 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 numpy as np

torch.manual_seed(0)

# Construct arguments for StridedSparsityConfig
# Parameters: shape, n_head, causal, block, num_local_blocks

# shape: tuple of dimensions that multiply to form sequence length
# Must be divisible by block size
shape = (8, 4)  # seq_len = 32

# n_head: number of attention heads
n_head = 2

# causal: whether to apply causal masking
causal = True

# block: block size for strided sparsity
# seq_len (32) must be divisible by block
block = 4

# num_local_blocks: number of local blocks to attend to
num_local_blocks = 2

ARGS = {
    "shape": shape,
    "n_head": n_head,
    "causal": causal,
    "block": block,
    "num_local_blocks": num_local_blocks,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type StridedSparsityConfig — 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 StridedSparsityConfig 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
scaled_dot_product_attention Ran
ran; our contract draft was wrong, not the code
wilson1yan/VideoGPT/videogpt/attention.py
code served (permissive licence) · get_code("9d35276799c65577")
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 3, dtype family float, shape (2, 3, 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 numpy as np
import torch
import torch.nn.functional as F

torch.manual_seed(0)

# Create small tensors for scaled dot product attention
# q, k, v shapes: (batch_size, seq_len, d_model)
batch_size = 2
seq_len_q = 3
seq_len_kv = 3
d_model = 4

q = torch.randn(batch_size, seq_len_q, d_model)
k = torch.randn(batch_size, seq_len_kv, d_model)
v = torch.randn(batch_size, seq_len_kv, d_model)

# mask: shape (batch_size, seq_len_q, seq_len_kv), with values 0 or 1
mask = torch.ones(batch_size, seq_len_q, seq_len_kv)

attn_dropout = 0.1
training = True

ARGS = {
    'q': q,
    'k': k,
    'v': v,
    'mask': mask,
    'attn_dropout': attn_dropout,
    'training': training
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
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, shape (2, 3, 4) — shape (2, 3, 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
view_range Not yet run
unverified (harvested, no recorded run)
wilson1yan/VideoGPT/videogpt/attention.py
code served (permissive licence) · get_code("9f28796c8276d371")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 5 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
view_range
brick of this paper's assembly: helper
2 other papers
2 later
2402.19470 (2024-02)
Towards Generalizable Tumor Synthesis
2404.12391 (2024-04)
On the Content Bias in Fréchet Video Distance

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

Transformers are powerful sequence models, but require time and memory that grows quadratically with the sequence length. In this paper we introduce sparse factorizations of the attention matrix which reduce this to O(n √ n). We also introduce a) a variation on architecture and initialization to train deeper networks, b) the recomputation of attention matrices to save memory, and c) fast attention kernels for training. We call networks with these changes Sparse Transformers, and show they can model sequences tens of thousands of timesteps long using hundreds of layers. We use the same architecture to model images, audio, and text from raw bytes, setting a new state of the art for density modeling of Enwik8, CIFAR-10, and ImageNet-64. We generate unconditional samples that demonstrate global coherence and great diversity, and show it is possible in principle to use self-attention to model sequences of length one million or more.

For agents

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

get_harvested_code_for_paper("1904.10509")
get_code_for_paper("1904.10509")
have("1904.10509")

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

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

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

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

Connect an agent — have() is free.