Reading preferences
Concept

Serving Models: GPUs, Batching, and Streaming

Trace an inference request and examine latency, memory, and throughput.

generative ai, serving, gpu, batching, streaming

Follow an inference request

A serving system accepts a request, checks authorization and limits, and schedules it on available compute. A GPU is specialised for parallel numerical work and has finite device memory. The inference engine manages model execution, token generation and often a key-value cache.

Prefill and decode

  1. The server tokenises the prompt and processes its input context (prefill).
  2. During decoding it generates tokens using the context and prior output; a KV cache avoids some repeated work but consumes memory.
  3. The server streams tokens as available, then records an outcome without logging unnecessary sensitive content.

See the reasoning

Follow an inference request

Distinguish prefill, decoding, and streaming. This is a prepared demonstration, not live code execution.

Prefill

Illustrative serving stages
  1. InputTokenise and process promptCurrent focus
  2. DecodeWaiting
  3. StreamNo output yet

The engine processes the prompt context.

Batch and observe

Batching can improve hardware utilisation and throughput but waiting for a batch can increase latency. Continuous batching can admit and retire requests at different times; exact behaviour depends on the engine. Measure time to first token, total latency, tokens per second, queue depth, memory, errors and cost for representative input and output lengths. Streaming is a delivery choice, not a guarantee of correct or safe output.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. Why are GPUs often used for model inference?
2. What does prefill process?
3. What is a batching trade-off?
4. What does streaming output improve for some users?

References and further reading