Glossary · Position and context
Sliding-window attention
Also: local attentionSWAchunked attentioninterleaved attention
Read it at the depth you need: one sentence · a paragraph · the math · in the models here
1In one sentence
Attention limited to the last W tokens on some or all layers, which caps those layers' KV cache and attention cost at W however long the context gets.
2In a paragraph
Full attention looks at every earlier token, so its cost and its cache grow with the context. A sliding window looks only at the most recent W tokens. Most models that use it mix the two: Gemma 3 has five windowed layers for each full one, gpt-oss alternates them, so long-range information still flows through the global layers. Llama 4 does something similar with fixed chunks: a token sees only earlier tokens in its own 8K chunk.
3The math, shapes and parameters
With Ls windowed layers of window W and L − Ls global ones, the KV cache for T tokens is
per-token size × [ (L − Ls) × T + Ls × min(T, W) ]
The saving only happens if the runtime evicts old entries for the windowed layers; the GPU-fit pages on this site do not assume it does. The weights are the same either way: a window changes which scores are computed, not the matrices.
4In the 96 models on this site
Models here with windowed or chunked layers, and their KV cache at full context with and without the window:
| Model | Windowed layers | Window | Kind | Context | KV, full | KV, windowed |
|---|---|---|---|---|---|---|
| Gemma 3 270M | 15 of 18 | 512 | sliding | 32K | 604 MB | 109 MB |
| Gemma 3 1B | 22 of 26 | 512 | sliding | 32K | 872 MB | 146 MB |
| Gemma 2 2B | 13 of 26 | 4,096 | sliding | 8K | 872 MB | 654 MB |
| Phi-3 Mini | 32 of 32 | 2,047 | sliding | 4K | 1.6 GB | 805 MB |
| Gemma 3 4B | 29 of 34 | 1,024 | sliding | 128K | 18.3 GB | 2.8 GB |
| OLMo 3 7B | 24 of 32 | 4,096 | sliding | 64K | 34.4 GB | 10.2 GB |
| Gemma 2 9B | 21 of 42 | 4,096 | sliding | 8K | 2.8 GB | 2.1 GB |
| Gemma 3 12B | 40 of 48 | 1,024 | sliding | 128K | 51.5 GB | 8.9 GB |
| gpt-oss-20b | 12 of 24 | 128 | sliding | 128K | 6.4 GB | 3.2 GB |
| Gemma 4 26B-A4B | 25 of 30 | 1,024 | sliding | 256K | 59.1 GB | 5.6 GB |
| Gemma 3 27B | 52 of 62 | 1,024 | sliding | 128K | 66.6 GB | 11.2 GB |
| Gemma 2 27B | 23 of 46 | 4,096 | sliding | 8K | 3.1 GB | 2.3 GB |
| Gemma 4 31B | 50 of 60 | 1,024 | sliding | 256K | 236 GB | 22.3 GB |
| OLMo 3 32B | 48 of 64 | 4,096 | sliding | 64K | 17.2 GB | 5.1 GB |
| Llama 4 Scout (17B-16E) | 36 of 48 | 8,192 | chunked | 256K | 51.5 GB | 14.1 GB |
| gpt-oss-120b | 18 of 36 | 128 | sliding | 128K | 9.7 GB | 4.8 GB |
| Inkling-Small | 35 of 42 | 512 | sliding | 1024K | 180 GB | 30.1 GB |
| Llama 4 Maverick (17B-128E) | 36 of 48 | 8,192 | chunked | 256K | 51.5 GB | 14.1 GB |
| Inkling | 55 of 66 | 512 | sliding | 1024K | 520 GB | 47.5 GB |
Introduced in Beltagy et al., “Longformer: The Long-Document Transformer” (2020).
Related
KV cache · Self-attention · Attention sinks · RoPE (rotary position embedding) · every term