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
Machine Learning
Machine Learning Engineer
OpenAI
November 29, 2026
Machine Learning Engineer
Onsite
Machine Learning
Hard

0

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
KV cache
grouped query attention
inference memory
transformer architecture
capacity planning
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
  • 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 Prep
Sample Answer
Clarify

Each layer stores one key and one value vector per KV head per token. Per-token bytes: 2×L×nkv×dhead×b2 \times L \times n_{kv} \times d_{head} \times b, where b=2b = 2 bytes for fp16....

Approach

Compute per-token cache with full multi-head attention (nkv=64n_{kv} = 64), then with GQA (nkv=8n_{kv} = 8), multiply by context length, and compare with memory left after weights....


Submit Your Answer
Markdown supported