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
Machine Learning
Machine Learning Engineer
Microsoft
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Medium

0

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
KV cache
autoregressive decoding
grouped-query attention
GPU memory
PagedAttention
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. 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 Prep
Sample 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 tt depend only on tokens up to tt. When generating token t+1t+1 we only need the new token's query, key and value, plus the cached keys and values of...


Submit Your Answer
Markdown supported