Skip to main content
QUICK REVIEW

[Paper Review] Randomized and Deterministic Attention Sparsification Algorithms for Over-parameterized Feature Dimension

Yichuan Deng, Sridhar Mahadevan|arXiv (Cornell University)|Apr 10, 2023
Stochastic Gradient Optimization TechniquesComputer Science3 citations
TL;DR

This paper presents randomized and deterministic algorithms for sparsifying attention matrices in over-parameterized settings where the embedding dimension $d$ greatly exceeds sequence length $n$. By exploiting symmetric logit matrices and leverage score sampling, the methods achieve accurate approximation of the attention matrix in $\widetilde{O}(\operatorname{nnz}(X) + n^\omega)$ time for the randomized version and $\widetilde{O}(\min\{\sum_i \operatorname{nnz}(X_i)^2, dn^{\omega-1}\} + n^{\omega+1})$ for the deterministic variant, reducing $d$ to $O(n)$ or $O(n\log(n/\delta))$ without significant accuracy loss.

ABSTRACT

Large language models (LLMs) have shown their power in different areas. Attention computation, as an important subroutine of LLMs, has also attracted interests in theory. Recently the static computation and dynamic maintenance of attention matrix has been studied by [Alman and Song 2023] and [Brand, Song and Zhou 2023] from both algorithmic perspective and hardness perspective. In this work, we consider the sparsification of the attention problem. We make one simplification which is the logit matrix is symmetric. Let $n$ denote the length of sentence, let $d$ denote the embedding dimension. Given a matrix $X \in \mathbb{R}^{n imes d}$, suppose $d \gg n$ and $\| X X^ op \|_{\infty} < r$ with $r \in (0,0.1)$, then we aim for finding $Y \in \mathbb{R}^{n imes m}$ (where $m\ll d$) such that \begin{align*} \| D(Y)^{-1} \exp( Y Y^ op ) - D(X)^{-1} \exp( X X^ op) \|_{\infty} \leq O(r) \end{align*} We provide two results for this problem. $\bullet$ Our first result is a randomized algorithm. It runs in $\widetilde{O}(\mathrm{nnz}(X) + n^ω ) $ time, has $1-δ$ succeed probability, and chooses $m = O(n \log(n/δ))$. Here $\mathrm{nnz}(X)$ denotes the number of non-zero entries in $X$. We use $ω$ to denote the exponent of matrix multiplication. Currently $ω\approx 2.373$. $\bullet$ Our second result is a deterministic algorithm. It runs in $\widetilde{O}(\min\{\sum_{i\in[d]}\mathrm{nnz}(X_i)^2, dn^{ω-1}\} + n^{ω+1})$ time and chooses $m = O(n)$. Here $X_i$ denote the $i$-th column of matrix $X$. Our main findings have the following implication for applied LLMs task: for any super large feature dimension, we can reduce it down to the size nearly linear in length of sentence.

Motivation & Objective

  • To address the computational bottleneck of attention computation in large language models (LLMs) when the feature dimension $d$ is much larger than sequence length $n$.
  • To develop efficient algorithms that sparsify the attention matrix while preserving approximation accuracy under the symmetric logit matrix assumption.
  • To reduce the effective feature dimension from $d$ to $O(n)$ or $O(n\log(n/\delta))$ while maintaining $O(r)$ error in the $\ell_\infty$ norm.
  • To provide both randomized and deterministic algorithms with provable time complexity and correctness guarantees for symmetric attention sparsification.

Proposed method

  • Leverage score approximation via a two-stage sampling process: first using sparse embedding matrices, then applying Johnson-Lindenstrauss transforms to accelerate computation.
  • Use of fast QR factorization on a projected matrix to compute approximate leverage scores efficiently.
  • Sampling of rows from the input matrix $X$ according to approximate leverage scores to construct a sparse embedding matrix $Y$ with $m \ll d$ columns.
  • Application of matrix Chernoff bounds to ensure concentration of the sampled matrix $\widetilde{H}$ around the true $XX^\top$, guaranteeing $\epsilon$-approximation with high probability.
  • Design of a deterministic algorithm that avoids randomness by using structured sampling based on column-wise sparsity and matrix multiplication complexity.
  • Integration of the sparsified matrix $Y$ into the attention computation via $D(Y)^{-1}\exp(YY^\top)$, ensuring bounded $\ell_\infty$ error relative to the original $D(X)^{-1}\exp(XX^\top)$.

Experimental results

Research questions

  • RQ1Can we achieve sub-quadratic time attention computation in over-parameterized settings where $d \gg n$?
  • RQ2Is it possible to sparsify the attention matrix while preserving $O(r)$ error in the $\ell_\infty$ norm under the symmetric logit assumption?
  • RQ3Can we design both randomized and deterministic algorithms for attention sparsification with provable time and correctness guarantees?
  • RQ4What is the minimal number of features $m$ required to maintain accuracy, and how does it scale with $n$ and $\delta$?
  • RQ5How can leverage score sampling be accelerated to achieve near-linear time complexity in $\operatorname{nnz}(X)$ and $n^\omega$?

Key findings

  • The randomized algorithm runs in $\widetilde{O}(\operatorname{nnz}(X) + n^\omega)$ time and succeeds with probability $1 - \delta$, selecting $m = O(n\log(n/\delta))$ features.
  • The deterministic algorithm runs in $\widetilde{O}(\min\{\sum_i \operatorname{nnz}(X_i)^2, dn^{\omega-1}\} + n^{\omega+1})$ time and selects $m = O(n)$ features.
  • The algorithms guarantee that $\|D(Y)^{-1}\exp(YY^\top) - D(X)^{-1}\exp(XX^\top)\|_\infty \leq O(r)$, where $r < 0.1$.
  • The leverage score approximation algorithm runs in $\widetilde{O}(\epsilon_\sigma^{-2}(\operatorname{nnz}(X) + n^\omega))$ time and outputs a $O(1)$-approximation to the true leverage scores with high probability.
  • The sampling process ensures that $\widetilde{H} = \frac{1}{T}\sum_{t=1}^T \frac{1}{p_{j_t}} a_{j_t}a_{j_t}^\top$ satisfies $(1-\epsilon_0)H \preceq \widetilde{H} \preceq (1+\epsilon_0)H$ with probability at least $1 - \delta_0$, using $T = \Theta(\epsilon_0^{-2}n\log(n/\delta_0))$ samples.
  • The theoretical framework enables dimensionality reduction from $d$ to $O(n)$ or $O(n\log(n/\delta))$ in feature space, significantly reducing computational cost for LLM inference.

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.