Attention's Quadratic Scaling: The Primary Compute Burden

The self-attention mechanism in Transformers causes computational costs to scale quadratically with context length; doubling the token window can quadruple attention computations, making it the leading driver of processing expense.

The top 3

  1. 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.
  2. Top 3 Efficient Attention Alternatives: To combat O(N²) costs, researchers employ: 1) Sparse Attention (e.g., BigBird, Longformer) restricting token interactions to O(N) or O(N log N). 2) Linear Attention (e.g., Performer, Linformer) using kernel approximations for O(N) complexity. 3) State Space Models (e.g., Mamba, Hyena) offering sub-quadratic scaling with RNN-like inference.
  3. Maximum Practical Context Lengths Limited by Quadratic Attention: Due to O(N²) scaling, standard Transformer models are often practically limited to context windows of 4K, 8K, or 16K tokens; beyond this, memory and computational requirements become prohibitively expensive without specialized optimizations.

Open the full topic