# Sliding Window Attention

> Sliding window attention is a form of attention in which each token attends only to a fixed number of nearby or preceding tokens rather than the whole sequence, so its cost grows linearly instead of quadratically with sequence length.

- Identifier: PTL-0270
- Category: Foundations
- Canonical URL: https://protologue.com/t/sliding-window-attention/
- Also known as: SWA, local attention, windowed attention, rolling buffer cache
- Introduced: 2020

## Description

Beltagy et al. used it in Longformer in 2020, combining local windowed attention with task-motivated global attention on a few tokens, so that the model scales linearly with sequence length. Stacking layers widens the receptive field, so information can still travel across a long document. Jiang et al. used causal sliding window attention in Mistral 7B in 2023 with a window of 4,096 tokens, reporting a theoretical attention span of about 131K tokens, and a rolling buffer cache that overwrites older keys and values and, by their account, reduces cache memory use by 8x on 32K-token sequences without affecting model quality. Tokens outside the window can be reached only indirectly through lower layers, and evicting the earliest tokens can destabilize generation unless attention sinks are kept.

## Broader terms

- [Transformer](https://protologue.com/t/transformer/)

## Related terms

- [KV Cache](https://protologue.com/t/kv-cache/)
- [Context Window](https://protologue.com/t/context-window/)
- [Attention Sinks](https://protologue.com/t/attention-sinks/)
- [Grouped-Query Attention](https://protologue.com/t/grouped-query-attention/)
- [Context Window Extension](https://protologue.com/t/context-window-extension/)
- [FlashAttention](https://protologue.com/t/flashattention/)

## Sources

- Beltagy et al. (2020). Longformer: The Long-Document Transformer. https://arxiv.org/abs/2004.05150
- Jiang et al. (2023). Mistral 7B. https://arxiv.org/abs/2310.06825

## Cite this entry

Protologue. (2026). Sliding Window Attention. In Protologue: A Taxonomy of Prompting and LLM Techniques (v1.9.1, PTL-0270). https://protologue.com/t/sliding-window-attention/

License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
