Sub topic 3
Prompt Processing and Token Generation Are Different Workloads
Assume you know what model weights, tokens, VRAM, system RAM, and quantisation mean. The key distinction is prefill versus decode:
- Prefill processes the input prompt. It can calculate many tokens in parallel, so it usually benefits from GPU compute.
- Decode generates one new token at a time. Each step reads the model weights and uses the growing KV cache, so memory bandwidth often limits speed.
Estimating a Tokens-per-Second Ceiling
A rough decode ceiling divides usable memory bandwidth by the model file size:
def decode_ceiling_tokens_per_s(bandwidth_gb_s, model_file_gb):
return bandwidth_gb_s / model_file_gb
print(decode_ceiling_tokens_per_s(100, 4.9))This prints about 20.4 tokens per second. It is an upper bound, not a promise. Runtime overhead, memory access patterns, the KV cache, and CPU-GPU transfers reduce the actual result.
| Workload | Main limit | Typical behavior |
|---|---|---|
| Prefill | Compute and parallelism | Fast for long prompts |
| Decode | Memory bandwidth and latency | One token at a time |
Splitting a Model Between GPU and CPU
If the weights and runtime state do not fit in VRAM, a runtime can offload only some layers to the GPU. The CPU keeps the remaining layers in system RAM. More GPU layers usually improve speed, but transfers between CPU and GPU can become a bottleneck.
llama-bench -m model-Q4_K_M.gguf -p 512 -n 128 -ngl 20Increase -ngl until VRAM is nearly full without causing allocation failures. Full offload is usually faster when it fits.
Quantisation and Quality
Quantisation stores weights with fewer bits. A Q4 file uses roughly four bits per weight, while a higher-bit file preserves more information and needs more memory. Lower-bit quantisation usually saves memory and may increase speed, but can reduce accuracy, reasoning quality, or instruction following.
Mixture-of-Experts Models
A mixture-of-experts (MoE) model stores many expert weights, so its total memory use can be large. For each token, however, a router activates only some experts. This can reduce compute per token without reducing the memory needed to store the model.
Measure Before Choosing
Use llama-bench to measure both workloads. Test the context length and GPU-layer setting you actually plan to use. Record prompt tokens per second and generation tokens per second separately.
Choose for the Goal
For a portable assistant, choose a quantisation that fits with the KV cache and runtime overhead. For maximum quality, use the highest-bit model that fits. For long context, reserve extra memory for the KV cache before deciding how many layers to offload.
Exercise
A 4.9 GB model runs on hardware with 100 GB/s of usable bandwidth. What is its rough decode ceiling?
Show answer
About 20.4 tokens per second, calculated as 100 ÷ 4.9. Real speed will be lower.