Skip to content

Menu

WorksComputer Science

Recursive Sparse Attention: Million-Token Length Extrapolation at Logarithmic Cost

Download PDFView on arXiv

Ask your agent about this work

Your agent reads this work through Valency, with its citations and similar works. Paste this at the start of a chat.

Use the Valency MCP. Work: W_3qn5cbhe. Fetch it with get_paper_by_id, then find its nearest works with find_similar_papers and tell me what it adds.

Works with any MCP client. Not connected yet? Connect your agent

Abstract

At context lengths of about 1M tokens, dense attention is costly in prefill and decoding, and training typically relies on long documents, which become scarcer as the target length increases. Most sparse attention methods score all preceding blocks or tokens, so their selection cost per query is O(L)O(L) at context length LL; hierarchical selection reduces it to O(log⁡L)O(\log L), but prior trainable hierarchical methods report accuracy only within their training length. We propose RecSA (Recursive Sparse Attention), which builds a tree over the KV cache in which each node summarizes its subtree with one key and one mean-pooled value. The keys come from one pooler per layer, shared by all levels and distilled from dense attention. Each level above the tokens selects at most kk candidates, so each query has O(log⁡L)O(\log L) selection cost and reads O(log⁡L)O(\log L) entries; the summaries of unselected candidates share one softmax with the exact tokens. Each entry's RoPE position is its index among the candidates of its level, so at any length every relative distance stays within the range seen during training. Initialized from Qwen3-4B and trained on 0.62B tokens at the original model's 32K training length, RecSA outperforms all baselines on RULER at every length from 131K to 2M; at 1M, it scores 60.5, compared with 40.0 for the best baseline, Dense + DCA. With our optimized kernels, RecSA is faster than dense attention in end-to-end prefill and decoding from 64K to 2M; at 524K on one H200 GPU, it accelerates prefill by 3.2x and decoding by 3.8x.

Introduction

State-of-the-art language models now support context windows of about 1M tokens (DeepSeek-AI et al., 2026). At such lengths, inference is costly and training data is scarce.

In prefill, the computation of dense attention grows quadratically with length, and in decoding, every generated token reads the entire KV cache. Training at the target length relies on sufficiently long documents, which become scarcer as the length increases (Gao et al., [15]). Some of these models reduce the inference cost with sparse attention (DeepSeek-AI et al., 2026). As language models continue to develop, the context they need is likely to keep growing. Longer contexts call for methods whose inference cost grows slowly with length and that need no training at the target length.

Trainable sparse attention methods such as MoBA (Lu et al., 2025), NSA (Yuan et al., [51]) and DSA (DeepSeek-AI et al., [12]) are trained at the target length. HSA (Hu et al., (2025); Leng et al. [22]; Hu et al. (2026b)) and HiLS (Hu et al., 2026a) train only on short sequences, InFLLM (Xiao et al., [47]) and InfiniteHiP (Lee et al., [37]) are training-free; neither group needs long docu-

Correspondence to: Hao Zhang <[email protected]>.

Preprint. ments to run far beyond the training length. All of these methods score every preceding block or token at the first level, so at context length LL the selection cost per query is O(L)O(L). Hierarchical selection scores a top level of bounded size and then only the children of selected nodes, which reduces this cost to O(log⁡L)O(\log L). HiP (Lee et al., [35]) and PISA (Tang et al., [41]) keep the original position of each key, so beyond the training length the distances to selected keys can exceed those seen in training. Hierarchical selection alone does not remove the need for context extension.

We propose RecSA, a Recursive Sparse Attention mechanism with hierarchical selection. It groups every 16 consecutive KV entries under a parent node and applies the same grouping to parent nodes, building a tree from the bottom up. Each node has one key and one mean-pooled value, which form the summary of its whole subtree. Selection starts at the top level, whose nodes form the first candidate list, and at each level scores every candidate against the query and selects at most kk of them. Their children form the candidate list of the next level, and this continues until the candidates are exact tokens. Unselected candidates also participate in the attention computation: their summaries and all exact tokens in the last candidate list share one softmax. Whenever the top level exceeds a fixed number of nodes, a level is added above it, so every candidate list has a bounded size, and the selection cost and the number of entries read per query are both O(log⁡L)O(\log L). RoPE (Su et al., 2024) is applied to every entry, summaries included, and the position of an entry is its index in the candidate list of its level, with the query at the last index. Every relative distance to the query is thus below 4,096, the maximum size of a candidate list with the default k=256k = 256. Longer sequences introduce no distance unseen during training at 32K.

A learnable pooler computes the key of a node from the keys of its children. Each attention layer has one pooler, applied recursively at every level of the tree, so adding a level requires no new parameters. Training starts from a pretrained dense model and has two stages. The first stage freezes the backbone and aligns the softmax over the scores of the candidate nodes at each level with the distribution of dense attention mass over their subtrees. The second stage freezes the pooler and trains the backbone under RecSA to adapt it to sparse attention. Both stages use only sequences at the training length of the original model.

We evaluate RecSA on Qwen3-4B (Yang et al., [49]), whose training length is 32K. The two stages process 0.62B tokens in total. For comparison, we train dense and sparse backbones on the same data and evaluate every backbone with each of two context extension methods, YaRN (Peng et al., [34]) and DCA (An et al., 2024); we also compare with two training-free methods. At every length, the token budget of each sparse method, i.e., the number of entries a query attends to, is matched to that of RecSA. The evaluation covers synthetic long-context tasks, perplexity on long texts, real-world long-document tasks and short-context benchmarks. At 1M, the token budget of RecSA is only 1.16% of the context, and RecSA scores 60.5 on RULER (Hsieh et al., [21]), compared with 1.6 for Dense + YaRN, as shown in Figure 1a. The strongest of the other baselines, Dense + DCA, scores 40.0 (Table 1). At 32K, RecSA matches Dense + YaRN on RULER; on short-context benchmarks, RecSA performs comparably to the original model.

Figure 1. RULER score and decoding latency from 32K to 2M. (b) End-to-end latency on one H200 GPU with batch size 1; Dense uses FlashAttention in the same framework. At 1M and 2M, host memory holds the exact tokens of RecSA (§4.3) and the part of the Dense KV cache beyond GPU memory; hollow markers indicate offloading. Arrows mark off-scale values. Percentages show the token budget of RecSA as a fraction of the context length.

Table header: Method | 32K | 131K | 262K | 524K | 1M | 2M

Method32K131K262K524K1M2M
Token budget5,8888,1928,7049,72811,57511,990
% of context18.06.253.321.861.160.60
Training-free
InfLLM45.029.329.227.425.724.2
InfiniteHiP79.663.757.749.436.634.0
Trained at 32K
Dense + YaRN94.580.048.33.61.61.1
Dense + DCA94.678.568.458.040.027.6
MoBA + YaRN81.631.95.10.91.00.6
MoBA + DCA81.837.923.818.112.57.2
DSA + YaRN95.380.557.118.86.01.4
DSA + DCA95.277.565.755.236.822.6
RecSA (ours)94.783.375.969.760.549.3

Table 1. RULER score (average over the 13 tasks) by context length. Token budget: entries the query at the last position attends to (for RecSA, exact tokens plus summaries), matched across the sparse methods. Best results are in bold.

We implement prefill and decoding for RecSA in Triton (Tillet et al., [43]) and CUDA. In prefill, some existing block-sparse kernels group adjacent queries and load the union of their selected blocks once for the group (Hu et al., 2026a). This sharing reuses each key, already rotated by RoPE, for every query in the group, but in RecSA the index of a key, and hence its rotation, varies with the candidate list of each query. Because RoPE makes the attention score depend on positions only through the relative position, we split the rotation between keys and queries so that the part applied to each key is the same for all queries, and the group still loads each KV block once. On one H200 GPU with batch size 1, RecSA accelerates prefill by 3.2×3.2\times and decoding by 3.8×3.8\times at 524K, compared with dense FlashAttention (Dao, [9]) in the same framework, and its decoding latency stays nearly constant from 131K to 524K (Figure 1b).

We make the following contributions:

  • We propose RecSA, which combines hierarchical selection over a tree built on the KV cache with summaries for the unselected candidates and candidate-local RoPE (§ 3.1 and § 3.2).

  • We distill the pooler, shared across levels, from dense attention and train RecSA only on sequences of 32K tokens (§ 3.3 and § 3.4).

  • We provide prefill and decoding kernels for RecSA; in prefill, a group of adjacent queries loads each KV block once, although their candidate lists give its keys different positions (§ 4).

  • On Qwen3-4B, we compare RecSA from 32K to 2M with dense and sparse baselines, trained on the same data or training-free, at matched token budgets (§ 5).

Background

Sparse attention. Sparse attention methods differ in how they select the entries each query attends to. Block-level methods select whole blocks of consecutive tokens. MoBA (Lu et al., 2025) scores each block by the dot product of the query with the mean of the block’s keys, and the query attends to the tokens of the highest-scoring blocks and of the current block, which contains the query. NSA [51] gates three attention branches: over compressed blocks, over selected blocks and over a sliding window. Token-level methods select individual tokens: in DSA [12], a lightning indexer with a few heads scores every preceding token, and the query attends to the highest-scoring tokens. We count every entry a query attends to toward the token budget, including entries that summarize several tokens and the tokens of attention sinks, local windows and the current block.

Length extrapolation. Positional encoding plays an important role in how LLMs generalize beyond their training length. Transformers without explicit positional encodings (NoPE) can generalize better [30], but remain limited by increasing attention dispersion [45]. Most LLMs, however, use RoPE (Su et al., 2024), which rotates a query at position tt by RtR_t and a key at position jj by RjR_j, so scores depend only on t−jt-j. Consequently, extrapolation introduces out-of-distribution relative distances (An et al., 2024). YaRN [34] mitigates this by rescaling the rotation angles of the low-frequency dimensions, while DCA (An et al., 2024) partitions the sequence into shorter chunks and remaps positions to stay within the training range. Sparse attention also improves extrapolation by limiting attention to relevant parts of a longer context [47, 22].

Recursive Sparse Attention

To scale context length without requiring longer training data or incurring quadratic attention costs, we introduce Recursive Sparse Attention (RecSA), as shown in Figure 2. In our model, each KV head is shared by a group G\mathcal{G} of G=4G=4 query heads through grouped-query attention (GQA) [1]. We describe one such group for the query at position tt, using zero-based indices.

Figure 2. One attention layer of RecSA (2202^{20} tokens, C=16C = 16, k=256k = 256, three levels). (a) The pooler computes the key Ki\mathbf{K}_i of a node from the keys of its 16 children; its value Vi\mathbf{V}_i is the mean of their values. (b) ss is the score of each candidate for the query qt\mathbf{q}_t (Eq. (2)); levels 2 and 1 each select 256 candidates by this score, whose children form the next candidate list, and level 0 has no selection; pruned nodes are not candidates. (c) Summaries and exact tokens share one softmax, with output ot\mathbf{o}_t.

Tree Construction and Hierarchical Selection

Tree construction. Each attention layer maintains one KV tree per KV head. Level 00 holds the key kjk_j of each token jj, before RoPE (§ 3.2), and its value vjv_j. Each group of C=16C=16 consecutive entries at level ℓ−1\ell-1 forms one parent node at level ℓ\ell, up to the top level D−1D-1 (DD levels in total). The pooler Pool computes the key of each node (§ 3.3), and the value of a node is the mean of its children’s values:

Ki(ℓ)=Pool⁡(KCi(ℓ−1),…,KCi+C−1(ℓ−1)),Vi(ℓ)=1C∑c=0C−1VCi+c(ℓ−1)(1)K_i^{(\ell)}=\operatorname{Pool}\left(K_{Ci}^{(\ell-1)},\ldots,K_{Ci+C-1}^{(\ell-1)}\right), \qquad V_i^{(\ell)}=\frac{1}{C}\sum_{c=0}^{C-1}V_{Ci+c}^{(\ell-1)} \tag*{(1)}

where Ki(ℓ)K_i^{(\ell)} and Vi(ℓ)V_i^{(\ell)} are the key and value of node ii at level ℓ\ell, with Kj(0)=kjK_j^{(0)}=k_j and Vj(0)=vjV_j^{(0)}=v_j. The key and value of a node form the summary of its subtree.

Hierarchical selection. Selection proceeds from the top level down (Figure 2b). Let at(ℓ)=⌊t/Cℓ⌋a_t^{(\ell)}=\lfloor t/C^\ell\rfloor denote the node of level ℓ\ell that contains position tt, which we call the current node. The candidate list At(ℓ)\mathcal{A}_t^{(\ell)} of level ℓ\ell is ordered by position in the sequence; at the top level, it holds the current node and all nodes before it. Query head hh scores candidate ii with its query qt,h\mathbf{q}_{t,h}:

st,h,i(ℓ)=(Rnℓ−1qt,h)T(RpiKi(ℓ))d,It,i(ℓ)=∑h∈Gexp⁡(st,h,i(ℓ))(2)s_{t,h,i}^{(\ell)}=\frac{\left(R_{n_{\ell-1}}\mathbf{q}_{t,h}\right)^{\mathsf{T}}\left(R_{p_i}K_i^{(\ell)}\right)}{\sqrt{d}}, \qquad I_{t,i}^{(\ell)}=\sum_{h\in\mathcal{G}}\exp\left(s_{t,h,i}^{(\ell)}\right) \tag*{(2)}

where d=128d=128 is the head dimension, RpR_p is the RoPE rotation at position pp, pip_i is the index of candidate ii in At(ℓ)\mathcal{A}_t^{(\ell)} and nℓ=∣At(ℓ)∣n_\ell=\lvert\mathcal{A}_t^{(\ell)}\rvert, so the query takes the last index (§ 3.2). As in NSA [51], the query heads in G\mathcal{G} share one selection, based on the importance It,i(ℓ)I_{t,i}^{(\ell)}. At each level ℓ≥1\ell\ge1, RecSA selects the current node and the k−1k-1 other candidates with the highest importance (k=256k=256 by default), and the children of the selected nodes, up to the query, form the candidate list of the next level:

