specbench-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- specbench_cli-0.1.0.dist-info/METADATA +236 -0
- specbench_cli-0.1.0.dist-info/RECORD +22 -0
- specbench_cli-0.1.0.dist-info/WHEEL +4 -0
- specbench_cli-0.1.0.dist-info/entry_points.txt +2 -0
- specbench_cli-0.1.0.dist-info/licenses/LICENSE +201 -0
- speculation_benchmark/__init__.py +45 -0
- speculation_benchmark/backends/__init__.py +27 -0
- speculation_benchmark/backends/base.py +73 -0
- speculation_benchmark/backends/llamacpp.py +660 -0
- speculation_benchmark/cli.py +661 -0
- speculation_benchmark/config.py +415 -0
- speculation_benchmark/hf_jobs.py +379 -0
- speculation_benchmark/publisher.py +196 -0
- speculation_benchmark/runner.py +479 -0
- speculation_benchmark/suites/__init__.py +19 -0
- speculation_benchmark/suites/base.py +96 -0
- speculation_benchmark/suites/bundled/assets/sample_architecture.png +0 -0
- speculation_benchmark/suites/bundled/assets/sample_bar_chart.png +0 -0
- speculation_benchmark/suites/bundled/coding_smoke.jsonl +5 -0
- speculation_benchmark/suites/bundled/multimodal_smoke.jsonl +2 -0
- speculation_benchmark/suites/loaders.py +715 -0
- speculation_benchmark/visualize.py +1228 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: specbench-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Benchmark llama.cpp speculative decoding token acceptance rates, speedup, and memory overhead across draft lengths and task suites.
|
|
5
|
+
Project-URL: Homepage, https://github.com/merveenoyan/specbench
|
|
6
|
+
Project-URL: Repository, https://github.com/merveenoyan/specbench
|
|
7
|
+
Project-URL: Issues, https://github.com/merveenoyan/specbench/issues
|
|
8
|
+
Author-email: Merve Noyan <merveenoyan@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: benchmark,dflash,eagle,gguf,huggingface,llama.cpp,llm,mtp,speculative-decoding
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: datasets>=3.0.0
|
|
24
|
+
Requires-Dist: httpx>=0.27.0
|
|
25
|
+
Requires-Dist: huggingface-hub>=0.27.0
|
|
26
|
+
Requires-Dist: matplotlib>=3.9.0
|
|
27
|
+
Requires-Dist: pillow>=10.0.0
|
|
28
|
+
Requires-Dist: pydantic>=2.8.0
|
|
29
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
30
|
+
Requires-Dist: rich>=13.9.0
|
|
31
|
+
Requires-Dist: typer>=0.12.5
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# `specbench`
|
|
35
|
+
|
|
36
|
+
Benchmark **speculative decoding** in [`llama.cpp`](https://github.com/ggml-org/llama.cpp) across draft lengths and task domains, push results to Hugging Face Hub, and plot dashboards to find the fastest setup for your hardware.
|
|
37
|
+
|
|
38
|
+
https://github.com/user-attachments/assets/771ae1b8-5b28-4af5-a71e-c80f75fcf209
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
## What It Measures
|
|
44
|
+
|
|
45
|
+
For every `(model, speculator, capability, draft_n_max)` run:
|
|
46
|
+
|
|
47
|
+
- **Acceptance rate** — pooled and per-sample token acceptance straight from `llama-server` timings.
|
|
48
|
+
- **Real speedup** — decode/prefill throughput (`tok/s`), latency, and `speedup_vs_baseline` vs. `draft_n_max = 0`.
|
|
49
|
+
- **Memory overhead** — peak GPU VRAM and extra memory added by the drafter (works on discrete NVIDIA GPUs and unified-memory systems like DGX Spark).
|
|
50
|
+
- **Effective draft length & quant metadata** — tracks requested vs. clamped `effective_draft_n_max` (e.g., DFlash block size) plus target and drafter quantizations.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
Requires **`llama.cpp`** (`llama serve` or `llama-server` on `PATH`) and **Python 3.11+**.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Install from PyPI (provides the `specbench` CLI)
|
|
58
|
+
pip install specbench-cli
|
|
59
|
+
|
|
60
|
+
# Or install globally with uv
|
|
61
|
+
uv tool install specbench-cli
|
|
62
|
+
|
|
63
|
+
# Or run without installing
|
|
64
|
+
uvx --from specbench-cli specbench --help
|
|
65
|
+
|
|
66
|
+
# Needed for gated models or pushing results to Hugging Face Hub
|
|
67
|
+
hf auth login
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
<details>
|
|
71
|
+
<summary>Install from source (for development)</summary>
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
git clone https://github.com/merveenoyan/specbench.git
|
|
75
|
+
cd specbench
|
|
76
|
+
uv sync
|
|
77
|
+
uv run specbench --help
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
</details>
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
### Single HF repo (auto-discovered drafter: DFlash, MTP, EAGLE-3, DSpark)
|
|
85
|
+
|
|
86
|
+
Modern `llama.cpp` automatically picks up `dflash-*`, `mtp-*`, `eagle3-*`, and `dspark-*` sidecar GGUFs from the same repo based on `--spec-type`:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# 1) Benchmark Q4_K_M with its matched Q4_K_M DFlash drafter
|
|
90
|
+
specbench run \
|
|
91
|
+
-m meta-models/Muse-Glimmer-30B-GGUF:Q4_K_M \
|
|
92
|
+
--spec-type draft-dflash \
|
|
93
|
+
--suite coding,multimodal,knowledge_work \
|
|
94
|
+
--ctx-size 32768 \
|
|
95
|
+
--max-tokens 2048 \
|
|
96
|
+
--hf-dataset merve/drafter-bench
|
|
97
|
+
|
|
98
|
+
# 2) Benchmark Q4_K_XL reusing the same Q4_K_M DFlash drafter from the repo
|
|
99
|
+
specbench run \
|
|
100
|
+
-m meta-models/Muse-Glimmer-30B-GGUF:Q4_K_XL \
|
|
101
|
+
--spec-type draft-dflash \
|
|
102
|
+
--suite coding,multimodal,knowledge_work \
|
|
103
|
+
--ctx-size 32768 \
|
|
104
|
+
--max-tokens 2048 \
|
|
105
|
+
--hf-dataset merve/drafter-bench
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> **Tips:** Pass `--no-mmproj` to skip loading the vision encoder for text-only suites, `--speculator-file <file.gguf>` to pin a specific drafter, or `--dry-run` to save locally under `results/` without pushing to the Hub.
|
|
109
|
+
|
|
110
|
+
### Separate target & drafter repos
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
specbench run \
|
|
114
|
+
-m unsloth/Qwen3-32B-GGUF:Q4_K_M \
|
|
115
|
+
-s unsloth/Qwen3-0.6B-GGUF:Q8_0 \
|
|
116
|
+
--spec-type draft-simple \
|
|
117
|
+
--suite coding,multimodal \
|
|
118
|
+
--hf-dataset <your-username/drafter-bench>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### YAML config
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
specbench run --config config.example.yaml
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Prompt Suites
|
|
128
|
+
|
|
129
|
+
Select built-in suites with `--suite` (comma-separated or repeated; defaults to 20 samples via `--limit 20`):
|
|
130
|
+
|
|
131
|
+
| Flag | Dataset | Focus |
|
|
132
|
+
| --- | --- | --- |
|
|
133
|
+
| `coding` | [`ArtificialAnalysis/SWE-Atlas-QnA-AA`](https://huggingface.co/datasets/ArtificialAnalysis/SWE-Atlas-QnA-AA) | Software engineering Q&A (Go/Python/C/TS) |
|
|
134
|
+
| `multimodal` | [`MMMU/MMMU_Pro`](https://huggingface.co/datasets/MMMU/MMMU_Pro) | Image + question reasoning |
|
|
135
|
+
| `knowledge_work` | [`ArtificialAnalysis/AA-Briefcase-Lite`](https://huggingface.co/datasets/ArtificialAnalysis/AA-Briefcase-Lite) | Long-context commercial due diligence |
|
|
136
|
+
| `coding=preset:livecodebench` | [`livecodebench/code_generation_lite`](https://huggingface.co/datasets/livecodebench/code_generation_lite) | Competitive coding (v6) |
|
|
137
|
+
| `coding=preset:smoke-coding` | Bundled offline smoke suite | Fast offline check (`preset:smoke-multimodal` also included) |
|
|
138
|
+
|
|
139
|
+
### Bring your own dataset
|
|
140
|
+
|
|
141
|
+
Point `--suite` at **any Hugging Face dataset** or **local `.jsonl`/`.json` file**. Splits (`test → validation → train`), prompt/image columns, and `messages`/`conversations` turn lists are auto-detected, and `llama-server` applies the model's own GGUF chat template:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Zero-config HF dataset
|
|
145
|
+
specbench run -m <repo:quant> --suite math=hf:org/my-math-prompts
|
|
146
|
+
|
|
147
|
+
# Optional overrides for multi-config datasets or custom columns
|
|
148
|
+
specbench run -m <repo:quant> \
|
|
149
|
+
--suite math="hf:openai/gsm8k?config=main&split=test&prompt_column=question"
|
|
150
|
+
|
|
151
|
+
# Local JSONL (supports optional "images": ["relative/path.png"])
|
|
152
|
+
specbench run -m <repo:quant> --suite coding=./my_prompts.jsonl
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Preview any suite before launching a server:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
specbench inspect-suite preset:coding --capability coding --limit 5
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Draft Token Sweeps
|
|
162
|
+
|
|
163
|
+
By default, `specbench` sweeps `--draft-tokens default` = **`[0, 4, 8, 12]`** (including `0` computes baseline speedup and memory delta automatically).
|
|
164
|
+
|
|
165
|
+
- `--draft-tokens spec-only` → `[4, 8, 12]`
|
|
166
|
+
- `--draft-tokens fine` → `[0, 1, 2, 4, 8, 12, 16]`
|
|
167
|
+
- `--draft-tokens 0,2,6,10,15` → custom list
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary>How <code>llama.cpp</code> block-size clamping is handled</summary>
|
|
171
|
+
|
|
172
|
+
Some speculators cap the maximum draft length internally:
|
|
173
|
+
|
|
174
|
+
- **DFlash (`draft-dflash`)** clamps to `dflash.block_size - 1` (e.g., `block_size=16` caps at `15`).
|
|
175
|
+
- **Chained multi-head MTP (`draft-mtp`)** clamps to `n_mtp_layers`.
|
|
176
|
+
- **`ngram-cache`** is fixed at `8` tokens.
|
|
177
|
+
- **Standalone draft (`draft-simple`) & EAGLE-3 (`draft-eagle3`)** accept arbitrary lengths.
|
|
178
|
+
|
|
179
|
+
When `llama.cpp` clamps a value, `specbench` logs a warning and records both `draft_n_max` (requested) and `effective_draft_n_max` (actual).
|
|
180
|
+
|
|
181
|
+
</details>
|
|
182
|
+
|
|
183
|
+
## Plotting Results
|
|
184
|
+
|
|
185
|
+
Generate the 2×2 dashboard (`dashboard.png`) plus standalone charts from a HF Hub dataset or local `results/<run_id>` folder:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
specbench plot merve/drafter-bench --output-dir ./charts
|
|
189
|
+
specbench plot merve/drafter-bench --model Muse-Glimmer --theme light --format svg
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Cloud GPUs via Hugging Face Jobs
|
|
193
|
+
|
|
194
|
+
No local GPU (or want to compare L40S, A100, H200)? `specbench hf-job` runs the same benchmark on [Hugging Face Jobs](https://huggingface.co/docs/hub/en/jobs) using `ghcr.io/ggml-org/llama.cpp:server-cuda` and pushes results straight to your dataset:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
specbench hf-job \
|
|
198
|
+
--flavor l40sx1 \
|
|
199
|
+
--timeout 2h \
|
|
200
|
+
--detach \
|
|
201
|
+
-m meta-models/Muse-Glimmer-30B-GGUF:Q4_K_M \
|
|
202
|
+
--spec-type draft-dflash \
|
|
203
|
+
--suite coding,multimodal,knowledge_work \
|
|
204
|
+
--limit 15 \
|
|
205
|
+
--ctx-size 32768 \
|
|
206
|
+
--hf-dataset <your-username/drafter-bench>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Check hardware flavors with `hf jobs hardware`, preview commands with `--print-command`, and monitor runs with `hf jobs ps` / `hf jobs logs <job_id> --follow`.
|
|
210
|
+
|
|
211
|
+
## Dataset Output
|
|
212
|
+
|
|
213
|
+
Runs write local Parquet + JSON checkpoints to `results/<run_id>/` and append to two HF dataset configs (`summary` and `samples`):
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
from datasets import load_dataset
|
|
217
|
+
|
|
218
|
+
summary = load_dataset("merve/drafter-bench", "summary", split="train")
|
|
219
|
+
samples = load_dataset("merve/drafter-bench", "samples", split="train")
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
<details>
|
|
223
|
+
<summary>Full schema columns</summary>
|
|
224
|
+
|
|
225
|
+
- **`summary`** *(one row per run, capability, and `draft_n_max`)*: `run_id`, `timestamp_utc`, `backend`, `llama_version`, `hardware`, `model_repo`, `model_file`, `model_quant`, `is_quantized`, `speculator_repo`, `speculator_file`, `speculator_quant`, `speculator_is_quantized`, `speculator_mode`, `spec_type`, `draft_n_max`, `effective_draft_n_max`, `capability`, `source_datasets`, `samples_total`, `samples_ok`, `samples_failed`, `total_prompt_tokens`, `total_predicted_tokens`, `total_draft_n`, `total_draft_n_accepted`, `acceptance_rate`, `mean_sample_acceptance_rate`, `avg_prompt_per_second`, `avg_predicted_per_second`, `avg_latency_s`, `speedup_vs_baseline`, `gpu_memory_peak_mib`, `speculator_extra_gpu_memory_mib`, `max_tokens`, `temperature`.
|
|
226
|
+
- **`samples`** *(one row per prompt)*: `draft_n`, `draft_n_accepted`, `acceptance_rate`, `prompt_tokens`, `predicted_tokens`, `prompt_per_second`, `predicted_per_second`, `latency_s`, `finish_reason`, `ok`, `error`, plus model/speculator/quant metadata.
|
|
227
|
+
|
|
228
|
+
</details>
|
|
229
|
+
|
|
230
|
+
## Custom `llama-server` & Tests
|
|
231
|
+
|
|
232
|
+
Point to a custom `llama-server` binary with `--llama-cmd /path/to/llama-server`, list presets with `specbench list-presets`, and run tests with:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
uv run pytest -v
|
|
236
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
speculation_benchmark/__init__.py,sha256=5Pfeb_5lRe6id22DnV051yHU_32EZGsattUMjKpxCrs,1169
|
|
2
|
+
speculation_benchmark/cli.py,sha256=ZoRRM0K3lDg7oC3jTY68aTPD5Y5-63natcRtypFKOII,23976
|
|
3
|
+
speculation_benchmark/config.py,sha256=ukQP2duj9sZGNqEwC-dpq5N8kGFotiQXJMuEFTExNxA,16235
|
|
4
|
+
speculation_benchmark/hf_jobs.py,sha256=vp6fK7Wn636ynUZRRYHQpRJ6wK181L3Kg_89f2PelsQ,14216
|
|
5
|
+
speculation_benchmark/publisher.py,sha256=uE49sXveYkNbKXuxRxwGD7EZCAUvB_AMz3j0zqHnrZ4,7359
|
|
6
|
+
speculation_benchmark/runner.py,sha256=NMs714GoT9fSPf7Y2ySvPLlrBQY7-g1v6gSd6aNBKGA,21430
|
|
7
|
+
speculation_benchmark/visualize.py,sha256=8Rh50jasNnIr_DQkNkHtcKlgzh0UoyS_mXg9cttto2s,40087
|
|
8
|
+
speculation_benchmark/backends/__init__.py,sha256=GilLiysLiEyV_NojLEY158JNYsTegXvhRm-DmR4wSyE,707
|
|
9
|
+
speculation_benchmark/backends/base.py,sha256=BhScEGMVFww1IfjqWodP6gBhR_ucJ7Muv_1wwtG-cTQ,2214
|
|
10
|
+
speculation_benchmark/backends/llamacpp.py,sha256=qTgPmWcIPOPZCviZg2-lWUSo7CkDXfVauYI3fnEIxxA,23857
|
|
11
|
+
speculation_benchmark/suites/__init__.py,sha256=iYPkZQkrSZzOs9nMmkN3ZArNQkJv08q6WZS-qsPxmfs,394
|
|
12
|
+
speculation_benchmark/suites/base.py,sha256=KYjBW81-H04TnfO0bAh2uTktv0eGz_wsbBhO1gwfl0s,3478
|
|
13
|
+
speculation_benchmark/suites/loaders.py,sha256=XM614z57y3HxfC0Y_kPxzd5axbI6Nab78lpfNCkbmdE,27144
|
|
14
|
+
speculation_benchmark/suites/bundled/coding_smoke.jsonl,sha256=-Gp_AZuKnq0NKkJokbwCzcA_Cp88ra_U8Vr7gv7pVuQ,1507
|
|
15
|
+
speculation_benchmark/suites/bundled/multimodal_smoke.jsonl,sha256=JHCwrW2IrGsxSLMqi_B2aSVlFyB83PvtFmzNg6dDzPo,482
|
|
16
|
+
speculation_benchmark/suites/bundled/assets/sample_architecture.png,sha256=8DCMhU47j0_GuymIP1_xhKJTt-AujWbVh4QkTC3VWQQ,2498
|
|
17
|
+
speculation_benchmark/suites/bundled/assets/sample_bar_chart.png,sha256=7h58OlVhQUA1hFVoFIwzOx2qUJ1RPcEmzBHUNUY2X0M,4624
|
|
18
|
+
specbench_cli-0.1.0.dist-info/METADATA,sha256=d_Ds0F1KcvZw2Ax3TSx8u3bzQQ2VusTe_pa4cMNVq1k,9874
|
|
19
|
+
specbench_cli-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
20
|
+
specbench_cli-0.1.0.dist-info/entry_points.txt,sha256=h0SMXhH1LPrZCWWeaHy9i29LAUqt49soWNKE7JZRj-Q,60
|
|
21
|
+
specbench_cli-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
22
|
+
specbench_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Speculative decoding benchmark tool for llama.cpp."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
from speculation_benchmark.config import (
|
|
6
|
+
DEFAULT_DRAFT_TOKENS,
|
|
7
|
+
DRAFT_TOKEN_PRESETS,
|
|
8
|
+
BenchmarkConfig,
|
|
9
|
+
GenerationConfig,
|
|
10
|
+
ModelSpec,
|
|
11
|
+
OutputConfig,
|
|
12
|
+
ServerConfig,
|
|
13
|
+
SuiteSpec,
|
|
14
|
+
resolve_draft_tokens,
|
|
15
|
+
)
|
|
16
|
+
from speculation_benchmark.hf_jobs import HFJobOptions, build_hf_jobs_command, submit_hf_job
|
|
17
|
+
from speculation_benchmark.runner import BenchmarkRunResult, run_benchmark
|
|
18
|
+
from speculation_benchmark.visualize import generate_visualizations, load_summary_rows
|
|
19
|
+
|
|
20
|
+
PACKAGE_NAME = "specbench-cli"
|
|
21
|
+
try:
|
|
22
|
+
__version__ = version(PACKAGE_NAME)
|
|
23
|
+
except PackageNotFoundError:
|
|
24
|
+
__version__ = "0.1.0"
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"BenchmarkConfig",
|
|
28
|
+
"BenchmarkRunResult",
|
|
29
|
+
"DEFAULT_DRAFT_TOKENS",
|
|
30
|
+
"DRAFT_TOKEN_PRESETS",
|
|
31
|
+
"GenerationConfig",
|
|
32
|
+
"HFJobOptions",
|
|
33
|
+
"ModelSpec",
|
|
34
|
+
"OutputConfig",
|
|
35
|
+
"PACKAGE_NAME",
|
|
36
|
+
"ServerConfig",
|
|
37
|
+
"SuiteSpec",
|
|
38
|
+
"__version__",
|
|
39
|
+
"build_hf_jobs_command",
|
|
40
|
+
"generate_visualizations",
|
|
41
|
+
"load_summary_rows",
|
|
42
|
+
"resolve_draft_tokens",
|
|
43
|
+
"run_benchmark",
|
|
44
|
+
"submit_hf_job",
|
|
45
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from speculation_benchmark.backends.base import (
|
|
2
|
+
CompletionResponse,
|
|
3
|
+
CompletionTimings,
|
|
4
|
+
SpeculationBackend,
|
|
5
|
+
)
|
|
6
|
+
from speculation_benchmark.backends.llamacpp import (
|
|
7
|
+
LlamaCppServerBackend,
|
|
8
|
+
build_llama_serve_command,
|
|
9
|
+
detect_hardware_tag,
|
|
10
|
+
detect_llama_version,
|
|
11
|
+
parse_effective_draft_n_max,
|
|
12
|
+
parse_nvidia_smi_compute_apps,
|
|
13
|
+
query_process_gpu_memory_mib,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"CompletionResponse",
|
|
18
|
+
"CompletionTimings",
|
|
19
|
+
"LlamaCppServerBackend",
|
|
20
|
+
"SpeculationBackend",
|
|
21
|
+
"build_llama_serve_command",
|
|
22
|
+
"detect_hardware_tag",
|
|
23
|
+
"detect_llama_version",
|
|
24
|
+
"parse_effective_draft_n_max",
|
|
25
|
+
"parse_nvidia_smi_compute_apps",
|
|
26
|
+
"query_process_gpu_memory_mib",
|
|
27
|
+
]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any, Protocol
|
|
5
|
+
|
|
6
|
+
from speculation_benchmark.config import GenerationConfig
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class CompletionTimings:
|
|
11
|
+
"""Timing and speculative decoding counters reported by the backend."""
|
|
12
|
+
|
|
13
|
+
prompt_n: int = 0
|
|
14
|
+
predicted_n: int = 0
|
|
15
|
+
draft_n: int = 0
|
|
16
|
+
draft_n_accepted: int = 0
|
|
17
|
+
prompt_ms: float | None = None
|
|
18
|
+
predicted_ms: float | None = None
|
|
19
|
+
prompt_per_second: float | None = None
|
|
20
|
+
predicted_per_second: float | None = None
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def acceptance_rate(self) -> float | None:
|
|
24
|
+
if self.draft_n <= 0:
|
|
25
|
+
return None
|
|
26
|
+
return self.draft_n_accepted / self.draft_n
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class CompletionResponse:
|
|
31
|
+
"""Normalized completion response from a speculative decoding backend."""
|
|
32
|
+
|
|
33
|
+
content: str
|
|
34
|
+
finish_reason: str | None
|
|
35
|
+
latency_s: float
|
|
36
|
+
timings: CompletionTimings
|
|
37
|
+
raw_usage: dict[str, Any] = field(default_factory=dict)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class SpeculationBackend(Protocol):
|
|
41
|
+
"""Protocol implemented by inference backends (local llama.cpp now, HF Jobs later)."""
|
|
42
|
+
|
|
43
|
+
def start(self, draft_n_max: int) -> None:
|
|
44
|
+
"""Start or reconfigure the backend for the given draft token count (0 = baseline)."""
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
def complete(
|
|
48
|
+
self,
|
|
49
|
+
messages: list[dict[str, Any]],
|
|
50
|
+
generation: GenerationConfig,
|
|
51
|
+
) -> CompletionResponse:
|
|
52
|
+
"""Execute a single OpenAI-format chat completion request and return timings."""
|
|
53
|
+
...
|
|
54
|
+
|
|
55
|
+
def stop(self) -> None:
|
|
56
|
+
"""Cleanly shut down the backend."""
|
|
57
|
+
...
|
|
58
|
+
|
|
59
|
+
def gpu_memory_peak_mib(self) -> float | None:
|
|
60
|
+
"""Return peak GPU memory (MiB) observed for the current/most recent sweep step."""
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
def effective_draft_n_max(self) -> int | None:
|
|
64
|
+
"""Return actual draft_n_max used by the backend (after any block-size clamping)."""
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
def detected_speculator_file(self) -> str | None:
|
|
68
|
+
"""Return the speculator GGUF filename detected from runtime logs, if any."""
|
|
69
|
+
...
|
|
70
|
+
|
|
71
|
+
def runtime_metadata(self) -> dict[str, Any]:
|
|
72
|
+
"""Return backend/runtime metadata to record alongside benchmark outputs."""
|
|
73
|
+
...
|