arXiv(opens in a new tab)cs.CLAug 2026Cited by 3 papers on PaperVantage

Manuscript Offprint

arXiv:2608.28444

Sliding-window beats linear attention

Alexia Jolicoeur-Martineau, Rhea Sanjay Sukthanker, Pashmina Cameron, Emy Gervais

Alexia Jolicoeur-Martineau

Microsoft

Applied Sciences Group (ASG)

alexiaj@microsoft.com

Pashmina Cameron

Microsoft

Applied Sciences Group (ASG)

pcameron@microsoft.com

Rhea Sanjay Sukthanker

Microsoft

Applied Sciences Group (ASG)

rsukthanker@microsoft.com

Emy Gervais

Independent

emy.gervais0@gmail.com

ABSTRACT

Due to the nature of quadratic attention, Large Language Models (LLMs) consume a lot of memory and energy. Every new token costs more than the previous one. For each additional token, the keys and values must be stored in memory indefinitely, which is unsustainable.

Several alternatives have been proposed to fix the quadratic scaling problem, one of which is retrofitting LLMs to use Linear Attention. This idea has attracted a lot of attention, given its promise to solve the quadratic scaling problem with state-of-the-art performance at low cost. However, this line of research has not been properly compared to simpler baselines.

In this work, we show that Sliding Window Attention (SWA) with sinks performs as well or better than post-trained Linear Attention models. We observe this across multiple LLMs on various downstream tasks. For long-context reasoning tasks (Needle-in-a-Haystack and BABILong), SWA achieves massively higher performance (2 to 10 times higher than linear attention). SWA requires no post-training, is extremely fast, and requires low memory; therefore, making it an extremely cheap and reliable solution.

To reduce inference memory cost, we strongly recommend switching to SWA instead of post-training linear models. Linear attention models may have shown some promise, but they likely require to be trained from scratch or extensive post-training in order to even match SWA.

NamePost-training TokensPost-training StagesRecovery (%) MMLU↑Average↑
SUPRA (Mercat et al., 2024)100B153.0 (0.0)88.1 (0.0)
Hedgehog (Zhang et al., 2024)40M236.9 (0.0)73.9 (0.0)
LoLCATs (Zhang et al., 2025a)40M283.2 (2.2)97.5 (1.3)
Liger-GLA (Lan et al., 2025)20M162.2 (5.8)92.0 (2.8)
MOHAWK (Bick et al., 2024b)3-5B356.9 (0.0)92.4 (0.0)
Mamba in the Llama (Wang et al., 2024)20B267.7 (0.0)86.7 (0.0)
Dijiangb^{b} (Chen et al., 2024)40B188.7 (0.0)-
ARWKV (Yueyu et al., 2025)60M/830M2/384.1 (0.0)94.7 (0.0)
Llama (Bick et al., 2025)8-12B391.5 (0.0)98.6 (0.0)
QLinAtt (Goldstein et al., 2025)350-700M374.0 (0.0)92.9 (0.0)
QRWKV6 (Goldstein et al., 2025)350-700M392.4 (2.7)99.1 (0.8)
QRWKV7 (Goldstein et al., 2025)350-700M386.4 (6.8)96.1 (4.1)
Sliding Window Attention (64 window-size, 4 sinks)0093.2 (3.5)99.0 (0.5)

Table 1: Performance recovery (student score divided by teacher score) on MMLU-5shot and the average of 6 benchmarks (MMLU-5shot, ARC-C, ARC-E, Hellaswag, PIQA, Winogrande).

INTRODUCTION

Large Language Models (LLMs) consume massive amounts of memory and energy because they scale quadratically with context-length (Vaswani et al., 2017). Every new token's keys and values must be added to the KV cache, and they contribute to an ever-growing memory and compute cost.

Linear attention methods (Katharopoulos et al., 2020) propose an alternative which reduces the time and memory complexity from quadratic to linear. This removes the need to store a KV cache which makes the memory cost small and fixed at inference-time instead of having an ever-growing KV cache.

While promising, linear attention models come with significant drawbacks: 1) lower expressivity, 2) untractable problem of having to decide what to remember so that important information is not overwritten/ignored, and 3) training is expensive and most software/hardware are not built for them.

