What is sparse attention?

Sparse attention is the general name for attention approaches in transformer models where each token attends not to every token in the sequence but to a subset chosen by a pattern or selection, cutting cost by leaving most of the attention matrix uncomputed.

Unlike linear attention, which uses all tokens but restructures the computation with kernel transformations, sparse attention limits which token pairs are computed. Sliding window attention is a specific sparse pattern looking only at nearby tokens.

Topic
Machine learning, models and training
Also known as
Sparse self-attention

How sparse attention works

  1. A pattern deciding which token pairs to compute is chosen: a local window, positions skipped at intervals, a few global tokens seeing the whole sequence or blocks.
  2. Attention is computed only for pairs in the pattern; the rest are skipped.
  3. Some methods select important tokens by content rather than a fixed pattern.
  4. As layers stack, information reaches distant tokens indirectly through the pattern.

In more detail

Hardware-aligned block-sparse attention

Fine-grained or irregular token-level sparsity often fails to accelerate modern GPUs due to uncoalesced memory access. Consequently, recent architectures (such as DeepSeek's Native Sparse Attention, MoBA and FlexAttention block masks) focus on hardware-aligned block-sparse patterns that map cleanly onto Tensor Core tiles.

Sparsity in prefill versus decode

Attention bottlenecks differ between prefill and autoregressive decoding: during prefill, sparse patterns cut quadratic compute; during decoding, latency is dominated by memory bandwidth when reading the KV cache, making dynamic sparse KV-cache selection or eviction (such as H2O or Quest) critical for throughput.

Commonly confused terms

TermHow it differs
FlashAttentionFlashAttention computes mathematically exact, dense attention across all token pairs while avoiding quadratic HBM memory allocation via GPU SRAM tiling; sparse attention approximates attention by omitting pairs to save both FLOPs and memory reads.

Why sparse attention matters for on-premises AI

Full attention cost grows with the square of sequence length; sparse attention slows that growth, easing long documents and log sequences on limited GPU memory. The cost is weaker links outside the pattern, so the chosen pattern is tested on the organisation's own long-document tasks. For sparse patterns to actually speed things up, the inference engine and hardware kernels must support them efficiently; otherwise the theoretical gain may not appear in practice.

ON-PREMISES EXAMPLE

For an in-house model reviewing policies and appendices hundreds of pages long, an insurer tries a sparse attention model, measuring processable document length alongside success at linking conditions across sections.

Common questions

How does sparse attention differ from sliding window attention?

Sparse attention is the general name for approaches limiting computed token pairs. Sliding window attention is one specific pattern looking only at nearby tokens.

Does sparse attention always speed things up?

No. Theoretical cost falls, but real speed depends on the inference engine and hardware kernels supporting the pattern efficiently.

Sources

In the glossary: Glossary, R to Z

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.