skip to content

Two llama.cpp builds of the same GGUF differ threefold in llama-bench; how do you read pp512 against tg128 and isolate the cause?

level: seniorimportance: nice to knowfreq 5%

answer

  1. two numbers, two phases
  2. -p 512 and -n 128 by default
  3. the backend and ngl columns
  4. the build: line and -o json
  5. sweep one parameter at a time

basics

~20 s

pp512 is prompt-processing speed over a 512-token prompt and tg128 is generation speed over 128 tokens, both in tokens per second. Check the backend, ngl and build fields first, then rerun both builds with identical explicit flags, sweeping one parameter.

solid answer

~40 s

`llama-bench` reports **pp512**, prompt processing of a 512-token batch (`-p`), and **tg128**, generating 128 tokens one at a time (`-n`), each averaged over five repetitions (`-r`) as tokens per second with a standard deviation, excluding tokenization and sampling. First read the identity fields: the `backend` column (`CPU` means no GPU backend was compiled in), `ngl`, and the `build:` line, or `-o json` for `build_commit`, `backends` and `gpu_info`. Then rerun both builds with the same explicit `-m`, `-ngl`, `-fa`, `-t`, `-b`/`-ub` and `-ctk`/`-ctv`. Where the gap sits narrows the cause: a pp-only gap points at the batched matrix kernels or threads; a gap in both usually means layers or the KV cache are not where you think. Sweep one parameter, such as `-ngl 30,33,35`, to confirm.

code

bash · 10 lines
bash
# Same model, same explicit settings, both binaries
for bin in ./build-a/bin/llama-bench ./build-b/bin/llama-bench; do
  "$bin" -m ./models/your-model.gguf \
    -p 512 -n 128 -r 5 \
    -ngl 99 -fa on -ctk f16 -ctv f16 -b 2048 -ub 512 \
    -o json > "$(dirname "$bin")/bench.json"
done

# Then sweep the one suspect, for example offload
./build-b/bin/llama-bench -m ./models/your-model.gguf -ngl 30,33,35

go deeper

for a junior

Recall that pp is prompt-processing speed and tg is generation speed, both in tokens per second, measured by default over 512 and 128 tokens.

for a middle

Explain the identity fields to check first and why each setting must be explicit on both binaries before speeds are compared.

for a senior

Use where the gap appears, pp only, both phases, or growing with depth, to choose between kernel, offload, backend and attention causes, and confirm with a one-variable sweep.

for a principal

Define a benchmark protocol for releasing builds: fixed models and flags, JSON results with build fingerprints, depth tests that match real traffic, and a threshold that blocks a regression.

## What llama-bench measures `llama-bench` is llama.cpp's performance tool. It loads a model and times two kinds of test: - **Prompt processing (pp)**: the model reads a prompt of `-p` tokens in batches. The default is `-p 512`, shown as `pp512`. - **Text generation (tg)**: the model produces `-n` tokens one after another. The default is `-n 128`, shown as `tg128`. - `-pg 512,128` runs a combined prompt-then-generate test, and `-d 4096` runs any test at a context depth, with the KV cache prefilled by that many tokens. Each test repeats `-r` times (default 5) and is reported as average **tokens per second** with a standard deviation. Tokenization and sampling are not included, so the numbers isolate the model's compute. The two numbers answer different questions. pp is how long a user waits before the first token on a long prompt; tg is how fast the answer streams. A prompt is processed as a large batch, so pp numbers are usually far higher than tg numbers on the same hardware. Why one phase stresses compute and the other memory bandwidth is the inference-foundations material; for diagnosis it is enough that they react to different causes. ## Read the identity fields first Before comparing speeds, confirm the two runs measured the same thing: | Field | Where | What a mismatch means | |---|---|---| | `backend` | table column | `CPU` means no GPU backend in that binary; `CUDA` against `Vulkan` means different code paths | | `ngl` | table column | layers offloaded; llama-bench defaults to `-1`, all of them | | `build:` | line under the table | the commit and build number of each binary | | `model`, `size` | table columns | the same GGUF, with the same quant type | | `build_commit`, `backends`, `gpu_info`, `cpu_info` | `-o json` output | the full fingerprint, for archiving results | A binary configured without `-DGGML_CUDA=ON` on a CUDA box is a common cause of a large gap, and the `backend` column shows it at a glance. ## Make the comparison fair Run both binaries with every relevant setting **explicit**, because defaults move between versions: 1. Same model file, same `-p`, `-n` and `-r`. 2. Same offload: `-ngl 99` or an exact count, rather than a default. 3. Same attention and cache: `-fa on` or `-fa off`, `-ctk f16 -ctv f16`. 4. Same batching: `-b 2048 -ub 512` are the defaults; set them on both. 5. Same threads with `-t` when any work runs on the CPU, and nothing else heavy running on the machine. ## Where the gap sits tells you where to look - **pp differs, tg about equal.** The batched matrix kernels or CPU threading differ. On CUDA the build guide's `GGML_CUDA_FORCE_MMQ` and `GGML_CUDA_FORCE_CUBLAS` options switch between custom quantized kernels and cuBLAS and mainly move prompt processing; on the CPU, `-t` and the BLAS build move pp, and the guide notes BLAS does not affect generation. - **Both differ.** Something structural: one build has fewer layers on the GPU, a different backend, or the KV cache kept off the device (`-nkvo 1`). The README's own `-ngl` sweep on a 7B model shows the stakes: going from 34 to 35 offloaded layers lifts pp512 from about 881 to 2400 t/s and tg128 from about 72 to 132 t/s. - **The gap grows with depth.** Rerun with `-d 0,4096`. If the slower build falls further behind at depth, look at attention: flash attention (`-fa`) and the cache types. - **Large standard deviation.** Thermal throttling, another process on the GPU, or too few repetitions; raise `-r` before believing a small difference. ## Sweep one variable Every test parameter accepts a list, and llama-bench runs all combinations. Change one thing at a time: - `-ngl 30,33,35` to find the cliff where the last layers move onto the GPU. - `-fa on,off` to measure flash attention on this backend. - `-t 4,8,16` for CPU-heavy runs. - `-lm mmap,none` to rule out load-mode effects. Two builds that "benchmark three times apart" usually turn out to differ in backend, offload or kernel choice rather than in the model itself. The interview answer is the method: verify identity, equalize flags, locate the gap in pp or tg, and confirm with a sweep.

  • Why can llama-bench numbers beat what users see from the same build in production?
    llama-bench excludes tokenization and sampling, runs warm-up passes and times a clean prompt at a fixed depth. Real requests add templating, sampling, long and varied contexts, and other load on the machine. Use `-d` to test at realistic depths and `-pg` for prompt-plus-generation, and treat bench results as a ceiling to compare builds, not a user latency.
  • pp512 doubled after a rebuild but tg128 did not move. What changed, most likely?
    Something in the batched path: a different matrix-multiplication kernel choice on CUDA (the `GGML_CUDA_FORCE_MMQ` or `GGML_CUDA_FORCE_CUBLAS` build options), a BLAS build on the CPU, or batch settings. Offload or backend changes would normally move generation too, so a pp-only change rules them out.

  • Compares two builds without checking the backend column or build line.
  • Treats tg128 as the speed of reading a long prompt.
  • Relies on defaults when comparing binaries from different llama.cpp versions.
  • Believes llama-bench numbers include tokenization and sampling time.
  • Changes several flags at once and credits the result to one.