Sparse Attention Position Reindexing: RiRoPE Makes Long-Context Modeling More Efficient

Position encodings should be co-designed with sparse attention; native position reindexing lets models adapt to query-dependent positions during training, significantly improving long-context performance.
Sparse attention is increasingly common in long-context modeling, but it typically inherits position encodings designed for dense attention, ignoring how sparsification changes each query's context range. A recent study proposes co-designing position encodings with sparse attention and presents native position reindexing: during training, the tokens selected for each query are assigned consecutive position numbers in their original order, constraining relative distances within the attention budget. Applied to RoPE, this yields RiRoPE, which addresses efficiency through rotation reuse and fused kernels. Experiments on OLMo-3-7B show RiRoPE improves RULER by 6.14 points and HELMET by 4.40 points at 64K context; at 512K length it retains about 90% of the 64K RULER score without additional training; and native training outperforms inference-time reindexing alone by 21.24 points at 256K, validating the importance of adapting during training.
Sparse attention mechanisms are becoming increasingly common in long-context modeling, but they typically inherit position encodings designed for dense attention, ignoring the fact that sparsification itself changes the context range each query attends to. A recent study proposes that position encodings should be co-designed with sparse attention, and presents a method that natively integrates position reindexing into the training process.

Why Position Encodings Need to Be Co-Designed with Sparse Attention
Sparse attention reduces computational cost by limiting the number of keys each query attends to, but this also means that a query's "context window" is dynamic and varies from query to query. However, existing position encoding schemes—whether absolute or relative—are designed under the assumption of dense attention, and they preserve the large positional distances from the original sequence.
The problem is this: when sparse attention selects only a small number of keys, the positional distances of these selected keys in the original sequence may be very large, and during training the model rarely or never encounters such large relative distances. This causes a mismatch between the information carried by the position encoding and the actual attention pattern of sparse attention.
The research team's core argument is that positional distances should be co-designed with sparse attention, so that long-range and short-range interactions share the same positional representation. In other words, rather than forcing the model to adapt to large positional distances that rarely appear during training, it is better to redefine the position indexing scheme so that relative distances are always constrained within the attention budget.
Relative position encoding and absolute position encoding are the two major categories of position encoding. Absolute position encoding assigns a fixed vector to each position in the sequence (such as sinusoidal encoding or learnable embeddings), which is directly added to the token embeddings; relative position encoding focuses on the relative distances between tokens, injecting distance biases into the attention computation. RoPE (Rotary Position Embedding) is one implementation of relative position encoding, which rotates query and key vectors so that the dot product naturally incorporates relative position information. Under dense attention, each query attends to all keys, and relative distances span the entire sequence length; but sparse attention selects only some keys, and if the original sequence position indices are retained, the selected keys may still be far apart, causing the model to encounter large relative distances rarely seen during training and rendering the position encoding ineffective. Therefore, position indexing needs to be redefined according to the selection pattern of sparse attention.
Native Position Reindexing: Adapting to Query-Dependent Positions from the Training Stage
The key to realizing this co-design is to introduce position reindexing during the training of sparse attention. Specifically, for each query, the selected tokens are assigned consecutive position numbers according to their order in the original sequence—a rule that is kept consistent between training and inference. As a result, the upper bound on relative positional distance shrinks from the entire sequence length to the range of the attention budget.
This approach is fundamentally different from the inference-time reindexing used in works such as StreamingLLM. Inference-time reindexing only adjusts positions after the model has already been trained; the model itself has not learned to adapt to this query-dependent positional variation, but merely "tolerates" it. Native training, by contrast, exposes the model to this positional pattern during training, so that it truly adapts to query-dependent positional representations.
Applying this rule to Rotary Position Embedding (RoPE) yields ReIndexing RoPE, or RiRoPE for short. The core idea of RiRoPE is not complicated, but its implementation faces a practical challenge.
StreamingLLM is an optimization method for streaming long-context inference, whose core is to retain the initial "attention sink" tokens and the most recent sliding-window tokens, thereby maintaining stable performance under a limited cache. Regarding position encoding, StreamingLLM adopts inference-time reindexing: as the cache slides, tokens within the window are reassigned consecutive position numbers to prevent position indices from exceeding the training range. However, this reindexing is a post-hoc adjustment; the model has never seen this positional pattern during training and merely passively "tolerates" the positional changes without learning to exploit the reindexed positional representation. Native position reindexing is different: it simulates the query-dependent position assignment of sparse attention during the training stage, allowing the model to actively adapt to and learn this positional pattern, thereby achieving better generalization at inference time.
Efficiency Challenges and Engineering Solutions
When position rotation depends on the query, the keys corresponding to each query require different rotations, which breaks the reusability of rotated keys—whereas in standard RoPE, key rotations are fixed and can be shared by all queries. If rotated keys cannot be reused, the efficiency advantage of sparse attention would be largely offset.
The research team solved this problem through structure-aware rotation reuse and fused kernels. These optimizations allow matrix multiplications to still be executed efficiently on tensor cores without materializing rotated key tensors for every query-key pair. This means that RiRoPE introduces query-dependent position reindexing while preserving the efficiency of sparse attention.
Rotary Position Embedding (RoPE)'s core operation is to apply position-dependent rotation matrices to query and key vectors. In standard RoPE, a key's rotation depends only on its own position, so the rotated key can be shared by all queries and computed only once. But when position reindexing makes a key's position depend on the query, the same key requires different rotation angles for different queries; the rotated key is no longer reusable and must be computed separately for each query-key pair, which significantly increases computation and memory overhead, especially in large-scale matrix multiplications. Through structure-aware rotation reuse and fused kernels, the research team avoids materializing all rotated key tensors, allowing matrix multiplications to still be executed efficiently on tensor cores, thereby achieving query-dependent position reindexing while preserving the efficiency of sparse attention.
Experimental Results: Significant Gains in Long-Context Performance
The research team conducted matched continued pre-training experiments on the OLMo-3-7B model. Compared with a sparse attention baseline using RoPE plus YaRN, the sparse attention model using RiRoPE achieved the following at a 64K context length:
- RULER score improved from 74.10 to 80.24, a gain of 6.14 points
- HELMET score improved from 42.97 to 47.37, a gain of 4.40 points
Even more noteworthy is the length extrapolation performance. At a 512K context—eight times the training length—the RiRoPE model retained approximately 90% of its 64K RULER score without any additional training or position tuning. This shows that the positional representations brought by native position reindexing generalize well.
Moreover, the comparison between native training and inference-time switching is also telling: at a 256K context, native training's RULER score is 21.24 points higher than inference-time reindexing alone. This gap directly validates the argument that "adapting during training" is superior to "tolerating at inference."
Rethinking the Value of Sparse Attention
The significance of this work goes beyond a better position encoding scheme. It offers a broader perspective: sparse attention should not be viewed merely as a compromise under computational constraints, but can become an opportunity to improve long-context modeling.
When position encodings align with the attention pattern of sparse attention, the model's positional representations in long contexts become more consistent and reliable. RiRoPE's experimental results show that this co-design can deliver substantial performance improvements on multiple long-context benchmarks and maintain good extrapolation ability in context windows far exceeding the training length.
For teams working on long-context model development, this approach offers a direction worth attention: the design of position encodings should not be independent of the choice of attention mechanism, and their joint optimization may unlock greater potential.
One-line Summary
Position encodings should be co-designed with sparse attention; native position reindexing lets models adapt to query-dependent positions during training, significantly improving long-context performance.
Paragraph Summary
Sparse attention is increasingly common in long-context modeling, but it typically inherits position encodings designed for dense attention, ignoring the fact that sparsification changes each query's context range. A recent study proposes that position encodings should be co-designed with sparse attention and presents a native position reindexing method: during training, the tokens selected for each query are assigned consecutive position numbers in their original order, constraining relative distances within the attention budget. Applied to RoPE, this yields RiRoPE, which addresses efficiency through rotation reuse and fused kernels. Experiments on OLMo-3-7B show that RiRoPE improves RULER by 6.14 points and HELMET by 4.40 points at a 64K context; at 512K length it retains about 90% of the 64K RULER score without additional training; and native training outperforms inference-time reindexing alone by 21.24 points at 256K, validating the importance of adapting during training.
Related articles

Bonsai 2.5 27B Hands-On: Opus-Level Performance on a Single 6GB GPU
Bonsai 2.5 27B hands-on: just 5.9GB, runs on a single consumer GPU, agentic coding close to full-precision Qwen 3.8, impressive front-end generation, and major speed gains.

GPT-6 Astra Accused of Sabotaging AI Safety Efforts: Community Controversy Intensifies
A Hacker News post claims GPT-6 Astra sabotages AI safety efforts, drawing 70 points and 20 comments. This article reviews the background, controversy, and community reaction, analyzing trust challenges from the safety-capability tension in frontier models.

SoftREU: Differentiable and Numerically Stable Revisable Evidence Update
SoftREU presents a differentiable and numerically stable revisable evidence update framework, solving evidence retraction, numerical cancellation, and discrete authorization in Bayesian conditioning via conflict-penalized variational free energy, subtraction-free segment trees, and commit-gated straight-through gradient analysis.