skip to content
← Scientific Spaces English

Continuous Softmax Attention

Softmax Attention should be familiar by now: it is a weighted mixing operator defined over a finite collection of vectors. Recently, the paper “Continuum Attention” proposed an interesting idea: make attention continuous. This reminded me that, as I previously discussed in “Why Does DeltaNet Require L2 Normalization?”, EFLA also makes a discrete RNN continuous and then discretizes it again, obtaining some interesting results. Earlier work in the SSM family followed a similar approach.

Seen this way, “continuization followed by discretization” seems to be a tried-and-true path of exploration. What interesting results might we obtain by making Softmax Attention continuous? Let us take a look together.

Problem Formulation #

Standard Softmax Attention is defined as

By making it continuous, we mean changing this to

Here, at non-integer points is defined by linear interpolation. Specifically, for any , define

This requires introducing two additional vectors, (used for ). We will discuss their values at the end.

Notice that the definition in Eq. differs slightly from the original paper. For symmetry, the paper changes the integration interval to . Although this is more symmetric, I feel it is less natural in a causal setting, so this article uses the interval instead. The derivation below does not depend much on this choice, however; the techniques are the same.

Preliminaries #

Eq. is only a formal definition. To use it in practice, we must evaluate the integrals explicitly. By the additivity of integration, we only need to evaluate each segment separately. Writing , we readily obtain

Here,

At , we use the limits, giving , respectively. These functions also satisfy the identity

We will use this identity to simplify the expressions in the next section. Also, their integral definitions show that and are always positive, so taking their logarithms later will not create an undefined expression.

Putting the Pieces Together and Simplifying #

Substituting these integrals into Eq. gives

First, simplify the numerator:

We see that the numerator has the form , where

The denominator is exactly what we obtain by replacing every with . We therefore immediately get for the denominator, and hence

Analyzing the Result #

Compared with standard Softmax Attention,

the changes introduced by continuization are an additional and the addition, to each , of a correction term . The extra is not a particularly fundamental change; we will discuss it briefly in a moment. For now, let us focus on .

For a general , depends both on and on the neighboring to its left and right. This resembles adding a short convolution to the attention matrix. The resemblance becomes clearer after Taylor-expanding :

Here, is precisely the second difference of , a simple short-convolution operation. Making Softmax Attention continuous thus does have much in common with “adding a short convolution to the attention matrix.”

As for , the pair plays the role of the sink token we introduce to address the attention-sink problem. In the continuous formulation, they primarily serve to fill out the intervals; this is simply a mathematical device. We generally have three choices: all zeros, , or trainable vectors. I chose all zeros in the experiments below.

Simple Experiments #

The fact that depends on both and its neighbors also means that we cannot reuse existing FlashAttention implementations. The underlying implementation principles still apply, however, and the theoretical FLOPs are essentially the same. I had K3 write a simple kernel, which ran at only about one quarter of the speed of Softmax Attention. The main difficulty is the large number of small operations, which are hard to accelerate. Still, it was enough to get an initial run going.

The first experimental result was that, although continuization introduces a local prior, it cannot completely replace positional encoding. In an architecture using full attention throughout, continuous Softmax Attention without RoPE is significantly worse than standard Softmax Attention with RoPE. Adding RoPE to the continuous version, by contrast, closes this gap.

As for training dynamics, when both versions use RoPE, continuous Softmax Attention is noticeably better early in training. But the gap gradually narrows, and by the end of training the two curves essentially coincide: the advantage disappears. My guess is that the main reason is that natural language is not a genuine time series, so continuization brings no substantial benefit. Perhaps only on genuine time series would there be a chance to measure an advantage.

I also tried switching from standard Softmax Attention to the continuous version partway through training. The initial loss jump was not particularly large, and the result gradually converged to essentially the same performance as the standard version.

Summary #

This article briefly derived a continuous form of Softmax Attention. The result resembles adding a short-convolution operation to the attention matrix. Although experiments on natural-language tasks did not reveal an advantage from this continuization, it is still an interesting result worth appreciating.