Skip to main content
QUICK REVIEW

[Paper Review] Data-Aware Random Feature Kernel for Transformers

Amirhossein Farzam, Hossein Mobahi|arXiv (Cornell University)|Mar 4, 2026
Advanced Neural Network ApplicationsComputer Science0 citations
TL;DR

DARKFormer learns a data-aligned random-feature kernel for transformer attention, enabling importance-sampling-like variance reduction and improved finetuning with linear complexity.

ABSTRACT

Transformers excel across domains, yet their quadratic attention complexity poses a barrier to scaling. Random-feature attention, as in Performers, can reduce this cost to linear in the sequence length by approximating the softmax kernel with positive random features drawn from an isotropic distribution. In pretrained models, however, queries and keys are typically anisotropic. This induces high Monte Carlo variance in isotropic sampling schemes unless one retrains the model or uses a large feature budget. Importance sampling can address this by adapting the sampling distribution to the input geometry, but complex data-dependent proposal distributions are often intractable. We show that by data aligning the softmax kernel, we obtain an attention mechanism which can both admit a tractable minimal-variance proposal distribution for importance sampling, and exhibits better training stability. Motivated by this finding, we introduce DARKFormer, a Data-Aware Random-feature Kernel transformer that features a data-aligned kernel geometry. DARKFormer learns the random-projection covariance, efficiently realizing an importance-sampled positive random-feature estimator for its data-aligned kernel. Empirically, DARKFormer narrows the performance gap with exact softmax attention, particularly in finetuning regimes where pretrained representations are anisotropic. By combining random-feature efficiency with data-aware kernels, DARKFormer advances kernel-based attention in resource-constrained settings.

Motivation & Objective

  • Address the quadratic attention cost and high Monte Carlo variance of isotropic random-feature methods.
  • Introduce a data-aligned kernel geometry that adapts to anisotropic query-key distributions.
  • Provide a tractable mechanism for importance sampling through learned covariance without per-sample weights.
  • Demonstrate improved performance and training stability in finetuning with limited feature budgets.
  • Validate the approach on Gemma-based models to show practicality in resource-constrained settings.

Proposed method

  • Replace the standard dot product with a Mahalanobis inner product using a learnable covariance Sigma = M^T M.
  • Use data-aware random features with a kernel exp(q^T Sigma k) and a corresponding phi_Sigma feature map with omega ~ N(0, Sigma).
  • Show that learning Sigma induces an implicit importance-sampling effect that lowers Monte Carlo variance without explicit per-sample weights.
  • Provide theoretical justification: variance-optimal sampling aligns with input geometry; in Gaussian case the optimal Sigma* is (I+2Λ)(I-2Λ)^{-1} when Λ is input covariance.
  • Argue that DARKFormer yields a tractable, data-aligned sampling strategy that improves performance under limited feature budgets and enhances training stability.
  • Empirically validate on Gemma models, focusing on finetuning scenarios with anisotropic query-key distributions.
Figure 1: The random feature attention replaces the softmax kernel with a linear approximation in the feature space, reducing the quadratic complexity in sequence length ( $L$ ) to linear in sequence length times sample size ( $m$ ).
Figure 1: The random feature attention replaces the softmax kernel with a linear approximation in the feature space, reducing the quadratic complexity in sequence length ( $L$ ) to linear in sequence length times sample size ( $m$ ).

Experimental results

Research questions

  • RQ1Does data-aligned random-feature attention reduce Monte Carlo variance for anisotropic query-key distributions?
  • RQ2Can a learned covariance in DARKFormer narrow the gap to exact softmax attention with a small feature budget?
  • RQ3Does data-aware kernel geometry improve training stability and efficiency during finetuning from pretrained weights?
  • RQ4How does the learned Sigma influence performance and robustness across different learning rates and finetuning regimes?

Key findings

  • DARKFormer narrows the performance gap with exact attention compared to isotropic PRF (Performer) baselines.
  • It achieves these gains without requiring large feature samples or extensive retraining.
  • DARKFormer improves training stability and reduces loss spikes across a range of learning rates during finetuning.
  • The approach is particularly advantageous in resource-constrained finetuning from pretrained weights.
  • Experiments on Gemma demonstrate improved next-token-prediction accuracy over Performer and competitive performance relative to exact softmax.
Figure 2: Next token prediction accuracy during pretraining (top) and finetuning (bottom) of the Gemma-2B model with a DARKFormer (green), a Performer (orange), learned feature kernel (LFK) (blue), a random baseline (yellow), a constant baseline (lime), and an exact softmax attention. The DARKFormer
Figure 2: Next token prediction accuracy during pretraining (top) and finetuning (bottom) of the Gemma-2B model with a DARKFormer (green), a Performer (orange), learned feature kernel (LFK) (blue), a random baseline (yellow), a constant baseline (lime), and an exact softmax attention. The DARKFormer

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.