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

Multi-query and grouped-query attention

Watch 8 query heads share fewer key and value heads, and the cache shrink.


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.07 · ATTENTION BAY8 QUERY HEADS · TOKEN 6 ASKS
01
Stage 1 of 6 · Query heads
The newest token makes 8 queries, one per attention head. Each query holds 2 numbers.
Explain it simply

On the left, each row is one token. The last token, token 6, is the newest one. It makes 8 queries, one for each attention head. A query is a short list of numbers that says what this head looks for.

6 token rows on the left. The newest token sends a ribbon to each of 8 query heads. Each query head shows 2 numbers.

Weights are random, not trained. Heads next to each other get similar weights.
tokens, queries, keys, valuesKV-head groupsattention, outputschange from MHAslots MHA would use
123456Q1Q2Q3Q4Q5Q6Q7Q8tokensquery headsq_i = x_6 · W_Q(i): 8 queries of 2 numbers123456Q1Q2Q3Q4Q5Q6Q7Q8tokensquery headsq_i = x_6 · W_Q(i): 8 queries of 2 numbers
Toy: 8 query heads of 2 numbers, 6 or 12 tokens
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
qi=xn WQ(i)\sy{q}{data}{q_i} = \sy{x}{data}{x_n}\,\sy{wq}{param}{W_Q^{(i)}}
q1=(−1.81, 1.16)q_1 = (-1.81,\ 1.16)

Each head multiplies the newest token by its own query weights.

Common mix-ups

MYTHWith one KV head, every query head looks at the same tokens.

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

Predict, then reveal
3 CHECKS · PRO
Q01With 1 KV head instead of 2, how many 6-token requests fit in the pool?

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.