At(D−1)=[0,…,at(D−1)],\mathcal{A}_t^{(D-1)}=[0,\ldots,a_t^{(D-1)}],
St(ℓ)={at(ℓ)}∪TopK⁡k−1({It,i(ℓ)}i∈At(ℓ)∖{at(ℓ)}),At(ℓ−1)=concat⁡i∈St(ℓ)[Ci,…,min⁡(Ci+C−1,at(ℓ−1))],(3)\mathcal{S}_t^{(\ell)}=\{a_t^{(\ell)}\}\cup\operatorname{TopK}_{k-1}\left(\{I_{t,i}^{(\ell)}\}_{i\in\mathcal{A}_t^{(\ell)}\setminus\{a_t^{(\ell)}\}}\right), \qquad \mathcal{A}_t^{(\ell-1)}=\operatorname{concat}_{i\in\mathcal{S}_t^{(\ell)}}[Ci,\ldots,\min(Ci+C-1,a_t^{(\ell-1)})], \tag*{(3)}

where ℓ=D−1,…,1\ell=D-1,\ldots,1, TopKk−1_{k-1} returns the indices of the k−1k-1 candidates with the highest importance and concat joins the child lists in increasing order of ii, so ∣At(ℓ−1)∣≤Ck\lvert\mathcal{A}_t^{(\ell-1)}\rvert\le Ck. Level 00 has no top-kk selection: the query attends to all of its candidate tokens (Eq. (4)). Among the candidates of each level ℓ≥1\ell\ge1, only the current node can contain tokens after the query. This node takes no part in the ranking and is always expanded, with its children taken only up to the query. Hence all tokens of the level-1 current node up to the query enter the softmax as exact tokens, and every summary covers a complete subtree before the query. RecSA adds no attention sink [48] or fixed local window.

Depth. For the query at position tt, the number of levels DD is set by its prefix, positions 00 to tt: whenever the top level exceeds CkCk nodes, a level is added above it. If the prefix has at most CkCk tokens, D=1D=1 and RecSA is equivalent to dense causal attention. With the default k=256k=256, Ck=4,096Ck=4{,}096; beyond 4,096 tokens, a prefix has two levels up to 65,536 tokens, three up to 1,048,576 tokens and four at 2M.

One softmax over summaries and tokens. The summaries of the unselected candidates and the exact tokens of level 0 share one softmax (Figure 2c), over entries e=(ℓ,i)e = (\ell, i) identified by level and index:

Et=({0}×At(0))∪⋃ℓ=1D−1({ℓ}×(At(ℓ)∖St(ℓ))),\mathcal{E}_t = \left(\{0\} \times\mathcal{A}_t^{(0)}\right) \cup\bigcup_{\ell=1}^{D-1} \left(\{\ell\} \times\left(\mathcal{A}_t^{(\ell)} \setminus\mathcal{S}_t^{(\ell)}\right)\right),
ot,h=∑e∈Etexp⁡(st,h,e)Ve∑e∈Etexp⁡(st,h,e)(4)\mathbf{o}_{t,h} = \frac{\sum_{e \in\mathcal{E}_t} \exp(s_{t,h,e})\mathbf{V}_e}{\sum_{e \in\mathcal{E}_t} \exp(s_{t,h,e})} \tag*{(4)}

where, for e=(ℓ,i)e = (\ell, i), st,h,e=st,h,i(ℓ)s_{t,h,e} = s_{t,h,i}^{(\ell)} is the score of Eq. (2)} and Ve=Vi(ℓ)\mathbf{V}_e = \mathbf{V}_i^{(\ell)}, and ot,h\mathbf{o}_{t,h} is the output of head hh. Because the top-level candidates cover the prefix and each selected node is replaced by its children up to the query, the summaries and the exact tokens partition the prefix. The softmax uses the score of a summary as its logit, with no correction for subtree size or level.

Cost. For fixed CC and kk, each level scores at most CkCk candidates, and the number of levels grows logarithmically with LL, so the selection cost per query is O(log⁡L)O(\log L). The token budget is the number of entries a query attends to, ∣Et∣≤Ck+(D−1)(Ck−k)|\mathcal{E}_t| \le Ck + (D - 1)(Ck - k): at most CkCk exact tokens at level 0 and, at each level above, the summaries of at most Ck−kCk - k unselected candidates (3,840 with the default kk). The number of entries a query reads, counting each candidate once, is the token budget plus the keys of the (D−1)k(D - 1)k selected nodes, which are expanded instead of entering the softmax; it is at most D⋅CkD \cdot Ck, also O(log⁡L)O(\log L).

Candidate-Local RoPE

RecSA applies RoPE (Su et al. [2024]) with one change, which we call candidate-local RoPE: every candidate of level ℓ\ell, summaries included, takes its index in A(ℓ)\mathcal{A}^{(\ell)} as its position, and the query takes the last index, that of the current node. Parts of the sequence skipped between candidates receive no positions. Each level has at most Ck=4,096Ck = 4{,}096 candidates (§ 3.1), so the relative distance between the query and any candidate always lies between 0 and 4,095. During backbone training on 32K sequences with k=256k = 256 (§ 3.4), the candidate list for level 0 reaches 4,096 tokens, so training covers every relative distance that occurs at inference with the same kk.

Figure 3 compares candidate-local RoPE with ReRoPE (Su, [39]), which puts every token beyond a window ww at distance ww from the query; under candidate-local RoPE, the candidates of one level are all at different distances from the query.

Figure 3. Relative distance to the query qt\mathbf{q}_t, the last of 64 tokens. (a) RoPE and ReRoPE (Su, [39]); gray bars stand for runs of tokens. (b) Candidate-local RoPE on an example tree with C=4C = 4 children per node and k=2k = 2 selected nodes per level: each selected node is drawn above its children, and at every level the distances stay below Ck=8Ck = 8. Dashed spans mark parts of the sequence skipped between candidates; they receive no positions.

Because one node can have different indices in the candidate lists of different queries, the tree stores keys before RoPE, and the pooler (§ 3.3) pools these keys without position input. We keep the RoPE base θ=106\theta= 10^6 of the original model, without scaling.

Pooler Distillation

Because the key of a node is used both in the importance shared by a GQA group (Eq. (2)) and in the logit of each head in the final softmax (Eq. (4)), both should reflect the dense attention mass on the subtree of the node, so we supervise the pooler with this mass. A mean-pooled key generally does not represent this mass accurately [22] (Hu et al. 2025). The pooler computes the key KK of node ii at level ℓ\ell from the keys of its children, xc=KCi+c(ℓ−1)x_c = K_{C_i+c}^{(\ell-1)} for c=0,…,C−1c = 0,\ldots,C-1 (Figure 2a):

K=μ+g(p−μ)+σm,αc=softmax⁡c(τ wT(xc−μ)/σ),p=∑cαcxc,m=W2SiLU⁡(W1[μ/ρ;(p−μ)/σ]+b1),(5)\begin{aligned} K &= \mu+ g(\mathbf{p}-\mu)+\sigma\mathbf{m},\\ \alpha_c &= \operatorname{softmax}_c\left(\tau\,\mathbf{w}^{\mathsf{T}}(\mathbf{x}_c-\mu)/\sigma\right),\quad\mathbf{p}=\sum_c\alpha_c\mathbf{x}_c,\\ \mathbf{m} &= W_2\operatorname{SiLU}\left(W_1[\mu/\rho;(\mathbf{p}-\mu)/\sigma]+\mathbf{b}_1\right), \tag*{(5)} \end{aligned}

where μ\mu is the mean of the xc\mathbf{x}_c, σ\sigma is the root mean square of the elements of all xc−μ\mathbf{x}_c-\mu, ρ\rho is the root mean square of the elements of μ\mu, w\mathbf{w} is a scoring vector, the scalars τ\tau and gg are an inverse temperature and a gate, [ ⋅ ; ⋅ ][\,\cdot\,;\,\cdot\,] denotes concatenation and σm\sigma\mathbf{m} is the MLP term. Mean pooling is the special case g=0g=0, W2=0W_2=0. Each attention layer has one pooler with 24,770 parameters, shared across levels and across all KV heads of the layer. Appendix § 9 gives the parameter shapes and implementation details.

For each level ℓ≥1\ell\geq1, we compute the attention mass that the frozen original model, with RoPE at the original positions, puts on the subtree of each candidate in A(ℓ)A^{(\ell)}, and average it over the GG heads of the group. Below the top level, the candidates cover only part of the prefix, so their masses need not sum to one; normalizing them over the candidate list gives the teacher distribution y(ℓ)\mathbf{y}^{(\ell)}. The student distribution π(ℓ)\boldsymbol{\pi}^{(\ell)} normalizes the importance of Eq. (2) over the same list. Both distributions use the queries and keys of the same forward pass of the frozen original model, so the loss of each layer depends only on the pooler of that layer. We fit the student distribution to the teacher distribution with a KL divergence:

πt,i(ℓ)=It,i(ℓ)/∑i′∈At(ℓ)It,i′(ℓ),LKL=∑t∑ℓ=1D−1KL⁡(yt(ℓ)∥πt(ℓ)).(6)\begin{aligned} \pi_{t,i}^{(\ell)} &= I_{t,i}^{(\ell)}\bigg/\sum_{i'\in A_t^{(\ell)}} I_{t,i'}^{(\ell)},\\ \mathcal{L}_{\mathrm{KL}} &= \sum_t\sum_{\ell=1}^{D-1}\operatorname{KL}\left(\mathbf{y}_t^{(\ell)}\mathbin\Vert\boldsymbol{\pi}_t^{(\ell)}\right). \tag*{(6)} \end{aligned}

Below the top level, the candidate lists come from the student’s own selection, which follows the same rule as at inference; no gradient flows through the selection.

The MLP term of the pooler can shift the keys of all nodes of a level by the same vector δ\delta. Under candidate-local RoPE, the score of candidate ii then gains qt,hTRpi−nℓ+1δ/d\mathbf{q}_{t,h}^{\mathsf{T}}R_{p_i-n_{\ell}+1}\delta/\sqrt{d}, which depends on the query and on the position of the candidate, but not on the content of the candidate’s subtree. Training can lower the KL through this positional bias, without the pooler learning to distinguish subtrees by their content. We add a shift penalty on the mean MLP term over the MℓM_\ell nodes of each level ℓ\ell of a tree, that is, on the shift shared by these nodes, but not on the differences between them:

Lshift=∑ℓ=1D−1∥1Mℓ∑iσimi∥2/(1Mℓ∑i∥μi∥2),(7)\mathcal{L}_{\mathrm{shift}}=\sum_{\ell=1}^{D-1}\left\lVert\frac{1}{M_\ell}\sum_i\sigma_i\mathbf{m}_i\right\rVert^2\bigg/\left(\frac{1}{M_\ell}\sum_i\lVert\mu_i\rVert^2\right), \tag*{(7)}

where σi\sigma_i, mi\mathbf{m}_i and μi\mu_i are those of node ii in Eq. (5); the denominator makes the penalty independent of the key scale.

Training

Stage 1: Pooler. We freeze the backbone and train only the parameters of the pooler (§ 3.3). Because the pooler (Eq. (5)) does not involve kk, this stage uses a smaller k=64k=64 to obtain deeper trees from 32K sequences. With Ck=1,024Ck=1,024, the training sequences of 32K tokens have three levels, and the pooler learns to construct the keys of level 2 from the pooled keys of level 1. Inference with the default k=256k=256 uses at most these three levels up to 1M; at 2M, it adds level 3, which reuses the same parameters. Stage 1 has two parts on the same sequences. The first part trains w\mathbf{w}, τ\tau and gg with the MLP term off (W2W_2 fixed at 0). Its loss is LKL\mathcal{L}_{\mathrm{KL}}; on retrieval and question-answering sequences with a single piece of evidence, we add an auxiliary cross-entropy whose target is the top-level node that contains the evidence. The second part freezes w\mathbf{w}, τ\tau and gg and trains W1W_1, b1\mathbf{b}_1 and W2W_2 with LKL+λLshift\mathcal{L}_{\mathrm{KL}}+\lambda\mathcal{L}_{\mathrm{shift}}. Appendix § 13 gives the hyperparameters and the sampled query positions.

Stage 2: Backbone. We freeze the pooler and train the whole backbone under RecSA with the default k=256k=256 and only the language modeling loss (data in § 5.1). Gradients also reach the backbone through the keys and values of the summaries, via the frozen pooler and mean pooling, respectively; no gradient flows through the selection.

Efficient Prefill and Decoding

Prefill

In prefill, adjacent queries select overlapping sets of parent nodes. Some existing block-sparse kernels process a group of adjacent queries over the union of their selected blocks and load each block once for the group, with its keys already rotated by RoPE (Hu et al., 2026a). Under candidate-local RoPE, however, a key can take different positions, and hence different rotations, in the candidate lists of different queries.

We split the rotation between keys and queries using slots: the mm-th node that a query selects at level ℓ\ell, in index order, is its slot mm. In Figure 4a, the parent node of the framed block is slot 2 of q1\mathbf{q}_1 and slot 3 of q3\mathbf{q}_3. Eq. (3) concatenates the child lists in slot order, and only the last list (that of the current node) can be truncated, so child cc of slot mm has index mC+cmC+c in At(ℓ−1)A_t^{(\ell-1)}. Because RaTRb=Rb−aR_a^{\mathsf{T}}R_b=R_{b-a}, the product in

Figure 4. Prefill and decoding of RecSA. (a) Prefill: rows correspond to the 16 adjacent queries of one thread block and columns to the union of the parent nodes they selected; numbers give the slot mm of the parent node for the query of the row. The black frame marks one block (the 16 children of a parent node), loaded once per pass and shared by the queries that selected its parent. (b) Decoding with KV offloading: blue indicates selected nodes and blocks, light orange unselected candidates (summaries) and gray other nodes.

Eq. (2) for this child becomes

(Rn−1qt,h)⊤RmC+cK=(Rn−1−mCqt,h)⊤RcK,(8)(R_{n-1}q_{t,h})^{\top}R_{mC+c}\mathbf{K}=(R_{n-1-mC}q_{t,h})^{\top}R_c\mathbf{K}, \tag*{(8)}

where n=nℓ−1n=n_{\ell-1} and K\mathbf{K} is the key of the child. The key-side rotation RcR_c depends only on cc, not on the query, so the rotated keys of each level are shared by all queries. The rest of the rotation moves to the query side: each query starts from Rn−1qt,hR_{n-1}q_{t,h} and is rotated by R−CR_{-C} after each node it selected. Our kernels give the same output as rotating the keys for each query, within floating-point error.

