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 , memory consumption and compute scale as . 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 linear time and space.

1. The Quadratic Bottleneck in Scaled Dot-Product Attention
Standard scaled dot-product attention, formalized by Vaswani et al. (2017), maps queries , keys , and values through an explicit attention matrix :
where the raw affinity matrix and the normalizer diagonal matrix are defined as:
Here, denotes element-wise exponentiation and is an all-ones column vector of length .
The quadratic cost stems directly from the matrix product . Constructing requires calculating pairwise inner products and storing an activation map in GPU memory for the backward pass. Because softmax normalizes rows after exponentiation, the operations cannot be rearranged using standard matrix associativity:
If could be factored into the product of two low-dimensional feature representations, where with , matrix associativity would allow computing first in time, followed by left-multiplication by in 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 and a key vector , the unnormalized attention affinity is:
By defining scaled vectors and , the kernel simplifies to the generalized exponential kernel:
Under classic kernel theory, any positive definite kernel can be decomposed as an inner product in a high-dimensional feature space :
where represents a randomized feature mapping parameterized by random vector . If an empirical estimator provides an unbiased approximation of , the full attention computation becomes:
By pulling the query feature outside the summation over sequence index , the key and value interactions can be pre-aggregated across the entire sequence into a global context tensor and a normalizer vector .
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 , Bochner's Theorem guarantees that the Fourier transform of the kernel is a valid probability distribution .
The exponential kernel can be rewritten in terms of the Gaussian kernel:
Applying trigonometric Random Fourier Features to approximate yields the trigonometric mapping:
where .
While is mathematically unbiased, trigonometric features exhibit severe failure modes when applied to self-attention:
- Negative Affinity Estimates: Because cosine and sine fluctuate across , the inner product can evaluate to negative values. The true softmax kernel is strictly positive ().
- Normalizer Collapse and Division by Zero: When summing over sequence length , the denominator can approach zero or turn negative, causing numerical singularity, gradient explosions, and training divergence.
- High Variance in Tails: For large queries and keys where is large, the variance of scales exponentially with , requiring an impractical number of random features () 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 . For any deterministic vector :
Setting , the expectation expands as:
Rearranging terms to isolate yields the identity:
Because the expectations and scalar exponential factors distribute linearly, the product can be combined under a single expectation:
This gives the positive random feature map :
Because the exponential function maps real numbers strictly to positive values ( for all ), every entry of is strictly positive. Consequently:
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 independently from introduces estimation variance. If two sampled vectors and are nearly collinear, they provide redundant information while failing to cover orthogonal subspaces of .
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 (where for integer block count ) is constructed in blocks of orthogonal matrices:
- Sample a random Gaussian matrix with entries .
- Apply QR decomposition , where is an exact orthogonal matrix ().
- Scale each row of by an independent radial sample from the chi-distribution with degrees of freedom: .
- Set the block projection matrix to .
Stacking such orthogonal blocks yields . By enforcing strict orthogonality among rows within each block ( for ), ORFs maintain the exact marginal distribution 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 ().
6. Causal Masking and Recurrent Inference
In autoregressive language models, tokens must not attend to future positions. The attention output for position must only incorporate keys and values from indices :
This formulation unlocks two structural computational efficiencies:
Parallel Prefix Sums During Training
The cumulative sum terms:
can be computed across all tokens simultaneously using a parallel prefix scan (cumsum) in time. This maintains parallel training throughput without instantiating lower-triangular attention masks.
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 memory and compute per step.
In a Performer, the context state updates recurrently:
The output for token is computed in constant time:
The memory footprint during generation is strictly bounded by the fixed state size of and , scaling as 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 | | | Unbiased Estimator | | Training Time Complexity | | | | | Training Space Complexity | | | | | Inference Step Complexity | | | | | KV Cache Growth | Linear () | Constant () | Constant () | | 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:
- Random Feature Budget vs. Softmax Fidelity: Approximating sharp softmax distributions with high concentration requires larger feature dimensions . While is sufficient for many language and biological modeling tasks, highly localized attention patterns can experience minor diffusion compared to exact softmax.
- Periodic Projection Resampling: In long training runs, drawing static orthogonal random projections at initialization can cause slight drift. Resampling periodically during training ensures uniform coverage of activation distributions across training steps.
- 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 () 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
- Choromanski et al. (2020): Rethinking Attention with Performers
- Google Research: Rethinking Attention with Performers
- Rahimi and Recht (2007): Random Features for Large-Scale Kernel Machines
- Yu et al. (2016): Orthogonal Random Features
- Katharopoulos et al. (2020): Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
- Vaswani et al. (2017): Attention Is All You Need
- Dao et al. (2022): FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness



