Sliding-window beats linear attention

TL;DR

Sliding Window Attention (SWA) with sinks outperforms post-trained linear attention, enabling efficient long-context reasoning without extra training.

cs.CL 🔴 Advanced 2026-08-28 43 views
Alexia Jolicoeur-Martineau Rhea Sanjay Sukthanker Pashmina Cameron Emy Gervais
deep learning attention mechanisms large models efficiency long-text

Key Findings

Methodology

The study conducts comprehensive comparisons across multiple pretrained models (from 1.3B to 70B parameters) on various benchmarks, including MMLU, ARC, and long-context reasoning tasks like Needle-in-a-Haystack and BABILong. It evaluates SWA (window size 64, 4 sinks) against linear attention and post-trained variants, focusing on inference performance, memory, and speed. The core algorithm, Sink-augmented SWA, restricts attention to recent tokens plus a few sink tokens at the start, preventing performance collapse. Experiments demonstrate that SWA achieves 2-10x performance gains in long-text tasks, with no need for additional training, making it highly practical.

Key Results

  • In long-context reasoning tasks such as Needle-in-a-Haystack and BABILong, SWA achieves 2-10 times higher accuracy than linear attention, with performance recovery up to 93.2% of the baseline. For example, at 4K tokens, SWA reaches 19% accuracy on BABILong, while linear attention only attains 5%.
  • Across models from 1.3B to 70B, SWA consistently recovers over 93% of baseline performance on benchmarks like MMLU, outperforming post-trained linear models like LoLCATs (83.2%) and QRWKV6 (92.4%). It also offers faster inference and lower memory consumption, especially with smaller window sizes.
  • In short-text tasks, SWA nearly matches full attention, with 99% performance recovery. In long-text scenarios, SWA's advantage becomes more pronounced, especially at 4K length, where it maintains high accuracy and efficiency, demonstrating robustness and scalability.

Significance

This work addresses a fundamental bottleneck in deploying large language models for long-text understanding—balancing performance, memory, and speed. By introducing a training-free, sink-augmented sliding window attention, it offers a simple yet powerful solution that surpasses existing linear attention methods in real-world scenarios. The approach enables models to handle longer contexts with minimal resource overhead, making large-scale AI more accessible and scalable in industry applications like document analysis, dialogue systems, and scientific research. It also opens avenues for further research into adaptive windowing and multi-modal extensions, promising broader impacts across AI fields.

Technical Contribution

The key technical innovation lies in integrating attention sinks with a sliding window mechanism, ensuring stable long-range dependencies without retraining. This design prevents the catastrophic performance drop seen in sink-free SWA and maintains high expressivity. The method's simplicity—applying a fixed attention mask during inference—coupled with extensive empirical validation, demonstrates that high performance can be achieved without complex training procedures. It fundamentally challenges the necessity of post-training linearization, providing a new paradigm for efficient inference in large models.

Novelty

This is the first comprehensive comparison showing that sink-augmented SWA can outperform or match post-trained linear attention models across diverse tasks and models without additional training. The innovation of combining attention sinks with a sliding window to prevent performance collapse is novel, addressing a critical gap in the literature. The work redefines the trade-offs between efficiency and accuracy, establishing a new baseline for long-context inference that is both simple and highly effective.

Limitations

  • While effective up to 4K tokens, the performance of SWA in ultra-long contexts (beyond 4K) remains untested, requiring further validation. The choice of window size and sink number influences results, demanding task-specific tuning. Although no training is needed, some tasks may benefit from fine-tuning or adaptive mechanisms to optimize performance. The method's robustness in multi-modal or highly dynamic scenarios also warrants future exploration. Additionally, the approach assumes a fixed attention pattern, which may limit flexibility in certain applications.

Future Work

Future research should explore adaptive window and sink configurations, possibly via learned or dynamic attention masks, to further improve long-text handling. Extending SWA to multi-modal data, such as video or images, with multi-dimensional sliding windows, is promising. Combining SWA with lightweight fine-tuning or reinforcement learning could unlock even higher performance. Investigating scalability to trillion-parameter models and real-time applications will be essential for industrial deployment. Lastly, integrating SWA into multi-task and multi-modal systems could broaden its impact.

AI Executive Summary

Large language models (LLMs) have revolutionized natural language processing but face significant challenges in handling long texts efficiently. The quadratic complexity of self-attention mechanisms results in enormous memory and computational costs, limiting practical deployment. While linear attention methods reduce these costs, they often compromise model expressivity and long-term memory, especially in long-context reasoning tasks. This paper introduces a simple yet powerful solution: Sink-augmented Sliding Window Attention (SWA). By restricting attention to recent tokens plus a few attention sinks at the start, SWA maintains high performance without additional training or fine-tuning.

Extensive experiments across multiple models, from 1.3B to 70B parameters, and diverse benchmarks demonstrate SWA's superiority in long-text tasks. In scenarios like Needle-in-a-Haystack and BABILong, SWA achieves 2-10x performance gains over linear attention, recovering up to 93% of baseline accuracy at 4K tokens. It also nearly matches full attention performance in short-text tasks, with 99% recovery. The method's simplicity—applying a fixed attention mask during inference—results in faster decoding and lower memory usage, making it highly suitable for real-world deployment.

