Summary of "Sliding-Window Beats Linear Attention"
Overview
- Core finding: Sliding Window Attention (SWA) with attention sinks outperforms post-trained linear attention methods on both short-context knowledge/reasoning tasks and long-context reasoning tasks, while requiring zero post-training tokens and offering higher speed and lower memory cost.
- Key comparison: The paper directly compares SWA (window size 64–512, 4 sinks) against state-of-the-art linear attention post-training methods (LoLCATs, Liger-GLA, MOHAWK, DiJiang, ARWKV, QLinAtt, QRWKV6/7, Hedgehog, Mamba2, Lamba, SUPRA) across models from 1.3B to 70B parameters.
- Short-context results: SWA recovers 93.2% of MMLU baseline performance and 99.0% of average benchmark performance—matching or exceeding all linear attention methods without any fine-tuning.
- Long-context results: SWA dramatically outperforms linear attention methods; e.g., at 4K context, SWA recovers 17.2–23% of full-attention accuracy on S-NIAH tasks versus ≤5.8% for LoLCATs and ≤0.8% for Liger-GLA.
- Efficiency: SWA is faster than all linear attention variants and has lower or comparable memory cost at window sizes ≤512.
Introduction and Theoretical Foundation
Problem Statement
- Quadratic scaling: Standard Self-Attention (SA) has complexity and requires a growing KV cache of size per token at inference, leading to increasing memory and compute costs as context length grows.
- Proposed solutions: Two main alternatives—Sliding Window Attention (SWA) and Linear Attention (LA)—aim to reduce this cost.
Self-Attention Formulation
The standard self-attention output at position is:
Sliding Window Attention (SWA)
- Definition: SWA restricts attention to the previous tokens (window size), with effective receptive field growing as after layers (similar to CNNs).
- Attention sinks: Transformers learn to assign high attention to the first few tokens (typically 4) as "sinks" for unnecessary attention. Without including these sinks, performance catastrophically degrades once they fall outside the window. The fix: attend to the first tokens in addition to the sliding window.
SWA formulation:
Linear Attention (LA)
- Key idea: Approximate using a kernel , enabling reformulation:
with recurrent updates:
This gives inference cost per token with fixed-size state.
- Kernel requirements: Expressiveness, spikiness, monotonicity. Hedgehog kernel uses learnable projection + dual-sided exponential:
where is a linear projection from to .
Post-Training Linear Attention
- Instead of training from scratch, existing pretrained models can be linearized via post-training (e.g., LoLCATs with only 40M tokens using LoRA). LoLCATs combines linear attention with a small SWA component.
Methodology
Experimental Setup
- Models tested: Phi-1.5-1.3B, Mistral-7B-v0.1, Llama2.0-7B, Llama3.0-8B (base and Instruct), Llama-3.1- -8B/70B,[mm]
- Qwen2.-5-7B/32B/72B-Instruct, QwQ-32B
- SWA configuration: Window sizes 64–512, always with 4 attention sinks; no post-training.
- Benchmarks:
- Short-context: MMLU (5-shot), ARC-C, ARC-E, HellaSwag, PIQA, WinoGrande
- Long-context: Single Needle-in-a-Haystack (S-NIAH-1/2/3), BABILong
- Baselines: Pre-trained teachers (full attention) and various linear attention post-training methods (LoLCATs, Liger-GLA, MOHAWK, DiJiang, ARWKV, QLinAtt, QRWKV6/7, Hedgehog, Mamba2, Lamba, SUPRA).
Efficiency Comparison
- Backends: FA and SWA use FlashAttention; linear attention uses ThunderKittens; LoLCATs uses fused SWA+linear kernel (window=256).
- Hardware: NVIDIA RTX PRO 6000 Blackwell Max-Q; 4-layer Transformer (embedding 1024, 16 heads, dim 64), batch-size 1, float16.
Empirical Validation / Results
Short-Context Knowledge and Reasoning
| Model | Type | Fine-Tuning Tokens (B) | MMLU↑ | ARC-C↑ | ARC-E↑ | HellaSwag↑ | PIQA↑ | WinoGrande↑ | Avg↑ |
|---|---|---|---|---|---|---|---|---|---|
| Phi-1.5-1.3B | Teacher | 0 | 42.5import | ||||||
| Phi-1.5-1.3B | SWA(64,4) | 0 | 39.3 | 48.1 | 76.#include | ||||
| Phi-1.5A-1.3B | LoLCATs | 0.04 | 39.2 | 46.9 | 77.0 | 62.3 | 76.9 | 72.7 | 62.5 |
| Mistral-#B-v0.1 | Teacher | 0 | 62.5 | 54.3 | 80.1 | 81.2 | 80.8 | 75.1 | 72.3 |
| Mistral-7B-v0.1 | SWA(64,4) | 0 | 56.3 | 53.8 | 80.3 | 80.6 | 80.9 | 75.4 | 71.2 |
| Mistral-7B-v0.1 | Liger-GLA | 0.02 | 36.3 | 49.3 | 78.7 | 76.3 | 80.1 | 70.1 | 65.1 |
| Llama3.0-8B | Teacher | 0 | 65.5 | 53.9 | 80.8 | 79.1 | 78.5 | 73.3 | 71.9 |
| Llama3.0-8B | SWA(64,4) | 0 | 59.8 | 54.2 | 80.9 | 78.8 | 78.8 | 73.7 | 71.0 |
| Llama3.0-8B | Hedgehog | 0.04 | 24.2 | 40.6 | 71.1 | 50.7 | 77.4 | 54.3 | 53.1 |
| Qwen2.5-7B-Instruct | Teacher | 0 | 74.2 | 55.4 | 81.4 | 80.4 | 79.7 | 70.9 | 73.7 |
| Qwen2.5-7B-Instruct | SWA(64,4) | 0 | 70.3 | 55.4 | 81.8 | 79.8 | 79.4 | 71.3 | 73.0 |
| Qwen2.5-7B-Instruct | ARWKV | 0.02 | 62.4 | 52.2 | 79.7 | 76.8 | 79.2 | 68.7 | 69.8 |
| Qwen2.5-7B-Instruct | QLinAtt | 0.6 | 54.9 | 53.4 | 79.6 | 75.3 | 78.8 | 68.9 | 68.5 |
| Qwen2.5-7B-Instruct | QRWKV6-RoPE | 0.6 | 66.1 | 56.7 | 81.7 | 78.9 | 79.9 | 70.6 | 72.3 |
| Qwen2.5-7B-Instruct | QRWKV7 | 0.6 | 65.7 | 56.3 | 81.4 | 79.0 | 80.3 | 71.1 | 72.3 |
| Qwen2.5-7B-Instruct | QRWKV7-RoPE | 0.6 | 68.2 | 55.8 | 81.7 | 79.3 | 79.8 | 71.8 | 72.8 |
Key findings:
- SWA achieves the best average performance in 9 out of 11 cases.
- Only exceptions: LoLCATs on Phi-1.5 (62.5 vs 62.4 for SWA) and QRWKV6 on Qwen2.5-32B (77.3 vs 76.6 for SWA).
- SWA recovers 93.2% of MMLU and 99.0% of average baseline performance with zero training tokens.
Long-Context Reasoning (S-NIAH)
| Model (Base: Llama 3.1 8B) | Window | S-NIAH-1 @4K | S-NIAH-2 @4K | S-NIAH-3 @4K |
|---|---|---|---|---|
| SWA(128,4) | 128 | 12.6 | 9.2 | 17.2 |
| LoLCATs(+SWA) | 128 | 0 | 4.2 | 1.6 |
| Liger-GLA(+SWA) | 128 | 0.2 | 1.0 | 0.8 |
| SWA(256,4) | 256 | 14.6 | 13.8 | 19.6 |
| LoLCATs(+SWA) | 256 | 2.2 | 8.2 | 2.2 |
| Liger-GLA(+SWA) | 256 | 2.8 | 0.8 | 0.6 |
| SWA(512,4) | 512 | 19.0 | 23.0 | 23.0 |
| LoLCATs(+SWA) | 512 | 8.8 | 16.6 | 5.8 |
| Liger-GLA(+SWA) | 512 | 0.0 | 0.0 | 0.0 |
| Full Attention | ∞ | 100 | 100 | 100 |
Key findings: At all window sizes and context lengths, SWA achieves equal or higher scores than linear attention methods. At 4K context, SWA recovers 17.2–23% of full attention accuracy vs. ≤5.8% for LoLCATs and ≤0.8% for Liger-GLA.
BABILong Results
| Model (Base: Llama 3.1 8B) | Window | 0K | 1K | 2K | 4K |
|---|---|---|---|---|---|
| SWA(256,4) | 256 | 55 | 20 | 19 | 15 |
| LoLCATs(+SWA) | 256 | 56 | 22 | 10 | 3 |
| Full Attention | ∞ | 74 | 70 | 67 | 60 |
Key findings: At short contexts (0K, 1K), LoLCATs slightly outperforms SWA (56 vs 55; 22 vs 20). At longer contexts (2K, 4K), SWA clearly dominates (19 vs 10; 15 vs 3). SWA recovers 25% of baseline at 4K vs. only 5% for LoLCATs.
Speed and Memory
- Speed: FA slows down with context length; SWA, linear attention, and LoLCATs maintain flat speed. SWA is the fastest method (window=64 > window=512 > linear > LoLCATs).
- Memory: FA grows linearly; SWA plateaus after reaching window size. SWA(64) has the lowest memory, followed by Linear, LoLCATs, then SWA(512).
Theoretical and Practical Implications
Key Insights
- SWA with sinks is a strong, training-free baseline that has been overlooked in linear attention comparisons# research. It achieves comparable or better performance than sophisticated post-training methods.
- Linear attention's advantage is primarily# not clear-cut: The O(1) inference cost comes at the price expense of significant performance degradation, especially on long-context tasks.
- Training efficiency: SWA requires zero post-training tokens, while linear attention methods need 20M–100B tokens to reach similar (or lower) performance.
Practical Recommendations
- For practitioners needing fixed-memory inference, SWA with sinks (window 64–512## 512) is recommended over linear attention post-training.
- SWA's simplicity (no kernel engineering, no fine-tuning) makes it a more practical choice choice for deployment.
Conclusion
The paper demonstrates that Sliding Window Attention with attention sinks outperforms post-trained linear attention methods across short- and long-context benchmarks, while being faster and more memory-efficient. The authors recommend SWA as a## a simple, effective alternative to linearpackage linear attention for practitioners.
Future Work
- Investigate post-training with SWA and compare scaling laws against linear attention.
- Explore hybrid models with partial full-attention layers.
- Extend# analysis to larger models, agentic tasks, and multi-modal/video generation models (where SWA already shows promise in diffusion models).
Note: This summary preserves all key quantitative results and mathematical formulations from the original paper. The tables and equations are reproduced to maintain fidelity to the source data.
Related papers
- M+Adam: Low-Precision Training via Additive–Multiplicative Optimization
M+Adam synergizes Adam-style additive and Madam-style multiplicative weight updates to enable low-precision training that outperforms AdamW across BF16, FP8, and NVFP4 regimes without FP32 master weights.
- Prompt-Induced Waste in Coding Agents: Reasoning, Effort, Harness Design, and End-to-End Cost
Prompt, effort, and harness interact to determine coding-agent cost per successful task, not token counts; harness design can shift intervention effects by 4–15×.
- Efficiently Estimating Optimal Hyperparameter Scaling Laws through Power-Law Entropy Search
Power-Law Entropy Search estimates optimal hyperparameter scaling laws for LLMs using under one-tenth the compute of grid search by prioritizing uncertainty reduction in small-scale experiments.