Sub topic 11
Estimating a tokens-per-second ceiling
This chapter assumes you can estimate weight memory from parameter count and bits per weight, and that you know what memory bandwidth is. It also assumes you know that prompt processing and token generation are different workloads. Here you turn those ideas into a speed estimate you can compute before you download anything.
The working model
Token generation (decode) produces one token at a time. To produce each token, the processor needs every weight of the model, so it reads roughly the whole model from memory once per token. The GPU or CPU can do the arithmetic faster than memory can deliver the weights, so memory is the bottleneck.
That gives a simple upper bound:
tokens per second ≤ memory bandwidth ÷ model size in memory
Bandwidth is in GB/s and model size is in GB, so the units cancel to tokens per second.
def decode_ceiling_tokens_per_s(bandwidth_gb_s, model_file_gb):
# Each generated token reads roughly all weights once,
# so bandwidth divided by model size is an upper bound.
return bandwidth_gb_s / model_file_gb
print(decode_ceiling_tokens_per_s(bandwidth_gb_s=100, model_file_gb=4.9))This prints about 20.4. A 4.9 GB file on a machine with 100 GB/s of bandwidth cannot generate faster than about 20 tokens per second.
Worked example
Take the 8B model at about 4.85 bits per weight from earlier chapters. Its weights are about 4.5 GiB, which is a file of roughly 4.9 GB. Compare three kinds of memory.
| Memory | Typical bandwidth | Ceiling for 4.9 GB |
|---|---|---|
| Dual-channel DDR5 system RAM | about 80 GB/s | about 16 tokens/s |
| Unified memory on a mid-range laptop chip | about 150 GB/s | about 31 tokens/s |
| Discrete GPU VRAM | about 500 GB/s | about 100 tokens/s |
The bandwidth figures are illustrative. Look up the spec of your own hardware.
The table shows two levers. A faster memory tier raises the ceiling. A smaller model, from fewer parameters or fewer bits per weight, also raises it. Dropping from 8-bit to 4-bit weights roughly doubles the ceiling because the file is about half the size.
Why real speed is lower
Treat the result as a ceiling, not a prediction. Real speed is usually 50 to 80 percent of it. Several things cause the gap:
- Software cannot reach the full theoretical bandwidth.
- Each token also reads the KV cache, which grows with context length, so long contexts slow generation.
- Dequantising weights and running the other layers adds compute time.
- Layers left on the CPU run at system RAM speed, which lowers the result (see the offload chapter).
Mixture-of-experts models
A mixture-of-experts model reads only the experts it activates for each token. For these models, use the size of the active weights, not the whole file, as the divisor. The full file must still fit in memory.
Checking your estimate
Compute the ceiling first, then measure with llama-bench (covered in a later chapter). If measured speed is far below about half the ceiling, look for layers on the wrong device, a very long context, or a thermal or power limit.
Exercise
A model file is 8 GB and your GPU has 400 GB/s of memory bandwidth. What is the decode ceiling? If you switch to a quantisation that makes the file 4 GB, what is the new ceiling, and what real speed would you expect at 60 percent of it?
Show answer
The first ceiling is 400 ÷ 8 = 50 tokens/s. With the 4 GB file the ceiling is 400 ÷ 4 = 100 tokens/s. At 60 percent of that, expect about 60 tokens/s.