As asked
What is the time and memory complexity of vanilla self-attention with respect to sequence length N and model dimension D? Why does this create a problem at long contexts, and name two architectural approaches that reduce the attention complexity.
Sample answer outline
Time complexity is O(N^2 * D) and memory is O(N^2) to store the attention matrix. At N=128K tokens the N^2 term becomes prohibitive. Approaches: sparse attention (BigBird, Longformer) limits each token to attend to a subset of positions; linear attention (Performer, RWKV kernel trick) approximates softmax attention in O(N*D). FlashAttention is not a complexity reduction but reduces IO complexity. Strong candidates can distinguish IO complexity from computational complexity.
Expect these follow-ups
- Does FlashAttention change the asymptotic computational complexity of attention, or only the IO complexity?