Manuscript Offprint

arXiv:2611.06055

Softmax Attention with Any Temperature in Fixed Dimension: Matching the Best Known Maximum-Inner-Product Bounds

Zixuan Huang, Guozhang Chen

Abstract

Attention is central to modern AI models for language, vision, and scientific modeling. However, direct evaluation compares every query with every key, requiring quadratic time in the context length, which limits its scalability to long contexts. Consequently, characterizing the complexity bounds of attention is of fundamental importance.

For every fixed dimension dd, we give an algorithm for mm queries, nn key-value pairs, and additive error ε\varepsilon, with expected time

O~((mn)k/(k+1)+m+n),k=⌊d/2⌋.\tilde{O}((mn)^{k/(k+1)}+m+n),\qquad k=\lfloor d/2\rfloor.

For fixed dimension and a fixed number of value channels, soft-O hides factors of the form polyd(b,log⁡(m+n),log⁡B,log⁡(1/ε))\text{poly}_d(b,\log(m+n),\log B,\log(1/\varepsilon)), where bb bounds input encoding lengths and BB bounds coordinate and value magnitudes. In particular, the dependence on BB and 1/ε1/\varepsilon is polylogarithmic, which allows arbitrary positive temperature. When m=nm=n and d≥2d\geq 2, the bound is \tilde{O}(n^{2-2/(\lfloor d/2\rfloor+1)): near-linear in dimensions two and three, with exponent 4/34/3 in dimensions four and five and 3/23/2 in dimensions six and seven. It improves the previous O~(n2−1/d)\tilde{O}(n^{2-1/d}) upper bound and matches the best known batch maximum-inner-product bound in each fixed dimension. Additionally, we reduce integer batch maximum inner product computation to one attention call with the same dimension and input sizes m,nm,n.

*Corresponding author.

Contents 1 Introduction 1 1.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Technical Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2.1 Normalization and the Planar Base Case . . . . . . . . . . . . . . . . . . . . . 4 1.2.2 Temperature Interpolation and Common-Anchor Blocks . . . . . . . . . . . . 5 1.2.3 Random Prefix Chains and Heavy/Light Recursion . . . . . . . . . . . . . . . 6 1.3 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2 Preliminaries 9 2.1 Computation and Error Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.2 Random Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.3 Analytic Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3 A Dimension-Preserving Reduction from Maximum Inner Product 13 3.1 Computing Exact Maxima from Attention . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2 Conditional Hardness in Superconstant Dimension . . . . . . . . . . . . . . . . . . . 14 4 A Deterministic Algorithm in Two Dimensions 14 4.1 Shifted-Kernel Products in the Plane . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.2 Centering and Radial Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.3 Radial and Boundary Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.4 Polynomial Approximation and Moment Sweeps . . . . . . . . . . . . . . . . . . . . 17 4.5 Kernel Products and Attention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.6 Online Queries after Preprocessing the Keys . . . . . . . . . . . . . . . . . . . . . . . 19 5 Shifted Kernels and Dimension Induction 19 5.1 Exact Maxima and Normalized Directions . . . . . . . . . . . . . . . . . . . . . . . . 20 5.2 Shifted-Kernel Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.3 Biased Products and Temperature Interpolation . . . . . . . . . . . . . . . . . . . . . 21 5.4 The Induction on the Dimension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 6 Geometric Data Structures in Fixed Dimension 23 6.1 Classical Geometric Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 6.2 Support Queries and Strict Reporting . . . . . . . . . . . . . . . . . . . . . . . . . . 23 6.3 Envelope Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 6.4 Sampling Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 7 Biased Exponential Products and the Main Theorem 25 7.1 Orientations, Hits, and Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 7.2 Anchor Blocks and Direct Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 7.3 Random Prefix Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 7.4 The Full Random Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 7.5 Truncated Prefixes and the Heavy/Light Recursion . . . . . . . . . . . . . . . . . . . 33 7.6 Error Analysis and the Proof of Proposition 5.6 . . . . . . . . . . . . . . . . . . . . . 34 7.7 Proof of Theorem 1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 8 A Static-Query Comparison with Semigroup Halfplane Aggregation 35 ii

9 Conclusion and Further Directions 36

A Numerical Stability and Precision 38 A.1 Input Size, Temperature, and Reduction Cost ..... 38 A.2 Arithmetic for Planar Kernel Products ..... 38 A.3 Arithmetic for Biased Block Products ..... 41 A.4 Precision under Composition and Recursion ..... 41 A.5 Exact Geometric Computation ..... 42 A.6 Uniform Perturbations and Caps ..... 43 A.7 Support Queries and Envelope Construction ..... 44 A.8 Interior Shifts for Cell Location ..... 45 A.9 Integer Encodings of Halfspace Ranges ..... 45

B Geometric Constructions and Sampling Proofs 45 B.1 Classical Polytope Facts ..... 45 B.2 Constructing Cuttings with a Fixed Bounding Simplex ..... 46 B.3 Strict Halfspace Reporting ..... 51 B.4 Canonical Cells and Point Location ..... 51 B.5 Sampling and Potential Estimates ..... 53 B.6 Implementing Batch Maximum Inner Product ..... 54

AI Methodology 56

Acknowledgment 56

References 56

iii

1 Introduction

Transformers and related attention-based architectures are central to modern AI, with wide applications in areas such as language processing [VSP+17], visual recognition [DBK+21], and biomolecular structure prediction [AAD+24]. By exponentiating query-key inner products into a sharp distribution concentrated on the most relevant keys, attention also exhibits close connections to classical problems in Theoretical Computer Science (TCS), such as Maximum Inner Product (Max-IP) problem, making it a fundamental subject of study in TCS.

As frontier problems grow in complexity, extending the context length of Transformers has become essential. However, the cost of direct attention evaluation grows quadratically, with n2n^2 pairwise interactions for a context of length nn even in fixed dimension. This quadratic bottleneck restricts the deployment of Transformers in a wide range of long-context applications, such as repository-level code generation or full-document analysis.

Practical algorithms reduce the cost of attention through memory-efficient exact evaluation, as in FlashAttention [DFERR22], and random-feature approximation with provable error guarantees, as in Performer [CLD+21]. Nevertheless, these methods did not establish a non-trivial asymptotic upper bound for attention that faithfully preserves the exact softmax semantics. Establishing theoretical upper bounds for attention helps us delineate the fundamental boundaries of where attention can be applied.

Formally, softmax attention maps queries, keys, and values to normalized exponential averages. For query vectors q1,…,qm∈Rd\boldsymbol{q}_1, \ldots, \boldsymbol{q}_m \in \mathbb{R}^d, key vectors k1,…,kn∈Rd\boldsymbol{k}_1, \ldots, \boldsymbol{k}_n \in \mathbb{R}^d, and scalar values v1,…,vnv_1, \ldots, v_n, the output associated with query qi\boldsymbol{q}_i is

∑j=1neqi⋅kjvj∑j=1neqi⋅kj.\frac{\sum_{j=1}^n \mathrm{e}^{\boldsymbol{q}_i \cdot \boldsymbol{k}_j} v_j}{\sum_{j=1}^n \mathrm{e}^{\boldsymbol{q}_i \cdot \boldsymbol{k}_j}}.

More generally, each key kj\boldsymbol{k}_j carries a vector vj=(vj1,…,vjr)\boldsymbol{v}_j = (v_{j1}, \ldots, v_{jr}) of rr values, one for each value channel, and the output of a query has one such average for each channel. Direct evaluation processes all mnmn query-key pairs, although the input and output sizes are only linear in m+nm+n when the dimension and number of value channels are fixed.

An inverse temperature β>0\beta > 0 rescales each score to βqi⋅kj\beta \boldsymbol{q}_i \cdot \boldsymbol{k}_j and is absorbed into the query coordinates. The polylogarithmic dependence on coordinate magnitudes therefore extends the computational bounds to every positive rational temperature (Remark 2.3).

Gupta, Huang, Saha, Xu, and Ye [GHSXY26] gave an algorithm with running time

O~(n2−1/d)\widetilde{\mathrm{O}}(n^{2-1/d})

for every fixed dimension dd. For each query, their algorithm retains keys whose scores lie within a logarithmic window of the row maximum and approximates the exponential on that window by a polynomial. It evaluates the resulting monomial sums with a simplex range-searching data structure [Mat92b], whose query cost yields the exponent 2−1/d2-1/d. Their reduction from maximum inner product also established conditional hardness in dimension 2O(log⁡∗n)2^{\mathrm{O}(\log^* n)} via the lower bound of Chen [Che20]. They further observe that attention whose query or key matrix has rank at most dd reduces to dimension dd through a rank factorization [GHSXY26, Theorem 1.2], so fixed-dimensional algorithms also apply to low-rank attention with a large head dimension. Additionally, they gave a reduction from dd-dimensional Max-IP to (d+1)(d+1)-dimensional attention, where Max-IP is the natural geometric core of attention: given query vectors xi\boldsymbol{x}_i and points yj\boldsymbol{y}_j, the batch problem asks for all maxima Mi=max⁡jxi⋅yjM_i = \max_j \boldsymbol{x}_i \cdot \boldsymbol{y}_j.

However, the above upper bound is not sufficiently tight, considering that in fixed dimension dd, the best known algorithms answer mm maximum-inner-product queries on nn points in O~((mn)k/(k+1)+m+\widetilde{\mathrm{O}}((mn)^{k/(k+1)}+m+

n)n) time, where k=⌊d/2⌋k=\lfloor d/2\rfloor [MS93; Cha96b]; for d≤3d\leq 3 this is near-linear [PS85; DK90]. Furthermore, because the reduction increases the dimension by one, one cannot obtain non-trivial hardness for 4-dimensional attention.

While Max-IP only seeks the extreme inner product, computing attention requires aggregating the exponentially weighted contributions of all keys. This leaves the question whether the global aggregation in softmax attention makes it strictly harder than Max-IP, or if we can still match the best known complexity of batch Max-IP and give a dimension-preserving reduction in every fixed dimension.

In this work, we study the bit complexity of softmax attention, with prescribed entrywise additive error ε\varepsilon. Our running-time bounds depend polynomially on the input encoding length and on log⁡(1/ε)\log(1/\varepsilon), so inverse-polynomial error contributes only polylogarithmic factors.

References (61)