SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.11089 · ACL · 2025

Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention

Yuqing Wang, Ming Zhang, Liang Zhao, Damai Dai, Lean Wang, Zhiping Xiao, Zhengyan Zhang, Chong Ruan, Huazuo Gao, Jingyang Yuan, Wangding Zeng, Wenfeng Liang, and 3 more

arXiv · PDF · Open in the Atlas

Code that ran

16 of 19 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 12 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/2502.11089.json · badge: /api/ran/2502.11089.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
microsoft/seerattention canonical (classifier label)
classifier basis not recorded on the link
13 ran · 3 no recorded run
britacatalin/bsa community
Papers with Code archive
3 ran · 0 no recorded run
FunctionStatusWhere it lives
NativeSparseAttention Ran
ran on a synthesized input · constructed an object; no result was computed
britacatalin/bsa/nsa/native_sparse_attention.py
code served (permissive licence) · get_code("b93448058eb3a756")
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, NativeSparseAttention: 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
from torch import Tensor

torch.manual_seed(0)

# Define ARGS dict with all required parameters for NativeSparseAttention
ARGS = {
    "dim": 16,
    "num_heads": 4,
    "ball_size": 2,
    "dimensionality": 3,
    "compress_block_size": 2,
    "selected_blocks_number": 2,
    "use_compress_mlp": True,
    "compress_mlp_expand_factor": 2.0,
    "use_group_selection": True,
    "group_selection_size": 4,
    "should_mask_blocks_in_ball": True,
    "use_token_gated_attention": True,
    "use_coarse_q_attn": True,
    "use_coarse_q_importance": True,
}
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 NativeSparseAttention — 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 NativeSparseAttention 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
StaticGatedAttention Ran
ran on a synthesized input
britacatalin/bsa/nsa/native_sparse_attention.py
code served (permissive licence) · get_code("f36889830d661d6f")
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 4, 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 torch.nn as nn

class StaticGatedAttention(nn.Module):

    def __init__(self, num_heads: int):
        super().__init__()
        self.gates = nn.Parameter(torch.zeros(1, num_heads, 2, 1, 1))

    def forward(self, branches: torch.Tensor) -> torch.Tensor:
        ones = torch.ones_like(self.gates[:, :, :1])
        fused = torch.cat([ones, torch.sigmoid(self.gates)], 2)
        return (fused * branches).sum(dim=2)


INIT_ARGS = {
    'num_heads': 3
}

ARGS = {
    'branches': torch.randn(2, 3, 3, 4, 5)
}

if __name__ == '__main__':
    model = StaticGatedAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {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 4, 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)
TokenGatedAttention Ran
ran on a synthesized input · constructed an object; no result was computed
britacatalin/bsa/nsa/native_sparse_attention.py
code served (permissive licence) · get_code("d9f141ee5201879b")
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, TokenGatedAttention: 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)

# Construct the TokenGatedAttention module
dim = 4
num_heads = 2
model = nn.Sequential(
    nn.Linear(dim, 3 * num_heads),
    nn.Sigmoid()
)
token_gated_attention = nn.Sequential(
    nn.Linear(dim, 3 * num_heads),
    nn.Sigmoid()
)

# Construct input tensors
# x: (B, dim) where B=2, dim=4
x = torch.randn(2, 4)

# branches: (B, H, N, S, D)
# B=2 (batch), H=2 (num_heads), N=3 (tokens), S=3 (strategies), D=5 (feature dim)
B = 2
H = 2
N = 3
S = 3
D = 5
branches = torch.randn(B, H, N, S, D)

ARGS = {
    "dim": dim,
    "num_heads": num_heads,
}
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 TokenGatedAttention — 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 TokenGatedAttention 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
apply_chat_template Ran
ran on a synthesized input
microsoft/seerattention/distillation_decode.py
code served (permissive licence) · get_code("202aa55ac60ff1f6")
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 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
import numpy as np

class MockTokenizer:
    def apply_chat_template(self, messages, tokenize=False):
        # Simple mock that formats messages as a string
        result = ""
        for msg in messages:
            result += f"{msg['role']}: {msg['content']}\n"
        return result

