attention-patterns -- full / sliding-window / hybrid / sink
Letting every word compare itself against every earlier word gets expensive quickly: the work per word grows with how much text came before it, and the notes held in memory never stop growing. So real models restrict what each word is allowed to read. A sliding window lets a word see only the last few thousand; a mixed design keeps most layers local and lets a few see everything; and a sink scheme keeps the first handful of words permanently visible alongside the window. Each of these is cheaper, and each gives up the same thing, because a word outside the allowed set is not read at all.
Interactive page: the masking schemes that decide which keys each query may read, and what they cost. Anchor: A3 attention pattern (Family B).
What it shows
An N×N grid (query rows × key cols) where attended cells are lit and masked cells dark. Scrub the transport through four patterns:
- Full (causal) — every query attends to all past keys (
j ≤ i). Attended set grows with position →O(i)per query, unbounded KV cache. - Sliding-window (SWA) — query attends only to the last
wkeys (i−w < j ≤ i). BoundedO(w)per query / cache (Mistral). - Hybrid by layer — a strip of per-layer grids, most local (SWA) and a few global (full): most layers cheap, a few see everything. The ratio is the model's choice, and the two Gemmas differ — Gemma 2 alternates 1: 1 with a 4096 window, Gemma 3 runs 5 local: 1 global with a 1024 window. The strip is drawn at Gemma 3's ratio.
- Attention sink — sliding window plus the first
stokens always attended (the "sink"), which stabilizes very long / streaming contexts (StreamingLLM).
A highlight query i slider outlines one row and the readout reports its attended-key count under the current pattern — making the O(i) vs O(w) cost difference concrete. Sliders for window w, sink size s, and N.
Render tier
T2 (WebGL2-tier surface; the grids are drawn as Canvas2D cell overlays for the 3-way attended / current-row / masked coloring).
Wiring
layout.mount + controls (N, window, sink, query i) + a per-pattern Transport, drawn with ctx + render.label. Per the 2026-06-13 interactivity contract: hover any cell for whether it is attended and why for the current pattern; drag the ◀ current-query handle down the rows (the attended band follows live); drag the window edge on sliding/sink to resize w; the query auto-sweeps down + loops (generation) and the pattern transport loops. Headless hooks: ?step=N/?play=1, ?hover=x,y (attended-reason tooltip), ?q=N (current query row), ?win=N (window size). Source: page.js.