SAS: Simple Attention Sparsification via End-to-End Optimization of Context Ranking

Zhiwei Li, Lei Zhu, Hao Gu, Xiang Hu, Yan Wang, Haitao Mi, Sirui Han, Leo Liang, Zhijiang GuoNeurIPS 2026

TL;DR

Making Large Language Models (LLMs) read long documents without melting GPUs usually involves dropping "unimportant" chunks of text—a discrete choice that breaks standard gradient descent and forces researchers to rely on clunky, indirect training tricks. Simple Attention Sparsification (SAS) fixes this by slipping a continuous, differentiable "gate" right into the attention math during training. This allows the model's final prediction error to directly teach the attention mechanism which historical memories actually matter, leading to massive accuracy boosts when memory budgets are tight.

What Problem Does This Paper Address?

Every time an LLM generates a word, standard "dense" attention looks back at every single preceding token. As context lengths stretch into the tens of thousands, this creates a quadratic compute bottleneck. Since retraining massive models from scratch is prohibitively expensive, post-training attention sparsification adapts existing dense models so each query only attends to a small budget of $K$ context blocks (chunks of tokens).

To pick the best blocks, recent methods attach a lightweight, trainable neural network called a selector. Here’s the catch: picking the "Top-$K$" blocks is a discrete, hard cutoff. It’s a mathematical brick wall for backpropagation—gradients from the final language modeling loss simply cannot flow backward through a hard selection step to update the selector.

To get around this, existing methods usually resort to layer-wise distillation: they train each layer's selector to mimic where the original dense model placed its attention weights. While clever, this creates a ranking misalignment. Mimicking dense attention weights ignores how layers might work together (complementarity) and completely overlooks the values ($\mathbf{V}$ matrix) actually carried by those tokens. Under a strict budget, copying the dense teacher wastes precious attention slots on tokens that look popular in a single layer, rather than tokens that actually help predict the next word.

Methods

Instead of treating sparse attention as a hard subset-selection puzzle, SAS reframes it as a continuous context ranking problem optimized end-to-end with the standard language modeling loss.

Figure 1: (a) Gradient Blockage in Discrete Selection. Sparse attention with discrete Top-K selection prevents gradients propagation from language modeling loss to selector. Existing approaches bypass this issue using auxiliary distillation [5, 4] or heuristics [6, 7]. (b) Differentiable Continuous Gating. SAS keeps discrete Top-K selection but attaches a continuous soft gate to each selected block, enabling gradient flow from the language modeling loss to the selector.

During training, SAS keeps the LLM backbone frozen and reuses a standard selector architecture (AttnGate from SeerAttention-R) to score historical blocks of 64 tokens, while always retaining the current block unbiased (gate $= 1$). What’s novel is how SAS routes gradients around the Top-$K$ brick wall through four deliberate design choices:

  1. Inner Log-Space Gate Injection: After picking the Top-$K$ blocks, SAS converts their continuous selector scores into log-space biases ($\log \mathbf{g}$) and adds them inside the attention $\operatorname{softmax}$ directly to the $\mathbf{q}\mathbf{K}^\top$ logits.
  2. Normalized Softmax Gates: Selector scores across historical blocks are normalized via $\operatorname{softmax}$ before taking the logarithm, forcing blocks to compete against one another.
  3. Continuous Ranking Preservation: Rather than collapsing selected gates into binary $1$s and $0$s (via Straight-Through Estimators), SAS keeps the continuous gate values during training so the model learns relative priorities among blocks.
  4. Sparse Training Scope & Fused Triton Kernel: Updating only the Top-$K$ selected blocks during training (rather than all blocks) is much cheaper. To avoid materializing massive attention matrices in GPU memory, the authors built a custom FlashAttention-style Triton kernel that fuses the log-gate addition and block-skipping directly into tile-level streaming computations.

At inference time, the continuous gates vanish—SAS simply runs fast, discrete Top-$K$ block-sparse attention using the selector's learned rankings.

Datasets

The authors do not introduce new benchmarks, relying instead on established datasets to test cross-domain generalization:

  • Training: Selectors are trained exclusively on math reasoning data—specifically OpenR1-Math-220K (at a 32,768-token sequence length).
  • Evaluation: The math-trained models are tested across three distinct domains:
  • Reasoning: MATH500, GPQA-Diamond, AIME24, and AIME25.
  • Long-Context Understanding: LongBench (inputs grouped up to 8K+ tokens).
  • Agentic Tool-Use: BFCL (Multi-Turn) and VitaBench (context extended to 65,536 tokens via YaRN).