# Construct the example with messages in the expected format
example = {
    'messages': [
        {'role': 'user', 'content': 'Hello, how are you?'},
        {'role': 'assistant', 'content': 'I am doing well, thank you for asking.'}
    ]
}

# Create a mock tokenizer
tokenizer = MockTokenizer()

ARGS = {
    'example': example,
    'tokenizer': tokenizer,
    'add_prefix': False,
    'prefix': '<think>\n'
}
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 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
apply_rotary_pos_emb Ran
ran on a synthesized input
microsoft/seerattention/seer_attn/modules/common.py
code served (permissive licence) · get_code("8c7b215a2004bfc6")
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 tuple, ndim 5, 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

torch.manual_seed(0)

# Define small tensors for query and key
# Shape: [batch_size, heads, seq_len, head_dim]
batch_size = 2
heads = 3
seq_len = 4
head_dim = 8

q = torch.randn(batch_size, heads, seq_len, head_dim)
k = torch.randn(batch_size, heads, seq_len, head_dim)

# Define cos and sin tensors
# Shape: [batch_size, seq_len, head_dim]
cos = torch.randn(batch_size, seq_len, head_dim)
sin = torch.randn(batch_size, seq_len, head_dim)

# position_ids is deprecated and unused, can be None
position_ids = None

# unsqueeze_dim specifies how to unsqueeze cos and sin for broadcasting
# Since q and k have shape [batch_size, heads, seq_len, head_dim],
# we use unsqueeze_dim=1 to make cos and sin broadcastable
unsqueeze_dim = 1

ARGS = {
    "q": q,
    "k": k,
    "cos": cos,
    "sin": sin,
    "position_ids": position_ids,
    "unsqueeze_dim": unsqueeze_dim,
}
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 tuple, ndim 5, dtype family float — 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
average_groups Ran
ran on a synthesized input
microsoft/seerattention/eval/longbench/average_sparsity.py
code served (permissive licence) · get_code("a8c8717e85efa3ea")
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 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 tempfile
import os

# Create a temporary file with sample data
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("1000:10.5\n")
temp_file.write("2500:20.3\n")
temp_file.write("5000:15.7\n")
temp_file.write("6500:25.1\n")
temp_file.write("9000:30.2\n")
temp_file.write("10000:35.8\n")
temp_file.close()

file_path = temp_file.name

ARGS = {
    'file_path': file_path
}
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 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
build_optimized_chunks Ran
ran on a synthesized input
microsoft/seerattention/distillation_decode.py
code served (permissive licence) · get_code("4334f4eeb6104bee")
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 Dataset. 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 datasets import Dataset
import random

torch.manual_seed(0)

# Create a minimal dataset with input_ids
dataset_dict = {
    'input_ids': [
        [1, 2, 3, 4, 5],           # sequence length 5
        [10, 11, 12],              # sequence length 3
        [20, 21, 22, 23],          # sequence length 4
        [30, 31],                  # sequence length 2
    ]
}
dataset = Dataset.from_dict(dataset_dict)

chunk_size = 10

ARGS = {
    'dataset': dataset,
    'chunk_size': chunk_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Dataset — a Dataset output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Dataset 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
calculate_averages_by_range Ran
ran on a synthesized input
microsoft/seerattention/eval/longbench/average_score.py
code served (permissive licence) · get_code("e9c41059655ed7e3")
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 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
import numpy as np

torch.manual_seed(0)

# Construct a data dictionary matching the expected structure
# The function expects a dict where:
# - Keys are dataset names
# - Values are dicts containing range keys ('0-4k', '4-8k', '8k+')
# - Each range key maps to a numeric value

data = {
    'dataset_1': {
        '0-4k': 100,
        '4-8k': 200,
        '8k+': 300
    },
    'dataset_2': {
        '0-4k': 150,
        '4-8k': 250,
        '8k+': 350
    },
    'dataset_3': {
        '0-4k': 120,
        '4-8k': 180,
        '8k+': 320
    }
}

ARGS = {
    'data': data
}
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 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
generate_base_sparsity_mask Ran
ran on a synthesized input
microsoft/seerattention/eval/efficiency/benchmark_sparse_attn.py
code served (permissive licence) · get_code("8498177d23b25d59")
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 (1, 8, 8) as a later run recorded it. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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)

