Explainer
Sliding-window and sparse attention
Designs in which each token draws on only some earlier tokens, to save work and memory on long inputs.
In full attention, each token can draw on every earlier token. Sliding-window attention, also called local or window attention, limits a layer to the most recent tokens: with a window of 128, a token sees only the last 128. Recent models often mix local and full layers: gpt-oss-20b alternates sliding and full layers with a window of 128 (its configuration file), and Gemma 3 uses five local layers for every global one (Gemma 3 report).
A sliding layer's cache stops growing once it holds a full window (Hugging Face cache guide). The quality cost has to be measured, because a distant fact now reaches a token only through the full layers or by hopping from window to window through the layers. Mistral's authors report an 8x smaller cache at 32,000 tokens “without impacting the model quality” (Mistral 7B paper), on their own tests.
Three names that sound alike solve different problems:
- Sparse attention. Chooses which tokens connect, by a fixed pattern or a learned selector (Sparse Transformers, NSA).
- Linear attention. Replaces the comparison with a running summary whose cost grows in step with the text (Katharopoulos et al.).
- Mixture of experts. Picks which feed-forward blocks run for each token; it is not attention at all (Mixtral, Mixture of experts).
Going deeper
A sliding window is not the context window, the limit on the whole input: gpt-oss-20b allows 131,072 positions while half its layers see only the last 128 tokens. DeepSeek-V3.2 uses a learned kind, DeepSeek Sparse Attention. Sparse and linear designs change what the model computes, unlike FlashAttention, which computes full attention exactly.
In the long read: names with attention in them. Next, FlashAttention.
Read next: FlashAttention