Estimate KV Cache Memory for Serving Long-Context Requests
Last updated: November 29, 2026
Quick Overview
For a 70B parameter decoder-only transformer with 80 layers, hidden size 8192, and 64 attention heads of dimension 128, estimate the key-value cache memory per token and per 32k-token request in fp16, then show how grouped-query attention with 8 KV heads changes how many concurrent long requests fit on an 8-GPU node with 80 GB each.
OpenAI
November 29, 20260
0
0 solved
For a 70B parameter decoder-only transformer with 80 layers, hidden size 8192, and 64 attention heads of dimension 128, estimate the key-value cache memory per token and per 32k-token request in fp16, then show how grouped-query attention with 8 KV heads changes how many concurrent long requests fit on an 8-GPU node with 80 GB each.
Long context and high concurrency are central to serving ChatGPT and the API, and the KV cache, not the weights, often limits throughput. The interviewer wants back-of-envelope fluency with transformer memory and an understanding of why architecture choices like GQA matter for serving cost.
What the Interviewer Expects
- Derives the per-token KV formula from the architecture
- Computes numbers with correct units
- Accounts for weight memory and overhead on the node
- Explains how GQA reduces cache size and what it trades off
- Mentions paging, quantized caches, and prefix sharing
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
- How does PagedAttention reduce fragmentation and enable prefix sharing?
- What happens to decode latency as context grows, and why is decode memory bandwidth bound?
- Would you quantize the KV cache to 8 bits, and what is the quality risk?
- How would you price long-context requests given these numbers?
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
Each layer stores one key and one value vector per KV head per token. Per-token bytes: , where bytes for fp16....
Approach
Compute per-token cache with full multi-head attention (), then with GQA (), multiply by context length, and compare with memory left after weights....