[Paper Review] KDEformer: Accelerating Transformers via Kernel Density Estimation
KDEformer accelerates Transformers by reformulating dot-product attention as a kernel density estimation (KDE) problem, enabling sub-quadratic computation with provable spectral norm error bounds. It achieves up to 18.3× speedup on ImageNet with less than 0.5% accuracy drop and outperforms exact attention in FID scores on BigGAN with 4.14× fewer FLOPs.
Dot-product attention mechanism plays a crucial role in modern deep architectures (e.g., Transformer) for sequence modeling, however, naïve exact computation of this model incurs quadratic time and memory complexities in sequence length, hindering the training of long-sequence models. Critical bottlenecks are due to the computation of partition functions in the denominator of softmax function as well as the multiplication of the softmax matrix with the matrix of values. Our key observation is that the former can be reduced to a variant of the kernel density estimation (KDE) problem, and an efficient KDE solver can be further utilized to accelerate the latter via subsampling-based fast matrix products. Our proposed KDEformer can approximate the attention in sub-quadratic time with provable spectral norm bounds, while all prior results merely provide entry-wise error bounds. Empirically, we verify that KDEformer outperforms other attention approximations in terms of accuracy, memory, and runtime on various pre-trained models. On BigGAN image generation, we achieve better generative scores than the exact computation with over $4 imes$ speedup. For ImageNet classification with T2T-ViT, KDEformer shows over $18 imes$ speedup while the accuracy drop is less than $0.5\%$.
Motivation & Objective
- To address the quadratic computational and memory bottlenecks in self-attention mechanisms of Transformers.
- To develop an attention approximation method with provable spectral norm error guarantees, rather than just entry-wise error bounds.
- To enable efficient inference and training on long-sequence models by reducing computational complexity.
- To improve generative performance and efficiency in vision and language models compared to prior approximate attention methods.
Proposed method
- Reduces the attention computation to a generalized kernel density estimation (KDE) problem for both the diagonal scaling matrix D and the attention matrix A.
- Uses importance sampling with KDE-based probabilities to select a small subset of columns for approximate attention computation.
- Employs a transform to map the exponential kernel density problem into a Gaussian KDE problem, leveraging state-of-the-art KDE solvers.
- Estimates the diagonal scaling matrix D via KDE to avoid explicit computation of the full attention matrix A.
- Applies sub-sampled matrix products using the estimated sampling matrix Π and diagonal matrix eD to compute the output efficiently.
- Provides a spectral norm error bound (Equation 1) that ensures stability and fidelity of the attention output.
Experimental results
Research questions
- RQ1Can the attention mechanism be reformulated as a kernel density estimation problem to enable sub-quadratic computation?
- RQ2Can KDE-based sampling and scaling reduce the computational complexity of attention while preserving model performance?
- RQ3Can spectral norm error bounds be achieved in attention approximation, offering stronger theoretical guarantees than entry-wise bounds?
- RQ4Does the proposed method outperform existing approximate attention mechanisms in accuracy, speed, and memory efficiency on long-sequence tasks?
- RQ5Can KDEformer improve generative quality in models like BigGAN while reducing FLOPs?
Key findings
- On BigGAN image generation, KDEformer achieves a lower FID score (better quality) than exact attention with 4.14× fewer FLOPs.
- For ImageNet classification with T2T-ViT, KDEformer achieves 82.08% top-1 accuracy—only 0.47% below exact computation—while reducing FLOPs by 18.3×.
- In end-to-end training on Long Range Arena, KDEformer runs 8× faster than exact attention on the Text dataset with minimal accuracy drop.
- KDEformer uses 2.28 GB peak memory on average across LRA datasets, significantly less than exact (9.21 GB) and competitors.
- The method achieves second-best average test accuracy on LRA (57.15%) while being the fastest and most memory-efficient among all approximations.
- Empirical results confirm that KDEformer outperforms Reformer, Performer, and ScatterBrain in both accuracy and efficiency across multiple benchmarks.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.