Study Module
Attention, KV-cache memory and decoding
Move from the attention equation to KV-cache memory, the tradeoffs of grouped-query and multi-query attention (GQA, MQA), how FlashAttention schedules memory, what grows with long context, serving latency, and decoding, all on one page.

Ways in
Choose where to start.
Follow the stages in order, start from a claim, start from the calculator, or keep the equations in view. All four use the same equations and calculator.
Study Module
From the attention equation to serving.
Seven stages, read as one mechanism: attention decides how much each new token draws from the stored values, the cache decides what is kept for reuse, and serving turns each symbol in the equations into a cost in memory, latency or quality.
Attention
How much should this query draw from each earlier token?
One weighted average of value vectors per head.Read the concept pageEquations
The four equations this path uses.
Mem_KV = B * N_layers * T * H_kv * d_head * 2 * bytesDouble the context and the cache doubles. During decoding the whole cache is read for every generated token.
Read the conceptKV-cache calculator
Change one input and watch the cache size.
This calculator starts at a serving-sized case: 4 sequences of 32,768 tokens each. The KV-cache reference works the same model for one sequence of 4,096 tokens, step by step.
The equation is already shown above, so this is a recall question rather than a prediction. Answer it to turn on the calculator.
Choose an answer to turn on the calculator.
0% smaller than full MHA under these settings.
MHA / GQA / MQA
Same attention equation, different cache width.
Each query head has its own KV head.
Each KV head is shared by a group of 4 query heads.
All query heads share one KV head.
Decoding
Sampling controls change the next-token set.
Six candidate tokens with made-up logits. Temperature reshapes their probabilities, top-k and top-p filter the candidate set, and what remains is renormalized. Predict which control decides the result before looking at the token list.
Choose first; the probe will then set the sliders to the high-temperature, top-k = 1 case.
Discussion
Questions to discuss
Pick one question. It becomes the focus of the question you compose for an assistant below.KV compression claim
What exactly is being compressed: heads, tokens, values, precision, or cache pages?
Fixed prompts generated from this item. They are not comments from people or independent reviews.
No source is attached yet; treat claims about sources as provisional.
The claim should end up supported by a source, weakened, or left explicitly unverified.
Ask what concrete observation would raise or lower confidence in this exact claim.
The claim is either source-supported, weakened, or marked unverified
Local action draftDraft unavailableNotes cannot be saved for this item yet
Notes cannot be saved for this item yet.
- The exact source passage, or the detail in the paper, behind the claim
- The equation, concept or small experiment that could refute the claim
- Benchmarks, assumptions, and counterexamples that would change confidence
- The claim is either source-supported, weakened, or marked unverified
- The mechanism is separated from benchmark or marketing language
- You know what evidence would raise or lower confidence
Ask about one thing
Choose what your question is about.
The question you compose below includes this choice, so it is about one stage, equation, calculator or discussion question rather than the whole page.
Double the context and the cache doubles. During decoding the whole cache is read for every generated token.
Ready to askStudy aid
Ask an assistant about this notebook
Compose a question with this notebook as context, then copy it into an AI assistant you already use.
Compose a question
Copy-only tool: this panel composes a prompt from this page and your choices above, for an AI assistant you already use. Nothing you enter here is sent from this page.