Why Attention's O(N²) Scaling is Inherent
Standard self-attention computes an N×N matrix of scores by multiplying queries with keys, where N is sequence length. This fundamental operation, costing O(N²dk) computation and O(N²) memory, means doubling context quadruples resource demand.
The top 3
- Every Token's Score Against Every Other: Self-attention's fundamental design requires computing a similarity score (dot product) for *each* query token against *all* key tokens in the input sequence, directly leading to N² (sequence length squared) individual interactions.
- QKᵀ Matrix Generates N×N Attention Map: The computational bottleneck lies in the `QKᵀ` operation, where an N-length query matrix (Q) is multiplied by an N-length key transpose matrix (Kᵀ), resulting in an N×N attention score matrix that directly defines the O(N²) complexity.
- Global Context Demands All-Pairwise Relationships: To establish comprehensive long-range dependencies and contextual understanding across the entire input sequence, self-attention must model every token's relationship to every other, necessitating O(N²) comparisons for its global perspective.
Sources
Open the full topic