First, we introduce the following notation:
and adopt the convention that function operations on vectors are element-wise (in the Hadamard sense), for example
In particular, pay close attention to the distinction between and , and between and : the former applies the function to each component first and then averages, while the latter averages first and then applies the function; the two are generally not equal.
In addition to the definitions above, and can also be connected via the gradient:
Next, we expand . Introducing , we have
The last step uses ; if needed, one can continue expanding further. If readers are not familiar with doing this, you can also leave it to Kimi to complete.
Here, introducing the offset of is a little trick to simplify the form; without introducing it, one can still obtain an equivalent result, except that each term in would be explicitly expanded:
For , we directly utilize the identity , and differentiating both sides of Eq. directly yields the expansion of . To this end, we use
to obtain
Note that if truncated to a finite number of terms, the right-hand side still maintains that all components sum to 1 (as can be seen from the gradient form of ), but it cannot guarantee the non-negativity of each component, which requires attention in practical applications (for instance, when taking the logarithm to compute entropy).
Besides taking the gradient, we can also expand using ; combining this with Eq. yields:
So what applications do these two expansions have? First is for , which is related to how MoBA-style Block Sparse Attention scores blocks. As we know, full attention scores each token according to , so for a given block , its score can reasonably be defined as the sum of the scores of each token, which is equivalent to
Its first-order approximation is , where , which corresponds precisely to MoBA's empirical practice of using AvgPooling as the intra-block landmark vector. If the first-order approximation feels too coarse, we can consider higher-order corrections. According to Eq. , the second-order term is
That is, the second-order approximation is , where is precisely the intra-block covariance matrix of . Furthermore, we can consider a diagonal approximation to reduce computational cost. The idea behind this higher-order correction is essentially the same as SPLA. Subsequent related work also includes HiLS, which additionally learns a non-uniformly weighted average center vector to replace .
Let , then we have the first-order approximation:
This is precisely the scheme discussed in the paper mentioned at the beginning, and it is also very intuitive in itself: the average vector provides a baseline for the relative magnitude of attention; tokens with greater similarity than should receive increased attention, and decreased attention otherwise. To improve accuracy, Based expands to the second order (which happens to guarantee non-negativity; see here), but from our perspective, considering the second-order approximation of is more principled, where the second-order term is
where can be converted into an inner product by introducing an outer product:
Therefore, similar to Based, truncating the softmax in softmax attention to a second-order approximation also results in linear attention.