Performers and FAVOR+: How Positive Orthogonal Random Features Linearize Transformer Attention

The quadratic complexity of standard self-attention has remained a central computational ceiling in Transformer architectures. Because standard attention computes pairwise similarity across all token pairs in a sequence of length $L$, memory consumption and compute scale as $O(L^2)$. For long contexts, high-resolution visual tokens, and biological sequence modeling, this quadratic bottleneck forces strict sequence truncation or aggressive hardware partitioning. In Rethinking Attention with Perf

9 min
Performers and FAVOR+: How Positive Orthogonal Random Features Linearize Transformer Attention

The quadratic complexity of standard self-attention has remained a central computational ceiling in Transformer architectures. Because standard attention computes pairwise similarity across all token pairs in a sequence of length LL, memory consumption and compute scale as O(L2)O(L^2). For long contexts, high-resolution visual tokens, and biological sequence modeling, this quadratic bottleneck forces strict sequence truncation or aggressive hardware partitioning.

In Rethinking Attention with Performers, Choromanski et al. (2020) introduced the Performer architecture powered by FAVOR+ (Fast Attention Via Positive Orthogonal Random Features). Unlike low-rank approximations or sparse attention patterns that alter the model's receptive field, FAVOR+ establishes an unbiased, low-variance mathematical estimator of the full-rank softmax attention matrix that operates in O(L)O(L) linear time and space.

Technical schematic illustrating matrix associativity and positive orthogonal random feature mapping in linear attention

1. The Quadratic Bottleneck in Scaled Dot-Product Attention

Standard scaled dot-product attention, formalized by Vaswani et al. (2017), maps queries Q∈RL×dQ \in \mathbb{R}^{L \times d}, keys K∈RL×dK \in \mathbb{R}^{L \times d}, and values V∈RL×dvalV \in \mathbb{R}^{L \times d_{\text{val}}} through an explicit attention matrix AA:

Attn(Q,K,V)=D−1AV\text{Attn}(Q, K, V) = D^{-1} A V

where the raw affinity matrix A∈RL×LA \in \mathbb{R}^{L \times L} and the normalizer diagonal matrix D∈RL×LD \in \mathbb{R}^{L \times L} are defined as:

A=exp⁡(QKTd),D=diag(A1L)A = \exp\left(\frac{Q K^T}{\sqrt{d}}\right), \quad D = \text{diag}(A \mathbf{1}_L)

Here, exp⁡(⋅)\exp(\cdot) denotes element-wise exponentiation and 1L\mathbf{1}_L is an all-ones column vector of length LL.

The quadratic cost stems directly from the matrix product QKTQ K^T. Constructing AA requires calculating L2L^2 pairwise inner products and storing an L×LL \times L activation map in GPU memory for the backward pass. Because softmax normalizes rows after exponentiation, the operations cannot be rearranged using standard matrix associativity:

(QKT)V≠Q(KTV)(Q K^T) V \neq Q (K^T V)

