Approaching I/O-optimality for Approximate Attention
AuthorsPál András Papp, Aleksandros Sobczyk, Anastasios Zouzias
Resources
This paper makes attention much cheaper to run by reducing memory traffic, bringing it closer to the theoretical limits of efficiency.
Key results
When M = Ω(d·r), the optimal I/O complexity is Θ(n·d), matching the trivial input-output lower bound.
For M = o(d·r) and g = o(log M), the upper bound is O(n·r·d·(4e2)^g / M^(g+1)).
The Case III lower bound requires d ≥ 5g.
What the paper found
Pál András Papp, Aleksandros Sobczyk, and Anastasios Zouzias, at Huawei Technologies, analyze the I/O complexity of approximate attention rather than arithmetic complexity, using the polynomial-based framework of Alman and Song from NeurIPS 2023. For Q, K, V in R^{n×d}, they show that replacing exp(QK^T/d) with a degree-g polynomial expansion yields matrices U1 and U2 with r = binom(d+g, g) features, and this structural change lets attention be tiled far more efficiently than FlashAttention. Their main result is a four-regime characterization of optimal data movement in the red-blue pebble game model: when fast memory satisfies M = Ω(dr), the I/O cost is Θ(nd), matching the trivial input-output lower bound; when M is smaller but g = o(log M), the cost is O(nrd(4e^2)^g / M^{g+1}) with a matching lower bound up to constants; when g is larger, they prove nearly linear-in-n bounds of O(min(nrd^2/M, nrd/√M)) and a corresponding Ω(nrdg/M) lower bound under d ≥ 5g; and for tiny caches, M = O(g^2), the cost is Θ(nrd/√M). The key novelty is a nonstandard tiling strategy that loads only w entries from a row of Q or K to generate up to τ(w)=binom(w+g, g) terms, enabling tiles whose shape depends on the combinatorics of the polynomial approximation rather than on d alone. Compared with FlashAttention, whose I/O cost is Θ(n^2d^2/M) in the favorable regime, these bounds remove a quadratic dependence on sequence length n and can save an almost-linear factor in I/O.
Original abstract
We revisit the I/O complexity of attention in large language models. Given query-key-value matrices $Q,K,V\in\mathbb{R}^{n\times d}$, and a machine with fast memory size $M$, the goal is to compute the "attention matrix" $A=\text{softmax}(Q K ^{\top}/\sqrt{d}) V$ with the minimal number of data transfers between fast and slow memory. Existing methods in the literature, most notably FlashAttention and its variants, incur an I/O cost that depends quadratically on $n$, while a trivial lower bound only requires $Ω(nd)$ I/O's to read the inputs and write the output. In this work, we present a technique for computing attention where the I/O cost only depends almost-linearly on $n$ in most parameter regimes. This is achieved by developing I/O-efficient algorithms inspired by the recent approximate attention framework of Alman and Song. We also prove corresponding lower bounds in each parameter regime to show that our algorithms are indeed close to I/O-optimal.
Read the original paperMore in Efficient AI
Browse all 55 papers →Decoding Looped Transformers Better for (Almost) Free
Weihao Liu, Huangjie Zheng, Tianrong Chen, Rohit Dilip, Richard He Bai, Yizhu Jiao, Yuyang Wang, Ruixiang Zhang
LoopCD turns the partially computed states of looped Transformers into free guidance, improving accuracy while often cutting inference compute nearly in half.
Scaling Laws for Looped Mixture of Experts
Yanbei Chen, Anirudh Goyal, Raghuraman Krishnamoorthi
This work develops scaling laws that explain how looping and sparse experts can be combined to build more capable models with less training and inference compute.
When Fancy Eviction Fails: Rethinking Cache Replacement For LLM Prefix Reuse
Yiyu Liu, Minlan Yu, Juncheng Yang
For LLM prefix caches, simple recency may beat fancy eviction rules, especially when workloads follow predictable session patterns.