通过预条件子求解注意力核回归问题
Solving Attention Kernel Regression Problem via Pre-conditioner
针对注意力矩阵这一大语言模型的计算瓶颈,论文定义了基于矩阵幂 (A^T A)^j 的回归问题与基于 Gram 矩阵逐元素指数 exp(AA^T) 的注意力核回归问题,并用 sketching 与预条件方法给出快速算法。对注意力核回归,其误差为 ε‖b‖₂,草图维度在对数因子内为 ε⁻²n 乘以核矩阵条件数;当 A 的行范数不超过 1 时,还给出草图维度不依赖 n 的算法。
arXiv:2308.14304v3 Announce Type: replace Abstract: The attention mechanism is the key to large language models, and the attention matrix serves as an algorithmic and computational bottleneck for such a scheme. In this paper, we define two problems, motivated by designing fast algorithms for proxy of attention matrix and solving regressions against them. Given an input matrix $A\in \mathbb{R}^{n\times d}$ and a response vector $b$, the first proxy, for $n\gg d$, uses powers of the matrix $A^\top A$, and we consider two types of regression problems: $\min_{x\in \mathbb{R}^d}\|(A^\top A)^jx-b\|_2$ and $\min_{x\in \mathbb{R}^d}\|A(A^\top A)^jx-b\|_2$ for any positive integer $j$. We design fast algorithms for these power regressions, based on sketching and preconditioning. The second proxy is applying exponential entrywise to the Gram matrix, denoted by $\exp(AA^\top)$ and solving the regression $\min_{x\in \mathbb{R}^n}\|\exp(AA^\top)x-b \|_2$. We call this problem the attention kernel regression problem, as the matrix $\exp(AA^\top)$ could be viewed as a kernel function with respect to $A$. For this problem, we show that the sketching and preconditioning approach known for Gaussian kernels gives error $\epsilon\|b\|_2$ for every $b$, with a sketch dimension that is, up to logarithmic factors, $\epsilon^{-2}n$ times the condition number of the kernel matrix, which is at least $n/e$ when the rows of $A$ have norm at most $1$. For rows of norm at most $1$, we also give an algorithm whose sketch dimension, up to logarithmic factors, does not depend on $n$. It sketches the kernel plus a ridge term, and for a given $K\geq 1$ its error is at most $\epsilon\|b\|_2$ plus $(1+\sqrt{\epsilon})$ times the best residual among solutions of norm at most $(K/n)\|b\|_2$. We hope these efforts will provide an alternative perspective of studying efficient approximation of attention matrices.
来源:arXiv (AI + Vision + Imaging) · arxiv.org