BLOG / SCHEDULING
The CPU budget behind every generated token
A GPU step depends on scheduling and request-state work around it. Overlap helps only when that work can stay ahead of the device.
Consider a server whose GPU kernels get faster while its token rate barely moves. Suppose its trace reveals gaps between forward passes. The device has finished its work; the next batch is not ready.
The next optimization depends on who is waiting for whom. CPU work matters when it delays a dependent GPU step or the delivery of a finished token. Total CPU utilization cannot identify that delay, and moving work to another thread does not necessarily remove it.
Find the work the GPU must wait for
The exact division varies by runtime, but the recurring tasks are familiar:
| Work | Why the next step may depend on it |
|---|---|
| Select runnable requests | Determines which sequences advance |
| Allocate and update KV blocks | Establishes where attention state will be read and written |
| Prepare inputs and metadata | Supplies token positions, block tables, and execution shapes |
| Process completed outputs | Identifies finished requests and updates their state |
| Deliver output | Turns model tokens into the response the client observes |
Some tasks can run in different processes or overlap several GPU steps. Others create a direct dependency. Tokenization mostly belongs to request admission; it should not automatically be charged to every decode iteration.
The engineering task is to identify which CPU work actually delays device execution, rather than adding all CPU time into one number.
A two-stage model
Let C represent the CPU stage required per iteration and G the GPU stage. If they execute serially, the iteration interval is approximately C + G.
If independent CPU preparation for the next iteration overlaps the current GPU work, an ideal steady-state interval approaches max(C, G). Real execution adds dependency, synchronization, and delivery costs that the two-stage model omits.
The distinction between steady state and the first iteration matters. A pipeline needs to fill before it reaches its repeating interval.
| Hypothetical configuration | CPU stage | GPU stage | Serial interval | Ideal overlapped interval |
|---|---|---|---|---|
| Initial kernels | 3 ms | 6 ms | 9 ms | 6 ms |
| Faster kernels | 3 ms | 2 ms | 5 ms | 3 ms |
Making the GPU stage three times faster improves the ideal overlapped interval only twofold. Once G falls below C, further kernel speedups leave that ideal interval at 3 ms. The next useful target has moved to CPU preparation or the dependency that exposes it. These are illustrative stage times, not framework measurements.
The next token is a dependency
Preparing the next batch early has a complication: its token inputs may depend on outputs the GPU has not produced yet.
An overlap design can separate metadata that is already known from values that must arrive later. SGLang's scheduler description explains its use of future-token handling and synchronization to prepare work ahead of the device. The causal dependency remains; the implementation arranges for the required values to become available before they are consumed.
There are also completion and cancellation decisions. A sequence can finish while work for the next step is being prepared. The runtime must handle that state transition correctly and avoid treating speculative bookkeeping as final.
“Asynchronous” therefore describes an execution arrangement, not the absence of dependencies or overhead. It is possible to move work to another thread and still wait for it at exactly the same point.
Classify a gap before optimizing it
Capture CPU scheduling, launch submission, device execution, synchronization, and output delivery on a timeline. For each gap between forward passes, ask which prerequisite became ready last.
| What the trace shows | Next investigation |
|---|---|
| GPU finishes before batch metadata is ready | CPU preparation and request-state work |
| Metadata is ready, but the next launch waits for a result | Whether the dependency can be narrowed or deferred |
| Work is submitted, but a device stage waits | Communication, device dependencies, or contention |
| GPU steps stay regular, but client token arrivals pause | Detokenization, serialization, transport, or consumer backpressure |
The table identifies candidate causes, not proof. Confirm them with a controlled change and check whether the predicted interval shrinks. Increasing CPU threads will not fix a GPU communication dependency; faster scheduling will not fix a slow output consumer.
Measure more than one batch size. A fixed preparation cost becomes more visible as GPU work shrinks, while larger batches may themselves require more scheduling and state-management work. Treating C as constant across a concurrency sweep can misidentify the crossover.
An overlap win must survive to the client
Separate pipeline fill from steady state. The first iteration cannot benefit from a previous GPU stage to hide behind. A long generation can amortize that startup cost; a short response may not.
Then compare device-step intervals with client-observed token gaps under the same request workload. If the device improves and the client does not, inspect the path after computation before claiming a serving-latency gain. Output buffering can make device execution efficient while producing uneven streams.
Run long enough to expose backlogs. A system can temporarily hide output processing behind GPU work by accumulating undelivered tokens. That is deferred work, not removed work. Track output queue age, CPU consumption, and useful completed requests alongside token timing.
The acceptance criterion for an overlap change is specific: the exposed dependency shrinks, the relevant client latency or sustainable completion rate improves, and another queue does not grow without bound. Faster kernels matter again once the surrounding pipeline can feed them and deliver their results.
What to remember
- Optimize the prerequisite that becomes ready last, rather than total CPU time.
- Ideal overlap approaches the slower stage, not zero overhead.
- Token dependencies and request completion require explicit coordination.
- Accept overlap gains only when they survive to client latency or sustainable completed work without a growing backlog.