Key Insights and Ideas

  • Modulating probabilities beats rescaling outputs: Placing gates outside the attention $\operatorname{softmax}$ (merely multiplying the output values $\mathbf{V}$) drops GPQA-Diamond accuracy from 54.4% to 41.6%. Injecting gates inside the $\operatorname{softmax}$ lets gradients reallocate attention mass based on relative token utility ($\mathbf{v}_i - \mathbf{o}$).
  • Competition prevents lazy gates: Why use $\operatorname{softmax}$ to activate selector scores instead of independent sigmoid gates or raw logits? Without competition, sigmoid gates lazily saturate toward $1$, and raw logits collapse toward $0$—both effectively reverting to ungated attention and destroying the ranking signal. Furthermore, $\operatorname{softmax}$ calibrates total historical context mass against the always-kept current block.
  • Math-learned routing transfers shockingly well: Even though the selector only ever saw math problems during training, its learned ability to rank relevant context transfers seamlessly to general reading comprehension (LongBench) and multi-turn agentic tool use.
  • Noisy sparse gradients still get the job done: Training only on the Top-$K$ sparse blocks means unselected blocks don't get evaluated on their own content, resulting in slower initial learning. Yet, by the end of one epoch, sparse-scope training completely catches up to full-scope training at a fraction of the compute cost.

Key Results

Tested on Qwen3 models (4B, 8B, and 14B), SAS consistently beats training-free baselines (Sliding Window, StreamingLLM, Quest) and its direct distillation-trained counterpart (SeerAttention-R, which uses the exact same backbone, selector, and training data):

  • Massive gains under tight budgets: At a tight 1024-token budget, SAS outperforms SeerAttention-R by +6.0 to +7.7 points on MATH500 and +10.6 to +15.5 points on GPQA-Diamond across model sizes.
  • Hard math reasoning: At a 2048-token budget on Qwen3-4B, SAS jumps ahead of SeerAttention-R by +13.0 points on AIME24 (68.85% vs. 55.83%), while Quest collapses to 0%. At a 4096 budget, SAS matches or slightly exceeds full dense attention (e.g., 71.72% vs. 71.25% on AIME24).
  • Long-context & Agentic tasks: On LongBench (Qwen3-14B, 2048 budget), SAS improves the longest 8K+ token bucket by +2.4 points over distillation. On multi-turn BFCL, it leads by up to +3.5 points, and at a 4096 budget, nearly recovers full dense attention performance across both BFCL and VitaBench.

Limitations and Future Work

In the main text, the authors note a subtle optimization trade-off in their chosen sparse training scope: because non-Top-$K$ blocks are masked out during the forward pass, they receive no direct gradient signal evaluating their own content—only noisy, correlated indirect updates via $\operatorname{softmax}$ normalization, causing slower early-stage convergence compared to full-scope training. Additionally, while the paper focuses primarily on post-training adaptation with frozen LLM backbones, the authors highlight continued pretraining—jointly training the LLM backbone and the sparse selector end-to-end (explored preliminarily in their appendix)—as a natural extension of the SAS paradigm.

Summary updated

Abstract

Post-training attention sparsification reduces the quadratic cumulative attention cost of pretrained Transformers by selecting a small set of context units (tokens or blocks) for each query. Existing trainable methods usually rely on a lightweight selector to score context units followed by a hard Top-$K$ selection, which blocks gradients from the language modeling loss. As a result, these methods commonly resort to distilling layer-wise dense attention distributions. While this approach encourages the selector to rank context units according to dense attention weights in the original model, such a ranking is not directly aligned with their impact on the model's final predictions under a fixed attention budget (ie, the number of attended context units per query), which can waste the limited attention budget on less useful units. To address this ranking misalignment, we propose **S**imple **A**ttention **S**parsification (SAS), a gated sparse attention mechanism that optimizes context ranking *end-to-end* with the language modeling loss. The key idea is to inject the selector's continuous scores into the attention logits during training, allowing the language modeling loss to update the selector through standard backpropagation. We identify several choices that are crucial to make this simple design work well in practice: placing the gate inside the attention $\operatorname{softmax}$ in log form, using normalized $\operatorname{softmax}$ gates to calibrate historical context against the always-retained current block, and preserving continuous selector scores so the model learns relative priorities rather than only hard selections. To support long-sequence training, we implement a memory-efficient Triton kernel that integrates our method into FlashAttention-style computation. Across reasoning, long-context understanding, and agentic tasks, SAS consistently outperforms trainable sparse attention baselines across attention budgets, with especially large gains under tight budgets, demonstrating more effective context ranking for downstream tasks.
BibTeX
@inproceedings{li2026sas,
  author = {Zhiwei Li and Lei Zhu and Hao Gu and Xiang Hu and Yan Wang and Haitao Mi and Sirui Han and Leo Liang and Zhijiang Guo},
  title = {{SAS: Simple Attention Sparsification via End-to-End Optimization of Context Ranking}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=Wgm2AWIzrX},
}
Figure