As asked
State the time and memory complexity of standard multi-head attention as a function of sequence length N and hidden dimension D. Explain which term dominates at long versus short contexts and why this drives the adoption of Flash Attention.
Sample answer outline
Time complexity is O(N^2 * D) for the attention matrix multiply plus O(N * D^2) for the projection matrices. Memory is O(N^2) for the attention score matrix. At short context (N much less than D), the projection dominates; at long context (N much greater than D), the N^2 attention score matrix dominates both memory and time. Flash Attention eliminates the O(N^2) memory materialization by computing in tiles, making long context tractable.
Expect these follow-ups
- At what sequence length does the N^2 term start to dominate for a 4096 hidden-dim model?
- How does multi-query attention reduce memory bandwidth cost during decode?