Module 11 · Lesson 2 of 5

Memory decides how many fit

Memory sets the batch size

Every running request keeps its saved work in GPU memory, so request size decides how many run at once.

Scene 1 of 5 · Two limits

This GPU has room for 8,000 tokens of saved work, and its batch has 8 seats.

QueueQueueGPUGPU0 of 8,000 used
  • Queue — healthy
  • GPU — healthy — 0 of 8,000 used
GPU memory for saved work (8,000 tokens)
  • Used0 tokens
  • Free (highlighted)8,000 tokens
Running
not shown yet
Waiting
not shown yet
  1. Two limits. This GPU has room for 8,000 tokens of saved work, and its batch has 8 seats.
  2. Short requests. 12 requests arrive; each grows to 800 tokens: a 700-token prompt plus a 100-token answer.
  3. Seats run out first. Memory could hold 10 of them, but the batch has 8 seats, so 4 wait in the queue.
  4. Long prompts. At 4,000 tokens each, memory holds only 2, so 10 of the 12 requests wait.
  5. Or one is paused. Preemption: if running answers outgrow memory, the server pauses one and later redoes its prompt and answer so far.
  6. Now you try. Set the saved tokens per request, and see how many of 12 can run. For example: 5 run at once, and 7 of 12 wait in the queue. Memory is the limit here: bigger requests leave room for fewer at once.

Scene 1 of 5: Two limits. This GPU has room for 8,000 tokens of saved work, and its batch has 8 seats.

Key points

  1. Saved work grows by one token at every step of the answer.
  2. When memory or the batch's seats run out, new requests wait.
  3. Long prompts mean far fewer requests run together.
  4. If answers outgrow memory, a server may pause one and redo its work later.

Go deeper in the Serving a language model lab →

Each request's saved work, the (see How a model writes), takes up memory on the . A longer or a longer answer so far means more saved work, so it takes more memory.

The GPU has a fixed amount of this memory. Once it is full, a new request cannot start: it waits in the until enough memory frees up.

Sometimes a running request is paused instead, called a . Its saved work is dropped to free memory for others. It must redo that work, its , once it starts again (see How a model writes).

Try it: the lab's long-prompts experiment shows requests getting paused this way.

Example. Illustrative: a request with a 700-token prompt and a 100-token answer saves 800 of work. So 8,000 tokens of memory hold 10 of them. With a 3,500-token prompt and a 500-token answer, each saves 4,000, so only 2 fit.

In system design: Memory sets how many requests run together. Long prompts and answers use more of it, so fewer requests fit, and the rest wait or get paused.

Check yourself

Prompts grow from 700 to 3,500 tokens. What happens to how many requests fit in GPU memory?