This work challenges the necessity of complex post-training linearization, offering a resource-efficient, robust alternative that scales well with model size and context length. Its broad applicability, from document analysis to scientific research, promises to accelerate the adoption of large models in industry. Future directions include adaptive attention mechanisms, multi-modal extensions, and integration with fine-tuning strategies, further enhancing long-text understanding capabilities.

Deep Analysis

Background

Transformers的出现极大推动了自然语言处理的发展,但其核心机制自注意力(Self-Attention)具有二次复杂度,导致在长文本处理时资源消耗巨大。为解决这一瓶颈,线性注意力(如Katharopoulos等2020)被提出,降低复杂度至线性,但在表达能力和长距离依赖建模方面存在不足。滑动窗口注意力(SWA,Beltagy等2020)通过限制关注范围,提升长文本记忆能力,但在没有特殊设计时会出现性能崩溃。近年来,结合后训练的线性化方法(如LoLCATs,Zhang等2025a)试图在保持性能的同时降低成本,但缺乏系统性比较,尤其在长文本推理中的表现仍待验证。

Core Problem

尽管线性注意力降低了复杂度,但在长文本推理任务中表现不佳,难以满足实际需求。全注意力机制虽效果优异,但资源消耗过大,限制了其应用范围。如何在保证模型性能的同时,降低推理成本成为核心难题。现有线性化方法多依赖后训练,增加了训练成本和复杂度,且在长文本场景中表现不稳定。缺乏一种无需微调、简单高效的方案,成为研究的瓶颈。

Innovation

提出带sink的滑动窗口注意力(SWA),通过在窗口边界引入attention sinks,避免性能崩溃,确保长文本中信息的持续捕获。该机制无需后训练,直接在推理阶段应用,极大简化流程。结合窗口机制和sink设计,兼顾效率与表达能力,显著提升长文本推理性能。创新点在于解决sink-free SWA的性能崩溃问题,提供一种高效、稳定的长文本注意力方案。

Methodology

  • �� 设计带sink的滑动窗口掩码,将关注范围限制在前w个tokens和4个sink tokens。
  • �� 在推理阶段直接应用此掩码,无需微调或后训练。
  • �� 通过在不同模型(1.3B-70B参数)上,验证在短文本和长文本任务中的性能。
  • �� 比较全注意力、线性注意力及其后训练版本,重点在长文本推理中的表现差异。
  • �� 多任务、多模型对比,确保结果的普适性和可靠性。

Experiments

采用公开数据集(如MMLU、ARC、Hellaswag、PIQA、Winogrande)评估模型性能,比较SWA与线性注意力及其后训练版本。参数包括窗口大小(64、128、256、512)和sink数量(4),在不同模型(1.3B-70B)上测试。性能指标为准确率和性能恢复率,特别关注长文本(4K)任务中的表现。还测量推理速度和内存消耗,验证SWA的效率优势。

Results

SWA在多模型、多任务中表现优异,长文本任务中性能提升2-10倍,恢复了93%以上的基线性能。在短文本任务中,几乎达到全注意力(99%)。在长文本推理(如单针马蜂窝、BABILong)中,SWA在4K长度下恢复17-23%的全注意力性能,线性注意力仅为5%。速度和内存方面,SWA优于全注意力和线性注意力,特别在较小窗口(64)时,内存最低,速度最快。

Applications

该方法适用于长文本理解场景,如法律文档、长篇小说、科学论文分析。无需微调,直接在预训练模型上应用,极大降低部署成本。未来结合微调可提升性能,适应更复杂、多模态任务,推动行业应用。

Limitations & Outlook

在超长文本(超过4K)或多模态场景中的表现尚未验证,需扩展研究。窗口大小和sink参数敏感,需调优。虽然无需微调,但某些任务中微调可能更优。模型在特殊场景可能存在信息丢失或性能下降,未来需自适应参数调节机制。

Plain Language Accessible to non-experts

想象你在整理一本超长的书,里面有很多章节(就像长篇文章或对话)。传统方法是逐页阅读,既慢又费力。现在,有一种聪明的技巧,就像用一个夹子,只夹住最近几页(窗口)和一些特别标记的重点页(sink),这样你不用翻遍全部内容,也不会漏掉重要信息。这样一来,你既能快速找到关键信息,又能节省空间和时间。这就像在电脑里用一种特殊的“夹子”机制,让大模型在理解超长文本时,既快又省资源,特别适合处理复杂的长篇内容。

ELI14 Explained like you're 14

你知道看一本很长的书,要花很多时间和空间吗?如果每次都翻到每一页,既慢又麻烦。现在,有一种聪明的方法,就像用一个特别的夹子,只夹住书的前几页和一些重要的页(比如目录或重点页),这样你不用翻全部内容,也能记住重点。这就像用标签或笔记,把重要的内容集中在一起,方便以后查找。这种技巧在电脑里也用,叫滑动窗口注意力,帮助大模型快速理解超长文本,既节省资源,又效果好。

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.

cs.CL cs.LG