ARGS = {
    'max_seqlen_q': 64,
    'max_seqlen_k': 128,
    'round_base': 16,
    'm_block_dim': 8,
    'n_block_dim': 16,
    'sparsity': 0.5,
    'causal': False,
    'device': 'cpu'
}
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 3, dtype family float, shape (1, 8, 8) — shape (1, 8, 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: none by the harness; any seed is in the setup block
get_tensors Ran
ran on a synthesized input
microsoft/seerattention/eval/efficiency/benchmark_sparse_attn.py
code served (permissive licence) · get_code("09bb2cb546d9e69e")
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 tuple. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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)

ARGS = {
    "bs": 2,
    "num_heads": 3,
    "seq_len": 4,
    "head_dim": 5,
    "dtype": torch.float16,
}
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 tuple — a tuple output has no array shape of its own; none is 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
layer_norm_ref Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
microsoft/seerattention/seer_attn/modules/layernorm.py
pointer only (licence: MIT); the stored copy get_code serves, from XsChen524/mode-mamba-ts, is pointer only (licence: NONE) · get_code("2ce8fcf5bedd19ec")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from XsChen524/mode-mamba-ts, and GitHub detected no licence in that repository 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. A run is recorded.

load_json Ran
ran; our contract draft was wrong, not the code
microsoft/seerattention/eval/longbench/average_score.py
code served (permissive licence) · get_code("cc892598a14c82a5")
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 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 json
import tempfile
import os

# Create a temporary JSON file with sample data
temp_dir = tempfile.mkdtemp()
temp_file = os.path.join(temp_dir, "test_data.json")

sample_data = {
    "key1": "value1",
    "key2": [1, 2, 3],
    "key3": {"nested": "object"}
}

with open(temp_file, 'w') as f:
    json.dump(sample_data, f)

ARGS = {
    "file_path": temp_file
}
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 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
rms_norm_ref Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
microsoft/seerattention/seer_attn/modules/layernorm.py
pointer only (licence: MIT); the stored copy get_code serves, from XsChen524/mode-mamba-ts, is pointer only (licence: NONE) · get_code("ab802ae3195c6316")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from XsChen524/mode-mamba-ts, and GitHub detected no licence in that repository 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. A run is recorded.

rotate_half Ran
ran; our contract draft was wrong, not the code
microsoft/seerattention/seer_attn/modules/common.py
code served (permissive licence) · get_code("e03d53ba9d4f9ae5")
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)

# The function takes a single parameter 'x' which is a tensor
# It accesses x[..., :x.shape[-1] // 2] and x[..., x.shape[-1] // 2:]
# So x needs to be a tensor with a last dimension that can be split in half
# Let's create a small tensor with batch size 2 and feature dimension 4

x = torch.randn(2, 4)

ARGS = {
    "x": x
}
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
tokenize_fn Ran
ran on a synthesized input
microsoft/seerattention/distillation_decode.py
code served (permissive licence) · get_code("3ef366d8b91a362a")
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 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
import torch.nn as nn

torch.manual_seed(0)

class SimpleTokenizer:
    def __call__(self, text, add_special_tokens=False, truncation=False, return_tensors='pt', padding=False):
        # Simulate tokenizer output
        # text is a list or string, we'll treat it as a list of strings
        if isinstance(text, str):
            text = [text]
        
        # Create simple token IDs - simulate tokenization
        # Return a dict with 'input_ids' key containing 2D tensor
        batch_size = len(text) if isinstance(text, list) else 1
        seq_length = 5
        input_ids = torch.randint(0, 1000, (batch_size, seq_length))
        
        return {
            'input_ids': input_ids
        }

tokenizer = SimpleTokenizer()

examples = {
    'text': ['hello world', 'how are you']
}

