skip to content
← Scientific Spaces English

Linearizing Softmax Attention into Gated DeltaNet

In the article "Taylor Expansions of LogSumExp and Softmax", we introduced approximate expansions of LogSumExp and Softmax, from which we obtained a simple scheme for linearizing Softmax Attention. In that article, however, the resulting linear attention was merely in the form of Vanilla Linear Attention.

In this post, we take a step further and attempt to linearize Softmax Attention into a linear attention variant equipped with the Delta Rule. Surprisingly, the end result is not the basic DeltaNet, but directly yields Gated DeltaNet (GDN).

Background #

Consider, for a given Query , how the Attention output varies with Key and Value. We introduce the notation

Using the Softmax expansion introduced in "Taylor Expansions of LogSumExp and Softmax", we obtain ; substituting this into the above equation yields

where are the means of the first Key and Value vectors, respectively. As can be seen, the final formula is indeed a form of linear attention, and specifically a variant of the earliest Vanilla Linear Attention (hereafter abbreviated as "VaLA").

From "A Brief History of Linear Attention: From Imitation and Innovation to Giving Back", we know that following VaLA came the Delta Rule and the corresponding DeltaNet, as well as subsequent extensions such as GDN, KDA, and so on, all of which are theoretically stronger linear attention mechanisms than VaLA. Can we, then, directly linearize Softmax Attention into DeltaNet, GDN, and the like to achieve a better approximation?

Recurrent Formulation #

In fact, Softmax Attention itself can be written in the form of an RNN, which we previously discussed in "Chapter of Spacetime: Viewing Attention as an RNN with Quadratic Complexity", and this conversion is not difficult to understand:

Rearranging yields

Keen-eyed readers may have already noticed that the increment on the right-hand side is of the form , which represents the "difference between the new observation and the old prediction"—this already faintly resembles the Delta Rule. Note that up to this point, we have not made any approximations; this equation is completely exact, hinting at an inherent connection between Softmax Attention and the Delta Rule.

It should also be pointed out that Eq. is an RNN for a fixed , whereas in reality each position has a distinct . These distinct vectors must each be plugged in and run for steps, respectively, to obtain their corresponding outputs. The total complexity is , which is precisely what is meant by "an RNN with quadratic complexity".

The reason is that for different , the recurrence processes are independent, so each must run through a complete pass, making the overall complexity quadratic. To achieve linearization, we must find a way to decouple the operations involving , letting the recurrence proceed purely within , and then combining the state variables of the recurrence with to produce the output. In this way, the recurrence process does not depend on , requiring only a single pass of iteration, and the complexity drops to linear.

Linear Approximation #

Next, we apply the first-order approximation of Softmax to , obtaining

Some readers might wonder: didn't we just complain that VaLA obtained from the first-order approximation of Softmax wasn't accurate enough? Why are we still using a first-order approximation now? The difference is that earlier we needed to approximate , where the indices spanned all pairs, whereas now we only need to approximate , that is, only approximating the diagonal part. The approximation burden is drastically reduced, and the approximation accuracy increases accordingly.

There is another perspective that can help us better understand this: first, rewrite differently

This equality tells us that for , can be decomposed into the product of and a series of . Directly applying a first-order approximation to , compared to approximating and separately, is analogous to the difference between and ; the latter can introduce cross terms, achieving higher accuracy.

Decoupling the Recurrence #

However, even with the approximation, this recurrence is still quadratic, and we have not yet achieved the goal of separating out . To get closer to it, we look for a solution of the following form:

where are independent of , with the convention . Of course, the exact solution definitely does not look like this; we are simply deliberately searching for a solution of the above form to serve as an approximation to the exact solution. Substituting it into the earlier recurrence gives

An intuitive idea is to use the degree in to separate the recurrence for , which would give recurrence relations for . However, the left-hand side has at most first-order terms in , whereas the right-hand side has a quadratic term like , so the decoupling cannot be carried out completely. For now, we can only obtain

Clearly, the recurrence for is actually computing the cumulative average of , so we can directly write . The problem is that on the right-hand side of Eq. , we still have . was assumed to be independent of , but this assumption cannot hold.

Simply Dropping It #

A simple approach is to consider to be a small quantity and drop it directly, which yields

This likewise has the form of a cumulative average, yielding

This looks like a new VaLA variant, but in fact it is completely equivalent to Equation ! To prove this, we only need to verify that

Thus,

This carries out an identical transformation from Equation to Equation .

Error Principle #

Another more accurate approach is to replace with some suitable quantity . Intuitively, replacing with would be a relatively natural and better choice, but that is not actually the case. Let us return to Equation , where writing out explicitly yields

Our goal is to replace the last with some , so that quadratic terms in will not appear in the subsequent approximate expansion; the resulting error is

Why is not necessarily good? Because it only guarantees that the error is lowest at the single position , yet the state variable at this moment actually still needs to serve the subsequent , so the ideal goal is: "For any that might appear, the error should be as small as possible"—this is what we follow when seeking : the "minimum error principle".

This error term has a multiplicative form: if is inherently small, the product will not be large either; conversely, if is very large, then must be small in order to bring the error down. From this, we obtain a "minimax strategy": first find what makes maximal, namely , and then choose so that the error is zero here, i.e., , which balances the errors on both the large and small sides.

The Grand Finale #

According to the linear approximation , the direction of that maximizes it is , but since its norm can be arbitrarily large, actually has no maximum. To obtain a finite result, we need to constrain 's norm. For simplicity, we assume that have comparable norms, so we can directly take

in this particularly simple form. Substituting it into Eq. yields

This is precisely what Gated DeltaNet (GDN) looks like! The standard form of GDN is

The difference lies in whether multiplies or only multiplies , but this difference is not essential, and the two can be converted into each other. At this point, we have completed the approximate transformation from Softmax Attention to Delta-rule-family attention, giving the final output

Summary #

Starting from the premise that "Softmax Attention is an RNN with quadratic complexity", this post first observes that its recursive increment naturally takes the form of a Delta Rule, then applies a first-order approximation to the diagonal elements of the Softmax matrix, and finally, following the "minimum error principle", seeks a replacement for the residual , successfully linearizing Softmax Attention into the form of Gated DeltaNet.

(Note: This article was completed under the guidance of Kimi K3.)