Training versus inference
Two entirely different cost profiles: why training is a one-off expense and inference an ongoing one that usually ends up larger.
The idea
Training is the education, inference is the daily work. Education costs a lot once; daily work costs a little every day, and over the years usually more.
The comparison
| Training | Inference | |
|---|---|---|
| Frequency | once, occasionally repeated | continuously |
| Duration | days to months | milliseconds to seconds |
| Hardware | many cards, fast interconnect | one or a few cards |
| Bottleneck | compute and interconnect | memory bandwidth |
| Failure consequence | repeat the run | a user waits or gets something wrong |
The two phases of inference
- 01
Prefill
The whole prompt is processed at once. That is one large matrix multiplication and fully loads the card. Time to first token depends almost entirely on prompt length.
- 02
Decode
Every further token is generated singly and depends on the previous one. Here the card is largely idle, waiting on memory.
That gives the two metrics that matter in practice:
| Metric | Meaning | Determined by |
|---|---|---|
| Time to first token | How quickly something happens | Prompt length, compute |
| Tokens per second after | How fluid it feels | Bandwidth, model size |
Users perceive 20 to 30 tokens per second as fluid, because that exceeds reading speed. A time to first token above two seconds reads as a hang, however fast the rest is.
Latency against throughput
Batch 1 -> 40 tokens/s per request, 40 tokens/s total
Batch 8 -> 35 tokens/s per request, 280 tokens/s total
Batch 32 -> 28 tokens/s per request, 896 tokens/s total
Batch 128 -> 15 tokens/s per request, 1920 tokens/s total
Throughput grows almost linearly while the individual request slows only a little. Batching is therefore nearly always the right call, until a response-time commitment breaks.
The cost formulas
Setting them equal gives the point where running overtakes training:
At D = 2e12 training tokens the point sits at 6e12 generated tokens. A service
answering a million requests a day at 500 tokens each generates 5e8 tokens per
day and reaches that point after roughly 33 years. At a hundred million requests
a day, after four months.
That calculation ignores that inference and training reach very different utilisation in practice. Training runs near peak; inference in the decode step runs at a few percent. Counting card-hours rather than FLOPs shifts the point by an order of magnitude in training's favour.
What follows for sizing
- Commit to time to first token and tokens per second separately.
- Cap maximum prompt and response length, or capacity cannot be planned.
- Configure batching with a maximum wait time, not a fixed batch size.
- Measure prefill and decode separately. A combined figure hides which phase is stuck.
- Plan for peaks with a queue rather than extra cards. Waiting is cheaper than standby.
Related courses and sources
PyTorch documentation
The reference for autograd, dtypes, memory behaviour and determinism. The place where questions about reproducibility actually get settled.
The place where questions about determinism and memory behaviour actually get settled.