How does linear attention achieve sub-quadratic complexity compared to softmax attention?

Last updated 22 November 2026

  • Softmax is replaced by a kernel feature map φ, and associativity lets φ(K)^T V be computed first as a small d×d summary. Cost drops from O(N²d) to O(Nd²) with no N×N matrix.

  • In causal form it becomes an RNN with a fixed-size state, giving constant time and memory per decoding step and no growing KV cache.

  • Trade-offs: it only approximates softmax, attention is less sharp, and the fixed state hurts exact recall. Gated variants (RetNet, Mamba-style, GLA) narrow the gap.

  • https://medium.com/@VectorWorksAcademy/ace-ai-interview-series-25-achieving-sub-quadratic-attention-532dc016d6a8
  • https://medium.com/data-science/linearizing-attention-204d3b86cc1e
  • https://haileyschoelkopf.github.io/blog/2024/linear-attn/
All Transformers interview questions