C.W.K.
Stream
Lesson 03 of 05 · published

Sparse and Sliding Window Attention

~13 min · longformer, bigbird, sliding-window, mistral

Level 0Observer
0 XP0/50 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Don't approximate — just attend less

If approximating softmax is hard, the alternative is to leave softmax exact and just attend to fewer tokens. The two early production winners are Longformer (Beltagy et al., 2020) and BigBird. Both use a combination of: a local sliding window (each token attends to its w neighbors), global tokens (a small set of designated tokens that attend everywhere and are attended to by everyone), and in BigBird's case, additional random connections.

The cost is O(n·w) where w is the window size. Linear in sequence length when w is fixed. The assumption is that most relevant information is local, with global tokens handling the rare long-range dependencies. For documents this works well; for tasks with arbitrary long-range dependencies, it loses information.

Sliding window in production: Mistral and Griffin

The version that actually shipped widely is sliding-window attention, used in Mistral 7B (window 4096), Mistral Large, and Google's Griffin family. Each layer attends only to a window of recent tokens; the model's stack-of-layers structure means information can still propagate further than the window because each layer's output feeds the next layer's window.

Mistral's architecture choice — sliding window 4096 with the model trained at higher context lengths — was a productionization of this idea, and it's a big reason Mistral's models punched above their parameter count for long context. Griffin (Google, 2024) combines sliding-window attention with a recurrent linear-RNN component, giving a hybrid that hit 6K tok/s vs. ~2K for Gemma at comparable scale.

Learned sparsity — NSA and MoBA

The 2025 generation of sparse attention got more interesting. NSA (Native Sparse Attention) and MoBA (Mixture of Block Attention), both ACL 2025 papers, use learned sparsity patterns: the model decides per-query which tokens are worth attending to, with sparsity constraints baked into the kernel for hardware efficiency.

Learned sparsity converges much closer to full-attention quality than fixed sparsity. The cost: the kernels are more complex than sliding window, and the patterns can be harder to debug. But the early production results (Moonshot's Kimi family uses this) are strong enough that NSA-style sparsity is likely the default sparse-attention pattern through 2027.

External links

Exercise

Run Mistral 7B with sliding-window enabled and a 32K-token document. Then ask it questions whose answer requires retrieving information from outside any single window (e.g., a fact stated at the very beginning, asked about at the very end). You should see degraded but not catastrophic performance — the multi-layer stack lets information propagate via window-overlap, but the model is clearly not seeing the full context at once. This is the practical limit of sliding window at the model level.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.