How does sliding-window attention trade global context for reduced computational cost?

Last updated 22 November 2026

  • Each token attends only to the previous w tokens, cutting compute to O(N·w) and capping the KV cache as a rolling buffer of size w.

  • Stacking layers widens the receptive field to roughly L·w (Mistral 7B: about 131k tokens), but this multi-hop path is lossy and hurts exact long-range retrieval.

  • Mitigations include interleaving global-attention layers (Gemma 2/3), global tokens (Longformer, BigBird), and attention-sink tokens for streaming (StreamingLLM).

  • https://www.geeksforgeeks.org/deep-learning/dilated-and-global-sliding-window-attention/
  • https://www.geeksforgeeks.org/deep-learning/longformer/
  • https://www.digitalocean.com/community/tutorials/sliding-window-attention-efficient-long-context-models
All Transformers interview questions