SWAA: Sliding Window Attention Adaptation for Efficient Long-Context LLMs Without Pretraining

Yijiong Yu, Jiale Liu, Qingyun Wu, Huazheng Wang, Ji Pei
12/11/2025
2 citations
cs.CLcs.AI
transformer-attention

Official code: yuyijiong/sliding-window-attention-adaptation (14 stars, Python, Apache-2.0, last commit 2026-02-20).

Abstract

The quadratic complexity of self-attention in Transformer-based Large Language Models (LLMs) renders long-context inference prohibitively expensive. While Sliding Window Attention (SWA), the simplest sparse attention pattern, offers a linear-complexity alternative, naively applying it to models pretrained with Full Attention (FA) causes catastrophic long-context performance collapse due to the training-inference mismatch.

Show full abstract

To address this, we propose Sliding Window Attention Adaptation (SWAA), a plug-and-play toolkit of recipes that adapt FA models to SWA without costly pretraining. SWAA systematically combines five strategies: (1) applying SWA only during prefilling; (2) preserving "sink" tokens; (3) interleaving FA/SWA layers; (4) chain-of-thought (CoT); and (5) fine-tuning. Our experiments demonstrate that while individual methods are insufficient, specific synergistic combinations can effectively recover original long-context capabilities. After further analyzing performance-efficiency trade-offs, we identify recommended SWAA configurations for diverse scenarios, which achieve 30% to 100% speedups for long-context LLM inference with acceptable quality loss. Our code is available at https://github.com/yuyijiong/sliding-window-attention-adaptation

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Adapt full attention LLM to sliding window attention

140Python, ShellNov 30, 20259 months agoApache-2.0

Similar Papers

Cite this paper

@article{yu2025swaa,
  title  = {SWAA: Sliding Window Attention Adaptation for Efficient Long-Context LLMs Without Pretraining},
  author = {Yijiong Yu and Jiale Liu and Qingyun Wu and Huazheng Wang and Ji Pei},
  year   = {2025},
  eprint = {2512.10411},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2512.10411v4}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2512.10411.svg)](https://codeofpaper.com/paper/2512.10411)

Discussion