Size the KV Cache and Speed Up LLM Inference for a Shopping Assistant

Last updated: November 29, 2026

Quick Overview

Explain what the key-value cache does during autoregressive LLM decoding, estimate its memory for a realistic model, and describe techniques to serve more concurrent shopping-assistant conversations per GPU.

Amazon
Machine Learning
Machine Learning Engineer
Amazon
November 29, 2026
Machine Learning Engineer
Onsite
Machine Learning
Hard

0

0

0 solved


Explain what the key-value cache does during autoregressive LLM decoding, estimate its memory for a realistic model, and describe techniques to serve more concurrent shopping-assistant conversations per GPU.

Serving generative assistants to Amazon-scale traffic, on AWS hardware such as GPUs or Inferentia, makes inference efficiency a real cost lever. Interviewers for LLM teams check whether candidates can do the memory arithmetic and know which optimizations target which bottleneck.

What the Interviewer Expects
  • Explain why caching keys and values avoids recomputation
  • Compute KV cache size per token and per sequence
  • Distinguish compute-bound prefill from memory-bound decode
  • Name techniques: grouped-query attention, quantization, paged attention, continuous batching
  • Discuss latency versus throughput trade-offs
Key Topics to Cover
KV cache
Autoregressive decoding
Grouped-query attention
Continuous batching
Inference optimization
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 speculative decoding speed up generation without changing outputs?
  • What is the effect of long retrieved contexts on cost?
  • How would you share cached prefixes across requests with the same system prompt?
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

Ask model size and architecture, context length (system prompt plus retrieved product content can reach several thousand tokens), target time-to-first-token and tokens per second, and hardware memory....

Approach

In decoding, each new token attends to all previous tokens. Without a cache we recompute keys and values for the whole prefix every step, O(n2)O(n^2) total work. The cache stores K,VK,V for each layer and...


Submit Your Answer
Markdown supported