22/26
Part 4 of 4 · Prefill, decode and memoryLearn and do
Fewer key/value heads: multi-query and grouped-query attention
Once the cache works, interviewers ask about its size. There are three answers, each with its paper, and this is the first.
Llama 3 8B has 32 query heads. Pick how many key/value heads they share:
0123
kv 04567
kv 1891011
kv 212131415
kv 316171819
kv 420212223
kv 524252627
kv 628293031
kv 7 query head key/value head, the part that is cached
- Cache per token
- 128 KiB
- Per 8,192-token sequence
- 1 GiB
- Sequences in 65 GiB
- 65
- Query heads per kv head
- 4
grouped-query: each group of 4 query heads shares one key/value head. The cache is 2 × 32 layers × 8 × 128 × 2 bytes = 131,072 bytes per token.
Multi-query attention (Shazeer, 2019) shares one key head and one value head across all the query heads.
Llama 3 8B's shape needs 128 KiB a token with 8 key/value heads. Multi-query attention keeps 1. How much a token now?
Pick an answer above to see the rest