One thread block processes the 4 query heads of one KV head for 16 adjacent queries (Figure 4a). A pass loops through the union of the parent nodes that the 16 queries selected, in index order: for each parent, the thread block loads the 16 children into shared memory once and scores them on tensor cores for all 64 query–head pairs, masking the queries that did not select this parent. On PG-19, each KV block loaded in the pass of level 0 serves 7.5, 5.2 and 4.1 of the 16 queries on average at 32K, 131K and 524K.

Each level ℓ≥1\ell\ge1 takes two passes: the first computes the importance of Eq. (2), and after selection, the second accumulates only the unselected candidates into an online softmax ([9]) as summaries. At the top level, whose candidates are the current node and all nodes before it, both passes are dense and tiled. Level 0 takes one pass, which accumulates all of its candidate tokens into the same softmax.

Decoding

In decoding (Figure 4b), the key and value of each new token are appended to level 0 (①). Except at a step that adds a level (§ 3.1), only the last node of each level ℓ≥1\ell\ge1 changes, and RecSA recomputes its key and value (②) from its 16 or fewer children by Eq. (1).

With batch size 1, each step has one query, and scoring a level with one thread block for each of the 8 KV heads would occupy at most 8 of the 132 SMs of an H200. RecSA instead splits the candidate list of each level into 16 segments, so that at least 128 thread blocks compute the importance, each relative to the maximum score in its segment (③). A second kernel rescales these values to the maximum over all segments and selects the same top-kk as without segments. The softmax accumulation is split into 16 segments in the same way, and their partial results are merged (⑤).

Because each level has at most CkCk candidates (§ 3.1), every kernel can use a fixed launch grid and read the current context length from GPU memory, so the decoding step of all 36 layers is captured as one CUDA graph and replayed at every step that does not add a level.

KV Offloading

At 1M and 2M, the full KV cache takes 137 and 275 GiB, which together with the 7.5 GiB of model weights exceeds the 140 GiB of memory on one H200. RecSA keeps the exact tokens in pinned host memory, and the GPU needs to hold only the levels above level 0 (less than 7% of the full KV cache) and buffers for the gathered exact tokens.

Selection reads only the keys of levels ℓ≥1\ell\ge1 and runs entirely on the GPU. A gather kernel then copies the exact tokens in the candidate list of level 0, the children of the kk selected level-1 nodes, from host memory over PCIe in 16-token blocks (④). Each step gathers at most Ck=4,096Ck=4{,}096 exact tokens per KV head and layer, at most 576 MiB over the 36 layers, independent of the context length.

After space is reserved for the generated tokens, the remaining GPU memory caches a suffix of the input. The gather kernel reads the cached blocks from the GPU cache and the others from host memory.

On the RULER samples of Appendix D.1, decoding at 1M and 2M takes 8.35 and 10.7 ms per token with the cache, compared with 19.8 and 20.6 ms without the cache.

Evaluation

Experimental Setup

Model and training. We apply RecSA to Qwen3-4B (Yang et al., [49]), whose training length is 32K, and train it with the two stages of § 3.4 on 0.62B tokens in total. The training data include synthetic retrieval tasks, document question answering, books, code and instructions whose responses were generated by the original model (Appendix E). Unless otherwise stated, we evaluate with the default k=256k = 256.

Baselines. We train three backbones, Dense, MoBA and DSA, from Qwen3-4B with the settings, sequences, order and number of steps of Stage 2; for DSA, the indexer is first warmed up as in DeepSeek-AI et al. [12]. We evaluate each backbone with YaRN and with DCA and name each model by its attention and its context extension method, such as Dense + YaRN. Qwen3-4B + YaRN denotes the original model with YaRN. The training-free InfLLM and InfiniteHiP run on the original model with their official implementations. At each length, the token budget of every sparse baseline, counted as in § 2, is matched to that of RecSA for the query at the last position (Table 1). Appendix E.4 gives the settings at each length.

Benchmarks. RULER (Hsieh et al., [21]) has 13 synthetic tasks (Appendix B). We report its official score, averaged over all tasks, with greedy decoding on 56 samples per task from 32K to 262K, 20 at 524K and 16 at 1M and above. All methods in Table 1 use the same samples. Perplexity at context length LL is computed on the last LL of the first 10610^{6} tokens of each of nine PG-19 books (Rae et al., [36]) (Appendix C). For long-document tasks, we select LongBench (Bai et al., [4]) and En.MC from InfiniteBench (Zhang et al., [52]), and for short-context tasks, MMLU (Hendrycks et al., [19]), ARC-C (Clark et al., [7]), GSM8K (Cobbe et al., [8]), IFEval (Zhou et al., [53]), HumanEval (Chen et al., [5]) and MBPP (Austin et al., [3]). Context lengths from 32K to 524K denote 2152^{15} to 2192^{19} tokens, and 1M and 2M denote 10610^{6} and 2×1062 \times10^{6} tokens.

Efficiency. We measure latency on one H200 GPU with batch size 1. In the same framework as RecSA, Dense uses FlashAttention-2 (Dao, [9]) for prefill and Flash-Decoding (Dao et al., [10]) for decoding. At 1M and 2M, host memory holds the exact tokens of RecSA (§ 4.3) and, in decoding, the part of the Dense KV cache beyond GPU memory. Appendix D.1 describes how we measure latency.

Length Extrapolation

Table 1 shows that RecSA achieves the highest RULER score at every length from 131K to 2M. It outperforms the strongest baseline by 2.8 points at 131K (DSA + YaRN) and by 11.7 at 524K and 20.5 at 1M (Dense + DCA). At 2M, RecSA scores 49.3, compared with 34.0 for InfiniteHiP (Lee et al., [37]), the strongest baseline at this length. At 32K, RecSA matches Dense + YaRN (94.7 vs. 94.5).

Beyond 131K, each backbone scores higher with DCA than with YaRN. For example, Dense + DCA scores 40.0 at 1M and Dense + YaRN 1.6. Like RecSA, DSA + DCA uses a matched token budget and keeps every relative distance within the range seen during training, but at 1M it scores 36.8, compared with 60.5 for RecSA. Keeping relative distances within the range thus does not by itself explain the higher score of RecSA.

On individual tasks (Table 2 and Appendix B), RecSA achieves the highest score on MK1, MQ, MV, S2 and VT at every length from 131K to 2M. For example, at 1M, RecSA scores 90.6 on multi-query retrieval (MQ) and 95.0 on variable tracking (VT); the strongest baselines on these two tasks score 37.5 (InfiniteHiP) and 82.5 (Dense + DCA).

MethodS1S2S3MK1MK2MK3MVMQVTCWEFWEQA1QA2Avg
131K
InfLLM100.07.10.05.457.10.07.63.660.036.486.38.98.929.3
InfiniteHiP100.091.191.173.232.10.076.386.657.155.986.355.423.263.7
Dense + YaRN100.0100.098.294.664.341.191.594.695.770.785.758.944.680.0
Dense + DCA100.098.2100.078.673.241.181.794.690.479.390.560.732.178.5
MoBA + YaRN87.510.725.019.614.31.818.88.981.841.858.330.416.131.9
MoBA + DCA98.214.317.919.623.28.917.912.181.848.288.737.525.037.9
DSA + YaRN100.0100.0100.094.666.126.888.896.498.280.584.567.942.980.5
DSA + DCA100.098.2100.078.669.637.579.092.989.381.886.362.532.177.5
RecSA (ours)100.0100.0100.0100.076.837.592.099.699.684.888.757.146.483.3
1M
InfLLM100.06.20.00.056.20.01.63.153.87.581.218.86.225.7
InfiniteHiP87.562.543.837.56.20.042.237.552.51.985.418.80.036.6
Dense + YaRN0.00.00.00.00.00.00.00.00.00.020.80.00.01.6
Dense + DCA100.056.275.056.26.20.029.726.682.52.579.26.20.040.0
MoBA + YaRN0.00.00.00.00.00.00.00.00.00.012.50.00.01.0
MoBA + DCA75.00.00.00.00.00.00.00.015.00.060.46.26.212.5
DSA + YaRN43.80.00.00.00.00.00.00.01.20.027.16.20.06.0
DSA + DCA100.031.262.543.86.20.029.720.371.221.972.96.212.536.8
RecSA (ours)100.087.5100.081.225.06.254.790.695.023.185.431.26.260.5

Table 2. RULER score per task at 131K and 1M. Retrieval: needle-in-a-haystack tasks with a single needle (S1–S3), multiple keys (MK1–MK3), multiple values (MV) or multiple queries (MQ). VT: variable tracking. CWE: common words extraction. FWE: frequent words extraction. QA1: SQuAD (Rajpurkar et al., [38]). QA2: HotpotQA (Yang et al., [50]). Best results in each column at each length are in bold. Appendix B gives the scores at all lengths.

From 131K to 1M, the perplexity of RecSA stays between 10.87 and 11.12 (Table 3). At 1M, the perplexity ranges from 54.42 to 414.69 for the methods with YaRN and from 14.57 to 19.18 for those with DCA.

Method32K131K262K524K1M
Trained at 32K
Dense + YaRN11.1711.8116.9660.94211.33
Dense + DCA11.1711.2712.2013.3914.57
MoBA + YaRN12.1113.5120.43122.30414.69
MoBA + DCA12.1112.8714.8517.1219.18
DSA + YaRN11.1511.8115.2325.8854.42
DSA + DCA11.1511.3212.3513.6715.01
RecSA (ours)11.2410.8711.0011.0811.12

Table 3. Perplexity on nine PG-19 books ([36]) by context length. Sparse methods use the token budgets of Table 1. InfLLM and InfiniteHiP are not listed because their key selection during prefill is not causal. Best results are in bold.

Short-Context and Long-Document Tasks

On the six short-context benchmarks (Table 4), RecSA performs comparably to Qwen3-4B; the largest difference is 1.8 points, on MBPP (61.8 vs. 63.6). On LongBench, RecSA scores 51.8, compared with 49.2 for the original Qwen3-4B and 50.9 for the Dense backbone. On En.MC, RecSA scores 66.8 and Qwen3-4B + YaRN 34.5; InfiniteHiP, Dense + DCA and DSA + DCA score 66.4, 62.4 and 62.0, respectively. Appendix C gives the scores of Dense on all benchmarks and the En.MC scores by input length.

BenchmarkQwen3-4BRecSA
MMLU (5-shot)70.170.5
ARC-C (0-shot)87.288.1
GSM8K (0-shot, CoT)91.590.7
IFEval (prompt, strict)79.178.6
HumanEval (0-shot, pass@1)82.381.7
MBPP (0-shot, pass@1)63.661.8
LongBench49.251.8
InfiniteBench En.MC34.566.8

Table 4. Scores on short-context benchmarks and long-document tasks. LongBench ([4]): average score over 12 English tasks and 2 code tasks. En.MC: multiple-choice questions about full-length novels from InfiniteBench ([52]), with inputs of 70K–746K tokens; Qwen3-4B uses YaRN for context extension on En.MC. Best results in each row are in bold.

Efficiency

Prefill of 32K tokens takes 1.59 s with RecSA and 1.46 s with Dense, and from 64K to 2M, RecSA is faster (Figure 5a). At 524K, prefill takes 80 s with RecSA and 257 s with Dense, a 3.2× speedup.

Figure 5. Efficiency on one H200 GPU with batch size 1. (a) Prefill time per token of RecSA and of Dense with FlashAttention in the same framework; hollow markers indicate RecSA with offloading (§ 4.3), and arrows mark values above the axis range. (b) Time breakdown of one decoding step of RecSA. Non-attention: the remaining step time, including the projections, the MLPs and the idle time between kernels. Gather: gathering the selected exact tokens from host memory and from the GPU cache (§ 4.3).

RecSA is faster than Dense in decoding at every measured length, including 32K (Figure 5b). From 131K to 524K, RecSA takes about 6.1 ms per token, while the latency of

Dense grows from 8.6 ms to 23.4 ms, 3.8× that of RecSA at 524K. At 1M and 2M, RecSA takes 8.35 and 10.7 ms per token, compared with 177 ms and 2.9 s for Dense. Copying the part of the Dense KV cache in host memory to the GPU accounts for 77% and 96% of the Dense latency, respectively.

The decoding step time of RecSA (Figure 5b) stays nearly constant from 131K to 524K, where the tree has three levels and each level scores at most Ck=4,096C_k = 4{,}096 candidates (§ 3.1). At these lengths, the non-attention part takes 3.35 ms, more than half of the step. At 1M and 2M, the selected exact tokens are gathered from host memory and from the GPU cache (Gather), and at 2M, the tree has a fourth level. A two-level variant scores every level-1 node at each step, 8,192 nodes at 131K and 125,000 at 2M, and RecSA is 1.1× faster than this variant at 131K and 1.9× faster at 2M (Table D.3).

Ablation Studies

Unless otherwise stated, each variant below is trained with the same data, order and steps as RecSA.

Summaries improve the average score at long contexts. A model trained and evaluated without summaries, whose softmax covers only the exact tokens, averages 70.4 over the four lengths from 131K to 1M, compared with 72.3 for RecSA (Appendix F).

Candidate-local RoPE improves length extrapolation. The standard RoPE variant is trained with both stages of § 3.4, the pooler included, but applies RoPE at absolute token positions. At 32K, it scores 95.2 and RecSA 94.7 (Figure 6a). Without YaRN, standard RoPE scores 1.0 at 131K, where relative distances exceed those seen during training. With YaRN, it scores 66.2 at 131K and 1.9 at 524K and 1M, while RecSA scores 83.3 at 131K and 60.5 at 1M.

Figure 6. RULER score in the ablation experiments. (a) Position encoding. Standard RoPE applies RoPE at absolute token positions and is evaluated with and without YaRN beyond 32K. (b) Pooler. KL and the shift penalty are the losses of Eqs. (6) and (7), and LM loss trains the MLP term with the language modeling loss. Backbone frozen: each pooler is trained on the original model and evaluated with it at 32K, 131K and 524K. Backbone trained: for KL + shift penalty and w/o MLP term, the backbone is then trained as in Stage 2. KL + shift penalty is the pooler of RecSA. (c) RecSA evaluated with k=128k = 128, 256 and 512. Appendix F gives all scores.

