arXiv(opens in a new tab)cs.LGSep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.35349

Quasi Linear Kernel Attention with Infinite Capacity

Nicolaj Rux, Johannes Hertrich, Sebastian Neumayer

ABSTRACT

The evaluation cost of transformers with softmax attention scales quadratically with sequence length. Kernel attention addresses this by replacing softmax with a more general kernel function. In this paper, we aim to identify kernels that retain the expressivity of attention while enabling quasi linear computation. To quantify expressivity, we introduce a capacity for each kernel, measuring the maximum sequence length for which the attention matrix can approximate the identity. A higher capacity thus indicates greater expressivity. We show that expressive kernels like softmax, Gauss, and Laplace have infinite capacity. In contrast, common quasi linear kernels, such as those derived from finite dimensional feature maps, exhibit finite capacity. As a solution, we propose additive kernels constructed from univariate spline and polynomial exponential kernels. We prove that these maintain infinite capacity while allowing quasi linear computation via sorting. Finally, we implement additive sorting kernels efficiently and benchmark them against modern softmax backends, demonstrating advantages for long sequences.

1 INTRODUCTION

Transformers (Vaswani et al., 2017) are the dominant architecture in language processing (Brown et al., 2020) and computer vision (Dosovitskiy et al., 2021). Their central building block is attention, which computes for query vectors q=(qm)m=1M⊆RD\boldsymbol{q} = (q_m)_{m=1}^M \subseteq \mathbb{R}^D, key vectors k=(kn)n=1N⊆RD\boldsymbol{k} = (k_n)_{n=1}^N \subseteq \mathbb{R}^D, and value vectors v=(vn)n=1N⊆RC\boldsymbol{v} = (v_n)_{n=1}^N \subseteq \mathbb{R}^C the MM attention vectors (ym)m=1M(y_m)_{m=1}^M as

ym=∑n=1NΦ(qm,kn)vn/∑n=1NΦ(qm,kn),m=1,…,M.(1)y_{m}=\sum_{n=1}^{N}\Phi(q_{m},k_{n})v_{n}\Big/\sum_{n=1}^{N}\Phi(q_{m},k_{n}),\qquad m=1,\ldots,M. \tag{1}

Most implementations use the softmax kernel Φ(q,k)=eτq⊤k\Phi(q, k) = e^{\tau q^\top k} with inverse temperature τ>0\tau > 0, which acts as similarity score between the vectors qq and kk. For M=NM = N, the computational effort scales quadratically with the sequence length NN. This has become the main computational bottleneck in practice. Current models are trained and deployed with context windows of 128k tokens and beyond (Llama Team, AI @ Meta, 2024), which involves substantial engineering effort (Dao et al., 2022; Dao, 2024). There have been several attempts to escape the quadratic complexity through approximations and windowed attention patterns; see Tay et al. (2022) for an overview.

In this paper, we focus on exact subquadratic attention, where the structure of the kernel Φ\Phi allows the computation of (1) in quasi linear time (Tsai et al., 2019). Within this class, Katharopoulos et al. (2020) achieved linear complexity by choosing kernels that factor over a finite feature map (FFM) φ:RD→RL\varphi: \mathbb{R}^D \to \mathbb{R}^L, i.e., Φ(q,k)=φ(q)⊤φ(k)\Phi(q, k) = \varphi(q)^\top \varphi(k). This construction yields symmetric positive definite (spd) kernels, which can be evaluated in linear time. However, for small LL, these approaches have been shown to admit only limited expressivity compared to softmax attention, see Schlag et al. (2021). At the same time, the cost of evaluating the finite feature map increases linearly with LL.

On the other hand, there exist several univariate kernels (namely D=1D = 1), for which the corresponding kernel sums can be evaluated exactly via quasi linear sorting algorithms. Examples are polynomial exponential kernels like the Laplace kernel (Hofmeyr, 2021) and piecewise linear kernels (Hertrich, 2024; Hertrich et al., 2024; Vialard & Boufadène, 2025). However, most of these algorithms do not generalize to higher dimensions. An exception is the Laplace kernel, for which the sums can be evaluated in quasi linear time for arbitrary D, see Langrené & Warin (2021), but the complexity depends exponentially on D, making the approach practically infeasible for D > 6.

Contribution Our goal is to identify kernels Φ\Phi such that the attention (1) is both expressive and computable in quasi linear time. To this end, we introduce the capacity of a kernel. Its definition is inspired by the associative recall experiment of Schlag et al. (2021) and measures up to which sequence length the identity can be approximated by the attention algorithm. Intuitively, this corresponds to the number of tokens that can be distinguished. Consequently, a higher capacity indicates higher expressivity. We prove that common choices have infinite capacity, including the softmax, Gauss, and Laplace kernels. This resembles the observation that their associated attention is expressive in practice. For kernels based on an FFM, we prove that the capacity is upper-bounded by the number L of considered features, reflecting their limited expressivity.

In order to achieve quasi linear attention with infinite capacity, we consider additive kernels of the form Φ(q,k)=ϕ(q1,k1)+…+ϕ(qD,kD)\Phi(q, k) = \phi(q_1, k_1) + \ldots + \phi(q_D, k_D), where ϕ\phi is a univariate kernel with quasi linear attention. For the univariate Laplace kernel ϕ(s,t)=exp⁡(−∣s−t∣)\phi(s, t) = \exp(-|s - t|) and the bump kernel ϕ(s,t)=max⁡(0,1−∣s−t∣)\phi(s, t) = \max(0, 1 - |s - t|), we prove that the capacity of both ϕ\phi and Φ\Phi is infinite, so that we obtain quasi linear attention with infinite capacity. We verify our findings in numerical experiments and provide an efficient CUDA implementation. For sequence lengths N≳2,048N \gtrsim 2,048, our implementation is faster than conventional single-precision PyTorch attention, which offers a comparable level of numerical precision and code optimization. Compared to the highly optimized half-precision FlashAttention, we reach the break-even point for N≳20,000N \gtrsim 20,000. Thanks to the quasi linear complexity of our algorithm, the advantage increases rapidly with the sequence length.

Related work Several works reduce the quadratic cost of attention by approximation, either through sparse and windowed attention patterns (Kitaev et al., 2020; Beltagy et al., 2020; Zaheer et al., 2020), or through low-rank approximations of the attention matrix (Wang et al., 2020; Xiong et al., 2021). For an extensive overview, see Tay et al. (2022). The FFM idea was refined by Choromanski et al. (2021); Peng et al. (2021); Qin et al. (2022) with feature maps tailored to the softmax kernel and by Schlag et al. (2021), who increased the feature dimension L after recognizing that it caps the attention capacity. Lower bounds on the recurrent state size required for multi-query associative recall were proven by Arora et al. (2024a). Building on this, Arora et al. (2024b) combine linear attention with sliding windows, while gated linear attention (Yang et al., 2024a) and DeltaNet (Yang et al., 2024b) use data-dependent gating and delta-rule updates of the recurrent state, respectively, to better use a fixed-size state. These models are recurrent and go beyond the normalized kernel sums considered in (1). Alternative notions of expressivity for attention mechanisms were considered in Yun et al. (2020); Furuya et al. (2025). Our proposed bump and Laplace variants have been previously considered in different contexts: Feng et al. (2026) approximate the Laplace kernel attention via a finite feature map/Nyström approach, and Vialard & Boufadène (2025) combine the univariate bump kernel with a linear or MLP layer before each attention module to project onto a single dimension. Finally, the additive kernels are related to kernel slicing, see also Appendix B.

References (76)