[论文解读] Randomized and Deterministic Attention Sparsification Algorithms for Over-parameterized Feature Dimension
该论文提出了在嵌入维度 $d$ 远大于序列长度 $n$ 的过参数化设置下,对注意力矩阵进行稀疏化的随机化与确定性算法。通过利用对称的logit矩阵和杠杆度采样,这些方法在随机版本中实现了 $\widetilde{O}(\operatorname{nnz}(X) + n^\omega)$ 时间内的注意力矩阵准确近似,在确定性版本中实现了 $\widetilde{O}(\min\{\sum_i \operatorname{nnz}(X_i)^2, dn^{\omega-1}\} + n^{\omega+1})$ 时间,将 $d$ 降低至 $O(n)$ 或 $O(n\log(n/\delta))$ 而不造成显著的精度损失。
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.
研究动机与目标
- 为解决当特征维度 $d$ 远大于序列长度 $n$ 时,大型语言模型(LLMs)中注意力计算的计算瓶颈问题。
- 在对称logit矩阵假设下,开发高效算法以稀疏化注意力矩阵,同时保持近似精度。
- 在保持 $\ell_\infty$ 范数下 $O(r)$ 误差的前提下,将有效特征维度从 $d$ 降低至 $O(n)$ 或 $O(n\log(n/\delta))$。
- 为对称注意力稀疏化提供兼具可证明时间复杂度与正确性保证的随机化与确定性算法。
提出的方法
- 通过两阶段采样过程实现杠杆度近似:首先使用稀疏嵌入矩阵,然后应用Johnson-Lindenstrauss变换以加速计算。
- 在投影矩阵上使用快速QR分解,以高效计算近似杠杆度。
- 根据近似杠杆度对输入矩阵 $X$ 的行进行采样,构建列数 $m \ll d$ 的稀疏嵌入矩阵 $Y$。
- 应用矩阵切尔诺夫不等式,确保采样矩阵 $\widetilde{H}$ 高概率集中在真实矩阵 $XX^\top$ 周围,从而保证 $\epsilon$-近似。
- 设计一种确定性算法,通过基于列级稀疏性与矩阵乘法复杂度的结构化采样避免随机性。
- 通过 $D(Y)^{-1}\exp(YY^\top)$ 将稀疏化矩阵 $Y$ 集成到注意力计算中,确保相对于原始 $D(X)^{-1}\exp(XX^\top)$ 的 $\ell_\infty$ 误差有界。
实验结果
研究问题
- RQ1我们能否在 $d \gg n$ 的过参数化设置下实现次二次时间复杂度的注意力计算?
- RQ2在对称logit假设下,是否可能在保持 $\ell_\infty$ 范数下 $O(r)$ 误差的前提下对注意力矩阵进行稀疏化?
- RQ3我们能否为注意力稀疏化设计兼具可证明时间复杂度与正确性保证的随机化与确定性算法?
- RQ4维持精度所需的最少特征数 $m$ 是多少?其与 $n$ 和 $\delta$ 的缩放关系如何?
- RQ5如何加速杠杆度采样,以实现在 $\operatorname{nnz}(X)$ 和 $n^\omega$ 时间内的近线性时间复杂度?
主要发现
- 随机算法的时间复杂度为 $\widetilde{O}(\operatorname{nnz}(X) + n^\omega)$,成功概率为 $1 - \delta$,选择的特征数为 $m = O(n\log(n/\delta))$。
- 确定性算法的时间复杂度为 $\widetilde{O}(\min\{\sum_i \operatorname{nnz}(X_i)^2, dn^{\omega-1}\} + n^{\omega+1})$,选择的特征数为 $m = O(n)$。
- 这些算法保证 $\|D(Y)^{-1}\exp(YY^\top) - D(X)^{-1}\exp(XX^\top)\|_\infty \leq O(r)$,其中 $r < 0.1$。
- 杠杆度近似算法的时间复杂度为 $\widetilde{O}(\epsilon_\sigma^{-2}(\operatorname{nnz}(X) + n^\omega))$,以高概率输出对真实杠杆度的 $O(1)$-近似。
- 采样过程确保 $\widetilde{H} = \frac{1}{T}\sum_{t=1}^T \frac{1}{p_{j_t}} a_{j_t}a_{j_t}^\top$ 满足 $(1-\epsilon_0)H \preceq \widetilde{H} \preceq (1+\epsilon_0)H$,概率至少为 $1 - \delta_0$,使用 $T = \Theta(\epsilon_0^{-2}n\log(n/\delta_0))$ 个样本。
- 该理论框架实现了从 $d$ 到 $O(n)$ 或 $O(n\log(n/\delta))$ 的特征空间降维,显著降低了大型语言模型推理的计算成本。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。