LLM Inference Scheduling Optimization: Multi-Step Scheduling and Chunked Prefill

    Two distinct phases dominate every large language model (LLM) inference request: compute-bound prefill and memory-bound decode. Mixing them in a single batch hurts GPU utilization, while naive scheduling introduces CPU overhead and long-prompt blocking. This article explains two widely adopted techniques—multi-step scheduling and chunked prefill—how they work, their trade-offs, and how to combine and evaluate them in production deployments.

    1. The Two Phases of an Inference Request

    When a large language model generates text, each request goes through two phases.

    The first phase is prefill. The model reads in the entire user-provided prompt at once, computes intermediate representations for every input token, and produces the first output token. Because this phase processes many tokens in parallel and is dominated by matrix operations, GPU compute is the main bottleneck—it is compute-bound.

    The second phase is decode. The model generates one new token at a time, but must repeatedly read the model weights and the historical key-value cache. The computation per step is small while memory traffic is heavy, so memory bandwidth becomes the bottleneck—it is memory-bound.

    The resource characteristics of the two phases differ significantly. If a scheduler mixes both types of requests in the same batch, all computations in the batch must wait for the slowest part to finish, and overall utilization drops. For this reason, many early inference systems ensured that all requests in a batch were either in prefill or in decode. This approach is simple to implement but introduces two problems. First, scheduling overhead accounts for a relatively high proportion of the decode phase. Second, the prefill of a long prompt can block requests that are already generating, causing users who have started receiving output to perceive stuttering.

    2. Multi-Step Scheduling: Amortizing Scheduling Overhead Across Steps

    Each time the scheduler decides “which requests participate in this round of computation,” it must perform queue management, memory block allocation, batch assembly, and result collection. These tasks run on the CPU side. When GPU single-step computation is fast, CPU-side scheduling overhead often becomes the bottleneck. The decode phase produces only one token per step, so scheduling overhead is especially high relative to single-step computation there.

    The idea behind multi-step scheduling is: once the scheduler fixes a batch, the executor runs n consecutive decode steps before collecting results in one pass. Scheduling overhead is amortized over n steps, and the average per-step overhead drops.

    This approach has several costs to watch:

    • The granularity of streaming output becomes coarser; tokens within the same batch are returned together.
    • If a request hits its end-of-sequence token midway, the subsequent steps computed for it are wasted, and the result collection logic must correctly discard those outputs.
    • When n is too large, newly arriving requests wait longer before being admitted to a batch, increasing queuing latency.

    Therefore, n should be chosen based on the actual workload, and usually needs to be determined through load testing.

    3. Chunked Prefill: Preventing Long Prompts from Monopolizing a Round

    Chunked prefill splits a long prompt into several chunks, processes only one chunk per round, and batches it together with requests that are currently decoding. This brings two benefits.

    First, decode requests no longer wait for long periods because of long prompts, so the interval between adjacent tokens becomes more stable. Second, the compute-bound nature of prefill and the memory-bound nature of decode complement each other. Within the same batch, the two types of operations can overlap in their use of different GPU resources, raising overall throughput.

    The key parameter for chunking is the per-round token budget. If the budget is too small, each chunk’s matrix operations are too small to keep the GPU busy, utilization drops, and the total processing time for long prompts grows. If the budget is too large, each round takes longer and decode latency rises again. In practice, the token budget should be the primary tuning lever, balancing time-to-first-token against token intervals.

    The following illustrative code demonstrates the scheduling logic only; it is not a specific implementation:

    1. def build_batch(running, waiting, token_budget):
    2. batch = []
    3. # 1. Allocate one token slot for each decoding request first
    4. for req in running:
    5. if req.is_decoding:
    6. batch.append((req, 1))
    7. token_budget -= 1
    8. # 2. Use the remaining budget to split prefill prompts into chunks
    9. for req in waiting:
    10. if token_budget <= 0:
    11. break
    12. chunk = min(req.remaining_prompt_tokens, token_budget)
    13. batch.append((req, chunk))
    14. token_budget -= chunk
    15. return batch

    4. Combining the Two Techniques

    Multi-step scheduling addresses the problem of scheduling too frequently, while chunked prefill addresses the problem of long requests blocking short ones. They operate at different layers and can be used together.

    In real deployments, consider the following order:

    1. Start with benchmarking to confirm whether the bottleneck lies in CPU scheduling or GPU compute.
    2. If scheduling overhead is a large proportion, try increasing the number of multi-step scheduling steps.
    3. If long prompts cause noticeable jitter in token intervals, introduce chunked prefill and tune the token budget.
    4. Change only one parameter at a time, and record changes in time-to-first-token, token interval, and throughput.

    5. Evaluation Metrics and Testing Considerations

    When evaluating these optimizations, it is recommended to observe three types of metrics simultaneously: time-to-first-token (TTFT), token interval (TPOT or ITL), and output tokens per second. Looking only at throughput can mask a degraded interactive experience, while looking only at latency may miss changes in resource utilization.

    Test data should closely resemble real traffic. Prompt length distribution, concurrency, and output length all affect the results. The optimal parameters can vary greatly across model sizes, hardware, and workloads, so a single set of test results should not be applied directly to other environments.