Skip to content
nonconvexcard

KV cache sizing with MHA and GQA

NumericalBeginner⏱ 30 minLLM Opskv cachegqamemory

Problem

Model A is 7B with L=32L = 32, d=4096d = 4096, 32 attention heads, multi-head attention. Model B is 70B with L=80L = 80, d=8192d = 8192, 64 query heads and 8 key/value heads (GQA). Both store the cache in BF16.

  1. Compute bytes of cache per token for each.
  2. Compute the cache for one 8192-token conversation in each.
  3. Compute what model B's cache would have been with full MHA, and state the GQA saving.

Compute the requested quantities and say what they mean. A number without an interpretation is not an answer.

Solution

Opening this before you have a real attempt on paper is the fastest way to feel like you understand something you cannot reproduce.

Related problems

All problems
SolvedProblemFieldTypeDifficultyTime
Implement the cluster sizing formula runAI SystemsCodingBeginner30 min
Product quantisation budget arithmeticRAGNumericalBeginner30 min
When activations dominateFine-TuningNumericalBeginner30 min
When does attention dominate the MLP?Deep LearningNumericalBeginner30 min
Will this fine-tune fit?Fine-TuningNumericalBeginner30 min