Distillation, the shift penalty and the MLP term improve the score at long contexts. With the backbone frozen (Figure 6b), the five poolers score between 73.6 and 78.9 at 32K but between 8.9 and 55.5 at 524K, where the pooler of RecSA (KL + shift penalty) scores highest. Training the MLP term with the language modeling loss instead of distillation gives the lowest scores at 131K and 524K, below mean pooling, and training with KL alone, without the shift penalty, lowers the score at 524K from 55.5 to 45.3. With the backbone trained, the decrease from removing the MLP term grows with length: 3.3 points at 131K, 11.5 at 262K, 19.3 at 524K and 23.4 at 1M. Appendix A.4 examines how the MLP term changes selection.

Increasing kk to 512 improves the score at every length. Because kk sets the token budget (§ 3.1), we evaluate the trained RecSA model with k=128k = 128 and k=512k = 512 (Figure 6c). At every length from 32K to 1M, k=512k = 512 scores higher than k=256k = 256, with 1.7×–1.9× the token budget, and k=128k = 128 scores lower at 131K, 262K and 1M. With k=512k = 512, relative distances in a candidate list reach 8,191, compared with at most 4,095 in training with k=256k = 256.

Related Work

Hierarchical selection and summaries. HiP ([35]) is training-free and selects level by level in a binary tree, scoring each block by one representative key. PISA ([41]) builds a pyramid of mean-pooled block keys, scores each candidate by the LogSumExp of the scores of its children and trains models with this selection. Both discard the unselected blocks. Other methods combine attention over selected tokens with coarse representations of the context. NSA attends to the compressed blocks of the whole context and to the selected blocks in separate branches. Multipole Attention ([20]) is training-free: in decoding, it clusters the keys with k-means, attends exactly to the keys of high-scoring clusters, approximates the other clusters by their centroids and normalizes both parts together. RecSA also normalizes summaries and exact tokens together, and they partition the prefix; the keys of its summaries come from a trained pooler, and each level scores a bounded number of candidates.

Sparse attention beyond the training length. Landmark Attention ([29], [22] (Hu et al. 2025)) and HiLS ((Hu et al., 2026a)) learn a representation for each block and train the block scores end to end with the language modeling loss. HSA pretrains models of about 240M parameters from scratch at 4K, fine-tunes them on RULER tasks and evaluates them up to 32M. HiLS pretrains models from scratch at 8K and evaluates them up to 4M; it also converts the pretrained Olmo3-7B to HiLS by continued pretraining at 8K, with RULER examples mixed into the training data, and evaluates it on RULER up to 1M.

Distilled selectors. SeerAttention ([17]) fits a block-level gate to the max-pooled attention map with a KL divergence and uses it in prefill; SeerAttention-R ([18]) applies such a gate in decoding. The warm-up stage of DSA ([12]) trains only the indexer, fitting it to dense attention with a KL divergence, before the whole model is trained. These methods supervise the scores of one level. RecSA supervises the scores of every level with the dense attention mass on the subtree of each candidate, through one pooler shared across levels, and the keys that the pooler computes serve both for selection and as the keys of summaries.

Position encoding. InfLLM ([47]) assigns one position to all tokens beyond the local window, InfiniteHiP gives the selected keys consecutive positions and Landmark Attention maps the retrieved blocks into a reserved range of positions. HiLS keeps RoPE only in the dimensions whose rotation period does not exceed the pretraining length; PISA applies RoPE to the high-frequency half of the dimensions of each head. Context extension methods, such as YaRN, DCA, ReRoPE, PI ([6]), LongRoPE ([14]) and SelfExtend ([28]), change the rotation angles or the assignment of positions. RecSA assigns each candidate its index in the candidate list of its level, and each level has at most CkCk candidates, so every relative distance stays below CkCk at any context length.

Training-free sparse attention and KV offloading. Training-free sparse methods accelerate prefill ([27, 33]) or decoding. Quest ([42]) estimates, at each decoding step, an upper bound on the query–key scores in every page of the KV cache, and the first pruning stage of InfiniteHiP scans all keys; in RecSA, the selection cost per query is O(log⁡L)O(\log L). InfLLM and InfiniteHiP, like RecSA (§ 4.3), keep most of the KV cache in host memory and cache part of it on the GPU.

Conclusion

We present RecSA, which builds a tree over the KV cache and selects level by level; the summaries of unselected candidates share one softmax with the exact tokens. Its selection cost and the number of entries read per query are O(log⁡L)O(\log L), and candidate-local RoPE keeps every relative distance within the range seen during training, so RecSA has no inherent limit on context length. We initialize RecSA from Qwen3-4B, distill its pooler from dense attention and train it only at the original model’s 32K training length. On RULER, RecSA outperforms all baselines from 131K to 2M. With our kernels, RecSA is faster than dense attention in end-to-end prefill and decoding from 64K to 2M.

AI Usage Disclosure

We used AI coding assistants for four tasks. Code generation: they wrote parts of the implementation to the authors’ specifications, including the training and evaluation scripts. Experiment execution: they launched and monitored the training and evaluation jobs that the authors specified and approved, and collected the results. Literature search: they helped find related work and check citation metadata against the original sources. Writing: they polished the grammar and phrasing of the authors’ text. Separately, some of the training data consists of responses generated by the original Qwen3-4B (Appendix § 13). The research ideas, the method, the experimental design, the analysis and the conclusions are the authors’ own. The authors reviewed all AI-assisted work and take full responsibility for the content of this paper.

Tree and Pooler

The pooler of each attention layer has the parameters w∈R128\mathbf{w} \in\mathbb{R}^{128}, τ\tau, gg, W1∈R64×256W_1 \in\mathbb{R}^{64 \times256}, b1∈R64\mathbf{b}_1 \in\mathbb{R}^{64} and W2∈R128×64W_2 \in\mathbb{R}^{128 \times64} Eq. (5), and clamps σ\sigma and ρ\rho to a minimum of 10−610^{-6}.

In Stage 1, the candidate lists in the KL Eq. (6) include the current node, whose key is pooled from all of its children Eq. (1).

Nodes with Fewer than CC Children

The last node of each level ℓ≥1\ell\ge1 has n<Cn < C children until it is full. For such a node, Eqs. (1) and (5) use only these nn children: the value is the mean of their values, μ\mu and σ\sigma are computed over them and the softmax that gives αc\alpha_c runs over them.

Tree Update in Decoding

In decoding, Recursive Sparse Attention (RecSA) recomputes the key and value of the node that contains the new token at each level, from level 1 up to the top level (Section 4.2). When the position tt of the new token is a multiple of CℓC^\ell, RecSA adds a node with one child at level ℓ\ell. When the top level exceeds CkCk nodes, RecSA builds a new top level from it by Eq. (1), and the existing levels do not change.

Initialization

The first part of Stage 1 initializes the pooler of every layer as follows, with separate random draws for each layer: w\mathbf{w} is a unit vector in a random direction, τ=0.05\tau= 0.05, g=1g = 1, the elements of W1W_1 are drawn independently and uniformly from [−1/16,1/16][-1/16, 1/16], b1=0\mathbf{b}_1 = 0 and W2=0W_2 = 0. The initial key is then p\mathbf{p}, and the small τ\tau keeps every αc\alpha_c close to 1/C1/C, so this key is close to the mean of the child keys. The first part leaves W1W_1, b1\mathbf{b}_1 and W2W_2 at these values, and the second part trains them from there.

Analysis of the MLP Term

We use the notation of Eq. (5) and write q\mathbf{q} for a query vector. With g=1g = 1, the score qTK\mathbf{q}^{\mathsf{T}}\mathbf{K} without the MLP term equals, up to a constant, the first-order Taylor expansion of log⁡∑cexp⁡(qTxc)\log\sum_c \exp(\mathbf{q}^{\mathsf{T}}\mathbf{x}_c) at q=τw/σ\mathbf{q} = \tau\mathbf{w}/\sigma (Hu et al., 2026a), because p\mathbf{p} is the gradient of this LogSumExp at that point. No single key can match this LogSumExp for every query, because qTK\mathbf{q}^{\mathsf{T}}\mathbf{K} is linear in q\mathbf{q} and the LogSumExp is not. The MLP term can move the key away from p\mathbf{p}, and we measure what it contributes.

Setup. We used 28 RULER [21] samples at 131K, four from each of S2, S3, MK1, MK2, MV, MQ and VT (Table 2). For each sample, we ran RecSA with

w/o MLP termRecSA
α\alpha on level-1 needle nodes0.230.52
LSE — node score1.210.34
Recall0.4680.625

Table A.1. The MLP term on needle nodes, the nodes that contain evidence for the answer. 131K, 28 RULER samples, queries of the first four answer tokens; w/o MLP term: W2=0W_2 = 0. α\alpha: the sum of the weights of the level-1 needle nodes among the 16 children of a level-2 needle node (0.14 if all children had equal weight). LSE: LogSumExp of the token scores below a node; the row LSE node score is for level-2 needle nodes; scores are centered over the nodes of each query. Recall: fraction of queries for which a level-2 needle node is among the top 1/8 of the level-2 nodes (0.635 when nodes are ranked by LSE).

the correct answer appended and kept the keys of every layer and the queries of the first four answer tokens. From these keys we recomputed levels 1 (16 tokens) and 2 (256 tokens) with and without the MLP term (W2=0W_2 = 0, all other parameters unchanged). We compared the score of each node with the LogSumExp (LSE) of the query’s scores over all tokens below it. Selection does not change when the scores of all nodes are shifted by the same amount, so we centered the scores over the nodes of each query. We call a node that contains evidence for the answer a needle node. We measure recall as the fraction of queries for which a needle node is among the top 1/8 of the nodes at its level.

Results. The MLP term does not correct the score of the node whose key it enters. Its contribution to that score, σqTm\sigma\mathbf{q}^{\mathsf{T}}\mathbf{m}, has a correlation below 0.1 in magnitude with the gap between the LSE and the mean score of the tokens below the node at both levels, and level-1 recall is unchanged (0.747 vs. 0.752). Its effect appears at the next level. The MLP term of a level-1 key enters the level-2 weights αc\alpha_c through wT(xc−μ)\mathbf{w}^{\mathsf{T}}(\mathbf{x}_c - \mu) and acts there as a query-independent bias: the logits of the level-1 needle nodes rise by 1.45, the sum of their weights increases from 0.23 to 0.52 (Table A.1) and the level-2 key moves closer to them. Of the 0.878 by which the MLP term raises the score of a needle node at level 2, the change in g(p−μ)g(\mathbf{p} - \mu) contributes 1.025 and the terms σm\sigma\mathbf{m} of both levels −0.147. With the MLP term at level 2 only, level-2 recall is 0.476, compared with 0.468 without the term; with the term at level 1 only, level-2 recall is 0.628. The keys of the original Qwen3-4B [49], on which the pooler is trained, give nearly the same numbers on 14 of these samples (two per task): the gap between the LSE and the node score falls from 1.23 to 0.37, and recall rises from 0.469 to 0.628.

RULER RESULTS PER TASK

Setup. We generate the samples with our reimplementation of the RULER generators (Hsieh et al., [21]), which differs from the official code in four ways. The essay haystack consists of web documents from DCLM-Baseline (Li et al., 2024) instead of the essays of Paul Graham. The uncommon words of CWE and the words of FWE are random strings of three consonant–vowel syllables, where the official code uses English words for CWE and random strings of six letters for FWE. The distractor keys of MK2 carry a numeric suffix, so that they stay unique at long contexts. QA1 draws its questions from SQuAD v1.1 instead of SQuAD 2.0. From 524K on, QA1 needs more distractor paragraphs than the development set of SQuAD v1.1 has, so the distractor paragraphs repeat. Each input is one user turn in the chat template of Qwen3-4B in non-thinking mode, and the assistant turn starts with the answer prefix of the task; with the template, an input has 95% to 100% of LL tokens. Each task keeps the official limit on generated tokens: 128 for S1 to MQ, 30 for VT, 120 for CWE, 50 for FWE and 32 for QA1 and QA2. The score is the string match of the official code: the fraction of gold answers that appear in the output or, for QA1 and QA2, whether any gold answer appears.

Results. Tables B.1 and B.2 list the score of each task, with the abbreviations of Table 2, for the methods of Table 1 at every length. They also list the original Qwen3-4B with YaRN (Peng et al., [34]) up to 524K, the original Qwen3-4B with DCA (An et al., 2024) up to 1M and the variants of Table F.1 with a trained backbone up to 1M.

SHORT-CONTEXT BENCHMARKS, LONG-DOCUMENT TASKS AND PERPLEXITY

Short-Context Benchmarks

The three models, Qwen3-4B, Dense and RecSA, receive the same questions and prompts. The generative benchmarks use the chat template of Qwen3-4B in non-thinking mode with greedy decoding. For RecSA, the score of each sample depends only on its first 4,096 tokens. In a multiple-choice question, these include the input and the option being scored; in a generation task, they include the input and the output up to the end of the answer or the code. In this range, RecSA is equivalent to dense causal attention (§ 3.1), so we evaluate the trained weights of RecSA with dense attention, using the scaled dot-product attention (SDPA) of PyTorch (Paszke et al., [32]) in Transformers (Wolf et al., [46]). Qwen3-4B and Dense are evaluated the same way.

The benchmarks are evaluated as follows:

  • MMLU (Hendrycks et al., [19]): all 14,042 questions, 5-shot with the first five questions of the dev set of each subject as examples, in the format of lm-evaluation-harness (Gao et al., [16]) and without the chat template. We compare the log-likelihoods of the option letters A–D.

  • ARC-C (Clark et al., [7]): all 1,172 questions, 0-shot. As in MMLU, the prompt gives the question and its options labeled with letters, without the chat template, and we compare the log-likelihoods of the letters.

  • GSM8K (Cobbe et al., [8]): all 1,319 questions, 0-shot, with “Please reason step by step, and put your final answer within \boxed{}.” appended to the question and at most 1,024 generated tokens. The answer is the number in the last \boxed{}, or the last number in the response if it has none.

  • IFEval (Zhou et al., [53]): 541 prompts with at most 1,280 generated tokens, scored by the checkers of lm-evaluation-harness 0.4.13; we report prompt-level strict accuracy. The checkers draw random numbers, so we set the seed of Python’s random module to 0, of NumPy to 1234 and of langdetect to 0.

  • HumanEval (Chen et al., [5]) and MBPP (Austin et al., [3]), with 164 and 500 problems: the humaneval_instruct and mbpp_instruct formats of lm-evaluation-harness, 0-shot, pass@1, with at most 1,024 and 512 generated tokens, respectively. Each program runs separately with a time limit of 10 s.

