What is sparse / sliding-window attention?
mediumAnswer
- Restrict each token to attend to a fixed neighborhood (window of size w) rather than all n tokens.
- Complexity drops from to O(n * w).
- Stack layers so the effective receptive field grows with depth.
- Used in Longformer (window + a few global tokens), BigBird, Mistral's sliding window attention.
- Great when relevant context is local.
- Combine with a few globally-attending tokens for long-range info.
Check yourself — multiple choice
- Removes softmax
- Each token attends within a fixed local window → O(n·w); stack layers to grow the effective range
- Same as vanilla attention
- Doubles complexity
Sliding-window / sparse attention: local window → O(n·w) instead of .
#attention#efficient-attention#transformers
Practise Deep Learning
214 interview questions in this topic.
Related questions
- Why is standard self-attention O(n²) in sequence length?
- How do Performer / Linformer / linear attention reduce O(n²)?
- How do Longformer / BigBird combine sparse and global attention?
- What is Flash Attention?
- What is the KV cache in transformer inference?
- Attention is quadratic in sequence length. Why is FlashAttention still a major win without changing that?