跳到正文
arXiv (AI + Vision + Imaging)· Zhao Song, Jianfei Xue, Jiahao Zhang, Lichen Zhang·· 1 天前AI 评分22

面向注意力近似的亚线性时间量子算法

Sublinear Time Quantum Algorithm for Attention Approximation

AI 导读

研究提出一种量子数据结构,仅通过行查询即可近似计算注意力模块 Att(Q, K, V) 的任意一行,预处理时间为 Õ(ε⁻¹n^0.5(s_λ³+s_λ²d+d)+ε⁻²s_λd),单次行查询耗时 Õ(s_λ²+s_λd)。据称这是首个相对 n 达到亚线性时间的注意力矩阵行近似量子数据结构,方法基于指数核的量子 Nyström 近似、量子多元均值估计与按行范数平方的量子采样。

正文 · 原文

arXiv:2602.00874v2 Announce Type: replace-cross Abstract: Given the query, key and value matrices $Q, K, V\in \mathbb{R}^{n\times d}$, the attention module is defined as $\mathrm{Att}(Q, K, V)=D^{-1}AV$ where $A=\exp(QK^\top/\sqrt{d})$ with $\exp(\cdot)$ applied entrywise, $D=\mathrm{diag}(A\mathbf{1}_n)$. The attention module is the backbone of modern transformers and large language models, but explicitly forming the softmax matrix $D^{-1}A$ incurs $\Omega(n^2)$ time, motivating numerous approximation schemes that reduce runtime to $\widetilde O(nd)$ via sparsity or low-rank factorization. We propose a quantum data structure that approximates any row of $\mathrm{Att}(Q, K, V)$ using only row queries to $Q, K, V$. Our algorithm preprocesses these matrices in $\widetilde{O}(\epsilon^{-1} n^{0.5} (s_\lambda^{3} + s_\lambda^{2} d + d) + \epsilon^{-2} s_\lambda d)$ time, where $\epsilon$ is the target accuracy and $s_\lambda$ is the $\lambda$-statistical dimension of the exponential kernel defined by $Q$ and $K$. Each row query can be answered in $\widetilde{O}(s_\lambda^2 + s_\lambda d)$ time. If every row sum of $A$ exceeds $\epsilon\|A\|+\lambda\sqrt n$, then with probability $1-1/\mathrm{poly}(n)$ the answers have Frobenius-norm error $O(\beta\|D^{-1}\|(\epsilon\|A\|_F+\lambda\sqrt n)\|V\|_F)$. Here $\beta=(1-(\epsilon\|A\|+\lambda\sqrt n)\|D^{-1}\|)^{-1}\geq 1$ is close to $1$ when every row sum is much larger than $\epsilon\|A\|+\lambda\sqrt n$. To our knowledge, this is the first quantum data structure that approximates rows of the attention matrix in sublinear time with respect to $n$. Our approach relies on a quantum Nystr\"om approximation of the exponential kernel, quantum multivariate mean estimation for computing $D$, and quantum sampling of the rows of $V$ by their squared norms, with a median over independent samples, for the multiplication with $V$.

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