Table C.1 lists the scores of the three models on all benchmarks, including LongBench (Appendix § 11.§ 2).

Long-Document Tasks

LongBench. Of the 14 English tasks of LongBench (Bai et al., [4]), we use 12 (NarrativeQA, MultiFieldQA-en, HotpotQA, 2WikiMQA, GovReport, QMSum, Multi-News, TREC, TriviaQA, SAMSum, PassageCount and PassageRetrieval-en), together with the 2 code tasks (LCC and RepoBench-P), 3,350 samples in total. Qasper and MuSiQue are sources of the training data (Appendix § 13.§ 1) and are excluded. The prompts, the maximum generation length of each task and the metrics follow the official settings. As in the official code, prompts longer than 31,500 tokens, the limit for 32K models, are truncated in the middle, and TREC, TriviaQA, SAMSum, LCC and RepoBench-P are used without the chat template. The other tasks use the chat template of Qwen3-4B in non-thinking mode. All prompts fit within the training length of Qwen3-4B, so Qwen3-4B runs without YaRN. All models use greedy decoding, and the score is the mean over the 14 tasks.

32KS1S2S3MK1MK2MK3MVMQVTCWEFWEQA1QA2Avg
InfLLM100.017.932.132.167.910.729.036.657.156.181.039.325.045.0
InfiniteHiP100.098.2100.096.458.919.695.199.653.276.282.787.567.979.6
Dense + YaRN100.098.2100.0100.094.6100.099.6100.099.393.289.987.566.194.5
Dense + DCA100.098.2100.0100.096.4100.099.6100.099.393.489.987.566.194.6
MoBA + YaRN100.071.496.476.876.889.367.072.394.686.690.582.157.181.6
MoBA + DCA100.071.491.178.680.487.564.777.795.485.791.182.157.181.8
DSA + YaRN100.0100.0100.0100.094.6100.0100.0100.098.994.691.791.167.995.3
DSA + DCA100.098.2100.0100.094.6100.0100.0100.099.395.291.191.167.995.2
RecSA (ours)100.0100.0100.098.296.496.498.2100.0100.095.289.992.964.394.7
Qwen3-4B + YaRN100.096.4100.098.289.376.898.799.154.373.283.383.960.785.7
Qwen3-4B + DCA100.098.2100.0100.089.378.698.799.153.672.782.783.962.586.1
w/o summaries100.0100.0100.0100.094.698.298.2100.099.693.686.991.166.194.5
w/o MLP term100.0100.0100.098.298.298.297.8100.0100.095.989.387.567.994.8
standard RoPE + YaRN100.098.2100.0100.094.6100.098.7100.0100.093.891.192.967.995.2
standard RoPE100.098.2100.0100.094.6100.098.7100.0100.093.891.192.967.995.2
top-k 128100.0100.0100.0100.096.489.395.1100.0100.093.289.994.667.994.3
top-k 512100.0100.0100.098.2100.0100.099.1100.0100.097.186.996.469.696.0
131KS1S2S3MK1MK2MK3MVMQVTCWEFWEQA1QA2Avg
InfLLM100.07.10.05.457.10.07.63.660.036.486.38.98.929.3
InfiniteHiP100.091.191.173.232.10.076.386.657.155.986.355.423.263.7
Dense + YaRN100.0100.098.294.664.341.191.594.695.770.785.758.944.680.0
Dense + DCA100.098.2100.078.673.241.181.794.690.479.390.560.732.178.5
MoBA + YaRN87.510.725.019.614.31.818.88.981.841.858.330.416.131.9
MoBA + DCA98.214.317.919.623.28.917.912.181.848.288.737.525.037.9
DSA + YaRN100.0100.0100.094.666.126.888.896.498.280.584.567.942.980.5
DSA + DCA100.098.2100.078.669.637.579.092.989.381.886.362.532.177.5
RecSA (ours)100.0100.0100.0100.076.837.592.099.699.684.888.757.146.483.3
Qwen3-4B + YaRN100.092.9100.085.750.05.475.487.957.134.680.446.428.665.0
Qwen3-4B + DCA100.098.2100.069.655.412.578.189.752.145.784.553.619.666.1
w/o summaries100.0100.0100.0100.071.435.791.599.199.680.987.557.141.181.8
w/o MLP term100.094.696.492.969.632.185.792.999.379.587.564.344.680.0
standard RoPE + YaRN100.080.492.971.432.10.072.379.996.178.283.948.225.066.2
standard RoPE0.00.00.00.00.00.00.00.00.00.013.10.00.01.0
top-k 128100.094.698.298.253.612.587.198.299.683.690.557.135.777.6
top-k 512100.0100.0100.0100.089.367.991.199.6100.088.688.171.448.288.0
262KS1S2S3MK1MK2MK3MVMQVTCWEFWEQA1QA2Avg
InfLLM100.03.60.03.655.40.04.04.563.230.286.917.910.729.2
InfiniteHiP100.080.485.762.528.60.062.971.472.932.986.944.621.457.7
Dense + YaRN98.269.680.450.026.81.845.142.485.423.457.132.116.148.3
Dense + DCA100.089.396.460.766.125.075.975.987.546.888.750.026.868.4
MoBA + YaRN0.00.00.01.88.90.00.40.90.00.736.97.18.95.1
MoBA + DCA94.61.81.81.88.90.02.73.169.616.685.112.510.723.8
DSA + YaRN100.075.087.567.923.20.048.263.893.645.072.042.923.257.1
DSA + DCA100.085.798.264.351.812.563.871.988.264.878.050.025.065.7
RecSA (ours)100.098.296.496.451.812.580.498.299.679.387.551.833.975.9
Qwen3-4B + YaRN100.060.767.951.810.70.043.345.138.93.258.328.68.939.8
Qwen3-4B + DCA100.089.3100.066.135.73.664.769.254.617.982.739.328.657.8
w/o summaries100.0100.098.294.633.93.683.597.399.370.588.750.037.573.6
w/o MLP term100.066.183.980.442.97.154.964.399.672.385.151.828.664.4
standard RoPE + YaRN87.58.95.410.70.00.05.81.869.625.458.38.95.422.1
standard RoPE0.00.00.00.00.00.00.00.00.00.00.00.00.00.0
top-k 128100.087.592.994.630.41.871.490.299.674.689.342.930.469.7
top-k 512100.0100.0100.094.664.314.378.198.799.384.690.558.937.578.5

Table B.1. RULER score per task, 32K–262K. The best Avg among the methods of Table 1 is in bold.

Table B.2. RULER score per task, 524K–2M (continued from Table B.1). The best Avg among the methods of Table 1 is in bold. †: the first 4 of the 20 samples of each task.

524KS1S2S3MK1MK2MK3MVMQVTCWEFWEQA1QA2Avg
InfLLM100.010.00.010.025.00.02.53.868.010.081.730.015.027.4
InfiniteHiP95.075.080.065.010.00.055.063.850.010.583.335.020.049.4
Dense + YaRN10.00.00.00.00.00.00.00.00.00.031.70.05.03.6
Dense + DCA100.085.090.055.070.00.067.555.076.012.088.335.020.058.0
MoBA + YaRN0.00.00.00.00.00.00.00.00.00.011.70.00.00.9
MoBA + DCA85.00.05.00.00.00.00.00.038.06.076.710.015.018.1
DSA + YaRN100.010.00.00.00.00.07.50.068.00.053.30.05.018.8
DSA + DCA100.080.090.055.055.00.047.542.584.042.076.730.015.055.2
RecSA (ours)100.095.095.095.045.00.068.892.5100.057.083.345.030.069.7
Qwen3-4B + YaRN†0.00.00.00.00.00.00.06.20.00.016.70.00.01.8
Qwen3-4B + DCA100.090.0100.035.015.00.047.542.561.02.081.745.020.049.2
w/o summaries100.090.0100.095.010.00.080.096.2100.043.593.340.030.067.5
w/o MLP term100.050.090.025.010.00.038.842.5100.040.088.335.035.050.4
standard RoPE + YaRN0.00.00.00.00.00.00.00.00.00.025.00.00.01.9
standard RoPE0.00.00.00.00.00.00.00.00.00.00.00.00.00.0
top-k 128100.090.090.090.030.00.063.885.099.060.593.345.030.067.4
top-k 512100.095.0100.095.055.00.067.593.8100.072.591.745.035.073.1
1MS1S2S3MK1MK2MK3MVMQVTCWEFWEQA1QA2Avg
InfLLM100.06.20.00.056.20.01.63.153.87.581.218.86.225.7
InfiniteHiP87.562.543.837.56.20.042.237.552.51.985.418.80.036.6
Dense + YaRN0.00.00.00.00.00.00.00.00.00.020.80.00.01.6
Dense + DCA100.056.275.056.26.20.029.726.682.52.579.26.20.040.0
MoBA + YaRN0.00.00.00.00.00.00.00.00.00.012.50.00.01.0
MoBA + DCA75.00.00.00.00.00.00.00.015.00.060.46.26.212.5
DSA + YaRN43.80.00.00.00.00.00.00.01.20.027.16.20.06.0
DSA + DCA100.031.262.543.86.20.029.720.371.221.972.96.212.536.8
RecSA (ours)100.087.5100.081.225.06.254.790.695.023.185.431.26.260.5
Qwen3-4B + DCA100.050.062.531.26.20.026.617.247.51.272.918.812.534.4
w/o summaries100.087.5100.087.56.20.059.493.8100.011.989.625.00.058.5
w/o MLP term100.00.062.525.012.50.028.121.996.220.085.431.20.037.1
standard RoPE + YaRN0.00.00.00.00.00.00.00.00.00.025.00.00.01.9
standard RoPE0.00.00.00.00.00.00.00.00.00.00.00.00.00.0
top-k 128100.068.881.256.26.20.050.076.6100.027.587.518.812.552.7
top-k 512100.087.5100.081.225.00.057.895.392.560.089.643.812.565.0
2MS1S2S3MK1MK2MK3MVMQVTCWEFWEQA1QA2Avg
InfLLM100.00.00.06.225.00.00.01.640.02.583.325.031.224.2
InfiniteHiP81.237.550.025.06.20.028.115.645.06.983.325.037.534.0
Dense + YaRN0.00.00.00.00.00.00.00.00.00.014.60.00.01.1
Dense + DCA100.012.525.025.00.00.015.63.165.00.081.218.812.527.6
MoBA + YaRN0.00.00.00.00.00.00.00.00.08.30.00.00.00.6
MoBA + DCA37.50.00.00.00.00.00.00.03.80.052.10.00.07.2
DSA + YaRN0.00.00.00.00.00.00.00.00.00.018.80.00.01.4
DSA + DCA100.00.012.512.50.00.012.50.073.89.454.212.56.222.6
RecSA (ours)100.075.056.268.86.20.039.170.395.05.075.025.025.049.3

Table B.2.

BenchmarkQwen3-4BDenseRecSA
MMLU (5-shot)70.170.370.5
ARC-C (0-shot)87.286.988.1
GSM8K (0-shot, CoT)91.590.990.7
IFEval (prompt, strict)79.179.578.6
HumanEval (0-shot, pass@1)82.381.181.7
MBPP (0-shot, pass@1)63.660.861.8
LongBench49.250.951.8

Table C.1. Scores of the original Qwen3-4B, the Dense backbone and RecSA. Dense is trained from Qwen3-4B with the settings of Stage 2 on the same sequences as RecSA (§ 5.1). Best results in each row are in bold.

En.MC. En.MC from InfiniteBench [52] has 229 questions with four options on 58 novels, in which the names of the characters are replaced. We input the whole novel without truncation, so the inputs have 70K to 746K tokens, including the question, the options and the template. The prompt uses the template that InfiniteBench provides for chat models, as one user turn in non-thinking mode; we generate at most 40 tokens with greedy decoding and score the output with the official method. Each question is assigned to the smallest of 131K, 262K, 524K and 1M that is at least as long as its input, and each baseline uses its settings at that length (Appendix § 13.§ 4). Table C.2 lists the scores.

Perplexity

Books. We take the books of the PG-19 [36] training set that have at least 10610^{6} tokens under the Qwen3 tokenizer and exclude two kinds. First, we exclude reference works made of unrelated entries, such as dictionaries and encyclopedias. Second, we exclude books that overlap with the training data: their title, URL or full-text hash appears in the metadata of the training data, or a training sequence contains one of their 50-word spans or one of their 50-token spans taken every 256 tokens. This check covers all sequences of the training pool (Appendix § 13.§ 1). Of several editions or volumes of one work, we keep one. Nine books remain, and Table C.3 lists them.

Computation. For context length LL, the window of each book is the last LL tokens of its first 10610^{6} tokens. The input is the plain text of the book, without a chat template or special tokens. We run one forward pass per window and report the exponential of the mean negative log-likelihood over the predicted tokens of the nine windows, which have the same length. The sparse methods use the token budgets of Table 1, and YaRN and DCA use their settings at each length (Appendix § 13.§ 4).

Efficiency

Experimental Setup

Environment. All measurements run on one H200 GPU with batch size 1 in bf16, with PyTorch 2.7.1, CUDA 12.8, Triton 3.3.1 [43], FlashAttention 2.8.3 [9] and Transformers 5.9.0.

Prefill. Up to 1M, the input is the window of length LL of The Anatomy of Melancholy (Appendix § 11.§ 3). At 2M, it is the first 10610^{6} tokens of The History of England, vol. II followed by the first 10610^{6} tokens of The Anatomy of Melancholy. We measure the wall-clock time of one complete prefill after a warm-up and report the median of 3 timed runs up to 262K and the time of one run from 524K. For RecSA, the time includes building the KV cache and the tree and, at 1M and 2M, writing the exact tokens to host memory. Dense runs the forward pass of Transformers with FlashAttention-2, computes the logits of the last position only and keeps no KV cache. At 2M, the intermediate results of the Dense forward pass over the whole sequence do not fit in GPU memory, so we compute the non-attention part in chunks of 131,072 tokens, while attention still calls FlashAttention once per layer over the whole sequence. In the prefill of RecSA at 2M, the two passes of level 1, which has 125,000 nodes, process 4 adjacent queries per thread block instead of 16 (§ 4.1).

Decoding. Up to 524K, the input is a sequence of random tokens generated with a fixed seed. At these lengths, all data reside on the GPU, and the number of candidates scored at each level and the number of entries read depend only on the position. At 524K, the step time on a RULER sample differs from that on the random sequence by less than 0.1%. At 1M and 2M, the amount read from host memory at each step depends on which nodes are selected, so we measure RecSA on two RULER samples at each length, one from MK1 and one from MQ (Table 2). Dense reads its whole KV cache at every step. We measure Dense on the same random sequence up to 524K and on random keys and values at 1M and 2M.

