Manuscript Offprint

arXiv:2610.28441

Stratified Sparse Attention: Reducing the Sparse-to-Dense Gap at Extreme Sparsity

Sahil Joshi, Prithvi Dixit, Aryan Katiyar, Agniva Chowdhury, Joseph E. Gonzalez, Anshumali Shrivastava, Aditya Desai, Kumar Krishna Agrawal

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

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 50× attention sparsity, recovering 94% and 85% of dense-attention performance, respectively. With optimized CUDA kernels, SSA achieves up to 2.96× 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.

1 Introduction

Large language models (LLMs) are rapidly expanding into long-context workloads, spanning large document collections [23], image analysis [10, 31], software engineering [15, 5], databases [48], video processing [33], and long-horizon agents that continuously accumulate observations, tool outputs, and interaction histories [3, 4]. As context lengths approach millions of tokens, efficient inference becomes increasingly challenging. During autoregressive decoding, each newly generated token attends to an ever-growing key-value (KV) cache, requiring keys and values to be repeatedly transferred from GPU high-bandwidth memory (HBM) onto on-chip SRAM for attention computation [35, 20]. At long contexts, this makes decoding increasingly memory-bandwidth bound: the attention cost per decoding

∗^{*}Equal contribution.

†^{\dagger}Department of Computer Science, Rice University, TX, USA.

‡^{\ddagger}Department of Electrical Engineering and Computer Sciences, UC Berkeley, CA, USA.

§^{§}Department of Computer Science, Stanford University, CA, USA.

¶Co-lead.

1^{1}Department of Computer Science and Engineering, Indian Institute of Technology Bombay, India.

Figure

Figure

Figure 1: Relative L2L_{2} error when varying the top-k:sampling budget allocation at 50×50\times sparsity (left) and varying sparsity with a fixed 3:2 top-k:sampling budget split (right).

step grows linearly with context length. Sparse attention addresses this bottleneck by attending to only a small fraction of the KV cache [39, 27, 46], reducing both memory traffic and attention latency. However, realizing these gains in practice requires sparse attention to satisfy two competing objectives: faithfully approximate dense attention at aggressive sparsity while remaining efficient enough to translate sparsity into end-to-end inference speedups [29, 25].

Existing sparse-attention methods can be broadly categorized by how they allocate a limited attention budget. First, approximate retrieval methods use proxy attention scores to deterministically select high-scoring tokens, typically through top-k retrieval. Representative methods include PQCache [46], and Quest [39], with recent approaches such as Tactic [50] extending this paradigm to top-p selection. While effective when attention is highly concentrated, deterministic retrieval can miss substantial attention mass when the distribution is diffuse or long-tailed [6, 9]. Second, sampling-based methods such as MagicPig [6] use importance sampling to approximate dense attention, providing broader coverage but introducing sampling variance that can lead to a larger gap from dense attention at limited budgets (see Table 5 in Appendix). Finally, hybrid methods such as vAttention [9] combine deterministic top-k retrieval with uniform sampling [42], preserving high-confidence tokens while extending coverage beyond the top-k set. Although this combination improves the trade-off between exploitation and coverage, a substantial gap to dense attention remains at aggressive sparsity (see Table 5 in Appendix). See Section 2 for more details. These observations motivate a fundamental question: Can we design a more effective sampling strategy that substantially narrows the sparse-to-dense accuracy gap?

Our preliminary studies reveal a key limitation of uniform sampling: while it provides coverage beyond the deterministic top-k set, it ignores the highly non-uniform distribution of residual attention mass 1^{1}. As shown in fig. 1, score-guided importance sampling (the principle that SSA uses) consistently achieves lower relative L2L_{2} error than uniform sampling. Motivated by this observation, we introduce Stratified Sparse Attention (SSA), a unified framework that combines deterministic retrieval of high-confidence heavy hitters with score-guided stochastic exploration of the remaining context. Rather than treating all residual tokens equally, SSA uses proxy attention scores to preferentially explore promising regions while preserving stochastic coverage of the long tail. This enables the sparse attention budget to better capture the attention mass that would otherwise be lost under aggressive sparsity. We evaluate SSA across diverse models, including Llama-3.1-8B-Instruct [12],

1^{1}Oracle-top-k + Importance Sampling uses exact attention scores for both top-k selection and residual importance sampling, providing an oracle reference for SSA.

Figure

(a) Qwen3.5-4B: Error

Figure

(b) Qwen3.5-9B: Error

Figure 2: Average attention error across different context lengths and sparsity levels for Qwen3.5-9B and Qwen3.5-4B on LOFT [22].

Qwen3.5-4B, Qwen3.5-9B, Ministral-3-3B-Instruct-2517, and Ministral-3-8B-Instruct-2517 [26], and across RULER [16], LongBench [2], LOFT [22], and AIME [28]. Across these evaluations, SSA consistently improves over deterministic, sampling-based, and hybrid sparse-attention baselines, substantially narrowing the gap to dense attention at extreme sparsity. Our contributions can be summarized as follows:

I. Unified Attention Paradigm: We introduce a unified sparse-attention framework that partitions tokens into deterministic and stochastic strata using a generic proxy score. By varying how tokens are retained or sampled, the framework recovers top-k, top-p, and hybrid top-k+sampling as special cases of importance-sampling-inspired sparse attention.

II. Theoretical Guarantees: We provide rigorous bounds for our proposed algorithm, characterizing how closely it approximates dense attention under a limited attention budget.

III. Efficient Kernel Support: We develop efficient CUDA/Triton kernels that realize the computational benefits of our approach in practice, delivering end-to-end decoding speedups over dense attention.

References (44)