3/30
Part 1 of 7 · Two clocksLearn

The first token waits for the whole prompt, and every later token waits for one step

A streamed answer is timed by two clocks. The time to first token (TTFT) runs from sending the request to the first token: Anthropic's docs define it as the time to generate the first token, from when the prompt was sent. The time per output token (TPOT) is the average gap between the tokens after that: the last token's time minus the first's, over the gaps between them. DistServe, a paper on serving, splits the work the same way: TTFT belongs to the prefill phase and TPOT to the decoding phase.

Here's one of those requests, timed token by token. latency_split returns both clocks, and you'll write it two steps from now.

# the assistant's 250-token answer
token_times = [0.35 + 0.03 * i for i in range(250)]
# sent at 0.0 s
ttft, tpot = latency_split(0.0, token_times)
print(f"first token after {ttft:.2f} s, then one every {tpot * 1000:.0f} ms")
print(f"last token at {token_times[-1]:.2f} s")
Predict

The first token arrives at 0.35 s and the rest follow 30 ms apart. When does the 250th token arrive?

Pick one to see what it prints.
Predict

An answer's first token arrives in 0.3 s, but the answer takes 12 s to finish. Where do you look first?

Pick an answer above to see the rest