Except for Dense at 1M and 2M, we first prefill the input. We then decode token by token, and each step includes the output logits. Up to 524K, each step takes the next token of the random sequence as input. On the RULER samples, each step takes the token that RecSA generates greedily, with the end-of-sequence token suppressed; RecSA without the GPU cache (§ 4.3) and the two-level variant (Appendix § 12.§ 4) take the same tokens. The whole decoding step is captured as one CUDA graph. At the top level, each of the 16 segments of § 4.2 is scored by 4 thread blocks per KV head, so 512 thread blocks compute the importance. After a warm-up, we synchronize at the end of each step and take the median step time over at least 32 steps; at 1M and 2M, the latency of RecSA is the mean of the medians of the two samples. Dense uses the Flash-Decoding kernel ([10]) of FlashAttention-2 with a preallocated KV cache, and the number of splits is that of the default heuristic of FlashAttention or 32, whichever is faster. The non-attention part of Dense (projections, MLPs and normalization) uses the same kernels as RecSA.

MethodAll (229)70K–131K (79)131K–262K (106)262K–524K (40)524K–746K (4)
Qwen3-4B + YaRN34.564.620.815.00.0
InfiniteHiP66.467.168.957.575.0
Dense + DCA62.469.664.245.050.0
DSA + DCA62.064.665.152.525.0
RecSA (ours)66.874.766.055.050.0

Table C.2. En.MC scores. The last four columns group the questions by input length, with the number of questions in parentheses. Best results in each column are in bold.

TitleGutenberg IDTokens
Modern Machine-Shop Practice, Vols. I and II392251,261,044
The Bible, King James Version301,405,554
History of the United Netherlands, 1584–160948851,003,719
The Anatomy of Melancholy108001,000,033
The Complete Memoirs of Jacques Casanova de Seingalt29811,531,970
The History of England, Vol. II (Smollett)192171,099,801
Abridgment of the Debates of Congress, 1789–1856404991,073,145
Complete Poetic and Dramatic Works of Robert Browning509541,348,826
Church History, Vols. 1–3 (Kurtz)514911,279,278

Table C.3. The nine PG-19 books. Tokens: length of the whole book.

Offloading at 1M and 2M. RecSA keeps the exact tokens in host memory and caches the most recent exact tokens on the GPU (§ 4.3). On the RULER samples, the cached range holds 80.1% of the input at 1M and 38.1% at 2M, and 89.2% and 77.4% of the selected level-1 nodes fall in it. Dense keeps the keys and values of the last 949,248 and 945,152 input tokens on the GPU, 95% and 47% of the input, which fills the available memory. The rest stays in pinned host memory and is copied to the GPU in chunks of 16,384 tokens at every step: 7.0 GiB at 1M and 144.9 GiB at 2M. FlashAttention computes attention over the part on the GPU and over each copied chunk, and the partial results are merged by their LogSumExp; the copies and the computation run one after another on one CUDA stream. The measured bandwidth from host to GPU is 51.6 GiB/s.

Latency

Table D.1 lists the prefill times behind Figure 5a and the decoding latencies of Figure 1b.

Decoding Latency Breakdown

To break down a step, we prefill the input again in a new process and run decoding steps under the PyTorch profiler, which records the time of every kernel in the CUDA graph. Up to 524K, the work of a step depends only on its position, so we profile 8 steps after the timed steps of Appendix § 12.§ 1. At 1M and 2M, it also depends on the selected nodes, so we profile the steps at the timed positions, with the same input tokens. We assign each kernel to one of the following parts and take the mean time of each part over the profiled steps:

  • Non-attention: the projections, the MLPs, the normalization, the embedding, the output layer and the idle time between kernels, which is the step time of Table D.1 minus the summed kernel time.

  • Tree update: appending the key and value of the new token to level 0 and recomputing the last node of each level (① and ② in Figure 4b). At 1M and 2M, this writes the new key and value to host memory and to the GPU cache and copies the children of the last level-1 node to the GPU.

  • Top level, Intermediate levels: scoring, top-kk selection and attention over the summaries at that level.

  • Gather: gathering the selected exact tokens from the GPU cache and from host memory (④ in Figure 4b).

  • Exact tokens: attention over the exact tokens in the candidate list of level 0.

  • Merge: merging the partial softmax results of the segments and the levels.

The time of a kernel that serves two adjacent levels is split between them in proportion to the time of the work of each level run alone. Table D.2 lists the results; the 1M and 2M columns are the means over the two RULER samples. In a Dense step at 1M and 2M, copying keys and values from host memory takes 136 of 177 ms and 2,823 of 2,945 ms.

Context lengthPrefill (s) RecSAPrefill (s) DenseDecoding (ms) RecSADecoding (ms) Dense
32K1.591.464.885.29
64K3.874.665.996.41
131K13.516.86.048.56
262K34.265.06.0613.3
524K79.82576.1523.4
1M1999088.35177
2M6033,67210.72,945

Table D.1. Prefill time (s) and decoding latency (ms per token) of RecSA and Dense. At 1M and 2M, host memory holds the exact tokens of RecSA and, in decoding, the part of the Dense KV cache that does not fit on the GPU.

Context length32K131K262K524K1M2M
Tree levels233334
Non-attention3.263.353.353.353.413.40
Tree update0.250.390.390.390.630.87
Top level0.890.730.800.911.240.70
Intermediate levels–1.030.980.960.982.01
Gather––––1.553.07
Exact tokens0.350.320.320.330.320.32
Merge0.150.210.210.210.210.28
Total4.886.046.066.158.3510.66

Table D.2. Time breakdown (ms) of one decoding step of RecSA (Figure 5b). The time of a kernel that serves two adjacent levels is split between them in proportion to the time of the work of each level run alone. –: the part does not occur at this length.

Tree Depth

Up to 65,536 tokens, RecSA uses at most two levels. For longer contexts, Table D.3 compares RecSA with a two-level variant, which scores every level-1 node at each step. The variant is slower than RecSA at every length, from 1.1× at 131K to 1.9× at 2M, because the number of level-1 nodes it scores grows linearly with the context length.

Training and Baselines

Training Data

Table E.1 lists the training data: task data, whose responses depend on information in the context, and general data, which we add to preserve the general capabilities of the original model.

Task data. The synthetic retrieval tasks insert records such as “[R248624] E407003 code V153512.” at line breaks into PG-19 books ([36]) or GitHub source code and ask for values in the records, for example the value of one key among near-duplicate keys, the values of up to 12 keys in a given order, the code reached through a chain of links

Context length131K262K524K1M2M
RecSA tree levels33334
Level-1 nodes8,19216,38432,76862,500125,000
RecSA6.046.066.158.3510.7
Two-level variant6.377.117.8311.520.5
Speedup of RecSA1.1×1.2×1.3×1.4×1.9×

Table D.3. Decoding latency (ms per token) of RecSA and of a two-level variant, which scores every level-1 node at each step, measured as in Appendix D.1. Up to 65,536 tokens, RecSA uses at most two levels. At 1M and 2M, both store the exact tokens in host memory.

DataPoolStage 1Stage 2Length
Task data
Synthetic retrieval5,5004,7694,76032,060–32,456
Document QA95883184032,749–32,787
General data
Books and code42029529532,741–32,768
Instructions58839839832,768
Long-form1501071079,325–24,623
Sequences7,6166,4006,400
Tokens245.2M206.4M206.4M

Table E.1. Training data. Pool: sequences available for training. Stage 1 and Stage 2: sequences read by each run. Length: tokens per sequence in the pool, chat template included.

or a sum of amounts. The document QA sequences hold 849 questions from MuSiQue ([44]) and 109 from Qasper ([11]); we add distractor passages from the training split of the same dataset to the context of each question. Each prompt specifies the response format, such as the answer alone or the answer with the identifiers of its supporting records or passages.

General data. The book and code sequences are contiguous spans of one PG-19 book or one GitHub repository. The instruction and long-form sequences pair a document window with one instruction, and their responses were generated by the original Qwen3-4B in non-thinking mode with greedy decoding. The instruction sequences use six instruction types, such as summarizing a passage or answering a question that the same model generated from the passage, with two templates per type for PG-19 books and two for GitHub code; their responses have at most 512 tokens. After generation, we prepend earlier text of the same document so that each instruction sequence has 32,768 tokens. The long-form instructions, from 14 templates, ask for about 400 to 600 words on a window of 8,600 to 24,000 tokens; only responses of 400 to 800 tokens are kept.

Loss masking. Task, instruction and long-form sequences use the chat template of Qwen3-4B in non-thinking mode, with an empty thinking block before the response; the language modeling loss covers only their response tokens, including the final end-of-turn token. Book and code sequences have no template, and the loss covers every next-token target.

Order and amount. The sequences of each kind of data are shuffled with a fixed seed, and the synthetic retrieval and document QA sequences are then shuffled into one order. Optimizer steps 1, 9, 17, . . . read only general sequences, and all other steps read task sequences. Each run reads 800 general and 5,600 task sequences and no sequence twice. The two parts of Stage 1 read the same sequences; Stage 2 reads the same general sequences and shares 5,200 task sequences with Stage 1. The three runs (the two parts of Stage 1 and Stage 2) process 0.62B tokens in total and read 6,800 distinct sequences with 219.4M tokens.

Training Hyperparameters

Table E.2 lists the hyperparameters of each run. All runs use AdamW with β1=0.9\beta_1 = 0.9, β2=0.95\beta_2 = 0.95, ϵ=10−8\epsilon= 10^{-8} and no weight decay, clip the gradient to a global norm of 1.0 and run on 8 NVIDIA H200 GPUs with one sequence per GPU in each forward and backward pass. The learning rate rises linearly during warm-up, stays at its peak and decays linearly over the last 15% of the steps, to 1/60 (Stage 1) or 1/120 (Stage 2) of the peak at the last step. In Stage 2, the loss of a sequence is the mean cross-entropy over the tokens that the loss covers, and all sequences have equal weight, so general data, read at one step in eight, carries one eighth of the total weight. Stage 2 keeps fp32 weights and computes in bf16; Stage 1 computes the pooler and its losses in fp32.

Stage 1 Query Sampling and Loss Computation

Tree. Every sampled query uses the tree of its whole sequence, even when its prefix alone would need fewer levels (§ 3.1). With k=64k = 64, a training sequence of length TT has three levels if T>16,384T > 16{,}384 and two otherwise; 51 of the 107 long-form sequences of Stage 1 have two. On a three-level sequence, a query at position t<16,384t < 16{,}384 has at most 64 top-level candidates, which are all selected and expanded; its top-level KL is still computed.

Query positions. For a sequence of length TT, we draw 256 positions tt uniformly, with replacement, with 1,024≤t<T1{,}024 \le t < T; the query set QQ is the union of the drawn positions and the task-specific positions XX. In a task sequence, XX contains the position tat_a that predicts the first response token that depends on the evidence, for example the first token of a value or of a cited record or passage identifier. In synthetic retrieval tasks, XX also contains the position of the first token of the question. General data has no task-specific positions. We write R=Q∖XR = Q \setminus X.

Stage 1Stage 2
ParametersFirst partSecond partbackbone
Count4,680887,0404.02B
Lossww, τ\tau, ggW1W_1, b1b_1, W2W_2LM
kk6464256
Learning rate10−210^{-2}3×10−33 \times10^{-3}2.5×10−62.5 \times10^{-6}
Warm-up steps202040
Steps400400800
Batch size16168
Accumulation221
Time37 min39 min7.7 h

Table E.2. Hyperparameters of RecSA training. Each run trains only the listed parameters; all other parameters are frozen. LKL\mathcal{L}_{\mathrm{KL}}: the KL terms of each part, with the query positions and weights of Appendix E.3. Laux\mathcal{L}_{\mathrm{aux}}: auxiliary cross-entropy. Lshift\mathcal{L}_{\mathrm{shift}}: shift penalty (Eq. (7)), with weight λ=10\lambda= 10. LM: language modeling loss. Learning rate: peak value. Batch size: sequences per optimizer step. Accumulation: gradient accumulation steps. Time: wall-clock time of the training loop, including checkpointing.

Losses. For one sequence and one layer, let KL‾(ℓ)(S)\overline{\mathrm{KL}}^{(\ell)}(S) be the mean of KL(yt(ℓ)∥πt(ℓ))\mathrm{KL}(y_t^{(\ell)} \mathbin\Vert\pi_t^{(\ell)}) (Eq. (6)) over the 8 KV heads and the positions t∈St \in S, with ℓ=top\ell= \text{top} for the top level; at level 1, the mean leaves out the pairs of a KV head and a position whose level-1 candidates hold less than 10−410^{-4} of the dense attention mass. Let P(S)P(S) be 32 positions drawn uniformly without replacement from SS, drawn anew for each layer. The two parts of Stage 1 minimize

L1=KL‾(top)(Q)+KL‾(1)(P(Q))+0.1Laux,\mathcal{L}_1 = \overline{\mathrm{KL}}^{(\mathrm{top})}(Q) + \overline{\mathrm{KL}}^{(1)}(P(Q)) + 0.1\mathcal{L}_{\mathrm{aux}},
L2=0.1[KL‾(top)(R)+KL‾(1)(P(R))]+KL‾(top)(X)+KL‾(1)(X)+10Lshift,\mathcal{L}_2 = 0.1\left[\overline{\mathrm{KL}}^{(\mathrm{top})}(R) + \overline{\mathrm{KL}}^{(1)}(P(R))\right] + \overline{\mathrm{KL}}^{(\mathrm{top})}(X) + \overline{\mathrm{KL}}^{(1)}(X) + 10\mathcal{L}_{\mathrm{shift}},

where the level-1 terms apply only to three-level sequences and a term over an empty set is zero. In the second part, the mean KL over the task-specific positions has ten times the weight of the mean over the other sampled positions.

