ML SYSTEM DESIGN & MLOPS · INTERVIEW QUESTION
What is continuous batching for LLM inference? How does it improve throughput?
🔴 advanced · Model Serving
Hint: Think about vLLM's PagedAttention and dynamic batch management.
Answer
Traditional static batching: wait for a fixed batch of requests, process together, return together. Problem: short sequences wait for long ones (padding waste), low GPU utilization. Continuous batching (iteration-level scheduling): process requests at the token level. As one request finishes generating, immediately fill its slot with a new request.
Benefits:
-
No padding waste — each request processes at its natural length.
-
Higher GPU utilization — no idle time waiting for slow requests.
-
Lower latency for short requests — don't wait for long ones.
PagedAttention (vLLM): manages KV-cache like virtual memory pages. Allocates non-contiguous memory blocks, eliminates pre-allocation waste (reduces KV-cache memory waste from 60-80% to ~4%). Enables larger batch sizes.
Key metrics: tokens per second (throughput), time to first token (TTFT), time per output token (TPOT).
Tools: vLLM, TGI (HuggingFace), TensorRT-LLM all support continuous batching. This is one of the most impactful optimizations for production LLM serving.
Related questions
- What is model distillation? How is it used in production?
- What are the key techniques for making Transformers efficient in production? Explain KD, quantization, pruning, and graph optimization.
- How do you deploy a fine-tuned LLM in production on cloud infrastructure?
- Design a real-time ML serving system for a recommendation engine handling 10k QPS.
- What is LLMOps and how does it differ from traditional MLOps?