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 79 papers →Latent Feedback Is a Compute and Data Amplifier
Benhao Huang, Chaitanya Dwivedi, Xuezhe Ma, Alexander Moreno, Hector Liu
Latent feedback may let language models get more value from each training token and FLOP than simply repeating the data.
MACaQ: Fast, Model Agnostic Calibrated Quantization for Low-Precision Weights and Activations
Lorenz K. Muller, Philippe Bich, Chiara Boretti, Hyun-Min Chang, Jiawei Zhuang, Lukas Cavigelli
MACaQ aims to make large neural networks cheaper to run by quantizing their weights and activations quickly, with little added inference overhead.
Mobile AI Factory: Building Specialized Language Models for Your Mobile Device
Evan Li, Krishna Deshpande, Wen Cheng, Shyamnath Gollakota
Mobile AI Factory automatically builds and tunes a small language model for a specific task and phone, aiming to deliver strong performance with less compute.