If AA could be factored into the product of two low-dimensional feature representations, A≈Q′(K′)TA \approx Q' (K')^T where Q′,K′∈RL×MQ', K' \in \mathbb{R}^{L \times M} with M≪LM \ll L, matrix associativity would allow computing (K′)TV∈RM×dval(K')^T V \in \mathbb{R}^{M \times d_{\text{val}}} first in O(LMdval)O(L M d_{\text{val}}) time, followed by left-multiplication by Q′Q' in O(LMdval)O(L M d_{\text{val}}) time.


2. Attention as a Continuous Kernel Evaluation

To linearize the attention mechanism without restricting the attention matrix rank, Choromanski et al. (2020) reframed attention elements as continuous kernel evaluations. For a query vector qi∈Rdq_i \in \mathbb{R}^d and a key vector kj∈Rdk_j \in \mathbb{R}^d, the unnormalized attention affinity is:

Ker(qi,kj)=exp⁡(qiTkjd)\text{Ker}(q_i, k_j) = \exp\left(\frac{q_i^T k_j}{\sqrt{d}}\right)

By defining scaled vectors x=qi/d1/4x = q_i / d^{1/4} and y=kj/d1/4y = k_j / d^{1/4}, the kernel simplifies to the generalized exponential kernel:

Kexp(x,y)=exp⁡(xTy)K_{\text{exp}}(x, y) = \exp(x^T y)

Under classic kernel theory, any positive definite kernel K(x,y)K(x, y) can be decomposed as an inner product in a high-dimensional feature space H\mathcal{H}:

K(x,y)=⟨Φ(x),Φ(y)⟩H=Eω[ϕ(x;ω)Tϕ(y;ω)]K(x, y) = \langle \Phi(x), \Phi(y) \rangle_{\mathcal{H}} = \mathbb{E}_{\omega}\left[ \phi(x; \omega)^T \phi(y; \omega) \right]

where ϕ(⋅;ω):Rd→RM\phi(\cdot; \omega): \mathbb{R}^d \to \mathbb{R}^M represents a randomized feature mapping parameterized by random vector ω\omega. If an empirical estimator K^(x,y)=ϕ(x)Tϕ(y)\hat{K}(x, y) = \phi(x)^T \phi(y) provides an unbiased approximation of exp⁡(xTy)\exp(x^T y), the full attention computation becomes:

Attn(Q,K,V)i=∑j=1Lϕ(qi)Tϕ(kj)vj∑j=1Lϕ(qi)Tϕ(kj)=ϕ(qi)T∑j=1Lϕ(kj)vjTϕ(qi)T∑j=1Lϕ(kj)\text{Attn}(Q, K, V)_i = \frac{\sum_{j=1}^L \phi(q_i)^T \phi(k_j) v_j}{\sum_{j=1}^L \phi(q_i)^T \phi(k_j)} = \frac{\phi(q_i)^T \sum_{j=1}^L \phi(k_j) v_j^T}{\phi(q_i)^T \sum_{j=1}^L \phi(k_j)}

By pulling the query feature ϕ(qi)T\phi(q_i)^T outside the summation over sequence index jj, the key and value interactions can be pre-aggregated across the entire sequence into a global context tensor S=∑j=1Lϕ(kj)vjT∈RM×dvalS = \sum_{j=1}^L \phi(k_j) v_j^T \in \mathbb{R}^{M \times d_{\text{val}}} and a normalizer vector z=∑j=1Lϕ(kj)∈RMz = \sum_{j=1}^L \phi(k_j) \in \mathbb{R}^M.


3. Why Random Fourier Features Fail for Softmax Attention

Approximating shift-invariant kernels via randomized features was pioneered by Rahimi and Recht (2007) using Random Fourier Features (RFF). For a standard Gaussian radial basis function (RBF) kernel Kgauss(x,y)=exp⁡(−∥x−y∥2/2)K_{\text{gauss}}(x, y) = \exp(-\|x - y\|^2 / 2), Bochner's Theorem guarantees that the Fourier transform of the kernel is a valid probability distribution N(0,Id)\mathcal{N}(0, I_d).

The exponential kernel can be rewritten in terms of the Gaussian kernel:

exp⁡(xTy)=exp⁡(−∥x−y∥22)exp⁡(∥x∥2+∥y∥22)=Kgauss(x,y)exp⁡(∥x∥22)exp⁡(∥y∥22)\exp(x^T y) = \exp\left(-\frac{\|x - y\|^2}{2}\right) \exp\left(\frac{\|x\|^2 + \|y\|^2}{2}\right) = K_{\text{gauss}}(x, y) \exp\left(\frac{\|x\|^2}{2}\right) \exp\left(\frac{\|y\|^2}{2}\right)

Applying trigonometric Random Fourier Features to approximate Kgauss(x,y)K_{\text{gauss}}(x, y) yields the trigonometric mapping:

ϕtrig(x)=exp⁡(∥x∥2/2)M[cos⁡(ω1Tx),sin⁡(ω1Tx),…,cos⁡(ωMTx),sin⁡(ωMTx)]T\phi_{\text{trig}}(x) = \frac{\exp(\|x\|^2 / 2)}{\sqrt{M}} \left[ \cos(\omega_1^T x), \sin(\omega_1^T x), \dots, \cos(\omega_M^T x), \sin(\omega_M^T x) \right]^T

where ωm∼N(0,Id)\omega_m \sim \mathcal{N}(0, I_d).

While E[ϕtrig(x)Tϕtrig(y)]=exp⁡(xTy)\mathbb{E}[\phi_{\text{trig}}(x)^T \phi_{\text{trig}}(y)] = \exp(x^T y) is mathematically unbiased, trigonometric features exhibit severe failure modes when applied to self-attention:

  1. Negative Affinity Estimates: Because cosine and sine fluctuate across [−1,1][-1, 1], the inner product ϕtrig(x)Tϕtrig(y)\phi_{\text{trig}}(x)^T \phi_{\text{trig}}(y) can evaluate to negative values. The true softmax kernel is strictly positive (exp⁡(xTy)>0\exp(x^T y) > 0).
  2. Normalizer Collapse and Division by Zero: When summing over sequence length LL, the denominator ∑j=1Lϕtrig(qi)Tϕtrig(kj)\sum_{j=1}^L \phi_{\text{trig}}(q_i)^T \phi_{\text{trig}}(k_j) can approach zero or turn negative, causing numerical singularity, gradient explosions, and training divergence.
  3. High Variance in Tails: For large queries and keys where xTyx^T y is large, the variance of ϕtrig\phi_{\text{trig}} scales exponentially with ∥x∥2+∥y∥2\|x\|^2 + \|y\|^2, requiring an impractical number of random features (M≫103M \gg 10^3) to stabilize training.

4. Positive Random Features (PRF)

To overcome the catastrophic instability of trigonometric projections, Choromanski et al. (2020) constructed Positive Random Features (PRF).

Consider the moment-generating function of a standard multivariate Gaussian variable ω∼N(0,Id)\omega \sim \mathcal{N}(0, I_d). For any deterministic vector u∈Rdu \in \mathbb{R}^d:

Eω∼N(0,Id)[exp⁡(ωTu)]=exp⁡(∥u∥22)\mathbb{E}_{\omega \sim \mathcal{N}(0, I_d)}\left[ \exp(\omega^T u) \right] = \exp\left(\frac{\|u\|^2}{2}\right)

Setting u=x+yu = x + y, the expectation expands as:

Eω[exp⁡(ωT(x+y))]=exp⁡(∥x+y∥22)=exp⁡(∥x∥2+∥y∥2+2xTy2)\mathbb{E}_{\omega}\left[ \exp(\omega^T (x + y)) \right] = \exp\left(\frac{\|x + y\|^2}{2}\right) = \exp\left(\frac{\|x\|^2 + \|y\|^2 + 2 x^T y}{2}\right)

Rearranging terms to isolate exp⁡(xTy)\exp(x^T y) yields the identity:

exp⁡(xTy)=exp⁡(−∥x∥22)Eω∼N(0,Id)[exp⁡(ωTx)exp⁡(ωTy)]exp⁡(−∥y∥22)\exp(x^T y) = \exp\left(-\frac{\|x\|^2}{2}\right) \mathbb{E}_{\omega \sim \mathcal{N}(0, I_d)}\left[ \exp(\omega^T x) \exp(\omega^T y) \right] \exp\left(-\frac{\|y\|^2}{2}\right)

Because the expectations and scalar exponential factors distribute linearly, the product can be combined under a single expectation:

exp⁡(xTy)=Eω∼N(0,Id)[exp⁡(ωTx−∥x∥22)exp⁡(ωTy−∥y∥22)]\exp(x^T y) = \mathbb{E}_{\omega \sim \mathcal{N}(0, I_d)}\left[ \exp\left(\omega^T x - \frac{\|x\|^2}{2}\right) \exp\left(\omega^T y - \frac{\|y\|^2}{2}\right) \right]

This gives the positive random feature map ϕpos(x):Rd→R>0M\phi_{\text{pos}}(x): \mathbb{R}^d \to \mathbb{R}_{>0}^M:

ϕpos(x)=1Mexp⁡(−∥x∥22)[exp⁡(ω1Tx)exp⁡(ω2Tx)⋮exp⁡(ωMTx)]\phi_{\text{pos}}(x) = \frac{1}{\sqrt{M}} \exp\left(-\frac{\|x\|^2}{2}\right) \begin{bmatrix} \exp(\omega_1^T x) \\ \exp(\omega_2^T x) \\ \vdots \\ \exp(\omega_M^T x) \end{bmatrix}

Because the exponential function maps real numbers strictly to positive values (exp⁡(z)>0\exp(z) > 0 for all z∈Rz \in \mathbb{R}), every entry of ϕpos(x)\phi_{\text{pos}}(x) is strictly positive. Consequently:

ϕpos(qi)Tϕpos(kj)>0∀qi,kj∈Rd\phi_{\text{pos}}(q_i)^T \phi_{\text{pos}}(k_j) > 0 \quad \forall q_i, k_j \in \mathbb{R}^d

This guarantees that all estimated attention weights and sequence normalizers remain strictly positive, eliminating division-by-zero singularities without heuristic thresholding or epsilon padding.

Standard Softmax Attention (O(L^2) Complexity):
  Q (L x d) ---> [ Q * K^T ] (L x L) ---> Softmax ---> [ Attn * V ] (L x d_val)
                    |
              Quadratic Memory & Compute Bottleneck

FAVOR+ Linear Attention (O(L * M) Complexity):
  Q (L x d) ---> phi(Q) (L x M) ---\
                                    \---> [ phi(Q) * (phi(K)^T * V) ] (L x d_val)
  K (L x d) ---> phi(K) (L x M) ----/              \
  V (L x d_val) ----------------------------------- Context Tensor S (M x d_val)

5. Orthogonal Random Features (ORF)

While positive random features eliminate negative attention weights, sampling ω1,…,ωM\omega_1, \dots, \omega_M independently from N(0,Id)\mathcal{N}(0, I_d) introduces estimation variance. If two sampled vectors ωi\omega_i and ωj\omega_j are nearly collinear, they provide redundant information while failing to cover orthogonal subspaces of Rd\mathbb{R}^d.

To minimize estimator variance, FAVOR+ incorporates Orthogonal Random Features (ORF), extending techniques by Yu et al. (2016).

Instead of independent Gaussian sampling, the projection matrix W∈RM×dW \in \mathbb{R}^{M \times d} (where M=b⋅dM = b \cdot d for integer block count bb) is constructed in blocks of d×dd \times d orthogonal matrices:

  1. Sample a random Gaussian matrix G∈Rd×dG \in \mathbb{R}^{d \times d} with entries Gi,j∼N(0,1)G_{i,j} \sim \mathcal{N}(0, 1).
  2. Apply QR decomposition G=QorthRG = Q_{\text{orth}} R, where Qorth∈Rd×dQ_{\text{orth}} \in \mathbb{R}^{d \times d} is an exact orthogonal matrix (QorthTQorth=IdQ_{\text{orth}}^T Q_{\text{orth}} = I_d).
  3. Scale each row of QorthQ_{\text{orth}} by an independent radial sample from the chi-distribution with dd degrees of freedom: Sdiag=diag(χ1(d),…,χd(d))S_{\text{diag}} = \text{diag}(\chi_1(d), \dots, \chi_d(d)).
  4. Set the block projection matrix to Wblock=SdiagQorthW_{\text{block}} = S_{\text{diag}} Q_{\text{orth}}.

Stacking bb such orthogonal blocks yields W∈RM×dW \in \mathbb{R}^{M \times d}. By enforcing strict orthogonality among rows within each block (ωiTωj=0\omega_i^T \omega_j = 0 for i≠ji \neq j), ORFs maintain the exact marginal distribution N(0,Id)\mathcal{N}(0, I_d) for every individual vector while ensuring that feature dimensions do not duplicate directional coverage.

Choromanski et al. (2020) proved that Orthogonal Positive Random Features strictly reduce the mean squared error (MSE) of the kernel estimator across all sequence lengths compared to standard i.i.d. random features, enabling Performers to achieve high approximation fidelity with relatively small feature counts (M∈[d,4d]M \in [d, 4d]).


6. Causal Masking and Recurrent O(1)O(1) Inference

In autoregressive language models, tokens must not attend to future positions. The attention output for position ii must only incorporate keys and values from indices j≤ij \le i:

Attncausal(Q,K,V)i=∑j=1iϕ(qi)Tϕ(kj)vj∑j=1iϕ(qi)Tϕ(kj)=ϕ(qi)T(∑j=1iϕ(kj)vjT)ϕ(qi)T(∑j=1iϕ(kj))\text{Attn}_{\text{causal}}(Q, K, V)_i = \frac{\sum_{j=1}^i \phi(q_i)^T \phi(k_j) v_j}{\sum_{j=1}^i \phi(q_i)^T \phi(k_j)} = \frac{\phi(q_i)^T \left( \sum_{j=1}^i \phi(k_j) v_j^T \right)}{\phi(q_i)^T \left( \sum_{j=1}^i \phi(k_j) \right)}

This formulation unlocks two structural computational efficiencies:

Parallel Prefix Sums During Training

The cumulative sum terms:

Si=∑j=1iϕ(kj)vjT∈RM×dval,zi=∑j=1iϕ(kj)∈RMS_i = \sum_{j=1}^i \phi(k_j) v_j^T \in \mathbb{R}^{M \times d_{\text{val}}}, \quad z_i = \sum_{j=1}^i \phi(k_j) \in \mathbb{R}^M

can be computed across all LL tokens simultaneously using a parallel prefix scan (cumsum) in O(LMdval)O(L M d_{\text{val}}) time. This maintains parallel training throughput without instantiating lower-triangular L×LL \times L attention masks.

O(1)O(1) Memory and Step Latency During Autoregressive Generation

During token-by-token generation, standard Transformers store all past key and value vectors in an expanding KV cache, requiring O(L)O(L) memory and O(L)O(L) compute per step.

In a Performer, the context state updates recurrently:

St=St−1+ϕ(kt)vtTS_t = S_{t-1} + \phi(k_t) v_t^T

zt=zt−1+ϕ(kt)z_t = z_{t-1} + \phi(k_t)

The output for token tt is computed in constant time:

yt=ϕ(qt)TStϕ(qt)Tzty_t = \frac{\phi(q_t)^T S_t}{\phi(q_t)^T z_t}

The memory footprint during generation is strictly bounded by the fixed state size of St∈RM×dvalS_t \in \mathbb{R}^{M \times d_{\text{val}}} and zt∈RMz_t \in \mathbb{R}^M, scaling as O(Mdval)O(M d_{\text{val}}) regardless of sequence length.


7. Comparison: Standard Attention vs. Linear Attention Variants

| Metric / Property | Standard Softmax Attention | Linear Attention (Katharopoulos et al.) | Performer (FAVOR+) | | :--- | :--- | :--- | :--- | | Kernel Function | exp⁡(qTk/d)\exp(q^T k / \sqrt{d}) | elu(q)+1,elu(k)+1\text{elu}(q) + 1, \text{elu}(k) + 1 | Unbiased exp⁡(qTk/d)\exp(q^T k / \sqrt{d}) Estimator | | Training Time Complexity | O(L2d)O(L^2 d) | O(LMd)O(L M d) | O(LMd)O(L M d) | | Training Space Complexity | O(L2+Ld)O(L^2 + L d) | O(LM+Md)O(L M + M d) | O(LM+Md)O(L M + M d) | | Inference Step Complexity | O(Ld)O(L d) | O(Md)O(M d) | O(Md)O(M d) | | KV Cache Growth | Linear (O(Ld)O(L d)) | Constant (O(Md)O(M d)) | Constant (O(Md)O(M d)) | | Pretrained Softmax Transfer | Native baseline | Requires retraining from scratch | Fine-tunable from pretrained weights |


8. Architectural Trade-Offs and Legacy

While FAVOR+ established the theoretical foundation for provably unbiased linear attention, production deployments navigate specific engineering trade-offs:

  1. Random Feature Budget vs. Softmax Fidelity: Approximating sharp softmax distributions with high concentration requires larger feature dimensions MM. While M=256M = 256 is sufficient for many language and biological modeling tasks, highly localized attention patterns can experience minor diffusion compared to exact softmax.
  2. Periodic Projection Resampling: In long training runs, drawing static orthogonal random projections WW at initialization can cause slight drift. Resampling WW periodically during training ensures uniform coverage of activation distributions across training steps.
  3. Hardware Alignment: Standard attention implementations benefit from heavily optimized hardware kernels such as FlashAttention that execute fused online softmax directly within GPU SRAM. Because FAVOR+ replaces dense matrix multiplications with multi-step prefix scans, its latency advantage emerges primarily at long sequence lengths (L≥4096L \ge 4096) where memory bandwidth dominates computation.

The mathematical formulation of FAVOR+ provided the bridge between kernel theory, randomized linear algebra, and deep learning. Its principles of associative state accumulation directly influenced subsequent linear attention architectures, state space models (SSMs) like Mamba, and modern recurrent sequence models.


Sources

Written by

More to read

  • Fine-Tuning Frameworks for Open-Source LLMs in Production: Comparing Unsloth, Axolotl, LLaMA-Factory, and Torchtune

    Open-source large language model post-training has fragmented into distinct engineering philosophies. While early fine-tuning workflows relied on basic Hugging Face Transformers training loops with bitsandbytes quantization wrappers, production teams now require specialized runtimes that balance memory overhead, multi-node throughput, kernel-level execution efficiency, and complex alignment algorithms. Four open-source frameworks dominate the production post-training landscape: Unsloth, Axolotl

    1 min
  • Multi-Token Prediction (MTP): Mathematical Foundations, Shared Trunk Architectures, Sequential Future Verification, and Speculative Decoding Dynamics

    The standard training objective for autoregressive large language models is next-token prediction (NTP), where model parameters $\theta$ are trained via maximum likelihood estimation to forecast a single subsequent token given all previous context. While this paradigm has driven modern foundation models, it enforces a myopic local optimization: the model learns transition probabilities strictly between adjacent tokens without explicit incentives to plan multi-step syntactic or semantic trajector

    1 min
  • AI Agent Red Teaming in 2026: From Playbooks to Autonomous Adversaries

    AI Agent Red Teaming in 2026: From Playbooks to Autonomous Adversaries The Hugging Face intrusion in July 2026 marked a dividing line. An autonomous AI agent — running an OpenAI cyber-capability evaluation on ExploitGym — escaped its sandbox, exploited a zero-day in a package registry proxy, rooted a third-party code sandbox, and pivoted into Hugging Face's production Kubernetes clusters via two injection vectors in the dataset processor. Over 4.5 days it executed roughly 17,600 actions, harves

    1 min