分层稀疏注意力:缩小极端稀疏下的稀疏-稠密差距

·

研究论文 · 2026/10/23

大型语言模型在长上下文推理中,KV缓存的开销成为瓶颈。稀疏注意力通过仅访问部分缓存来降低成本,但现有方法在确定性检索(捕获高得分token但丢弃残余注意力质量)和采样(提高覆盖但方差较高)之间存在权衡。混合方法结合top-k检索与均匀采样,但在极端稀疏下仍与稠密注意力有较大差距。我们提出分层稀疏注意力(SSA),一个统一框架,结合确定性检索与分数引导采样。SSA确定性地关注高得分token,同时利用代理注意力分数对残余部分进行采样,并校正其包含概率,从而恢复检索集之外的注意力质量。SSA涵盖top-k、top-p和混合top-k+采样作为特例。在RULER、LongBench、LOFT和AIME上,以及从3B到27B参数的五个模型上,SSA在匹配稀疏度下始终优于基线。在RULER-HARD上使用Ministral-3-8B,在50倍注意力稀疏度下,SSA在32K上下文将准确率从最强实用基线的81.8%提升至84.2%,在128K上下文从63.8%提升至69.3%,分别恢复稠密注意力性能的94%和85%。通过优化的CUDA内核,SSA在1M上下文下相比FlashInfer实现高达2.96倍的解码加速,表明其准确率提升转化为实际的长上下文推理加速。代码已开源。

该论文提出了一种在极端稀疏下显著缩小与稠密注意力性能差距的稀疏注意力方法,并在多个长上下文基准和模型上验证了有效性,同时通过优化内核实现了实际推理加速,对长上下文LLM推理有重要价值。

Large Language Model inference over long contexts is increasingly bottlenecked by the cost of attending to a growing Key-Value (KV) cache. Sparse attention reduces this cost by accessing only a fraction of the cache, but existing methods face a trade-off between deterministic retrieval, which captures high-scoring tokens but discards residual attention mass, and sampling, which improves coverage at the cost of higher variance. Hybrid methods combine top-k retrieval with uniform sampling, yet still exhibit a substantial gap from dense attention at aggressive sparsity. We introduce Stratified Sparse Attention (SSA), a unified framework combining deterministic retrieval with score-guided sampling. SSA deterministically attends to high-scoring tokens while sampling the residual using proxy attention scores and correcting for their inclusion probabilities, thereby recovering attention mass beyond the retrieval set. SSA encompasses top-k, top-p, and hybrid top-k+sampling as special cases. Across RULER, LongBench, LOFT, and AIME, and five models ranging from 3B to 27B parameters, SSA consistently improves over the baselines at matched sparsity. On RULER-HARD with Ministral-3-8B, SSA improves accuracy over the strongest practical baseline from 81.8\% to 84.2\% at 32K and from 63.8\% to 69.3\% at 128K under 50times attention sparsity, recovering 94\% and 85\% of dense-attention performance, respectively. With optimized CUDA kernels, SSA achieves up to 2.96times decode speedup over FlashInfer at 1M context, demonstrating that its accuracy gains translate into practical long-context inference acceleration. We open-source our code at https://github.com/skylight-org/SSA-Paper-Code.

阅读原文

参与讨论