The auxiliary cross-entropy Laux\mathcal{L}_{\mathrm{aux}} is the mean of −log⁡πta,i(top)-\log\pi_{t_a,i}^{(\mathrm{top})} over the 8 KV heads, where ii is the top-level node that contains the start of the evidence. It applies to the 982 of the 6,400 sequences that have a single piece of evidence starting before tat_a. The shift penalty Lshift\mathcal{L}_{\mathrm{shift}} evaluates Eq. (7) for each KV head, with MℓM_\ell counting every node of level ℓ\ell, including the partial last node, and averages it over the 8 KV heads; the denominator is clamped to at least 10−1210^{-12}. The penalty covers levels 1 and 2, or level 1 on two-level sequences, and applies to every sequence.

We sum the losses of the 36 layers and average them over the 16 sequences of each optimizer step; the loss of each layer updates only the pooler of that layer. Gradient clipping applies jointly to the poolers of all layers.

Baselines

Training setup. Dense, MoBA ((Lu et al., 2025)) and DSA ([12]) start from the original Qwen3-4B and train all backbone parameters with the Stage 2 settings of Table E.2, on the same sequences in the same order. Training uses RoPE without scaling, and Dense uses FlashAttention-2 ([9]). In training, MoBA and DSA attend to at most 5,888 entries per query, the token budget of RecSA at 32K.

MoBA. We use the official implementation in all 36 layers, with blocks of 128 tokens. Each query head scores the complete blocks before its position by the dot product of the query with the mean key of the block, and attends to its current block and the k−1k - 1 highest-scoring blocks. MoBA adds no parameters; k=46k = 46 in training.

DSA. Each layer has a lightning indexer with 16 heads of dimension 128, two per GQA group, and one indexer key per token, normalized by LayerNorm over all 128 dimensions, with RoPE on its first 64 dimensions. The indexer has 202M parameters in total, runs in fp32 and takes the normalized input of the attention layer, detached from the backbone. For each query and GQA group, DSA attends to the kk tokens with the highest index scores (Eq. (1) of DSA, summed over the two heads of the group), without sink tokens or a local window. As in DSA, we first warm up the indexer on the frozen original model with dense attention, using the KL divergence of Eq. (3) of DSA to the attention distribution averaged over the 4 heads of the group. The warm-up runs for 950 steps of 16 sequences (0.49B tokens), about 2.4 passes over the Stage 2 sequences, with AdamW, no weight decay and a learning rate that rises over 20 steps to 10−310^{-3} and then stays constant. Each sequence contributes 4,096 query positions. If at most 2,048 positions are covered by the language modeling loss or predict a covered token, the query positions include all of them, and the rest are drawn uniformly without replacement; otherwise all 4,096 are drawn uniformly without replacement. During backbone training, the indexer continues to train with the KL divergence restricted to the selected tokens (Eq. (4) of DSA), at a learning rate of 5×10−55 \times10^{-5} under the Stage 2 schedule; this loss does not reach the backbone.

Training-free methods. InfLLM ([47]) and InfiniteHiP ([37]) run on the original Qwen3-4B with their official implementations and their own position encoding, without YaRN. InfLLM uses blocks of 128 tokens with 4 representative tokens each.

Token budgets. Table E.3 lists the settings at each length. MoBA selects whole blocks, so its kk is the budget divided by 128 and rounded down; at 1M and 2M, it attends to at most

32K131K262K524K1M2M
Token budget5,8888,1928,7049,72811,57511,990
MoBA blocks466468769093
InfLLM
Initial128128128256256256
Local3,8405,3765,7606,2727,4797,766
Blocks152122253031
InfiniteHiP
Sink448640640768896896
Window1,7922,4962,6882,9443,5753,734
Selected3,6485,0565,3766,0167,1047,360
YaRN ss–48163264

Table E.3. Settings of the baselines at each context length. Token budget: entries the query at the last position attends to under RecSA (Table 1); DSA uses it as kk. MoBA: selected blocks of 128 tokens, the current block included. InfLLM: initial tokens, local window and retrieved blocks of 128 tokens. InfiniteHiP: sink tokens, sliding window and selected tokens. YaRN: scaling factor ss; –: not applied.

most 11,520 and 11,904 entries. The configuration files in the official code of InfLLM set 128 initial tokens, a 4,096-token local window and 16 retrieved blocks; the 3K setting of the InfiniteHiP paper has 256 sink tokens, a 1,024-token window and 2,048 selected tokens. We scale these parts in proportion to the token budget and set the local or sliding window so that the parts sum to it.

Context extension. YaRN ([34]) scales the RoPE frequencies by the smallest power of two ss with 32,768 s≥Ls \ge L for context length LL, with α=1\alpha= 1, β=32\beta= 32 and the attention logits multiplied by (0.1ln⁡s+1)2(0.1 \ln s + 1)^2; at 32K, it is not applied. DSA + YaRN also scales the RoPE frequencies of the indexer. DCA ((An et al., 2024)) uses chunks of 31,744 tokens and a local window of 1,024 tokens at every length, so that no relative distance exceeds 32,768 and keys within 1,024 tokens of the query keep their original distances. DCA keeps θ=106\theta= 10^6 without frequency scaling and, as in its vLLM implementation ([31]), multiplies the attention logits by γ2\gamma^2, with γ=max⁡(1,0.1ln⁡(N/32,768)+1)\gamma= \max(1, 0.1 \ln(N / 32,768) + 1) for an input of NN tokens. MoBA + DCA and DSA + DCA compute their selection scores at the position indices of DCA. Qwen3-4B + YaRN and Qwen3-4B + DCA are the original Qwen3-4B, without training, with the same settings; Appendix § 10 lists their RULER scores.

Ablations

Table F.1 gives the RULER score of each variant from 32K to 1M. The variant w/o summaries is RecSA trained and evaluated without summaries, and the variant w/o MLP term is RecSA trained and evaluated with W2=0W_2 = 0 in the pooler (Eq. (5)). The variants standard RoPE and standard RoPE + YaRN are the same model, trained like RecSA with both stages of § 3.4, the pooler included, but with RoPE applied at absolute token positions, and evaluated without and with YaRN beyond 32K. Each key is rotated at its absolute position before pooling, so the pooler pools rotated keys and the summaries receive no further rotation. The variants top-kk 128 and top-kk 512 are the RecSA model evaluated with k=128k = 128 and k=512k = 512 instead of 256; the token budget row below each gives the entries the query at the last position attends to (for k=256k = 256, see Table 1). Under Backbone frozen, the backbone is the original model, only the pooler is trained and the variants are evaluated at 32K, 131K and 524K. KL + shift penalty is the pooler of RecSA after Stage 1 (§ 3.4). KL sets λ=0\lambda= 0 in the second part of Stage 1. The variant w/o MLP term in this block is the pooler after the first part of Stage 1, with W2=0W_2 = 0. LM loss trains the MLP term in the second part of Stage 1 with the language modeling loss instead of LKL+λLshiftL_{\mathrm{KL}} + \lambda L_{\mathrm{shift}}. Mean pooling has no trainable parameters.

Variant32K131K262K524K1MAvg
RecSA94.783.375.969.760.572.3
w/o summaries94.581.873.667.558.570.4
w/o MLP term94.880.064.450.437.158.0
standard RoPE + YaRN95.266.222.11.91.923.0
standard RoPE95.21.00.00.00.00.3
top-kk 12894.377.669.767.452.766.9
token budget3,9684,3524,8645,8885,980
top-kk 51296.088.078.573.165.076.2
token budget9,72815,87216,38417,40819,255
Backbone frozen
KL + shift penalty76.567.7–55.5––
KL74.763.6–45.3––
w/o MLP term78.965.9–43.2––
mean pooling73.852.2–16.7––
LM loss73.640.6–8.9––

Table F.1. RULER score in the ablation experiments (average over the 13 tasks). Avg: average over the four lengths from 131K to 1M. –: not evaluated.

Averaged over the 148 samples per task from 131K to 1M, the variant w/o summaries scores 15.5 points lower than RecSA on MK2 and 7.8 points lower on CWE, and its average over the other 11 tasks differs from that of RecSA by 0.1 points; Appendix § 10 gives its score on each task at each length. Its perplexity on the nine PG-19 books (Table 3) is 11.24, 10.88, 11.00, 11.02 and 11.07 from 32K to 1M, compared with 11.24, 10.87, 11.00, 11.08 and 11.12 for RecSA.