To tackle the expensive training, a solution is to take an existing pretrained models and swap its expensive quadratic attention with a linear attention. This would normally require fine-tuning with billions of tokens (Bick et al., 2024a), but LoLCATs (Zhang et al., 2025a) showed that this could be done with as little as 40M tokens by combining Hedgehog (Zhang et al., 2024) and Sliding Window Attention (SWA). In doing so, LoLCATs recovers most of the full attention performance on knowledge and reasoning tasks.

Given the promises of these linearizing methods, we gave them a try. What we found was striking. We discovered that changing the attention mask to Sliding Window Attention (SWA) with attention sinks (meaning that we attend to the k previous tokens and the first 4 tokens) gives us better downstream performance than most linearized models. For long-context tasks, the performance gap is even more pronounced, whereas SWA obtains much higher accuracy than linear attention post-training.

The fact that SWA with sinks retains most of the performance of the original model is well known (Xiao et al., 2024; Cabannes et al., 2026), however, to our knowledge, linearizing methods have not been compared to SWA with sinks. In this work, we provide this direct comparison for a wide variety of models (ranging from 1.3B to 70B) on various benchmarks (short and long context). In doing so, we demonstrate that pretrained models can already use SWA at inference time to obtain high performance at a fixed inference memory cost without needing any post-training or specialized linear kernels.

Notation We denote Sliding Window Attention (SWA) in the following way: SWA(w, s), where w is the window-size (varies from 64 to 512) and s is the number of attention sink (always fixed at 4).

Full attention

Figure

LoLCATs(+SWA)

SWA with sinks

Softmax

Attention (SA)

Linear

Attention (LA)

(SA + LA)

Figure 1: Different types of attention masks: Full attention (FA), LoLCATs/Liger-GLA (mixture of linear attention and SWA), and Sliding Window Attention (SWA) with sinks.

2 BACKGROUND

2.1 TRANSFORMERS AND SELF-ATTENTION (SA)

Transformers (Vaswani et al., 2017) are the backbone of modern Large Language Models (LLMs). They process a sequence of LL consecutive tokens. Assuming discrete tokens (with vocab-size VV) used in language, the tokens are embedded (V→DV \to D), transforming the shape of the sequence to [L,D][L, D]. Transformers then process this sequence by alternating between a transformation on the dimension DD using Multi-Layer Perceptron (MLP) and on the dimension LL using Self-Attention (SA). Both MLP and SA use residual connections (x←x+f(x)x \leftarrow x + f(x) where ff is either the MLP or SA). The final output is then projected back into shape [L,V][L, V] to predict the next-token probabilities.

Self-Attention works as follows: the data of shape [L,D][L, D] is linearly projected to keys k\mathbf{k}, queries q\mathbf{q}, and values v\mathbf{v} and the output is transformed in the following way:

xt=∑i=1tat,ivi∑i=1tat,i=∑i=1texp⁡(qtki⊤/d)vi∑i=1texp⁡(qtki⊤/d),fortin[1,…,L](1)\mathbf{x}_{t}=\frac{\sum_{i=1}^{t}a_{t,i}\mathbf{v}_{i}}{\sum_{i=1}^{t}a_{t,i}}=\frac{\sum_{i=1}^{t}\exp(\mathbf{q}_{t}\mathbf{k}_{i}^{\top}/\sqrt{d})\mathbf{v}_{i}}{\sum_{i=1}^{t}\exp(\mathbf{q}_{t}\mathbf{k}_{i}^{\top}/\sqrt{d})},\mathrm{for}t\mathrm{in}[1,\ldots,L] \tag{1}

Several variants of the formulation have proposed, such as Multi-Query Attention (Shazeer, 2019), Grouped Query Attention (Ainslie et al., 2023). Unlike MLP which has complexity O(LD2)\mathcal{O}(LD^{2}), Self-Attention has complexity O(DL2)\mathcal{O}(DL^{2}) and it requires a KV cache at inference time to keep tracks of all previous keys and values in order to make the inference cost per new token linear O(L)\mathcal{O}(L). The quadratic scaling with respect to context-length and the ever-growing KV cache is a big problem for LLMs as it increases in memory and requires more processing time as the sequence grows.

Many engineering tricks have been exploited to make self-attention more efficient (Dao et al., 2022; Dao, 2023; Kwon et al., 2023; Zhang et al., 2023) and compress the KV cache (Liu et al., 2023; Li et al., 2024; Tang et al., 2024). However, the quadratic problem remains. Various solutions have been suggested, but we focus on the following two: Sliding Window Attention (SWA) and Linear Attention (LA).

References (60)