quant-phJan 31, 2026

Sublinear Time Quantum Algorithm for Attention Approximation

Authors: Zhao Song, Jianfei Xue, Jiahao Zhang, Lichen Zhang

Organizations: Simons Institute for the Theory of Computing, UC Berkeley. · New York University. · Massachusetts Institute of Technology.

Abstract

Given the query, key and value matrices Q,K,V∈Rn×dQ, K, V\in \mathbb{R}^{n\times d}, the attention module is defined as Att(Q,K,V)=D−1AV\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\mathbf{1}_n). The attention module is the backbone of modern transformers and large language models, but explicitly forming the softmax matrix D−1AD^{-1}A incurs Ω(n2)Ω(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λ3+sλ2d+d)+ε−2sλd)\widetilde{O}(ε^{-1} n^{0.5} (s_λ^{3} + s_λ^{2} d + d) + ε^{-2} s_λd) time, where εε is the target accuracy and sλs_λ is the λλ-statistical dimension of the exponential kernel defined by QQ and KK. Each row query can be answered in O~(sλ2+sλd)\widetilde{O}(s_λ^2 + s_λd) time. If every row sum of AA exceeds ε∥A∥+λnε\|A\|+λ\sqrt n, then with probability 1−1/poly(n)1-1/\mathrm{poly}(n) the answers have Frobenius-norm error O(β∥D−1∥(ε∥A∥F+λn)∥V∥F)O(β\|D^{-1}\|(ε\|A\|_F+λ\sqrt n)\|V\|_F). Here β=(1−(ε∥A∥+λn)∥D−1∥)−1≥1β=(1-(ε\|A\|+λ\sqrt n)\|D^{-1}\|)^{-1}\geq 1 is close to 11 when every row sum is much larger than ε∥A∥+λnε\|A\|+λ\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 nn. Our approach relies on a quantum Nyström approximation of the exponential kernel, quantum multivariate mean estimation for computing DD, and quantum sampling of the rows of VV by their squared norms, with a median over independent samples, for the multiplication with VV.

Figures & tables

Explore similar work

CardsList
  1. Efficiently Approximating Attention Is Hard

    Sep 29, 2026Lukas Haverbeck, Carmen Amo Alonso, Andres Felipe Posada-Moreno +2Attention ApproximationEfficient Attention

  2. Approaching I/O-optimality for Approximate Attention

    May 22, 2026Pál András Papp, Aleksandros Sobczyk, Anastasios ZouziasSelf-AttentionEfficient Attention

  3. A Quantum Roadmap for Softmax Attention: Exact Born-Rule Analogs for Softmax Attention on the Probability Simplex

    Aug 11, 2026Eric A. F. Reinhardt, Adam J. HauserSoftmax AttentionQuantum Machine Learning