Optimizing LLM Inference Frameworks: Multi-Step Scheduling and Chunked Prefill
As large language models (LLMs) are deployed across a growing range of business scenarios, optimizing inference performance has become a core challenge for developers and enterprises. This article examines two key optimization techniques recently adopted by mainstream inference frameworks—multi-step scheduling and chunked prefill—explaining their underlying mechanics, how they address compute-bound and memory-bound bottlenecks, and how to apply them in production deployments.
As large language models (LLMs) become deeply embedded in various business scenarios, optimizing inference performance has emerged as a core challenge for developers and enterprise users alike. During autoregressive generation, the model produces tokens one at a time, placing extreme demands on GPU compute while putting significant pressure on scheduling and memory management. To achieve higher throughput and lower latency within limited hardware budgets, mainstream inference frameworks continue to innovate on scheduling strategies. This article explores two key optimization techniques recently introduced in inference frameworks—multi-step scheduling and chunked prefill—and explains the underlying logic and engineering value behind them.
1. LLM Inference Architecture and Bottleneck Analysis
Before diving into specific techniques, it is worth reviewing the two core phases of LLM inference:
- Prefill phase: The model receives the user’s input prompt, processes it in parallel, and generates the first output token along with the corresponding KV cache. This phase involves large-scale matrix multiplications and is a classic compute-bound scenario. GPU compute is fully utilized, but memory bandwidth often sits idle.
- Decode phase: The model generates subsequent tokens one by one based on the existing KV cache. Since only one token is processed per step, the computation is small, but the massive KV cache must be read repeatedly—making this a classic memory-bound scenario. Memory bandwidth is saturated while GPU compute units starve.
Traditional inference frameworks require all requests in a batch to be in the same phase—either all prefilling or all decoding. This strict separation fragments hardware utilization and is one of the root causes of performance bottlenecks. Additionally, the scheduling overhead during the decode phase cannot be ignored.
2. Core Optimization #1: Multi-Step Scheduling
2.1 The CPU Overhead Bottleneck in Traditional Decode Scheduling
In traditional single-step scheduling, the inference engine goes through a complete CPU–GPU interaction cycle for every token generated. This cycle includes: the scheduler scanning all active requests, preparing input tensors, transferring tensors from CPU to GPU, executing GPU kernels, and synchronizing outputs back to the CPU. As model size and concurrency grow, this per-iteration CPU scheduling overhead becomes extremely costly. In some scenarios, scheduling overhead can even exceed actual GPU compute time, leaving the GPU idle and severely limiting system throughput.
2.2 How Multi-Step Scheduling Amortizes Overhead
Multi-step scheduling addresses this problem with a simple idea: the scheduler makes one decision and executes N consecutive decode steps.
In this mode, once the scheduler completes its request-state evaluation and resource allocation, it does not re-enter the scheduling loop on the next step. Instead, it “locks” the currently allocated resources and runs N decode iterations back to back. During these N steps, the CPU performs no complex scheduling calculations—it simply updates pointers and incremental data—thereby amortizing the expensive scheduling cost across N generation steps.
# Pseudocode example: multi-step scheduling logicdef multi_step_scheduling(engine, steps=5):while has_active_requests():# 1. Single CPU scheduling decisionbatch = engine.scheduler.schedule()# 2. Execute N decode steps without re-entering the schedulerfor step in range(steps):output = engine.execute_decode(batch)engine.update_kv_cache(batch, output)# Handle early termination conditions such as EOS; otherwise continueif any(request_finished(output)):break
2.3 Performance Gains
By amortizing CPU overhead, multi-step scheduling dramatically reduces CPU–GPU communication frequency and scheduling latency. This allows the GPU to execute compute tasks more tightly packed, significantly improving overall throughput. The gains are especially pronounced in long-form generation scenarios, such as lengthy content creation or complex code generation.
3. Core Optimization #2: Chunked Prefill
3.1 Limitations of Traditional Batch Scheduling
As noted earlier, traditional scheduling strictly separates the prefill and decode phases. When a new request with a long prompt arrives, the system must allocate a large block of compute time to complete its prefill. During this period, requests already in the decode phase must wait. This creates two serious problems:
- Low resource utilization: In a pure prefill batch, memory bandwidth sits idle; in a pure decode batch, compute units sit idle.
- Increased tail latency: Prefilling a long prompt blocks short requests that are decoding, delaying responses and increasing both time-to-first-token (TTFT) and time-per-output-token (TPOT).
3.2 The Core Idea of Chunked Prefill
Chunked prefill breaks the phase isolation. It splits a long prompt into multiple fixed-size chunks. During scheduling, the engine can mix one “prefill chunk” with multiple “decode requests” in the same batch.
For example, suppose the current batch contains 10 decoding requests that stress memory bandwidth but require little compute. The engine can carve out a 256-token prompt chunk and add it to the batch. The GPU then processes the 10 decode requests while using otherwise idle compute capacity to handle part of the new request’s prompt.
3.3 Efficiency Gains Under Heterogeneous Workloads
This mixed-batch scheduling aligns perfectly with the resource complementarity described by the Roofline model. Prefill requests consume compute; decode requests consume bandwidth. Overlapping the two keeps both the GPU compute units and memory controllers under high load.
From a system perspective, chunked prefill delivers two major benefits:
- Lower latency: New requests no longer wait for all ongoing decode requests to finish; instead, they slip in quickly as small chunks, dramatically shortening time-to-first-token. At the same time, long prefill tasks no longer block decode tasks, improving overall response time.
- Higher throughput: Hardware utilization is maximized, and the total number of tokens processed per unit of time increases significantly.
4. Engineering Practices and Cloud-Native Deployment Recommendations
In practice, combining multi-step scheduling with chunked prefill can produce a highly competitive LLM inference service. For enterprise deployments, a reliable cloud-native infrastructure is typically required. For example, when deploying an LLM inference service on the container platform and heterogeneous compute resources of Baidu AI Cloud, you can maximize the value of cloud resources through careful tuning of scheduling parameters:
- Set the number of multi-step iterations appropriately: The step count N should be tuned based on the specific GPU model and model size. Too few steps fail to amortize overhead effectively; too many may waste compute when requests finish early. Benchmarking in the range of 5–10 steps is generally recommended.
- Optimize chunk size: The chunk size in chunked prefill directly determines the balance between compute and memory access. Chunks that are too large may reintroduce the long-task blocking problem, while chunks that are too small increase tensor-concatenation overhead. As a general starting point, setting the chunk size in the range of several hundred tokens—based on the capacity of the GPU’s streaming multiprocessors—is reasonable.
- Monitoring and elastic scaling: Use the cloud platform’s monitoring and alerting services to observe GPU compute utilization and memory bandwidth in real time. When concurrency fluctuates, leverage elastic scaling of cloud compute to keep the inference engine running in its optimal load range.
5. Conclusion
Optimizing LLM inference performance is a systems engineering effort involving coordination across algorithms, low-level kernels, and system scheduling. Multi-step scheduling tackles scheduling overhead from the time dimension, improving throughput by amortizing costs across steps. Chunked prefill addresses resource complementarity from the spatial dimension, breaking hardware utilization bottlenecks by mixing compute-intensive and memory-intensive tasks. Understanding and applying these two techniques is valuable guidance for developers building low-latency, high-throughput AI-native applications. As business scenarios continue to deepen, staying current with—and practicing—these underlying architectural optimizations will be key to maintaining technical competitiveness in the AI era.
