char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Ruixiang Wangserver-bench : add speed-bench for speculative decoding benchmarking (#23869)689a9a470

char/aliceai-t5-moe
5.2 KiB117 linesraw

SPEED-Bench server benchmark

A lightweight SPEED-Bench client for benchmarking an already-running llama-server through its OpenAI-compatible API. It is primarily meant to evaluate speculative decoding (draft model, n-gram, MTP, EAGLE3, ...) by reporting per-category throughput, latency, and draft acceptance.

The dataset handling follows the aiperf SPEED-Bench tutorial, which also documents the dataset layout in more detail.

Install

pip install -r tools/server/bench/speed-bench/requirements.txt

Start a server

The client does not launch the server, so start llama-server yourself first. If you care about throughput numbers, set the client --concurrency to the server's slot count (--np):

llama-server \
  -m target.gguf \
  -c 8192 \
  --port 8080 \
  -ngl 99 -fa on \
  --np 1 \
  --jinja

For speculative decoding, start the server with the appropriate flags for your setup (e.g. a draft model with -md, or --spec-type ngram-mod). See the speculative decoding doc for details.

Run

python tools/server/bench/speed-bench/speed_bench.py \
  --url localhost:8080 \
  --bench qualitative \
  --category coding \
  --osl 1024 \
  --concurrency 1

Options

OptionDefaultDescription
--urllocalhost:8080Server URL. The scheme and /v1 are optional and a trailing slash is fine, so localhost:8080 and http://localhost:8080/v1/ both work.
--modelnoneOptional model field sent in each request.
--benchqualitativeSPEED-Bench config, e.g. qualitative, throughput_1k. See available dataset variants.
--categoryallCategory filter within the bench; comma-separated list or all. For qualitative the categories are coding, humanities, math, multilingual, qa, rag, reasoning, roleplay, stem, summarization, writing. For the throughput_{ISL} splits they are high_entropy, low_entropy, mixed.
--osl1024Output sequence length, mapped to max_tokens.
--extra-inputs{"temperature":0}Extra request fields as a JSON object.
--concurrency1Concurrent client requests; usually match --np.
--limitnoneMax samples per category (handy for smoke tests).
--timeout600Per-request timeout in seconds.
--outputnoneSave raw per-request results and the summary to JSON.

A few common ones:

  • --category all runs every category in the bench.
  • --category coding,math runs just those two.
  • --bench throughput_8k runs a fixed-input-length throughput split.
  • --limit 8 keeps at most 8 samples per category, which is enough for a quick check.

The throughput_{ISL} splits use fixed input lengths (1k - 32k), so they are handy for long-context testing and for comparing different llama-server batching settings (e.g. sweeping -ub / --ubatch-size) on prompts of a known size. Make sure the server -c is large enough for the chosen split. When raising -ub, also raise -b to at least the same value, since the physical ubatch cannot exceed the logical batch.

When --output is given, the JSON file holds the run config, the selected_samples / completed_samples / failed_samples counts, the per-category summary rows, and the per-sample results.

Metrics

The summary prints one row per category plus an overall row:

  • samples - how many samples finished successfully.
  • avg_prompt_t/s - prefill throughput from llama.cpp (timings.prompt_per_second), averaged over the category's samples.
  • avg_pred_t/s - decode throughput from llama.cpp (timings.predicted_per_second), averaged over the category's samples.
  • avg_latency - average end-to-end request latency seen by the client.
  • accept_rate - accepted / draft_n over the category, or n/a if nothing was drafted (draft_n == 0).

Baseline vs speculative decoding

Save a run from each server with --output, then diff the two JSON files with speed_bench_compare.py.

First, start a plain llama-server (no speculative decoding) and save a baseline:

python tools/server/bench/speed-bench/speed_bench.py \
  --url localhost:8080 \
  --bench qualitative \
  --category all \
  --osl 1024 \
  --concurrency 1 \
  --output baseline.json

Then restart llama-server with speculative decoding enabled and save another run:

python tools/server/bench/speed-bench/speed_bench.py \
  --url localhost:8080 \
  --bench qualitative \
  --category all \
  --osl 1024 \
  --concurrency 1 \
  --output spec.json

Finally compare the two:

python tools/server/bench/speed-bench/speed_bench_compare.py \
  --baseline baseline.json \
  --speculative spec.json

The comparison table adds:

  • decode_speedup = spec_avg_pred_t/s / base_avg_pred_t/s
  • latency_speedup = base_avg_latency / spec_avg_latency

Keep --bench, --category, --osl, and --limit the same across both runs, otherwise they won't be using the same prompts.

1# SPEED-Bench server benchmark
2
3A lightweight [SPEED-Bench](https://huggingface.co/datasets/nvidia/SPEED-Bench) client for benchmarking an already-running `llama-server` through its OpenAI-compatible API. It is primarily meant to evaluate speculative decoding (draft model, n-gram, MTP, EAGLE3, ...) by reporting per-category throughput, latency, and draft acceptance.
4
5The dataset handling follows the [aiperf SPEED-Bench tutorial](https://github.com/ai-dynamo/aiperf/blob/main/docs/tutorials/speed-bench.md), which also documents the dataset layout in more detail.
6
7## Install
8
9```bash
10pip install -r tools/server/bench/speed-bench/requirements.txt
11```
12
13## Start a server
14
15The client does not launch the server, so start `llama-server` yourself first. If you care about throughput numbers, set the client `--concurrency` to the server's slot count (`--np`):
16
17```bash
18llama-server \
19  -m target.gguf \
20  -c 8192 \
21  --port 8080 \
22  -ngl 99 -fa on \
23  --np 1 \
24  --jinja
25```
26
27For speculative decoding, start the server with the appropriate flags for your setup (e.g. a draft model with `-md`, or `--spec-type ngram-mod`). See the [speculative decoding doc](../../../../docs/speculative.md) for details.
28
29## Run
30
31```bash
32python tools/server/bench/speed-bench/speed_bench.py \
33  --url localhost:8080 \
34  --bench qualitative \
35  --category coding \
36  --osl 1024 \
37  --concurrency 1
38```
39
40## Options
41
42| Option | Default | Description |
43| --- | --- | --- |
44| `--url` | `localhost:8080` | Server URL. The scheme and `/v1` are optional and a trailing slash is fine, so `localhost:8080` and `http://localhost:8080/v1/` both work. |
45| `--model` | none | Optional `model` field sent in each request. |
46| `--bench` | `qualitative` | SPEED-Bench config, e.g. `qualitative`, `throughput_1k`. See [available dataset variants](https://github.com/ai-dynamo/aiperf/blob/main/docs/tutorials/speed-bench.md#available-dataset-variants). |
47| `--category` | `all` | Category filter within the bench; comma-separated list or `all`. For `qualitative` the categories are `coding`, `humanities`, `math`, `multilingual`, `qa`, `rag`, `reasoning`, `roleplay`, `stem`, `summarization`, `writing`. For the `throughput_{ISL}` splits they are `high_entropy`, `low_entropy`, `mixed`. |
48| `--osl` | `1024` | Output sequence length, mapped to `max_tokens`. |
49| `--extra-inputs` | `{"temperature":0}` | Extra request fields as a JSON object. |
50| `--concurrency` | `1` | Concurrent client requests; usually match `--np`. |
51| `--limit` | none | Max samples per category (handy for smoke tests). |
52| `--timeout` | `600` | Per-request timeout in seconds. |
53| `--output` | none | Save raw per-request results and the summary to JSON. |
54
55A few common ones:
56
57- `--category all` runs every category in the bench.
58- `--category coding,math` runs just those two.
59- `--bench throughput_8k` runs a fixed-input-length throughput split.
60- `--limit 8` keeps at most 8 samples per category, which is enough for a quick check.
61
62The `throughput_{ISL}` splits use fixed input lengths (1k - 32k), so they are handy for long-context testing and for comparing different `llama-server` batching settings (e.g. sweeping `-ub` / `--ubatch-size`) on prompts of a known size. Make sure the server `-c` is large enough for the chosen split. When raising `-ub`, also raise `-b` to at least the same value, since the physical ubatch cannot exceed the logical batch.
63
64When `--output` is given, the JSON file holds the run `config`, the `selected_samples` / `completed_samples` / `failed_samples` counts, the per-category `summary` rows, and the per-sample `results`.
65
66## Metrics
67
68The summary prints one row per category plus an `overall` row:
69
70- `samples` - how many samples finished successfully.
71- `avg_prompt_t/s` - prefill throughput from llama.cpp (`timings.prompt_per_second`), averaged over the category's samples.
72- `avg_pred_t/s` - decode throughput from llama.cpp (`timings.predicted_per_second`), averaged over the category's samples.
73- `avg_latency` - average end-to-end request latency seen by the client.
74- `accept_rate` - `accepted / draft_n` over the category, or `n/a` if nothing was drafted (`draft_n == 0`).
75
76## Baseline vs speculative decoding
77
78Save a run from each server with `--output`, then diff the two JSON files with `speed_bench_compare.py`.
79
80First, start a plain `llama-server` (no speculative decoding) and save a baseline:
81
82```bash
83python tools/server/bench/speed-bench/speed_bench.py \
84  --url localhost:8080 \
85  --bench qualitative \
86  --category all \
87  --osl 1024 \
88  --concurrency 1 \
89  --output baseline.json
90```
91
92Then restart `llama-server` with speculative decoding enabled and save another run:
93
94```bash
95python tools/server/bench/speed-bench/speed_bench.py \
96  --url localhost:8080 \
97  --bench qualitative \
98  --category all \
99  --osl 1024 \
100  --concurrency 1 \
101  --output spec.json
102```
103
104Finally compare the two:
105
106```bash
107python tools/server/bench/speed-bench/speed_bench_compare.py \
108  --baseline baseline.json \
109  --speculative spec.json
110```
111
112The comparison table adds:
113
114- `decode_speedup = spec_avg_pred_t/s / base_avg_pred_t/s`
115- `latency_speedup = base_avg_latency / spec_avg_latency`
116
117Keep `--bench`, `--category`, `--osl`, and `--limit` the same across both runs, otherwise they won't be using the same prompts.