Attention kernels, KV heads and long context 00:00:01 The conversation filling the cabinet A user doubles the conversation length and Iris runs out of memory, even though nobody changed the weights. Pull open the cabinet beside the decoder. Every retained position has left something there for future steps. Long contexts increase both the work of mixing positions and the size of retained decoding state. Tiled attention changes where intermediate calculations are stored. Sharing key and value heads reduces the bytes retained per position. Position-encoding schemes change how the model represents distance. Give this cabinet thirty-two layers, eight stored key and value heads, a head width of one hundred twenty-eight and two bytes per element. Keys and values occupy separate slots. Count both before multiplying by two thousand forty-eight positions. 00:00:52 Count the retained keys and values A single sequence is active. The model has 32 layers, 8 key and value heads and head dimension 128. Stored cache elements use two bytes. Multiply positions by layers, key and value heads, dimension, bytes and two for keys and values. Query head count is irrelevant to this particular cache shape. Doubling context doubles this payload. FlashAttention changes memory traffic for attention computation. it does not make stored history independent of length. L is layer count, S cached positions, H the number of key and value heads, d the head dimension and b bytes per element. With 32 layers, 2048 positions, 8 heads, dimension 128 and 2 bytes, the cache holds two to the twenty-eighth power in bytes. That is a little over two hundred sixty-eight million bytes. In binary units the cache occupies exactly two hundred fifty-six mebibytes. 00:01:55 Separate cache size from attention work FlashAttention tiles the exact attention computation to reduce expensive traffic between G P U memory levels. It avoids materializing the full score matrix in high-bandwidth memory. Its principal improvement is I/O efficiency. standard dense attention still considers quadratically many query–key pairs in sequence length. Trace an attention tile that reads Q and K, updates running normalization and accumulates V. The full score matrix need not be written to device memory. Multi-query attention shares a key and value head across query heads. Grouped-query attention shares each key and value head within a group. Both can reduce key and value-cache size and bandwidth during decoding. The number of query heads and the number of key and value heads are different inputs to a cache estimate. With 32 query heads, GQA using eight key and value heads stores one quarter as many key and value heads as ordinary 32-head attention at equal head width. RoPE encodes relative position through rotations of queries and keys. ALiBi applies a distance-dependent bias to attention scores. Both affect how positions influence attention. A configuration that accepts a longer prompt still needs tests for retrieval and reasoning at distant positions. Move the same source fact from token 500 to token 15000. Compare evidence recovery with the same question and distractors. Diagnose the actual bottleneck by separating prompt processing, per-token decoding and retained memory. Supporting a larger position index does not by itself establish that the model can recover a fact from the middle of a long document. 00:03:43 Which head count belongs in the estimate? The model has 32 query heads and 8 key and value heads. Which count enters this cache estimate? Only keys and values are retained in this estimate. Grouped query heads share those stored representations. At these settings one sequence takes two hundred fifty-six mebibytes of raw cache. Doubling the stored positions doubles that term. Head sharing, allocation overhead and concurrent requests decide what the real cabinet must hold.