References

  1. [1]Ainslie, J., Lee-Thorp, J., de Jong, M., Zemlyanskiy, Y., Lebrón, F., and Sanghavi, S. GQA: Training generalized multi-query transformer models from multi-head checkpoints. In Conference on Empirical Methods in Natural Language Processing (EMNLP), pp. 4895–4901, 2023.
  2. [3]Austin, J., Odena, A., Nye, M., Bosma, M., Michalewski, H., Dohan, D., Jiang, E., Cai, C., Terry, M., Le, Q., and Sutton, C. Program synthesis with large language models. arXiv preprint arXiv:2108.07732, 2021.arxiv.org/abs/2108.07732
  3. [4]Bai, Y., Lv, X., Zhang, J., Lyu, H., Tang, J., Huang, Z., Du, Z., Liu, X., Zeng, A., Hou, L., Dong, Y., Tang, J., and Li, J. LongBench: A bilingual, multitask benchmark for long context understanding. In Annual Meeting of the Association for Computational Linguistics (ACL), pp. 3119–3137, 2024.arxiv.org/abs/2308.14508
  4. [5]Chen, M., Tworek, J., Jun, H., Yuan, Q., Pinto, H. P. d. O., Kaplan, J., Edwards, H., Burda, Y., Joseph, N., Brockman, G., Ray, A., Puri, R., Krueger, G., Petrov, M., Khlaaf, H., Sastry, G., Mishkin, P., Chan, B., Gray, S., Ryder, N., Pavlov, M., Power, A., Kaiser, L., Bavarian, M., Winter, C., Tilet, P., Such, F. P., Cummings, D., Plappert, M., Chantz is, F., Barnes, E., Herbert-Voss, A., Guss, W. H., Nichol, A., Paino, A., Tezak, N., Tang, J., Babuschkin, I., Balaji, S., Jain, S., Saunders, W., Hesse, C., Carr, A. N., Leike, J., Achiam, J., Misra, V., Morikawa, E., Radford, A., Knight, M., Brundage, M., Murati, M., Mayer, K., Welinder, P., McGrew, B., Amodei, D., McCandlish, S., Sutskever, I., and Zaremba, W. Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374, 2021.arxiv.org/abs/2107.03374
  5. [6]Chen, S., Wong, S., Chen, L., and Tian, Y. Extending context window of large language models via positional interpolation. arXiv preprint arXiv:2306.15595, 2023.arxiv.org/abs/2306.15595
  6. [7]Clark, P., Cowhey, I., Etzioni, O., Khot, T., Sabharwal, A., Schoenick, C., and Tafjord, O. Think you have solved question answering? Try ARC, the AI2 reasoning challenge. arXiv preprint arXiv:1803.05457, 2018.arxiv.org/abs/1803.05457
  7. [8]Cobbe, K., Kosaraju, V., Bavarian, M., Chen, M., Jun, H., Kaiser, L., Plappert, M., Tworek, J., Hilton, J., Nakano, R., Hesse, C., and Schulman, J. Training verifiers to solve math word problems. arXiv preprint arXiv:2110.14168, 2021.arxiv.org/abs/2110.14168
  8. [9]Dao, T. FlashAttention-2: Faster attention with better parallelism and work partitioning. In International Conference on Learning Representations (ICLR), 2024.arxiv.org/abs/2307.08691
  9. [10]Dao, T., Haziza, D., Massa, F., and Sizov, G. Flash-Decoding for long-context inference. https://crfm.stanford.edu/2023/10/12/flashdecoding.html, 2023.
  10. [11]Dasigi, P., Lo, K., Beltagy, I., Cohan, A., Smith, N. A., and Gardner, M. A dataset of information-seeking questions and answers anchored in research papers. In Conference of the North American Chapter of the Association for Computational Linguistics (NAACL), pp. 4599–4610, 2021.
  11. [12]DeepSeek-AI, Liu, A., Mei, A., Lin, B., Xue, B., Wang, B., Xu, B., Wu, B., Zhang, B., Lin, C., Dong, C., Lu, C., Zhao, C., Deng, C., Xu, C., Ruan, C., Dai, D., Guo, D., Yang, D., Chen, D., Li, E., Zhou, F., Lin, F., Dai, F., Hao, G., Chen, G., Li, G., Zhang, H., Xu, H., Li, H., Liang, H., Wei, H., Zhang, H., Luo, H., Ji, H., Ding, H., Tang, H., Cao, H., Gao, H., Qu, H., Zeng, H., Huang, J., Li, J., Xu, J., Hu, J., Chen, J., Xiang, J., Yuan, J., Cheng, J., Zhu, J., Ran, J., Jiang, J., Qiu, J., Li, J., Song, J., Dong, K., Gao, K., Guan, K., Huang, K., Zhou, K., Huang, K., Yu, K., Wang, L., Zhang, L., Wang, L., Zhao, L., Yin, L., Guo, L., Luo, L., Ma, L., Wang, L., Zhang, L., Di, M. S., Xu, M. Y., Zhang, M., Zhang, M., Tang, M., Zhou, M., Huang, P., Cong, P., Wang, P., Wang, Q., Zhu, Q., Li, Q., Chen, Q., Du, Q., Xu, R., Ge, R., Zhang, R., Pan, R., Wang, R., Yin, R., Xu, R., Shen, R., Zhang, R., Liu, S. H., Lu, S., Zhou, S., Chen, S., Cai, S., Chen, S., Hu, S., Liu, S., Hu, S., Ma, S., Wang, S., Yu, S., Zhou, S., Pan, S., Zhou, S., Ni, T., Yun, T., Pei, T., Ye, T., Yue, T., Zeng, W., Liu, W., Liang, W., Pang, W., Luo, W., Gao, W., Zhang, W., Gao, X., Wang, X., Bi, X., Liu, X., Wang, X., Chen, X., Zhang, X., Nie, X., Cheng, X., Liu, X., Xie, X., Liu, X., Yu, X., Li, X., Yang, X., Li, X., Chen, X., Su, X., Pan, X., Lin, X., Fu, X., Wang, Y. Q., Zhang, Y., Xu, Y., Ma, Y., Li, Y., Li, Y., Zhao, Y., Sun, Y., Wang, Y., Qian, Y., Yu, Y., Zhang, Y., Ding, Y., Shi, Y., Xiong, Y., He, Y., Zhou, Y., Zhong, Y., Piao, Y., Wang, Y., Chen, Y., Tan, Y., Wei, Y., Ma, Y., Liu, Y., Yang, Y., Guo, Y., Wu, Y., Wu, Y., Cheng, Y., Ou, Y., Xu, Y., Wang, Y., Gong, Y., Wu, Y., Zou, Y., Li, Y., Xiong, Y., Luo, Y., You, Y., Liu, Y., Zhou, Y., Wu, Z. F., Ren, Z. Z., Zhao, Z., Ren, Z., Sha, Z., Fu, Z., Xu, Z., Xie, Z., Zhang, Z., Hao, Z., Gou, Z., Ma, Z., Yan, Z., Shao, Z., Huang, Z., Wu, Z., Li, Z., Zhang, Z., Xu, Z., Wang, Z., Gu, Z., Zhu, Z., Li, Z., Zhang, Z., Xie, Z., Gao, Z., Pan, Z., Yao, Z., Feng, B., Li, H., Cai, J. L., Ni, J., Xu, L., Li, M., Tian, N., Chen, R. J., Jin, R. L., Li, S. S., Zhou, S., Sun, T., Li, X. Q., Jin, X., Shen, X., Chen, X., Song, X., Zhou, X., Zhu, Y. X., Huang, Y., Li, Y., Zheng, Y., Zhu, Y., Ma, Y., Huang, Z., Xu, Z., Zhang, Z., Ji, D., Liang, J., Guo, J., Chen, J., Xia, L., Wang, M., Li, M., Zhang, P., Chen, R., Sun, S., Wu, S., Ye, S., Wang, T., Xiao, W. L., An, W., Wang, X., Sun, X., Wang, X., Tang, Y., Zha, Y., Zhang, Z., Ju, Z., Zhang, Z., and Qu, Z. DeepSeek-V3.2: Pushing the frontier of open large language models. arXiv preprint arXiv:2512.02556, 2025.
  12. [14]Ding, Y., Zhang, L. L., Zhang, C., Xu, Y., Shang, N., Xu, J., Yang, F., and Yang, M. LongRoPE: Extending LLM context window beyond 2 million tokens. In International Conference on Machine Learning (ICML), pp. 11091–11104, 2024.arxiv.org/abs/2402.13753
  13. [15]Gao, C., Wu, X., Lin, Z., Zhang, D., and Hu, S. NExTLong: Toward effective long-context training without long documents. In International Conference on Machine Learning (ICML), pp. 18566–18584, 2025a.arxiv.org/abs/2501.12766
  14. [16]Gao, L., Tow, J., Abbasi, B., Biderman, S., Black, S., DiPofi, A., Foster, C., Golding, L., Hsu, J., Le Noac’h, A., Li, H., McDonell, K., Muennighoff, N., Ociepa, C., Phang, J., Reynolds, L., Schoelkopf, H., Skowron, A., Sutawika, L., Tang, E., Thite, A., Wang, B., Wang, K., and Zou, A. The language model evaluation harness. https://zenodo.org/records/12608602, 2024.
  15. [17]Gao, Y., Zeng, Z., Du, D., Cao, S., Zhou, P., Qi, J., Lai, J., So, H. K.-H., Cao, T., Yang, F., and Yang, M. SeerAttention: Self-distilled attention gating for efficient long-context prefilling. In Advances in Neural Information Processing Systems (NeurIPS), pp. 55846–55869, 2025b.DOI
  16. [18]Gao, Y., Guo, S., Cao, S., Xia, Y., Cheng, Y., Wang, L., Ma, L., Sun, Y., Ye, T., Dong, L., So, H. K.-H., Hua, Y., Cao, T., Yang, F., and Yang, M. Sparse attention adaptation for long reasoning. In International Conference on Learning Representations (ICLR), 2026.arxiv.org/abs/2506.08889
  17. [19]Hendrycks, D., Burns, C., Basart, S., Zou, A., Mazeika, M., Song, D., and Steinhardt, J. Measuring massive multitask language understanding. In International Conference on Learning Representations (ICLR), 2021.
  18. [20]Hooper, C., Zhao, S., Manolache, L., Kim, S., Mahoney, M. W., Shao, Y. S., Keutzer, K., and Gholami, A. Multipole attention for efficient long context reasoning. In Advances in Neural Information Processing Systems (NeurIPS), pp. 37382–37405, 2025.arxiv.org/abs/2506.13059
  19. [21]Hsieh, C.-P., Sun, S., Kriman, S., Acharya, S., Rekesh, D., Jia, F., Zhang, Y., and Ginsburg, B. RULER: What’s the real context size of your long-context language models? In Conference on Language Modeling (COLM), 2024. Hu, X., Leng, J., Zhao, J., Tu, K., and Wu, W. Hardware-aligned hierarchical sparse attention for efficient long-term memory access. In Advances in Neural Information Processing Systems (NeurIPS), pp. 88925–88950, 2025.
  20. [22]Leng, J., Hu, X., Wang, J., Li, J., Wu, W., and Lu, Y. Understanding and improving length generalization in hierarchical sparse attention models. In International Conference on Learning Representations (ICLR), 2026.arxiv.org/abs/2510.17196
  21. [27]Jiang, H., Li, Y., Zhang, C., Wu, Q., Luo, X., Ahn, S., Han, Z., Abdi, A. H., Li, D., Lin, C.-Y., Yang, Y., and Qiu, L. MInference 1.0: Accelerating pre-filling for long-context LLMs via dynamic sparse attention. In Advances in Neural Information Processing Systems (NeurIPS), pp. 52481–52515, 2024.arxiv.org/abs/2407.02490
  22. [28]Jin, H., Han, X., Yang, J., Jiang, Z., Liu, Z., Chang, C.-Y., Chen, H., and Hu, X. LLM maybe LongLM: SelfExtend LLM context window without tuning. In International Conference on Machine Learning (ICML), pp. 22099–22114, 2024.arxiv.org/abs/2401.01325
  23. [29]Mohtashami, A. and Jaggi, M. The impact of positional encoding on length generalization in transformers. In Advances in Neural Information Processing Systems (NeurIPS), pp. 54567–54585, 2023.
  24. [30]Kazemnejad, A., Padhi, I., Natesan Ramamurthy, K., Das, P., and Reddy, S. The impact of positional encoding on length generalization in transformers. In Advances in Neural Information Processing Systems (NeurIPS), 2023.arxiv.org/abs/2305.19466
  25. [31]Kwon, W., Li, Z., Zhuang, S., Sheng, Y., Zheng, L., Yu, C. H., Gonzalez, J. E., Zhang, H., and Stoica, I. Efficient memory management for large language model serving with PagedAttention. In ACM Symposium on Operating Systems Principles (SOSP), pp. 611–626, 2023.arxiv.org/abs/2309.06180
  26. [32]Paszke, A., Gross, S., Massa, F., Lerer, A., Bradbury, J., Chanan, G., Killeen, T., Lin, Z., Gimelshein, N., Antiga, L., Desmaison, A., Köp f, A., Yang, E., DeVito, Z., Rai-son, M., Tejani, A., Chilamkurthy, S., Steiner, B., Fang, L., Bai, J., and Chintala, S. PyTorch: An imperative style, high-performance deep learning library. In Advances in Neural Information Processing Systems (NeurIPS), pp. 8026–8037, 2019.arxiv.org/abs/1912.01703
  27. [33]Lai, X., Lu, J., Luo, Y., Ma, Y., and Zhou, X. FlexPrefill: A context-aware sparse attention mechanism for efficient long-sequence inference. In International Conference on Learning Representations (ICLR), 2025.arxiv.org/abs/2502.20766
  28. [34]Peng, B., Quesnelle, J., Fan, H., and Shippole, E. YaRN: Efficient context window extension of large language models. In International Conference on Learning Representations (ICLR), 2024.arxiv.org/abs/2309.00071
  29. [35]Lee, H., Park, G., Lee, Y., Suh, J., Kim, J., Jeong, W., Kim, B., Lee, H., Jeon, M., and Hwang, S. J. A training-free sub-quadratic cost transformer model serving framework with hierarchically pruned attention. In International Conference on Learning Representations (ICLR), 2025a.arxiv.org/abs/2406.09827
  30. [36]Rae, J. W., Potapenko, A., Jayakumar, S. M., Hillier, C., and Lillicrap, T. P. Compressive transformers for long-range sequence modelling. In International Conference on Learning Representations (ICLR), 2020.arxiv.org/abs/1911.05507
  31. [37]Lee, H., Park, G., Suh, J., and Hwang, S. J. InfiniteHiP: Extending language model context up to 3 million tokens on a single GPU. arXiv preprint arXiv:2502.08910, 2025b.arxiv.org/abs/2502.08910
  32. [38]Rajpurkar, P., Zhang, J., Lopyrev, K., and Liang, P. SQuAD: 100,000+ questions for machine comprehension of text. In Conference on Empirical Methods in Natural Language Processing (EMNLP), pp. 2383–2392, 2016.
  33. [39]Su, J. Rectified rotary position embeddings. https://github.com/bobone/rope, 2023.
  34. [41]Tang, B., Qin, Z., Pan, Y., Li, Z., and Liu, P. Block sparse attention with log-linear complexity. arXiv preprint arXiv:2609.31093, 2026.arxiv.org/abs/2609.31093
  35. [42]Tang, J., Zhao, Y., Zhu, K., Xiao, G., Kasicki, B., and Han, S. QUEST: Query-aware sparsity for efficient long-context LLM inference. In International Conference on Machine Learning (ICML), pp. 47901–47911, 2024.arxiv.org/abs/2406.10774
  36. [43]Tillet, P., Kung, H. T., and Cox, D. Triton: An intermediate language and compiler for tiled neural network computations. In ACM SIGPLAN International Workshop on Machine Learning and Programming Languages (MAPL), pp. 10–19, 2019.DOI
  37. [44]Trivedi, H., Balasubramanian, N., Khot, T., and Sabharwal, A. MuSiQue: Multihop questions via single-hop question composition. Transactions of the Association for Computational Linguistics (TACL), 10:539–554, 2022.arxiv.org/abs/2108.00573
  38. [45]Wang, J., Ji, T., Wu, Y., Yan, H., Gui, T., Zhang, Q., Huang, X., and Wang, X. Length generalization of causal transformers without position encoding. arXiv preprint arXiv:2404.12224, 2024.arxiv.org/abs/2404.12224
  39. [46]Wolf, T., Debut, L., Sanh, V., Chaumond, J., Delangue, C., Moi, A., Cistac, P., Raulin, T., Loup, R., Funtowicz, M., Davison, J., Schleifer, S., von Platen, P., Ma, C., Jernite, Y., Plu, J., Xu, C., Le Scao, T., Gugger, S., Drame, M., Lhoest, Q., and Rush, A. M. Transformers: State-of-the-art natural language processing. In Conference on Empirical Methods in Natural Language Processing: System Demonstrations (EMNLP), pp. 38–45, 2020.DOI
  40. [47]Xiao, C., Zhang, P., Han, X., Xiao, G., Lin, Y., Zhang, Z., Liu, Z., and Sun, M. InfLLM: Training-free long-context LLMs with an efficient context memory. In Advances in Neural Information Processing Systems (NeurIPS), pp. 119638–119661, 2024a.arxiv.org/abs/2402.04617
  41. [48]Xiao, G., Tian, Y., Chen, B., Han, S., and Lewis, M. Efficient streaming language models with attention sinks. In International Conference on Learning Representations (ICLR), 2024b.arxiv.org/abs/2309.17453
  42. [49]Yang, A., Li, A., Yang, B., Zhang, B., Hui, B., Zheng, B., Yu, B., Gao, C., Huang, C., Lv, C., Zheng, C., Liu, D., Zhou, F., Huang, F., Hu, F., Ge, H., Wei, H., Lin, H., Tang, J., Yang, J., Tu, J., Zhang, J., Yang, J., Yang, J., Zhou, J., Zhou, J., Lin, J., Ding, K., Bao, K., Yang, K., Yu, L., Deng, L., Li, M., Xue, M., Li, M., Zhang, P., Wang, P., Zhu, Q., Men, R., Gao, R., Liu, S., Luo, S., Li, T., Tang, T., Yin, W., Ren, X., Wang, X., Zhang, X., Ren, X., Fan, Y., Su, Y., Zhang, Y., Zhang, Y., Wan, Y., Liu, Y., Wang, Z., Cui, Z., Zhang, Z., Zhou, Z., and Qiu, Z. Qwen3 technical report. arXiv preprint arXiv:2505.09388, 2025.arxiv.org/abs/2505.09388
  43. [50]Yang, Z., Qi, P., Zhang, S., Bengio, Y., Cohen, W. W., Salakhutdinov, R., and Manning, C. D. HotpotQA: A dataset for diverse, explainable multi-hop question answering. In Conference on Empirical Methods in Natural Language Processing (EMNLP), pp. 2369–2380, 2018.arxiv.org/abs/1809.09600
  44. [51]Yuan, J., Gao, H., Dai, D., Luo, J., Zhao, L., Zhang, Z., Xie, Z., Wei, Y., Wang, L., Xiao, Z., Wang, Y., Ruan, C., Zhang, M., Liang, W., and Zeng, W. Native sparse attention: Hardware-aligned and natively trainable sparse attention. In Annual Meeting of the Association for Computational Linguistics (ACL), pp. 23078–23097, 2025.arxiv.org/abs/2502.11089
  45. [52]Zhang, X., Chen, Y., Hu, S., Xu, Z., Chen, J., Hao, M. K., Han, X., Thai, Z. L., Wang, S., Liu, Z., and Sun, M. ∞Bench: Extending long context evaluation beyond 100K tokens. In Annual Meeting of the Association for Computational Linguistics (ACL), pp. 15262–15277, 2024.DOI
  46. [53]Zhou, J., Lu, T., Mishra, S., Brahma, S., Basu, S., Luan, Y., Zhou, D., and Hou, L. Instruction-following evaluation for large language models. arXiv preprint arXiv:2311.07911, 2023.arxiv.org/abs/2311.07911

AI tools statement

This work lists 1 AI tool.

  • AI coding assistants · AI tool

    Roles
    Data curationInvestigationSoftwareWriting — review & editing
    Verification
    self-declared at submission

Recorded on the work at submission, not per version. Names and roles are shown as submitted; roles use the CRediT taxonomy.

How AI tools are recorded

Paper details

Cite this paper

Publication

Published
Version
Latest

Data & code

No code, data or supplementary files were declared for this version.

Pick where to look, or just type