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

Naive attention's memory traffic

Watch every byte that plain attention moves between HBM and the chip.


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 · 28.01 · MEMORY BAYQ, K, V IN HBM · 384 B
01
Stage 1 of 6 · Inputs in HBM
Q, K and V sit in HBM. Each has 16 rows of 4 values.
Explain it simply

Attention starts with three tables of numbers, called Q, K and V. Each row belongs to one token. They live in HBM, the big main memory of the GPU. The SRAM band above is fast, but this toy chip holds only 256 bytes there.

The HBM band holds Q, K and V, 16 by 4 each. S, P and O are empty outlines.

Q, K, VS, P in HBM (traffic to remove)O and byte countschip, kernelnot written
SRAM · on chipholds 256 BHBMno kernel has runQ, K, V wait in HBMQ16×4K16×4S16×16P16×16V16×4O16×4naive0 BInputs in HBMQ, K, V: 3 · Nd · 2 B = 3 · 64 · 2 = 384 BSRAM · on chipholds 256 BHBMno kernel has runQ, K, V wait in HBMQ16×4K16×4S16×16P16×16V16×4O16×4naive0 BInputs in HBMQ, K, V: 3 · Nd · 2 B = 3 · 64 · 2 = 384 B
Toy: 1 head, 16 tokens × 4 values in FP16, seeded random, not trained; larger N and d count bytes only
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
Q, K, V: N×d\sy{q}{data}{Q},\ \sy{k}{data}{K},\ \sy{v}{data}{V}:\ N \times d
3⋅Nd⋅2 B=3⋅64⋅2=384 B3 \cdot N d \cdot 2\,\text{B} = 3 \cdot 64 \cdot 2 = 384\,\text{B}

Q, K and V each have N rows of d values.

Common mix-ups

MYTHMost attention traffic is reading Q, K and V.

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

Predict, then reveal
3 CHECKS · PRO
Q01With d = 4, go from 16 to 64 tokens. Does traffic grow about 4 or over 10 times?

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.