Why is standard self-attention in sequence length?
mediumAnswer
- For each of n query tokens, compute a dot product with each of n key tokens → dot products, each of size d.
- Then a softmax over n weights per query.
- Both compute and memory are .
- Fine at n = 512-2048; painful at n = 32k+.
- Motivates efficient / sparse / linear-attention variants and paging tricks (Flash Attention doesn't reduce complexity but cuts memory dramatically via tiling).
Check yourself — multiple choice
- Attention is O(n)
- Every query attends to every key → dot products → compute and memory
- Attention is O(1)
- Attention is O(n log n)
Self-attention: n queries × n compute + memory.
#attention#transformers#efficient-attention
Practise Deep Learning
214 interview questions in this topic.
Related questions
- How do Performer / Linformer / linear attention reduce O(n²)?
- What is sparse / sliding-window attention?
- 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?