跳到正文
arXiv (AI + Vision + Imaging)· P\'al Andr\'as Papp, Aleksandros Sobczyk, Anastasios Zouzias·AI 评分32

近似注意力机制的 I/O 复杂度逼近最优

Approaching I/O-optimality for Approximate Attention

AI 导读

研究重新审视大语言模型注意力计算的 I/O 复杂度,提出受 Alman 与 Song [NeurIPS'23] 近似注意力方法启发的 I/O 高效算法,将 I/O 开销对上下文长度 n 的依赖从 FlashAttention 等方法的二次方降至近线性。作者同时给出不同参数区间下与上界几乎匹配的算法相关下界,表明所提算法已接近 I/O 最优。

正文 · 原文

arXiv:2605.23751v2 Announce Type: replace 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 the context length $n$, while a trivial lower bound only requires $\Omega(nd)$ I/O's to read the inputs and write the output. In this work we show that the dependence on $n$ can be reduced to almost-linear, by developing I/O-efficient algorithms inspired by the recent approximate attention method of Alman and Song [NeurIPS'23]. We also provide (algorithm-specific) lower bounds in different parameter regimes, which nearly match the corresponding upper bounds, indicating that the proposed algorithms are indeed close to I/O-optimal.

来源:arXiv (AI + Vision + Imaging) · arxiv.org