TL;DR
When large language models use sparse attention to read massive documents, they skip over irrelevant words—yet they still keep the original, miles-apart page numbers for the words they actually read. This paper asks a wonderfully simple question: what if we renumber each query’s selected tokens consecutively during training, compressing the gaps? By co-designing position indexing with sparse attention, models can effortlessly extrapolate to 8x their training length without breaking a sweat—or GPU efficiency.
What Problem Does This Paper Address?
Long-context Transformers face two headaches as sequences grow: attention scores get diluted across too many tokens, and positional encodings—like the ubiquitous Rotary Position Encoding (RoPE)—encounter vast distances between tokens that were rarely or never seen during training.
Sparse attention fixes the first problem (and saves compute) by letting each query attend to a fixed budget of $B$ relevant keys. However, it leaves the second problem wide open: those surviving keys keep their original sequence positions. A query at token 500,000 attending to a key at token 12 still faces a massive positional gap, even if it only attends to 1,000 tokens total. Prior streaming methods tried renumbering surviving tokens consecutively at inference time, which is a bit like handing an actor a rewritten script on opening night—the model merely tolerates the shifted geometry rather than exploiting it.
Methods
The authors introduce native position reindexing and instantiate it with RoPE to create RiRoPE (ReIndexing RoPE). For every query, the tokens it selects are assigned consecutive position IDs ($0, 1, \dots, B-1$) in their original order during both training and inference, bounding all relative distances by the attention budget $B$.
While easy during token-by-token decoding, doing this in parallel during training creates a nasty systems bottleneck: every query selects a different subset of keys, meaning the same key simultaneously needs different positional rotations for different queries! Materializing rotated keys per query-key pair would destroy memory and prevent fast tensor-core matrix multiplications.
To make RiRoPE fast, the authors exploit attention structure in two ways:
- Block-Sparse Multi-Head Attention (MHA): When keys are selected in contiguous blocks of size $b$, a token's reindexed distance neatly splits into a fixed intra-block offset and a query-dependent inter-block count. Keys are rotated once by their intra-block offset and cached; queries simply accumulate an extra rotation of $R(b)$ per selected block inside a fused FlashAttention-style kernel.
- Shared-KV Attention (MQA/MLA): When multiple query heads share keys and selections, the kernel rotates each selected key once on the fly and reuses it across all heads in the matrix multiplication.
To test this on the dense OLMo-3-7B model, the authors convert its global layers to block-sparse attention using a lightweight learned indexer trained end-to-end via a block-count-corrected LogGate mechanism.
Datasets
No new benchmarks are introduced. For continued pretraining, the authors use the open OLMo-3 training pipeline and data mixtures: 50B tokens at an 8K context length (Stage 2 mid-training), followed by 50B tokens at 64K (Stage 3 extension). Models are evaluated on:
- Long-context benchmarks: RULER (synthetic retrieval up to 512K) and HELMET (realistic long-context tasks up to 256K).
- Standard capabilities: Math (GSM8K, Minerva MATH, MATH-500), Code (HumanEval, MBPP), and General reasoning/knowledge (MMLU, MMLU-Pro, BBH, HellaSwag, ARC-C, WinoGrande, DROP).
Key Insights and Ideas
- Sparsity is a modeling opportunity, not just a budget cut: Usually, sparse attention is treated as an approximation of dense attention. Here, sparsity actively solves length extrapolation by ensuring long-range interactions share the exact same well-trained positional representations ($[0, B-1]$) as short-range ones.
- Native training beats post-hoc patches: Training with reindexed positions massively outperforms switching to reindexing at inference time, proving the model genuinely learns to use the compressed, query-specific coordinate system.
- Slightly higher LM loss doesn't mean worse downstream performance: Sparse-RiRoPE finishes training with a tiny ~0.0015 higher language-modeling loss than dense attention, yet decisively beats it on long-context retrieval.
Key Results
- In-range gains (64K): Without any frequency scaling, Sparse-RiRoPE beats Sparse-RoPE+YaRN by 6.14 points on RULER ($74.10 \to 80.24$) and 4.40 points on HELMET ($42.97 \to 47.37$), while preserving general 8K capabilities (achieving the top average score of 62.56 across 15 tasks).
- Zero-shot length extrapolation (up to 512K): At 512K—8x the training context—RiRoPE scores 72.17 on RULER (retaining ~90% of its 64K performance). Meanwhile, Full-RoPE+YaRN collapses to 2.81, Sparse-RoPE+YaRN drops to 15.21, and NoPE (no positional encoding) trails at 70.63.
- Native vs. Inference-only: Native RiRoPE training outperforms inference-only reindexing by 15.39 RULER points at 64K and 21.24 points at 256K.
- Minimal compute overhead: Online inter-block rotation on an NVIDIA H20 adds just 6.4% forward GPU time at 256K when accounting for indexer and preparation steps (and drops even lower for GQA).
Limitations and Future Work
- Encoding & Architecture Scope: Experiments only test RoPE on OLMo-3’s MHA architecture via continued pretraining. Applying native reindexing to other schemes (like ALiBi), testing end-to-end MLA/GQA models, and pretraining from scratch remain open.
- Blindness to Skipped Gaps: Because reindexing compresses unselected tokens completely, two adjacent selected tokens look identical in position whether they were originally separated by 2 words or 20,000. Incorporating auxiliary gap metadata could help.
- Beyond Text: The authors highlight causal video generation (e.g., generating long videos from short-clip training under a fixed context budget) as a natural next frontier.
Summary updated