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 $ε\|b\|_2$ for every $b$, with a sketch dimension that is, up to logarithmic factors, $ε^{-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 $ε\|b\|_2$ plus $(1+\sqrtε)$ 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.
翻译:暂无翻译