Inference and Serving, lesson 7
Prompt length on different GPUs
How prompt length and hardware set prefill time.
You know the model reads the whole prompt (prefill) before it writes the first token ("Reading the prompt, writing the reply"), and that this sits inside TTFT ("First token and every token after").
Part 1. Longer prompt, longer wait
Paste a whole contract into a chatbot and the first word takes noticeably longer than for "hi". The model has to read every token of the prompt before it can write anything, and reading isn't free.
There's a handy rule for how much work that is. Each token passing through the model costs about 2 operations per parameter, one multiply and one add. For an 8-billion-parameter model that's 2 × 8 billion = 16 billion operations per prompt token.
Example 1.1
Prefill work for an 8B model
- 1,000 tokens×16 billion=16 trillion ops
A short document. 16 trillion operations.
- 8,000 tokens×16 billion=128 trillion ops
Eight times the prompt, eight times the work.
- 32,000 tokens×16 billion=512 trillion opsplus extra for attention
At long prompts the attention part grows faster than this, because every token looks back at every token before it ("The price of a long context"). The rule of thumb starts to undercount.
FLOP
One floating-point operation: a single multiply or add on decimal numbers. Work is counted in FLOPs. Hardware speed is quoted in FLOP per second, usually written FLOPS, and modern GPUs reach hundreds of trillions (teraFLOPS, TFLOPS).
Your turn
A 4,000-token prompt has 0.13 s of prefill. You add retrieved documents and the prompt grows to 8,000 tokens. Roughly what happens to the prefill time?
Part 2. Prefill keeps the GPU busy
Keep going with Pro
You've done the first part. Pro opens the rest of this lesson, and every other one.
- Prefill keeps the GPU busy
- Hardware sets the speed limit
- A number you can carry around
Inference and Serving overviewSpotted a mistake? Tell us.