Book a call

Blog/Post

Compounding GPU and CPU work on a small model

Large speedups come from a stack of optimizations, each one exposing the next bottleneck. Here the bottleneck moved between the GPU and the CPU.

Large speedups come from a stack of optimizations. Each one exposes the next bottleneck. A small model on one GPU shows this well. In each decoding step, the GPU runs the model while the CPU prepares the next step. The step lasts as long as the slower of the two. When we made the GPU faster, the CPU became the bottleneck. When we then cut the CPU’s work, the GPU became the bottleneck again, and further GPU changes made the step faster.

The deployment

We serve a 4B model with a draft model on one B200, at 1 to 8 requests at a time, and optimize speed per request. Each decoding step runs the draft model and the target model on the GPU. Between steps the CPU schedules requests, prepares the inputs for the next step, samples, checks which draft tokens are accepted and updates each request. The CPU’s work is about the same from 1 to 8 requests, and on a small model the GPU’s step is short, so the two are close.

GPU work moves the limit to the CPU

Where we started, the GPU took 6.4 ms per step and the CPU’s part took 4.3 ms, so the GPU set the pace (Figure 1). Our first GPU changes cut the GPU’s part to 3.8 ms. One of them prepares the draft model’s attention inputs with 3 kernels instead of 22, which takes that part from 143 µs to 20 µs. But the step only fell to 4.3 ms. The CPU now set the pace, and in more than half of all steps the GPU waited for it. From then on a faster kernel no longer made the step faster: a fused MLP kernel that saved time in isolation left the step unchanged.

Fig. 1Time per decoding step as each optimization is added
CPUGPUGPU waiting on the CPU
Baseline
6.4 ms
After GPU work
4.3 ms
After CPU work: one CUDA graph per step
3.8 ms
After more GPU work
3.4 ms

One CUDA graph per step moves it back

We captured the whole step as one CUDA graph: the draft model, the target model, and the sampling and bookkeeping between them. Each step now copies its inputs into fixed buffers and replays the graph, so the CPU’s part fell from 4.3 ms to 1.5 ms. The GPU waited for the CPU in only 7% of steps, down from more than half. The step fell to 3.8 ms, the GPU’s own time.

GPU work pays again

With the CPU no longer setting the pace, GPU work counted again, and more of it took the step to about 3.4 ms. The fused MLP kernel shows the change most clearly. Before the graph it left the step unchanged; after the graph it took 9.3% off every step.

What carries over

Together, these changes took the step from 6.4 ms to about 3.4 ms. Most of them only paid off because of an earlier one. The fused MLP kernel is the clearest case. Before the CUDA graph it saved nothing. After the graph it took 9.3% off every step.

A general engine keeps parts of the step outside its graphs so that it can support every sampler, drafter and scheduling feature. One graph per step works here because this deployment fixes its drafter and sampler.

This is how we work on every deployment. We profile, remove the largest bottleneck, and profile again. A deployment ends up with a stack of optimizations, often a dozen or more, built one on top of another.

We do this work for one deployment at a time.