Sublinear Time Quantum Algorithm for Attention Approximation
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 , the attention module is defined as where with applied entrywise, . The attention module is the backbone of modern transformers and large language models, but explicitly forming the softmax matrix incurs time, motivating numerous approximation schemes that reduce runtime to via sparsity or low-rank factorization. We propose a quantum data structure that approximates any row of using only row queries to . Our algorithm preprocesses these matrices in time, where is the target accuracy and is the -statistical dimension of the exponential kernel defined by and . Each row query can be answered in time. If every row sum of exceeds , then with probability the answers have Frobenius-norm error . Here is close to when every row sum is much larger than . To our knowledge, this is the first quantum data structure that approximates rows of the attention matrix in sublinear time with respect to . Our approach relies on a quantum Nyström approximation of the exponential kernel, quantum multivariate mean estimation for computing , and quantum sampling of the rows of by their squared norms, with a median over independent samples, for the multiplication with .
Figures & tables
| Sequence length | Value dimension | Number of layers | Number of heads | |
|---|---|---|---|---|
| OLMo2-1B | 4096 | 128 | 16 | 16 |
| OLMo2-7B | 4096 | 128 | 32 | 32 |
| OLMo2-1B | 0.1708 | 1.3769 | 11.3137 | 1.7126 | 2.7439 |
| OLMo2-7B | 0.1685 | 1.3586 | 11.3137 | 2.1345 | 2.7439 |