Topic 7
Hidden tokens, and wrap-up
Everything so far assumed every generated token is shown to the user. Increasingly it isn't. A model may first write a plan, call tools, or reason step by step, and only then write the answer the user sees.
From the model's side, the first token comes as quickly as ever. From the user's side, the first visible token comes only after all the hidden ones. AI Engineering (Ch. 9) notes that some teams call this time to publish, to make clear it is the first token the user actually sees.
Predict first
Drag the slider to change how many tokens stay hidden. The first visible token moves right one decode step at a time. For an agent that calls tools between steps, the tool time is added on top.
Quick check
Summary
- Users feel two waits: time to first token, mostly prefill, and total latency, mostly decode. Streaming makes the first one what matters, and past reading speed (about 120 ms per token, from the book) tokens needn't be much faster than a reader can read.
- Record one timestamp per token; TTFT, inter-token latency, TPOT and total latency are all arithmetic on that list. Warm up first, wait for asynchronous hardware, and say where the clock is.
- Latency is a distribution. Report p50 and p99, not the mean: the same request on our CPU ranged from 60 to 176 ms.
- TTFT grows with the prompt; time per token barely does. Hardware gains depend on the workload: our GPU was 1.6× faster at 16 tokens and 2.3× at 960.
- Throughput is work done per second across everyone. Batching 16 requests raised it about 7× on the CPU while each user got slower.
- Goodput counts only requests that meet the SLO, and is the honest target. Hidden tokens make time to publish later than TTFT.
Next
Lesson 2: where the time goes. Why decoding 16 requests at once costs far less than 16 times one, what memory bandwidth has to do with it, and a batching simulator to find the batch size that maximises goodput.