Hugging FaceRémi Ouazan Reboul, Pedro Cuenca, Aritra Roy GosthipatyTutorial
Unlocking asynchronicity in continuous batching
Summary
Continuous batching improves GPU utilization with tightly packed batches, but its synchronous loop makes the CPU and GPU take turns, leaving the GPU idle while the CPU prepares each next batch. Profiling 8K-token generation with a batch size of 32 and an 8B model recorded 300.6 seconds, with the GPU idle for 24.0% of runtime. The post builds asynchronous batching by overlapping CPU preparation with GPU computation, using non-default CUDA streams, non-blocking transfers, and synchronization events to coordinate dependencies. In the same experiment, GPU activity rose to 99.4% and total generation time fell to 234.5 seconds, a 22% speedup, without new kernels or model changes while maintaining model accuracy.
Context
Synchronous continuous batching leaves the CPU and GPU alternating between useful work, so the GPU waits while the CPU samples outputs, updates request state, reschedules batches, and prepares inputs. In the profiled workload, this CPU overhead left the GPU idle for 24.0% of total generation time.
Approach / What changed
Asynchronous batching separates CPU batch preparation from GPU computation. It uses non-default CUDA streams for GPU work, assumes non-blocking transfers, and coordinates dependencies with events so batch N+1 can be prepared while batch N computes. GPU-to-CPU output processing still synchronizes when outputs are ready.
Takeaways
In the 8K-token, batch-size-32, 8B-model experiment, synchronous generation took 300.6 seconds and left the GPU idle for 24.0% of runtime.
Asynchronous batching raised GPU activity from 76.0% to 99.4% and reduced generation time to 234.5 seconds, producing a 22% speedup.
The implementation overlaps CPU scheduling with GPU work through non-default CUDA streams and event-based synchronization, without adding kernels or changing the model.
Source and freshness
- Source
- huggingface.co
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.