Llama-2 70B uses 64 query heads, how many KV heads does it actually keep?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Llama-2 70B uses 8 KV heads for 64 query heads, an 8x KV cache reduction via grouped-query attention. The 7B and 13B use plain MHA.
Imagine 64 students all asking different questions in a library. Plain multi-head attention assigns 64 personal librarians and 64 bookshelves, very expensive at scale. Llama-2 70B groups the students into 8 study rooms of 8 each; everyone in one room shares one librarian and one shelf. The questions stay individual (each student keeps their own query), but the reference material is shared. You go from 64 librarians to 8, and the students' results stay nearly as good. That sharing pattern is what GQA does for the KV cache.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
60s: state the numbers (64 query heads, 8 KV heads, group size 8), explain that it is GQA, give the KV cache reduction (8x: 21 GB to 2.7 GB at 8k context), note that 7B and 13B kept plain MHA, mention G = 8 was on the flat part of the quality curve in Meta's ablations.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming every Llama-2 variant uses GQA. Only the 70B does in the original release. The 7B and 13B kept plain MHA where the KV cache was not the binding constraint.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.