MLCrack

    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:

    1. No padding waste — each request processes at its natural length.

    2. Higher GPU utilization — no idle time waiting for slow requests.

    3. 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.