A Fast Optimization View: Reformulating Single Layer Attention in LLM Based on Tensor and SVM Trick, and Solving It in Matrix Multiplication Time
Published 14 Sep 2023 in cs.DS, cs.LG, and stat.ML | (2309.07418v1)
Abstract: LLMs have played a pivotal role in revolutionizing various facets of our daily existence. Solving attention regression is a fundamental task in optimizing LLMs. In this work, we focus on giving a provable guarantee for the one-layer attention network objective function L(X,Y)=j0=1∑<sup>n</sup>i0=1∑<sup>d</sup>(⟨⟨exp(A<em>j0x),1n⟩<sup>−1</sup>exp(A</em>j0x),A3Y<em>,i0⟩−bj0,i0)<sup>2. Here A∈R<sup>n<sup>2</sup></sup>×d<sup>2 is Kronecker product between A1∈R<sup>n</sup>×d and A2∈R<sup>n</sup>×d. A3 is a matrix in R<sup>n</sup>×d, A<em>j0∈R<sup>n</sup>×d<sup>2 is the j0-th block of A. The X,Y∈R<sup>d</sup>×d are variables we want to learn. B∈R<sup>n</sup>×d and b</em>j0,i0∈R is one entry at j0-th row and i0-th column of B, Y</em>,i0∈R<sup>d is the i0-column vector of Y, and x∈R<sup>d<sup>2 is the vectorization of X. In a multi-layer LLM network, the matrix B∈R<sup>n</sup>×d can be viewed as the output of a layer, and A1=A2=A3∈R<sup>n</sup>×d can be viewed as the input of a layer. The matrix version of x can be viewed as QK<sup>⊤ and Y can be viewed as V. We provide an iterative greedy algorithm to train loss function L(X,Y) up ϵ that runs in O((T<em>mat(n,n,d)+T</em>mat(n,d,d)+d<sup>2ω)</sup>log(1/ϵ)) time. Here Tmat(a,b,c) denotes the time of multiplying a×b matrix another b×c matrix, and ω≈2.37 denotes the exponent of matrix multiplication.