English

Sublinear Time Quantum Algorithm for Attention Approximation

Quantum Physics 2026-02-03 v1 Data Structures and Algorithms Machine Learning

Abstract

Given the query, key and value matrices Q,K,VRn×dQ, K, V\in \mathbb{R}^{n\times d}, the attention module 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 module is the backbone of modern transformers and large language models, but explicitly forming the softmax matrix D1AD^{-1}A incurs Ω(n2)\Omega(n^2) time, 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\"om approximation of the exponential kernel, quantum multivariate mean estimation for computing DD, and quantum leverage score sampling for the multiplication with VV.

Cite

@article{arxiv.2602.00874,
  title  = {Sublinear Time Quantum Algorithm for Attention Approximation},
  author = {Zhao Song and Jianfei Xue and Jiahao Zhang and Lichen Zhang},
  journal= {arXiv preprint arXiv:2602.00874},
  year   = {2026}
}

Comments

ICLR 2026

R2 v1 2026-07-01T09:29:40.503Z