ARGS = {
    'tokenizer': tokenizer,
    'examples': examples
}
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 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
tokenize_fn Ran
ran on a synthesized input
microsoft/seerattention/distillation_prefill.py
code served (permissive licence) · get_code("f9963e3bc9860eda")
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 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
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self):
        self.eos_token = "</s>"
    
    def __call__(self, text, truncation=False, return_tensors=None, pad_to_multiple_of=None, padding=False):
        # Simulate tokenizer output with small tensors
        # Create token ids of shape (batch_size, seq_length)
        input_ids = torch.randint(0, 100, (1, 8))
        attention_mask = torch.ones_like(input_ids)
        return {
            'input_ids': input_ids,
            'attention_mask': attention_mask
        }

# Create example data
example = {
    'text': ['hello world', 'foo bar']
}

# Define the arguments
ARGS = {
    'tokenizer': MinimalTokenizer(),
    'tranining_max_length': 4,
    'example': example
}
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 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
apply_rotary_pos_emb_single Not yet run
unverified (harvested, no recorded run)
microsoft/seerattention/seer_attn/modules/common.py
code served (permissive licence) · get_code("89cf2076c1b8ce86")
How it ran

no invocation recorded.

ref_program_fa Not yet run
unverified (harvested, no recorded run)
microsoft/seerattention/eval/efficiency/decode_kernel_eval.py
code served (permissive licence) · get_code("ea5becf731d3b58d")
How it ran

no invocation recorded.

run_benchmark Not yet run
unverified (harvested, no recorded run)
microsoft/seerattention/eval/efficiency/benchmark_sparse_attn.py
code served (permissive licence) · get_code("046184b390b18314")
How it ran

no invocation recorded.

Also present in other papers' code

Of 19 samples lifted from this paper's linked repositories, 19 carry a function identity and 0 do not. Of the 19 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 1 the same month, 3 later) and 15 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
rotate_half 360 other papers
240 dated earlier, 9 the same month, 103 later, 5 same year, order not determinable, 3 undated · 30 only as an assembly brick
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2203.08913 (2022-03)
Memorizing Transformers
2302.13971 (2023-02)
LLaMA: Open and Efficient Foundation Language Models
and 357 more not named here
layer_norm_ref 8 other papers
7 dated earlier, 1 later
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
2406.02528 (2024-06)
Scalable MatMul-free Language Modeling
2406.03344 (2024-06)
Audio Mamba: Bidirectional State Space Model for Audio Representation Learning
and 5 more not named here
rms_norm_ref 8 other papers
7 dated earlier, 1 later
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
2406.02528 (2024-06)
Scalable MatMul-free Language Modeling
2406.03344 (2024-06)
Audio Mamba: Bidirectional State Space Model for Audio Representation Learning
and 5 more not named here
load_json 1 other paper
1 dated earlier
2405.17814 (2024-05)
FAIntbench: A Holistic and Precise Benchmark for Bias Evaluation in Text-to-Image Models

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

Long-context modeling is crucial for nextgeneration language models, yet the high computational cost of standard attention mechanisms poses significant computational challenges. Sparse attention offers a promising direction for improving efficiency while maintaining model capabilities. We present NSA, a Natively trainable Sparse Attention mechanism that integrates algorithmic innovations with hardware-aligned optimizations to achieve efficient long-context modeling. NSA employs a dynamic hierarchical sparse strategy, combining coarse-grained token compression with finegrained token selection to preserve both global context awareness and local precision. Our approach advances sparse attention design with two key innovations: (1) We achieve substantial speedups through arithmetic intensity-balanced algorithm design, with implementation optimizations for modern hardware. (2) We enable end-to-end training, reducing pretraining computation without sacrificing model performance. As shown in Figure 1, experiments show the model pretrained with NSA maintains or exceeds Full Attention models across general benchmarks, long-context tasks, and instruction-based reasoning. Meanwhile, NSA achieves substantial speedups over Full Attention on 64k-length sequences across decoding, forward propagation, and backward propagation, validating its efficiency throughout the model lifecycle.

For agents

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

get_harvested_code_for_paper("2502.11089")
get_code_for_paper("2502.11089")
have("2502.11089")

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

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

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

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

Connect an agent — have() is free.