HSR-Enhanced Sparse Attention Acceleration

Bo Chen, Yingyu Liang, Zhizhou Sha, Zhenmei Shi, Zhao Song

TL;DR

Processing massive contexts in Large Language Models (LLMs) is notoriously bottlenecked by the quadratic cost of attention. This paper introduces a theoretical framework that frames sparse attention as a geometric Half-Space Reporting (HSR) problem, accelerating both ReLU and Softmax attention during decoding and prefilling to sub-linear time per query while introducing provably negligible error.

What Problem Does This Paper Address?

As LLMs scale context windows to 128k tokens and beyond, computing attention becomes a major operational bottleneck:

  1. Prompt prefilling ($m = \Theta(n)$ queries) scales quadratically as $O(n^2)$.
  2. Generation decoding ($m = \Theta(1)$ per step) scales linearly with the cache size as $O(n)$ per token.

Prior acceleration attempts often rely on aggressive low-rank approximations or bounded-entry assumptions that can break down in practice. However, empirical studies reveal that attention matrices are naturally sparse—especially in ReLU attention (where sub-threshold values become exact zeros) and standard Softmax attention (which exhibits "massive activations," where only a handful of tokens dominate the attention distribution). The core challenge is efficiently finding which key tokens matter without computing all inner products first.

Methods

The authors map the search for high-scoring query-key pairs directly onto computational geometry:

  • The HSR Connection: Finding keys where the score exceeds a threshold $b$ (i.e., $\langle Q_i, K_j \rangle / \sqrt{d} \ge b$) is mathematically equivalent to reporting which points lie inside a geometric half-space $\langle a, x \rangle \ge b$.
  • Two Algorithmic Frameworks:
  • Generation Decoding (Fixed Key Cache): Uses a static HSR tree initialized once in $O(n^{\lfloor d/2 \rfloor})$ time. Subsequent token queries identify the top keys in $O(d \log n + dk)$ time, yielding an inference runtime of $O(m n^{4/5})$ (assuming dimension $d$ is a small constant).
  • Prompt Prefilling (Dynamic Keys): Because keys change across inputs, building heavy structures is counterproductive. The algorithm builds a lightweight HSR structure in $O(n \log n)$ time and queries each token in $O(d n^{1 - 1/\lfloor d/2 \rfloor} + dk)$ time, cutting total prefilling time to $O(n^{2 - 1/\lfloor d/2 \rfloor} + n^{1+4/5})$.
  • Activation Pruning:
  • $\text{ReLU}^\alpha$ Attention: Sub-threshold entries evaluate to zero, so skipping them introduces zero error.
  • Softmax Attention: By retaining only the top-$r$ ($r = n^{4/5}$) massive activations, the authors prove an $\ell_\infty$ error bound that vanishes polynomially as context length grows.

Datasets

  • PaulGrahamEssays (from the LLMTest-NeedleInAHaystack benchmark): Used to evaluate generation quality under sparse Softmax attention. Sequences were fed with an initial context of $2^{15} = 32,768$ tokens followed by 1,024 generated tokens.
  • No new benchmarks were created; existing long-context text was leveraged for perplexity evaluations.

Key Insights and Ideas

  • Geometric Duality for Transformers: Instead of heuristic nearest-neighbor searches (e.g., locality-sensitive hashing or graph ANN), exact computational geometry structures can formally break the $O(n)$ barrier per query.
  • Gaussian Sparsity Guarantee: Using Gaussian tail bounds and Bernstein inequalities, the authors prove that setting threshold $b = \sigma_a \sqrt{0.4 \log n}$ ensures at most $2n^{4/5}$ keys fire per row with high probability ($1 - \delta$).
  • Vanishing Softmax Error: Under the "massive activation" condition (where the top-$n^\gamma$ tokens hold average attention scores greater than $\beta_1 \log n$), the $\ell_\infty$ output error scales as: $$\| \text{Attn}_s - \widehat{\text{Attn}}_s \|_\infty \le \frac{2 \|V\|_\infty}{n^{\gamma + (\beta_1 - \beta_2)\|q\|_2 - 1}}$$ This formalizes why dropping the long tail of low-attention tokens has virtually no impact on generation.

Key Results

  • Theoretical Complexity Reductions:
  • Decoding runtime drops from naive $O(mn)$ to $O(m n^{4/5})$.
  • Prefilling runtime drops from naive $O(n^2)$ to $O(n^{2 - 1/\lfloor d/2 \rfloor} + n^{9/5})$.
  • At $n = 1{,}024\text{k}$ tokens, theoretical sparsity reaches 94% (only 64,304 keys computed per query).
  • Empirical LLM Stability: Evaluated on LLaMA 3.1 8B Instruct, Mistral Nemo 12B, and Phi 3.5 Mini 3.8B Instruct:
  • Perplexity remained virtually flat when selecting as few as the top-$2^4$ ($r = 16$) keys out of $2^{15} = 32,768$ tokens.
  • Sharp degradation occurred only when $r$ fell below $2^4$, validating that only an extremely tiny fraction of tokens is necessary to maintain model capability.

Limitations and Future Work

  • Theoretical vs. Practical Implementation: The work does not include a full GPU/hardware implementation. The classical HSR data structure from Agarwal et al. (1992) lacks modern parallel implementations on GPUs.
  • Curse of Dimensionality: The pre-processing and query bounds depend exponentially on feature dimension $d$ (via $\lfloor d/2 \rfloor$), requiring the assumption that head dimension $d$ remains a small constant.
  • Future Work: The authors plan to investigate practical GPU implementations of HSR-style structures and extend their theoretical sparsity framework to other activations, such as SELU, CELU, and PReLU.

Summary updated

BibTeX
@inproceedings{chen2025hsr,
  author = {Bo Chen and Yingyu Liang and Zhizhou Sha and Zhenmei Shi and Zhao Song},
  title = {{HSR-Enhanced Sparse Attention Acceleration}},
  booktitle = {CPAL (Proceedings Track)},
  year = {2025},
  url = {https://openreview.net/forum?id=wso1gABiPZ},
}
Figure