Log inStart free
LESSON 9.09 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Sparse and block-sparse attention

Watch a fixed pattern skip most attention scores, then run in whole tiles.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 9.09 · ATTENTION BAY16 TOKENS · 136 SCORES
01
Stage 1 of 6 · Full attention
In causal attention, each query scores every earlier key. 16 tokens need 136 scores.
Explain it simply

Each row is one token asking a question, called the query. Each column is a token it may read, called a key. Every filled cell is one score the model must compute. Double the tokens and you get about four times the cells.

A 16 by 16 grid of query rows and key columns. The 136 cells on and below the diagonal are filled. Bars on the right show 1 to 16 keys per row.

computed score, weightskipped scoretile, 1-layer readlost weightskipped tile
the 1cat 2sat 3on 4the 5mat 6because 7it 8was 9warm 10and 11the 12sun 13was 14out 15. 161234567891011121314151612345678910111213141516full causal attentionkeys →queries ↓scores per row16 · 17 / 2 = 136 scoresthe 1cat 2sat 3on 4the 5mat 6because 7it 8was 9warm 10and 11the 12sun 13was 14out 15. 161234567891011121314151612345678910111213141516full causal attentionkeys →queries ↓scores per row16 · 17 / 2 = 136 scores
Toy: 16 tokens, head width 4, causal
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
sij=qi⋅kjd,j≤i\sy{s}{out}{s_{ij}} = \frac{\sy{q}{data}{q_i}\cdot\sy{k}{data}{k_j}}{\sqrt{d}},\quad j \le i
n(n+1)2=16⋅172=136\tfrac{n(n+1)}{2} = \tfrac{16\cdot 17}{2} = 136

Each score is a query times a key, scaled, for earlier keys only.

Common mix-ups

MYTHSparse attention keeps the keys with the largest weights.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With BigBird and 1×1 tiles, does every token reach all earlier tokens in two layers?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.