SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.15176 · ICLR · 2025

ReAttention: Training-Free Infinite Context with Finite Attention Scope

Qun Liu, Xipeng Qiu, Qipeng Guo, Kai Lv, Xiaoran Liu, Hang Yan, Linlin Li, Ruixiao Li, Zhigeng Liu, Yuerong Song

arXiv · PDF · Open in the Atlas

Code that ran

5 of 7 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; 2 no recorded run), measured 2026-11-23; 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/2407.15176.json · badge: /api/ran/2407.15176.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
OpenMOSS/ReAttention community
Papers with Code archive
5 ran · 2 no recorded run
FunctionStatusWhere it lives
InternLM2Config Ran
ran on a synthesized input · constructed an object; no result was computed
OpenMOSS/ReAttention/re_attention/re_attention_internlm2.py
code served (permissive licence) · get_code("527cb7435bdc4949")
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, InternLM2Config: 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 transformers.configuration_utils import PretrainedConfig

torch.manual_seed(0)

ARGS = {
    "vocab_size": 103168,
    "hidden_size": 4096,
    "intermediate_size": 11008,
    "num_hidden_layers": 32,
    "num_attention_heads": 32,
    "num_key_value_heads": 8,
    "hidden_act": "silu",
    "max_position_embeddings": 2048,
    "initializer_range": 0.02,
    "rms_norm_eps": 1e-6,
    "use_cache": True,
    "pad_token_id": 0,
    "bos_token_id": 1,
    "eos_token_id": 2,
    "pretraining_tp": 1,
    "tie_word_embeddings": False,
    "rope_theta": 10000.0,
    "rope_scaling": None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type InternLM2Config — 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 InternLM2Config 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
InternLM2DynamicNTKScalingRotaryEmbedding Ran
ran on a synthesized input · constructed an object; no result was computed
OpenMOSS/ReAttention/re_attention/re_attention_internlm2.py
code served (permissive licence) · get_code("38584a280024ab4b")
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, InternLM2DynamicNTKScalingRotaryEmbedding: 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
from torch import nn

torch.manual_seed(0)

# InternLM2DynamicNTKScalingRotaryEmbedding inherits from InternLM2RotaryEmbedding
# The __init__ parameters are: dim, max_position_embeddings, base, device, scaling_factor
# The forward method expects x as a tensor with shape[2] being the sequence length

# Create a small tensor input with shape (batch, heads, seq_len, dim)
# We use batch=2, heads=3, seq_len=5, but the forward only uses shape[2] for seq_len
x = torch.randn(2, 3, 5, 4, dtype=torch.float32)

ARGS = {
    'dim': 4,
    'max_position_embeddings': 2048,
    'base': 10000,
    'device': None,
    'scaling_factor': 1.0,
}
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 InternLM2DynamicNTKScalingRotaryEmbedding — 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 InternLM2DynamicNTKScalingRotaryEmbedding 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
InternLM2LinearScalingRotaryEmbedding Ran
ran on a synthesized input · constructed an object; no result was computed
OpenMOSS/ReAttention/re_attention/re_attention_internlm2.py
code served (permissive licence) · get_code("9e90ccd3a37a21f2")
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, InternLM2LinearScalingRotaryEmbedding: 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
from torch import nn

torch.manual_seed(0)

# InternLM2LinearScalingRotaryEmbedding inherits from InternLM2RotaryEmbedding
# Looking at __init__, the parameters are:
# - dim: embedding dimension
# - max_position_embeddings: max sequence length
# - base: base for frequency calculation
# - device: device to place buffers on
# - scaling_factor: scaling factor for embeddings

# Looking at forward(), it expects:
# - x: input tensor with shape (batch, ..., seq_len)
# - position_ids: optional position indices

# Create a small input tensor
batch_size = 2
seq_len = 5
dim = 4
x = torch.randn(batch_size, 1, seq_len, dtype=torch.float32)

# Create position_ids (optional, but let's provide it for completeness)
position_ids = torch.arange(seq_len, dtype=torch.float32).unsqueeze(0).expand(batch_size, -1)

ARGS = {
    'dim': dim,
    'max_position_embeddings': 2048,
    'base': 10000,
    'device': None,
    'scaling_factor': 1.0,
}
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 InternLM2LinearScalingRotaryEmbedding — 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 InternLM2LinearScalingRotaryEmbedding 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
InternLM2RotaryEmbedding Ran
ran on a synthesized input · constructed an object; no result was computed
OpenMOSS/ReAttention/re_attention/re_attention_internlm2.py
code served (permissive licence) · get_code("e4795a1e154a649a")
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, InternLM2RotaryEmbedding: 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
from torch import nn

torch.manual_seed(0)

ARGS = {
    'dim': 4,
    'max_position_embeddings': 2048,
    'base': 10000,
    'device': None,
    'scaling_factor': 1.0,
}
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 InternLM2RotaryEmbedding — 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 InternLM2RotaryEmbedding 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; our contract draft was wrong, not the code
OpenMOSS/ReAttention/re_attention/re_attention_internlm2.py
code served (permissive licence) · get_code("7bf1caee3962da6f")
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)

# Construct small tensors for the function
batch_size = 2
seq_len = 3
num_heads = 4
head_dim = 4

# Query and key tensors: [batch_size, num_heads, seq_len, head_dim]
q = torch.randn(batch_size, num_heads, seq_len, head_dim)
k = torch.randn(batch_size, num_heads, seq_len, head_dim)

# Cosine and sine embeddings: [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, so None is fine
position_ids = None

# unsqueeze_dim specifies where to add dimension for broadcasting
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
Cache Not yet run
unverified (harvested, no recorded run)
OpenMOSS/ReAttention/re_attention/re_attention_internlm2.py
code served (permissive licence) · get_code("f6aa9e46f3abe262")
How it ran

no invocation recorded.

InternLM2Attention Not yet run
unverified (harvested, no recorded run)
OpenMOSS/ReAttention/re_attention/re_attention_internlm2.py
code served (permissive licence) · get_code("db90ada3ac49e1ae")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 7 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

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

The long-context capability of the Large Language Models (LLM) has made significant breakthroughs, but the maximum supported context length in length extrapolation remains a critical bottleneck limiting their practical applications. The constraint of context length in LLMs arises from the self-attention mechanism, which cannot effectively and efficiently capture the semantic relationships within infinitely long contexts via the limited pre-trained positional information and attention scope. In this work, we propose ReAttention, a training-free approach enabling LLM based on the self-attention mechanism to support an infinite context with a finite attention scope under sufficient memory resources. ReAttention performs the position-agnostic top-k attention before the ordinary position-aware self-attention, freeing LLMs from the length extrapolation issue. We validate the performance of ReAttention on the LongBench, L-Eval, and InfiniteBench and demonstrate that it is on par with traditional methods. Furthermore, we also apply ReAttention on mainstream LLMs, including LLaMA3.1-8B and Mistral-v0.3-7B, enabling them to support context lengths of at least 1M and even expanding the context length of LLaMA3.2-3B-chat by 128× to 4M without any further training in Needle-In-A-Haystack tests. We also improve the efficiency of ReAttention with Triton and achieve an efficient extrapolation without additional overhead. The code is available at https://github.com/OpenMOSS/ReAttention.

For agents

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

get_harvested_code_for_paper("2407.15176")
get_code_for_paper("2407.15176")
have("2407.15176")

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

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

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

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

Connect an agent — have() is free.