Home Knowledge Base Sparse Attention

Sparse Attention is the family of attention mechanism variants that restrict the full N×N attention matrix to a sparse pattern — reducing the quadratic O(N²) time and memory complexity of standard self-attention to O(N√N), O(N log N), or O(N), enabling transformer models to process much longer sequences than would be feasible with dense attention while retaining most of the representational power.

Why Sparse Attention?

Sparse Attention Patterns

PatternWhat Tokens Attend ToComplexityExample
Sliding WindowW nearest neighborsO(N×W)Mistral, Longformer (local)
DilatedEvery k-th token within windowO(N×W/k)Longformer (dilated)
Global + LocalSome tokens attend globally, rest locallyO(N×(W+G))Longformer, BigBird
StridedFixed stride pattern (blockwise)O(N√N)Sparse Transformer (Strided)
RandomRandomly selected tokensO(N×R)BigBird (random component)
Block SparseDense attention within blocksO(N×B)Block-sparse attention

Sliding Window Attention (Mistral/Mistral-style)

Longformer (Beltagy et al., 2020)

1. Local (sliding window): Every token attends to W neighbors. 2. Dilated: Attend to tokens spaced k apart → larger receptive field. 3. Global: Designated tokens (e.g., [CLS]) attend to all tokens.

BigBird (Zaheer et al., 2020)

Linear Attention

Modern Hybrid Approaches

Sparse attention is the enabling architecture for long-context transformers — by intelligently selecting which token pairs to compute attention for, these methods extend the practical reach of transformers from thousands to millions of tokens while preserving the ability to capture the long-range dependencies that make attention powerful.

sparse attentionefficient attentionlocal attentionsliding window attentionlinear attention

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.