Prefill and Decode for Concurrent Requests - Optimizing LLM Performance
LLM token generation splits into a compute-bound prefill phase, which processes all prompt tokens in parallel to produce the first token, and a memory-bandwidth-bound decode phase, which produces later tokens one at a time. These map to time to first token and time per output token. Static batching leaves the GPU underutilized and delays new requests. Prefill-first continuous batching (vLLM, TGI) minimizes time to first token but pauses running decodes. Chunked prefill interleaves prefill chunks with decode steps, trading a small time-to-first-token increase for smoother decoding. At TNG it raised total throughput by about 50%, and the default chunk size is recommended when load patterns are unpredictable.
Related posts
- How Long Prompts Block Other Requests - Optimizing LLM Performance
Hugging Face hardMasterUnder vLLM's default chunked-prefill scheduling, a single long prompt blocks the prefill queue, and any prefill running alongside decodes slows token generation for requests already in progress. The queue-blocking problem is largely solved by vLLM's newer parallel partial prefills, which batch several requests' prefills while capping how many long prompts run concurrently, cutting time-to-first-token for short requests. The decode slowdown is more fundamental. TNG compares three mitigations from running 24 H100s: deprioritizing long prompts, routing them to a separate server, and disaggregated prefill. Disaggregated prefill isolates decodes best but needs a second full deployment, leaves GPUs unevenly utilized, and is still experimental in vLLM.
- Continuous batching from first principles
Hugging Face mediumAdeptContinuous batching falls out naturally once you optimize LLM serving for throughput, and the post derives it step by step from attention, causal masking, KV caching and chunked prefill. The KV cache cuts the cost of generating each new token from O(n²) to O(n) at O(n) memory, about 16 KB per token per layer for Llama-2-7B in float16. Chunked prefill splits long prompts across forward passes. Padded batched generation wastes compute when prompts finish at different times, and dynamic batching needs heavy padding because newly inserted prompts must prefill while others decode, which motivates continuous batching's mixing of prefill and decode tokens in one forward pass.
- Cache-aware prefill–decode disaggregation (CPD) for up to 40% faster long-context LLM serving
Together AI hardMasterCache-aware prefill–decode disaggregation (CPD) extends standard PD serving with a dedicated pre-prefill tier for low-reuse (cold) long prompts, a router that estimates prefix-cache reuse per request, and a three-level KV cache hierarchy (GPU memory, host DRAM, RDMA-connected distributed cache). Cold prefills compute new context and write KV state to the distributed cache, so warm requests on normal prefill nodes fetch KV blocks instead of queueing behind multi-second prefills. On B200 GPUs with a synthetic coding-agent workload, CPD raised sustainable throughput from about 0.75–0.8 to 1.1–1.15 QPS per GPU (~40%) and kept median TTFT far lower near saturation, without worsening p90 tail latency. The gains come from scheduling and cache reuse on the prefill path, not faster model execution.
- Boost your throughput with dynamic batching
Modal mediumAdept
Modal added a `@modal.batched()` decorator that groups incoming requests into batches flushed when either `max_batch_size` is reached or `wait_ms` elapses, avoiding the unbounded waits of fixed-size batching. Batching helps GPU inference because model weights (over 6 GB for Whisper large v3) must be moved from memory to compute units per pass, and inference is usually memory-bandwidth bound. On an A10G, batching Whisper with a max batch size of 64 raised throughput from about 1.2 to 3.3 requests per second per container, cutting inference cost by roughly 65%. The function only needs to accept and return lists.
- Assisted Generation: a new direction toward low-latency text generation
Hugging Face mediumAdeptAssisted generation cuts autoregressive LLM latency by letting a much smaller assistant model with the same tokenizer greedily draft candidate tokens, then verifying them all in a single forward pass of the large model. The large model keeps matching tokens plus the first divergent one. The draft length adapts: it grows by 2 when every candidate matches and shrinks by 1 otherwise. The approach exploits the fact that forward passes are memory-bandwidth bound. In 🤗 Transformers it is exposed through an `assistant_model` argument to `generate` (batch size 1 only) and yields up to 2x speedups, 3x with INT8, and up to 10x when the model relies on memory offloading. It works best on input-grounded tasks like ASR and summarization, and with sampling only at low temperatures.