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

Sep 29, 2026

Efficiently Approximating Attention Is Hard

Softmax attention is ubiquitous in modern machine learning, but its quadratic scaling with sequence length makes it costly. To reduce this cost, attention is often approximated with fast algorithms, which incur error but can still perform well in practice and on some inputs. At the same time, the growing diversity of attention applications makes approximation guarantees that do not depend on particular input structure a compelling target. For such uniform guarantees over all inputs, known runtime lower bounds rule out fast algorithms for near-exact attention, but leave open the practically important regime: is there an efficient algorithm with even a modest uniform approximation guarantee? We answer this question negatively. Under standard complexity-theoretic assumptions, no truly subquadratic algorithm can approximate attention with any nontrivial additive or relative guarantee uniformly over all inputs. This impossibility holds in the mildest parameter regime for which known algorithms do not already achieve strong approximation guarantees in near-linear time, and extends to practically relevant relaxations: even after polynomial preprocessing of the KV cache, no efficient algorithm can obtain a nontrivial uniform approximation guarantee, or identify a small set of keys receiving substantial attention under sparsity. Overall, our results settle the computational limits of uniform attention approximation.
May 22, 2026

Approaching I/O-optimality for Approximate Attention

We revisit the I/O complexity of attention in large language models. Given query-key-value matrices Q,K,V∈Rn×dQ,K,V\in\mathbb{R}^{n\times d}, and a machine with fast memory size MM, the goal is to compute the "attention matrix" A=softmax(QK⊤/d)VA=\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 nn, while a trivial lower bound only requires Ω(nd)Ω(nd) I/O's to read the inputs and write the output. In this work we show that the dependence on nn 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.
Aug 11, 2026

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

The attention mechanism forms the foundation of many modern AI models such as the Transformer. In one subclass of problems where attention is used, inputs and outputs are bound to the probability simplex so that all outputs sum to one. In this setting, softmax attention admits an exact, component-by-component quantum realization. Attention scores are Hadamard-test statistics on block-encoded projections of amplitude-encoded inputs. The exponential softmax is the interior of a cosine-squared family generated by Born-rule measurement under an exact bijection, whose boundary expresses sparse attention with exact zeros at finite parameter values. The softmax temperature is a repetition count where post-selected measurement rounds realize discretized inverse temperature exactly. Value aggregation is a deterministic column-loading channel that dilates the column-stochastic value matrix. The gated residual is the preparation angle of a single ancilla, with the additive identity at a mixing angle of ππ/2. Every learnable parameter is a rotation-gate angle. The composed layer is exact in the infinite-shot limit with one measure-and-reload step per attention score; a fully-coherent variant is εε-approximate via quantum singular value transformation in the infinite depth limit. The algebraic core is machine-checked in Lean 4.