Estimate KV Cache Memory for Grouped-Query and Sliding-Window Models

Last updated: November 29, 2026

Quick Overview

For a 7B-class decoder with 32 layers, 32 query heads, 8 key/value heads, head dimension 128 and fp16 KV, compute the KV cache size per token, for one 32k-token sequence, and for a batch of 64, then show how a 4,096-token sliding window changes the answer.

Mistral AI
Statistics & Math
Machine Learning Engineer
Mistral AI
November 29, 2026
Machine Learning Engineer
Phone Screen
Statistics & Math
Easy

0

0

0 solved


For a 7B-class decoder with 32 layers, 32 query heads, 8 key/value heads, head dimension 128 and fp16 KV, compute the KV cache size per token, for one 32k-token sequence, and for a batch of 64, then show how a 4,096-token sliding window changes the answer.

Back-of-the-envelope memory math is a quick filter for Mistral AI inference and platform roles, since choices like grouped-query attention and sliding windows in Mistral 7B exist largely to shrink KV memory. The interviewer checks that you count both K and V, apply the KV-head count rather than query heads, and turn bytes into a batch-size decision on a real GPU.

What the Interviewer Expects
  • Write the per-token formula 2 x layers x kv_heads x head_dim x bytes
  • Use KV heads (8), not query heads (32)
  • Scale to sequence length and batch correctly with units in GiB
  • Show the sliding window caps per-sequence memory at W tokens
  • Relate the result to GPU memory left after weights
  • State assumptions such as fp16 and no paging overhead
Key Topics to Cover
KV cache
Grouped-query attention
Sliding-window attention
Capacity planning
Unit arithmetic
How to Approach This
  1. Define your hypotheses (H0 and H1) clearly before performing any test.
  2. Calculate required sample size BEFORE running an experiment, using power analysis.
  3. Remember the Central Limit Theorem: sample means become approximately normal with large n.
  4. Watch for Simpson's paradox. Always segment data by key dimensions.
  5. Distinguish between statistical significance and practical significance.
Possible Follow-up Questions
  • What does fp8 or int8 KV quantization buy you, and what does it risk?
  • How many concurrent 32k sequences fit on an 80 GB GPU after weights?
  • How does tensor parallelism split the KV cache?
  • Why does the window cap memory but not compute for prefill?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Browse Statistics Questions
Sample Answer
Clarify

Assume fp16 (2 bytes), keys and values both cached, every layer caches, no padding or paging overhead. Weights at fp16 for about 7.2B parameters take roughly 14.5 GB....

Approach

Per token per layer we store K and V, each of size kv_heads x head_dim. Multiply by layers and bytes, then by tokens, then by batch. Then compare full attention against a rolling window of W tokens....


Submit Your Answer
Markdown supported

Related Questions