Inference and Serving, lesson 13
Continuous batching
Static, dynamic and continuous batching, and what each does to latency.
You know why a batch shares the cost of reading the weights ("Throughput and Little's law", "Arithmetic intensity"), and how a paged cache hands out memory in blocks ("How big the cache gets").
Part 1. Fill up, run to the end
The simplest server waits for four requests, starts them together, and runs until every one is done. Then it takes the next four. Say these four need 3, 10, 4 and 6 output tokens.
Example 1.1
Four slots, tokens left in each
- step 031046
All four start together. Each step makes one token in every busy slot.
- after step 3done713
The first request is finished. Its slot sits empty, even if people are waiting.
- after step 6done4donedone
Three slots idle. The GPU still reads all the weights each step, to make one token.
- after step 10donedonedonedone23 tokens ÷ 40 slot-steps=57.5% busy
The longest request decides when the batch ends. Only 23 of 40 slot-steps made a token.
Static batching
Form a batch, run it until every request in it is done, then form the next. Easy to build. Wasteful when output lengths vary, which for chat they always do.
Your turn
With static batching, a new request arrives just after step 4 of that batch. When does it start?
Part 2. Wait a little, then go
Keep going with Pro
You've done the first part. Pro opens the rest of this lesson, and every other one.
- Wait a little, then go
- Refill every step
- What the scheduler does each step
- When the cache runs out
Inference and Serving overviewSpotted a mistake? Tell us.