---
title: "Unlocking asynchronicity in continuous batching"
description: "Synchronous continuous batching makes the CPU and GPU take turns, and profiling an 8B model generating 8K tokens at batch size 32 shows the GPU idle for 24% of the 300.6-second runtime while the CPU prepares batches."
url: "https://swe.quest/articles/unlocking-asynchronicity-in-continuous-batching-fe214c7fa26641ee"
canonical: "https://huggingface.co/blog/continuous_async"
source: "Hugging Face"
published: "2026-05-14"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 20
tags: ["inference","performance","concurrency","hardware","llms"]
---

# Unlocking asynchronicity in continuous batching

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2026-05-14, 20 min read, Deep dive. Original: [https://huggingface.co/blog/continuous\_async](https://huggingface.co/blog/continuous_async)

## Summary

Synchronous continuous batching makes the CPU and GPU take turns, and profiling an 8B model generating 8K tokens at batch size 32 shows the GPU idle for 24% of the 300.6-second runtime while the CPU prepares batches. Asynchronous batching overlaps preparation of batch N+1 with compute of batch N. It does this with three non-default CUDA streams (H2D, compute, D2H) ordered by CUDA events, plus double-buffered input/output slots to avoid race conditions. The design, implemented in transformers' continuous batching, needs no kernel or model changes. It must also carry tokens produced by batch N into batch N+1's inputs.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)

## Prerequisites

- KV cache ([easy posts on Caching](https://swe.quest/tags/caching.md?difficulty=easy))
- continuous batching
- PyTorch on GPU ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))
- LLM inference basics ([easy posts on Inference & serving](https://swe.quest/tags/inference.md?difficulty=easy))

## Keywords

CUDA streams, CUDA events, continuous batching, transformers, PyTorch, Hugging Face

## Related posts

- [Continuous batching from first principles](https://swe.quest/articles/continuous-batching-from-first-principles-b2a5a3d9c00e56be.md): Hugging Face · 2025-11-25 · Medium · 17 min read · Inference & serving, LLMs, Performance engineering
  Continuous batching falls out naturally once you optimize LLM serving for throughput, and the post derives it step by step from attention, causal masking, KV caching and chunked prefill.
- [Boost your throughput with dynamic batching](https://swe.quest/articles/boost-your-throughput-with-dynamic-batching-c7c722ba8af78c33.md): Modal · 2024-09-16 · Medium · 4 min read · Inference & serving, Performance engineering, Serverless, Python
  Modal added a \`@modal.batched()\` decorator that groups incoming requests into batches flushed when either \`max\_batch\_size\` is reached or \`wait\_ms\` elapses, avoiding the unbounded waits of fixed-size batching.
- [Prefill and Decode for Concurrent Requests - Optimizing LLM Performance](https://swe.quest/articles/prefill-and-decode-for-concurrent-requests-optimizing-llm-performance-66a6db57e54903ca.md): Hugging Face · 2025-04-16 · Medium · 10 min read · Inference & serving, LLMs, Performance engineering, Hardware
  LLM token generation splits into a compute-bound prefill phase, which processes all prompt tokens in parallel to produce the first token, and a memory-bandwidth-bound decode phase, which produces later tokens one at a time.
- [Host overhead is killing your inference efficiency](https://swe.quest/articles/host-overhead-is-killing-your-inference-efficiency-42291cc0b68e5c36.md): Modal · 2025-11-18 · Medium · 7 min read · Inference & serving, Performance engineering, Hardware
  GPU idle time while the CPU prepares work (host overhead) shows up as low GPU kernel utilization and directly multiplies inference cost; 50% overhead means GPU spend is 2x what it could be.
- [We reverse-engineered Flash Attention 4](https://swe.quest/articles/we-reverse-engineered-flash-attention-4-e0ddc41706e090a5.md): Modal · 2025-09-26 · Hard · 18 min read · Inference & serving, Hardware, Performance engineering, Concurrency, LLMs
  Flash Attention 4, Tri Dao's attention kernel for Nvidia Blackwell GPUs, reportedly runs about 20% faster than cuDNN's closed-source attention kernels.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
