Batching

A serving system that groups multiple requests or decode steps together so accelerators stay busier, raising throughput while often adding wait time for each individual request.

Opening summary

Batching is the serving habit of waiting just long enough to run several requests or token-generation steps together instead of one by one. That denser work usually improves hardware utilization and tokens per second, but it can also make one reader wait longer before service begins.

At a glance

Released

July 2022

System type

Serving

Related models

No related models listed yet.

Related modules

No related modules listed yet.

What It Is

This is a serving system, not a model architecture change. It decides when separate requests or decode steps should be combined into one larger unit of work so the runtime can use the accelerator more efficiently.

Where It Sits

Batching sits around the execution path for prefill and decode. The model still computes the same attention and feed-forward layers, but the serving layer decides whether those layers run for one request at a time or for a packed group that shares the same kernel launches, memory movement, and scheduling window.

How It Works

Incoming work enters a queue, the runtime collects compatible items into a batch, and the accelerator runs that grouped work in one denser pass. During prefill the grouped work may be several prompts at once. During decode it may be one next-token step from many active sequences. After that shared step finishes, each request continues on its own output path even though it just shared compute with its neighbors.

System flow: how a batch forms and runs

Legend: the top and bottom boxes are per-request handling steps, while the middle boxes are the shared batch-formation and shared execution stages.

Batching System Flow
Request and weight flow
Batching adds a queue-and-pack step before model execution so more useful work can share the same serving pass.

Practical Impact

The gain is higher throughput and better device utilization because fixed overhead is amortized across more useful tokens. The cost is that a request may wait in queue for batch formation, and an oversized or poorly matched batch can stretch first-token latency or inter-token latency even while total system output improves. In practice, batching sits across the same serving path as prefill, decode, and the KV cache, which is why operators sometimes separate the batched prompt pass from the batched token loop with a prefill/decode split.
textrequestlatencyapproxtextqueueingwait+textsharedsteptime,quadtextthroughputproptofractextusefultokenspersteptextstepoverhead\\text{request latency} \\approx \\text{queueing wait} + \\text{shared step time}, \\quad \\text{throughput} \\propto \\frac{\\text{useful tokens per step}}{\\text{step overhead}}

Tags

References

  1. Yu, Gyeong-In, et al. "Orca: A Distributed Serving System for Transformer-Based Generative Models." 16th USENIX Symposium on Operating Systems Design and Implementation (OSDI 22), 2022, https://www.usenix.org/conference/osdi22/presentation/yu.