ICLR2026

Sublinear Time Quantum Algorithm for Attention Approximation

Zhao Song, Jianfei Xue, Jiahao Zhang, Lichen Zhang

1 citation

Abstract

Given the query, key and value matrices Q,K,VRn×dQ, K, V\in \mathbb{R}^{n\times d}, the attention matrix is defined as Att(Q,K,V)=D1AV\mathrm{Att}(Q, K, V)=D^{-1}AV where A=exp(QK/d)A=\exp(QK^\top/\sqrt{d}) with exp()\exp(\cdot) applied entrywise, D=diag(A1n)D=\mathrm{diag}(A{\bf 1}_n). The attention matrix is the backbone of modern transformers and large language models, but explicitly forming the softmax matrix D1AD^{-1}A incurs Ω(n2)\Omega(n^2), motivating numerous approximation schemes that reduce runtime to O~(nd)\widetilde O(nd) via sparsity or low-rank factorization.

We propose a quantum data structure that approximates any row of Att(Q,K,V)\mathrm{Att}(Q, K, V) using only row queries to Q,K,VQ, K, V. Our algorithm preprocesses these matrices in O~(ϵ1n0.5(sλ2.5+sλ1.5d+α0.5d))\widetilde{O}\left( \epsilon^{-1} n^{0.5} \left( s_\lambda^{2.5} + s_\lambda^{1.5} d + \alpha^{0.5} d \right) \right) time, where ϵ\epsilon is the target accuracy, sλs_\lambda is the λ\lambda-statistical dimension of the exponential kernel defined by QQ and KK, and α\alpha measures the row distortion of VV that is at most d/srank(V)d/{\rm srank}(V), the stable rank of VV. Each row query can be answered in O~(sλ2+sλd)\widetilde{O}(s_\lambda^2 + s_\lambda d) time.

To our knowledge, this is the first quantum data structure that approximates rows of the attention matrix in sublinear time with respect to nn. Our approach relies on a quantum Nyström approximation of the exponential kernel, quantum multivariate mean estimation for computing DD, and quantum leverage score sampling for the multiplication with VV.