Appearance
Sparse Linear Attention: Viewing SWA from the Perspective of Linear Attention
Because linear attention contains decay factors, its context capability is usually limited to some extent, so it can be viewed as a kind of sliding-window attention (SWA) with a very long window. From another perspective, however, SWA can also be viewed as a highly discretized form of linear attention: the KV cache preserved by SWA can be regarded as a highly discretized state space in linear attention. Next, we discuss these two perspectives separately and introduce some related papers, such as Raven.
Background: Linear attention
A normal linear state model maintains a fixed-size state matrix
Here,
Figure 1: An SSM densely updates the entire state, SWA updates one row of the KV cache in FIFO order, and Raven uses routing to select which fixed slots to update.
Viewing SWA from the linear-state perspective
In SWA, every time a token is added, one row is added to the KV cache while the other rows remain unchanged. If every row of the SWA KV cache is viewed as a slot, its update can be written as
To make comparison with the state of linear attention convenient, let the window size be
Viewing the linear state from the SWA perspective
Conversely, we can also use SWA-style slots to understand the linear-attention or SSM update above.
If we continue to view every row of
Note that decay is not present in every linear-attention model; naive linear attention may simply accumulate the state.
Sparse linear memory: The middle ground
We can therefore build an initial intuition: SWA updates one slot at each step, while traditional linear attention updates every slot at each step. Is there a compromise that preserves both the expressive capability of linear attention and the sparse updates of SWA?
This suggests updating only a subset of slots at each step, making updates to the state space sparse. This is where sparse linear memory comes from. There are many ways to select the slots, such as the
Long-term questions for sparse linear memory
I still have some questions about this idea. Although sparse writes reduce interference, they do not remove finite capacity. Perhaps the method can extrapolate to 5M tokens, but what happens after that? Can a model obtain genuine long-context memory capability in this way?
In addition, the longer the text becomes, the more likely fixed slots are to collide. After the memory is expanded, the model must find the target with a limited read budget. A larger state space also greatly increases GPU-memory consumption and infrastructure requirements.
More fundamentally, writing happens before the future query, so the model cannot predict which ordinary token will become important later. The pattern is data-independent and already fixed during training. How can it continue learning instead of merely making the state larger?