arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2611.07232cs.CLcs.LG
收藏

递归稀疏注意力:对数成本下的百万 token 长度外推

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

University of California, San Diego(加利福尼亚大学圣迭戈分校);Carnegie Mellon University(卡内基梅隆大学)

Ruitian Wang, Xinyu Yang, Minshen Zhang, Hao Zhang

AI总结:

提出 RecSA 递归稀疏注意力,构建树状 KV 缓存实现对数成本的百万 token 长度外推,在 RULER 基准上优于基线,且在 64K-2M 长度下比密集注意力更快。

摘要:

在约 1M token 的上下文长度下,密集注意力的预填充与解码成本高昂,且训练通常依赖长文档,而随着目标长度增加,长文档愈发稀缺。多数稀疏注意力方法会对所有先前块或 token 打分,因此在上下文长度为 L 时,每个查询的选择成本为 O(L);分层选择可将其降至 O(log L),但现有可训练分层方法仅在训练长度内报告准确率。我们提出 RecSA(递归稀疏注意力),它在 KV 缓存上构建树,每个节点用一个键和一个均值池化值总结其子树。键来自每层的一个池化器,该池化器由所有层级共享并从密集注意力中蒸馏而来。每个 token 上方的层级最多选择 k 个候选,因此每个查询的选择成本为 O(log L),读取 O(log L) 个条目;未选候选的摘要与精确 token 共享一个 softmax。每个条目的 RoPE 位置是其在所在层级候选中的索引,因此在任意长度下,每个相对距离都保持在训练期间见过的范围内。RecSA 基于 Qwen3-4B 初始化,在原始模型 32K 训练长度下用 0.62B token 训练,在 RULER 上从 131K 到 2M 的所有长度均优于所有基线;在 1M 时,其得分为 60.5,而最佳基线 Dense + DCA 为 40.0。通过我们优化的内核,RecSA 在 64K 到 2M 的端到端预填充与解码中比密集注意力更快;在一块 H200 GPU 上的 524K 长度下,它将预填充加速 3.2 倍,解码加速 3.8 倍。

英文摘要:

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)$ at context length $L$; hierarchical selection reduces it to $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 $k$ candidates, so each query has $O(\log L)$ selection cost and reads $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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