Size the KV Cache and Explain Why It Limits LLM Batch Size
Last updated: November 29, 2026
Quick Overview
Explain what the key-value cache does during autoregressive decoding, compute its memory footprint for a 32-layer model with a 4,096-dimensional hidden state, and describe techniques that shrink it.
Microsoft
November 29, 20260
0
0 solved
Explain what the key-value cache does during autoregressive decoding, compute its memory footprint for a 32-layer model with a 4,096-dimensional hidden state, and describe techniques that shrink it.
Azure OpenAI and Copilot capacity is often bounded by GPU memory for the KV cache rather than by compute. The interviewer checks that you understand why caching works, can do the arithmetic, and know the main reduction techniques.
What the Interviewer Expects
- Explain why keys and values of past tokens can be reused while decoding
- Derive the per-token memory formula
- Compute a concrete number and relate it to batch size on an 80 GB GPU
- Describe grouped-query or multi-query attention
- Mention paged allocation, quantization and sliding windows
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- Why is decoding memory-bandwidth bound rather than compute bound?
- How does prefix caching help a Copilot system prompt shared by all users?
- What breaks if you quantize the KV cache too aggressively?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Model: 32 layers, hidden size 4,096, 32 attention heads of size 128, fp16 cache, standard multi-head attention unless stated....
Approach
In causal attention the keys and values for token depend only on tokens up to . When generating token we only need the new token's query, key and value, plus the cached keys and values of...
Submit Your Answer
Microsoft Machine Learning Engineer Interview Guide
Interview process, tips, and preparation timeline