Randomized and Deterministic Attention Sparsification Algorithms for Over-parameterized Feature Dimension

Yichuan Deng, Sridhar Mahadevan, Zhao SongarXiv 2023

Abstract

Large language models (LLMs) have demonstrated remarkable capabilities across diverse domains, yet the computational demands of their attention mechanisms remain a significant hurdle. Recent theoretical work has begun to explore the static and dynamic maintenance of attention matrices, but the challenge of high-dimensional embeddings persists. This paper investigates the sparsification of the attention problem, specifically focusing on scenarios where the embedding dimension $d$ significantly exceeds the sequence length $n$ ($d \gg n$). By assuming a symmetric logit matrix, we propose two novel algorithms—one randomized and one deterministic—to compress the feature dimension to a size nearly linear in $n$ while maintaining provable error bounds. Our findings suggest that for over-parameterized models, the effective dimensionality required for accurate attention computation is much lower than previously assumed.

Introduction

In modern Transformer architectures, the embedding dimension $d$ is often "super large" to capture complex semantic relationships. However, this high dimensionality creates a computational bottleneck during the attention phase, $\text{Att}(Q, K, V) = D^{-1} \exp(QK^\top)V$. While sequence length $n$ typically dictates the quadratic scaling of attention, the hidden costs associated with $d$ become prohibitive in over-parameterized regimes.

This research addresses the Symmetric Attention Approximation problem. Given a matrix $X \in \mathbb{R}^{n \times d}$ where $d \gg n$, we seek a compressed matrix $Y \in \mathbb{R}^{n \times m}$ (with $m \ll d$) such that the resulting attention matrix approximates the original within a controlled error bound $O(r)$. Specifically, we assume the logit matrix is symmetric ($Q = K = X$) and that the spectral norm of the product is bounded.

Algorithmic Frameworks

1. Randomized Sparsification via Leverage Score Sampling

The first approach utilizes Leverage Score Sampling to identify and preserve the most informative dimensions of the input matrix $X$. By estimating the importance of each dimension, the algorithm samples $m = O(n \log(n/\delta))$ rows to construct the compressed matrix $Y$.

  • Efficiency: The algorithm runs in $\widetilde{O}(\mathrm{nnz}(X) + n^{\omega})$ time, where $\mathrm{nnz}(X)$ is the number of non-zero entries and $\omega \approx 2.373$ is the exponent of matrix multiplication.
  • Reliability: It achieves a success probability of $1-\delta$, ensuring that the approximation error remains within $O(r)$ for the normalized attention matrix.

2. Deterministic Sparsification

For applications requiring absolute certainty, we provide a deterministic algorithm inspired by recent advances in derandomized linear programming. This method eliminates the failure probability inherent in sampling-based approaches.

  • Dimension Reduction: This algorithm achieves a tighter compression, choosing exactly $m = O(n)$ dimensions.
  • Complexity: The deterministic path is more computationally intensive, running in $\widetilde{O}(\min\{\sum_{i\in[d]}\mathrm{nnz}(X_i)^2, dn^{\omega-1}\} + n^{\omega+1})$ time. While slower than the randomized version, it provides a theoretical guarantee that the compressed representation is optimal in size.

Theoretical Insights

The core of these methods lies in the stability of the "softmax" denominator ($D^{-1}$) during compression. The authors utilize Taylor expansions for the exponential function and perturbation analysis of Positive Semidefinite (PSD) matrices. A key technical lemma demonstrates that if two PSD matrices are spectrally close, their individual entries—and thus their entry-wise exponentials—remain relatively close. This allows the reduction of the feature dimension to a size nearly linear in the sequence length without sacrificing the precision of the attention output.

Implications and Limitations

Key Findings

  • Dimension-to-Length Reduction: The most significant result is the proof that for any super-large feature dimension, the effective rank required for attention can be reduced to $O(n)$ or $O(n \log n)$.
  • Input Sparsity: The randomized algorithm's runtime is dominated by the number of non-zero entries, making it highly efficient for sparse datasets.

Future Directions

While this work provides a rigorous foundation for attention sparsification, several avenues for future research remain:

  • Symmetry Constraint: The current proofs rely on the assumption that $Q=K$. Extending these results to the general asymmetric case ($Q \neq K$) used in standard Transformers is a critical next step.
  • Value Matrix Integration: The study focuses on approximating attention weights ($D^{-1}A$); future work should incorporate the value matrix $V$ into the approximation bounds.
  • Computational Speed: Bridging the gap between the speed of randomized algorithms and the optimality of deterministic algorithms remains an open challenge.

Conclusion

This work demonstrates that the over-parameterization of feature dimensions in LLMs can be algorithmically managed. By sketching the feature matrix into a lower-dimensional space, we can significantly reduce the computational overhead of the attention mechanism while maintaining theoretical convergence and error guarantees.

Summary updated

BibTeX
@misc{deng2023randomized,
  author = {Yichuan Deng and Sridhar Mahadevan and Zhao Song},
  title = {{Randomized and Deterministic Attention Sparsification Algorithms for Over-parameterized Feature Dimension}},
  year = {2023},
  eprint = {2304.04397},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2304.04397},
}
Figure