NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

S2O: Early Stopping for Sparse Attention via Online Permutation

Yu Zhang, Songwei Liu, Chenqian Yan, Sheng Lin, Beichen Ning, Fangmin Chen, Xing Wang

TL;DR

S2O (Early Stopping for Sparse Attention via Online Permutation) breaks through the "sparsity ceiling" of traditional block-sparse attention by logically reordering token loading on the fly. By using lightweight index mapping to front-load high-importance tokens and applying a dynamic early-stopping rule, it achieves up to a 7.51× attention speedup and 3.81× end-to-end prefill speedup on long-context models without sacrificing accuracy.

What Problem Does This Paper Address?

As Large Language Models (LLMs) scale to handle massive context windows (e.g., 128K tokens or more), the standard attention mechanism becomes a severe bottleneck due to its quadratic ($O(L^2)$) time and memory complexity.

To mitigate this, researchers often turn to block-sparse attention, which groups tokens into fixed-size blocks to maintain high GPU utilization and align with memory access constraints. However, the authors identify a fundamental flaw: actual attention heatmaps in LLMs exhibit fine-grained, stripe-like structures rather than neat, coarse blocks.

Attention heatmaps showing how S2O compacts dispersed attention mass into a concentrated region compared to the original layout and local permutation (PBS).

Because traditional block-sparse methods select entire coarse blocks, they end up wasting substantial computation on low-importance tokens trapped inside those selected blocks (intra-block redundancy). Physically rearranging the tensors in memory to cluster the important tokens is too computationally expensive. S2O solves this dilemma by emulating global permutation entirely within the data-loading stage of the attention kernel.

Methods

S2O introduces a FlashAttention-compatible solution that decouples the physical memory layout from the logical order of computation through two main steps:

  1. Intra-Segment Lightweight Ranking (Step 1): The input sequence is partitioned into segments. Within each segment, queries ($Q$) are sorted locally using a cheap guide vector to front-load those likely to cause prominent horizontal stripes. Concurrently, historical Key/Value ($K/V$) blocks are ranked globally using a line-level mean pooling signal that effectively captures the stripe-like attention structures. This produces lightweight index arrays (Qperm and Kperm) without physically moving any tensors in High Bandwidth Memory (HBM).
  2. Online Permutation and Early Skipping (Step 2): During the attention computation, a custom Triton-based kernel uses these coordinate indices to gather non-contiguous tokens directly into on-chip SRAM. Because the blocks are traversed in descending order of estimated importance, S2O tracks the marginal attention-mass gain.
The two-step workflow of S2O: index-based permutation followed by a two-pass sparse attention kernel with early stopping.

To maintain numerical stability and handle causal masking, the kernel executes in two passes:

  • Pass 1 (Dense Init): Computes a local dense causal window within the segment to initialize stable online-softmax states.
  • Pass 2 (Sparse Attention): Resumes the states and traverses the historical prefix blocks in the sorted order. Once the marginal gain falls below a predefined threshold ($\tau$), the kernel stops early and skips the remaining low-contribution blocks.

Datasets

The authors evaluated S2O across three widely recognized long-context benchmarks using Llama-3.1-8B and Qwen3-8B models:

  • RULER: Evaluates effective context window behaviors across a variety of retrieval and aggregation tasks up to 128K context length.
  • LongBench v2: A dataset designed for deep understanding and reasoning over long-context multi-tasks.
  • InfiniteBench: Focuses on ultra-long context tasks including code debugging, long-document QA, and key-value retrieval.

Key Insights and Ideas

  • The Block-Stripe Mismatch: Coarse block selection imposes an intrinsic sparsity ceiling. Finer-grained sparsity is necessary, but hardware requires regular block-wise computation. S2O elegantly bridges this gap by using block-wise computation on logically permuted fine-grained selections.
  • Logical Address Mapping over Physical Shuffling: Inspired by virtual-to-physical memory mapping, the authors realize that high bandwidth utilization on modern GPUs does not strictly require contiguous $K/V$ loads, provided that the data remains contiguous along the head dimension ($D=128$). This allows index-driven gathering to emulate global permutation with less than 10% overhead.
  • Monotone-Gain Early Stopping: Traditional sparse attention pre-commits to a fixed $Top-K$ subset of blocks. By sorting blocks online by importance, S2O turns sparsification into a dynamic execution policy: stop computing the moment the mathematical contribution drops below a threshold, optimizing the error budget dynamically.

Key Results

  • Superior Sparsity-Error Trade-off: On Llama-3.1-8B at a 128K context length, S2O reduces single-operator Mean Squared Error (MSE) by 3.82× at matched sparsity, and reduces prefill compute density by 3.31× at matched MSE compared to prior state-of-the-art methods.
  • Wall-Clock Speedups: S2O delivers up to a 7.51× speedup for the attention operator alone and a 3.81× end-to-end prefill latency speedup over standard FlashAttention.
End-to-end prefill latency breakdown and speedup comparison of S2O against FlashAttention and other baselines at 128K context length.
  • Downstream Accuracy: S2O maintains downstream task accuracy comparable to full dense attention across all benchmarks, proving that the skipped blocks truly contain negligible attention mass.

Limitations and Future Work

  • Retrieval Overhead Scaling: The key-scoring mechanism scales quadratically with respect to the number of segments ($O(L^2/S)$). While negligible at 128K, for ultra-long contexts (e.g., millions of tokens), the retrieval overhead could become non-negligible unless segment lengths ($S$) are dynamically scaled or hierarchical retrieval methods are introduced.
  • Hyperparameter Tuning: S2O relies on two primary hyperparameters: segment length $S$ and early-stop threshold $\tau$. Finding the optimal balance between retrieval overhead and sparsity gains currently requires manual empirical tuning.

Summary updated

BibTeX
@inproceedings{zhang2026s,
  author = {Yu Zhang and Songwei Liu and Chenqian Yan and Sheng Lin and Beichen Ning and Fangmin Chen and Xing Wang},
  title = {{S2O: Early Stopping for Sparse Attention via Online Permutation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.351},
}
Figure