File size: 7,585 Bytes
5b238b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# speed-bench — Long-Context Inference Benchmarking Toolkit

A reproducible benchmark package for cold prefill and decode speed on the **llama.cpp `/v1/chat/completions`** endpoint. It includes the benchmark scripts, fixed prompt datasets, and measured results.

## Contents

```
bench.py                     Benchmark runner (fixed-length sweep / dataset replay)
report.py                    Combine results/*.json into a standard report (see below)
prompts/prompt_<L>.txt       Fixed prompt datasets: 1024 / 4096 / 65536 / 131072 tokens
datasets/                    Real-world benchmark dataset: 2 families x 3 tiers x 10 = 60 samples
  all_samples.jsonl          All 60 samples
  code_samples.jsonl         30 code samples
  general_qa_samples.jsonl   30 general QA samples
  1k_samples.jsonl           20 samples in the 1K tier
results/bench_53_211.json    Raw measured results (complete per-request timings)
config.json                  Full deployment details (quantization, n_ctx, sampling parameters, server fingerprint)
```

## Usage

```bash
python bench.py http://HOST:PORT MODEL results/out.json \
       --lengths 1024,4096,65536,131072 --runs 2
```

The benchmark uses only the Python standard library (`transformers` is required for `--rebuild-prompts`). It processes lengths in the order given by `--lengths`, runs each tier `--runs` times, and writes the results to JSON after every run so an interruption does not lose completed data.

## Metric definitions

Use these settings when reproducing the measurements:

| Item | Setting | Reason |
|---|---|---|
| Rate source | Server-reported `timings` (`prompt_per_second` / `predicted_per_second`) | Client timing includes network and queueing overhead |
| `cache_prompt` | `false` | A cache hit makes prefill appear close to zero and produces misleading results |
| `temperature` | `0` | Reduces decode-side variation |
| `max_tokens` | `256` | Keeps the setting consistent across tiers for comparable decode rates |
| Reasoning mode | `enable_thinking: false` + `reasoning_effort: low` | Otherwise reasoning can consume the output and make decode lengths incomparable |
| Streaming | `stream: true` + `stream_options.include_usage` | Required to collect TTFT and usage |

TTFT is measured by the client as the time until the first SSE event containing content. All other metrics are reported by the server.

## Report format

```bash
python report.py results/bench_32_165_1k.json results/bench_32_165_4k.json ... --out report.md
```

The report contains one row for each (Dataset × Context) pair. Values are averaged across all samples in that tier. Failed requests are excluded from the averages and counted separately (`--out` writes the Markdown report to disk).

| Dataset | Context | Input Tokens | Output Tokens | Prefill (tok/s) | TTFT (s) | Decode (tok/s) | E2E Latency (s) |
|---|---|---|---|---|---|---|---|
| code | 1k | 1039 | 246 | 431.6 | 2.65 | 16.5 | 17.35 |
| code | 4k | 3847 | 243 | 460.4 | 9.06 | 15.0 | 24.94 |
| general_qa | 1k | 1039 | 221 | 463.2 | 2.59 | 16.4 | 15.79 |
| general_qa | 4k | 3978 | 243 | 496.4 | 8.31 | 15.0 | 24.22 |

## Dataset mode: `datasets/`

The benchmark uses real-world text as input, which better represents practical workloads than synthetic repeated text. The dataset contains **2 families × 3 tiers × 10 samples = 60 samples**:

| File | Contents |
|---|---|
| `all_samples.jsonl` | All 60 samples, each with a `task_family` field |
| `code_samples.jsonl` | 30 code samples (HumanEval tasks with CrossCodeEval code blocks as context) |
| `general_qa_samples.jsonl` | 30 long-document QA and summarization samples from LongBench-Pro |

| File | Family | 1k | 4k | 64k | 128k |
|---|---|---|---|---|---|
| `all_samples.jsonl` / family-specific files | code | — | 10 | 10 | 10 |
| | general_qa | — | 10 | 10 | 10 |
| `1k_samples.jsonl` | code | 10 | — | — | — |
| | general_qa | 10 | — | — | — |

**The 1K tier is an additional tier** derived in advance from the paired 4K tasks. Only the context between the anchor points is trimmed; the `<CURRENT_TASK>` block and the original question remain unchanged. As a result, the `tokenizer` field is `local-o200k (openai/gpt-oss-120b)`, while the original 60 samples use `server-tokenizer`. The `construction` field in both sets documents their origin.

Fields in each record:

- `messages` — **A chat payload that can be sent directly**; the benchmark uses it as-is rather than rebuilding it.
- `expected_prompt_tokens` — The expected prompt token count calibrated with the tokenizer of the measured server (4k → 4096, 64k → 65536/65535, 128k → 114687/114688). `prompt_tokens_delta` in the results is the measured value minus this expectation and checks that the requested tier was sent correctly.
- `template_overhead` — 52 tokens for the chat template, already included above.
- `target_tokens` / `scale` / `task_family` / `source_dataset` / `source_id`
- `canonical_solution` (code) / `answer` (QA) — Reference answers for spot checks only; they do not affect benchmarking.

The target for the 128K tier is **114,688 tokens** (112 × 1024), not the commonly cited 131072. Do not mix the two values.

```bash
# Run the full 4K tier with four concurrent requests
python bench.py http://HOST:PORT default results/out.json \
  --dataset datasets/all_samples.jsonl --scale 4k --concurrency 4

# Run only the code family, limited to five samples
python bench.py http://HOST:PORT default results/out.json \
  --dataset datasets/code_samples.jsonl --limit 5
```

Each result JSON record includes `id / task_family / scale / target_tokens / expected_prompt_tokens`. After the run, the benchmark prints an aggregate table by tier with mean prefill tok/s, decode tok/s, TTFT, total time, and error count.

## Prompt datasets

Each `prompts/prompt_<L>.txt` file repeats the `FILLER` paragraphs until the target token count and then appends the same question. The files are calibrated with the **o200k-harmony vocabulary** used by the measured llama.cpp service for the gpt-oss model family:

| File | Target | Actual tokens | Characters |
|---|---|---|---|
| prompt_1024.txt | 1024 | 977 | 5,087 |
| prompt_4096.txt | 4096 | 4,057 | 21,159 |
| prompt_65536.txt | 65536 | 65,437 | 341,451 |
| prompt_131072.txt | 130,816 (leaving room for 256 output tokens) | 130,667 | 681,833 |

The token counts in the table are for the plain text under the o200k vocabulary. The server-reported `prompt_tokens` also includes chat-template overhead (about 60–70 tokens for the Harmony template), so values such as 1044 and 4100 in the results are expected.

**Why use fixed files:** If every user builds the prompt locally with a different tokenizer, “64K” does not represent the same input across services and the measured rates are not comparable. Sending the fixed files ensures that everyone sends identical text.

**Using a different vocabulary family:** The actual token count may shift by a few percent (for example, another vocabulary may count the same 64K prompt as 68K). If needed, run `python bench.py --rebuild-prompts <hf-tokenizer-id-or-local-path>` to regenerate the files and state the tokenizer used in the report.

**Relation to `results/`:** `results/bench_53_211.json` was measured with prompts calibrated using the **server tokenizer**. Compared with the files shipped in this package, its token counts differ by about 0.1% (for example, 65,504 vs. 65,437). To align them exactly, rerun the benchmark after the server is available and overwrite the corresponding files in `results/`.