Notes

Sparse Attention

Full attention compares every token with every other token, and then discovers that almost all of those comparisons carried no weight. Sparse attention declines to compute the pairs that were never going to matter.

Patterns decided in advance

The simplest versions fix the pattern before training: strided and local blocks in the Sparse Transformer, and in BigBird a mix of a local window, a few global tokens every sequence attends to, and a sprinkling of random links. The mix is deliberate — local edges capture nearby structure, global tokens act as a relay so any two positions can reach each other in a couple of hops, and the whole thing costs linear rather than quadratic work. Crucially the skipping has to be block-structured: a GPU multiplies tiles, so dropping scattered individual entries saves nothing.

What you give up
  • It is an approximation. Unlike FlashAttention, which reorders memory traffic and returns the identical result, sparse attention computes a different, cheaper function.
  • Learned and dynamic variants — routing or clustering tokens so each attends to the group it belongs to — fit the data better and are harder to make fast.
  • The practical win appears only at long sequence lengths; under a few thousand tokens a dense kernel usually wins outright.
Why it matters

This is one of the two ways a model gets a long context at all, the other being better dense kernels. Reading an architecture card, it tells you something real: a model built on sparse attention has a prescribed map of which positions can see which, and a question whose answer depends on two facts the pattern never connects is one it is structurally poor at.

Sparse attention computes only a chosen subset of token pairs instead of all of them, cutting attention's quadratic cost to roughly linear. The subset follows a pattern — local windows, strides, a few global tokens, sometimes random links — designed so information can still travel between any two positions in a few hops. Unlike FlashAttention it changes the result rather than just the memory traffic, so it is an approximation: the pattern decides which long-range dependencies the model can represent.

At a party of two hundred people, nobody has a conversation with all two hundred. You talk to the people around you, plus a couple of hosts who know everyone and relay news across the room. Everyone still ends up informed, and nobody has to shake two hundred hands.

An AI language system normally compares every word in a text with every other word, which becomes punishingly expensive for long documents. Sparse attention organises those comparisons like the party: each word checks its neighbours, plus a few well-connected words that act as relays. Most of the pairings are simply skipped. It is far cheaper, with the catch that two distant words can only connect through the shortcuts provided.