{
  "id": "sliding-window-attention",
  "code": "PTL-0270",
  "term": "Sliding Window Attention",
  "aliases": [
    "SWA",
    "local attention",
    "windowed attention",
    "rolling buffer cache"
  ],
  "category": "foundations",
  "definition": "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.",
  "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.",
  "example": null,
  "broader": [
    "transformer"
  ],
  "narrower": [],
  "related": [
    "kv-cache",
    "context-window",
    "attention-sinks",
    "grouped-query-attention",
    "context-window-extension",
    "flashattention"
  ],
  "introduced": 2020,
  "added": "2026-11-27",
  "sources": [
    {
      "title": "Longformer: The Long-Document Transformer",
      "authors": "Beltagy et al.",
      "year": 2020,
      "url": "https://arxiv.org/abs/2004.05150"
    },
    {
      "title": "Mistral 7B",
      "authors": "Jiang et al.",
      "year": 2023,
      "url": "https://arxiv.org/abs/2310.06825"
    }
  ],
  "url": "https://protologue.com/t/sliding-window-attention/",
  "citation": "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/"
}