amagi-draftbench 0.1.0__tar.gz

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.
Files changed (26) hide show
  1. amagi_draftbench-0.1.0/LICENSE +22 -0
  2. amagi_draftbench-0.1.0/PKG-INFO +217 -0
  3. amagi_draftbench-0.1.0/README.md +197 -0
  4. amagi_draftbench-0.1.0/pyproject.toml +37 -0
  5. amagi_draftbench-0.1.0/setup.cfg +4 -0
  6. amagi_draftbench-0.1.0/src/amagi_draftbench/__init__.py +6 -0
  7. amagi_draftbench-0.1.0/src/amagi_draftbench/__main__.py +3 -0
  8. amagi_draftbench-0.1.0/src/amagi_draftbench/bench.py +165 -0
  9. amagi_draftbench-0.1.0/src/amagi_draftbench/cli.py +283 -0
  10. amagi_draftbench-0.1.0/src/amagi_draftbench/power.py +191 -0
  11. amagi_draftbench-0.1.0/src/amagi_draftbench/prompts.py +89 -0
  12. amagi_draftbench-0.1.0/src/amagi_draftbench/report.py +262 -0
  13. amagi_draftbench-0.1.0/src/amagi_draftbench/servers.py +400 -0
  14. amagi_draftbench-0.1.0/src/amagi_draftbench/stream.py +220 -0
  15. amagi_draftbench-0.1.0/src/amagi_draftbench/sweep.py +389 -0
  16. amagi_draftbench-0.1.0/src/amagi_draftbench.egg-info/PKG-INFO +217 -0
  17. amagi_draftbench-0.1.0/src/amagi_draftbench.egg-info/SOURCES.txt +24 -0
  18. amagi_draftbench-0.1.0/src/amagi_draftbench.egg-info/dependency_links.txt +1 -0
  19. amagi_draftbench-0.1.0/src/amagi_draftbench.egg-info/entry_points.txt +2 -0
  20. amagi_draftbench-0.1.0/src/amagi_draftbench.egg-info/requires.txt +3 -0
  21. amagi_draftbench-0.1.0/src/amagi_draftbench.egg-info/top_level.txt +1 -0
  22. amagi_draftbench-0.1.0/tests/test_power.py +111 -0
  23. amagi_draftbench-0.1.0/tests/test_report_cli.py +220 -0
  24. amagi_draftbench-0.1.0/tests/test_servers.py +212 -0
  25. amagi_draftbench-0.1.0/tests/test_stream.py +172 -0
  26. amagi_draftbench-0.1.0/tests/test_sweep.py +249 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex
4
+ Copyright (c) 2026 Amagisolutionsgroup, Inc. (AmagiLabs)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,217 @@
1
+ Metadata-Version: 2.4
2
+ Name: amagi-draftbench
3
+ Version: 0.1.0
4
+ Summary: Find the draft model (or n-gram lookup) that speeds up your local LLM: speculative-decoding sweeps for llama.cpp and vLLM with tok/s, acceptance rate, tokens per joule and peak VRAM, plus a pick per VRAM budget.
5
+ Author-email: "AmagiLabs (Amagisolutionsgroup, Inc.)" <dev@amagisolutionsgroup.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/amagilabs/amagi-draftbench
8
+ Keywords: llm,speculative-decoding,draft-model,llama.cpp,vllm,benchmark,gpu,localllama,cli
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Environment :: Console
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Classifier: Topic :: System :: Benchmark
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=7.0; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # amagi-draftbench
22
+
23
+ Find out which draft model, if any, makes your local LLM faster on your own GPU. amagi-draftbench starts llama-server (or vLLM, or any server you give it) once per target and draft pair, then measures decode tok/s, speedup, draft acceptance rate, tokens per joule and peak VRAM. It also tests n-gram drafting, which needs no draft model at all, and recommends a draft for each VRAM budget.
24
+
25
+ ![amagi-draftbench showing RTX 3090 results and a per-VRAM recommendation](https://raw.githubusercontent.com/amagilabs/amagi-draftbench/main/assets/demo.gif)
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ pipx install amagi-draftbench
31
+ ```
32
+
33
+ Not on PyPI yet. Until it is, install from a clone with `pipx install .` or `pip install .`
34
+
35
+ Python 3.9 or newer, no other dependencies. You also need a llama.cpp build with `llama-server` (or vLLM) and GGUF models.
36
+
37
+ ## Usage
38
+
39
+ Write a sweep config, run it, then read the results:
40
+
41
+ ```bash
42
+ amagi-draftbench init-config --target ~/models/Qwen2.5-32B-Instruct-Q4_K_M.gguf \
43
+ --draft ~/models/Qwen2.5-0.5B-Instruct-Q8_0.gguf --draft ~/models/Qwen2.5-1.5B-Instruct-Q4_K_M.gguf \
44
+ --ngram --hardware rtx3090 -o configs/q25-32b.json
45
+ amagi-draftbench sweep configs/q25-32b.json
46
+ amagi-draftbench report results/ --by-prompt
47
+ amagi-draftbench recommend results/
48
+ ```
49
+
50
+ `sweep` runs the target alone first, then once with each draft. Every run gets a fresh server, a warm-up request and the same prompts at temperature 0. Results land in `results/<hardware>_<backend>_<name>.json`. If a sweep stops partway, run it again and it carries on from where it stopped.
51
+
52
+ To benchmark one server you started yourself (upstream issue #2):
53
+
54
+ ```bash
55
+ llama-server -m target.gguf -md draft.gguf -ngl 99 -ngld 99 -np 1 --port 8081
56
+ amagi-draftbench bench --url http://127.0.0.1:8081
57
+ amagi-draftbench bench --url http://127.0.0.1:8081 --compare-url http://127.0.0.1:8080 # 8080 runs without a draft
58
+ ```
59
+
60
+ `find-server` shows which `llama-server` it will use and which draft features that build has:
61
+
62
+ ```
63
+ $ amagi-draftbench find-server ~/llama.cpp/build/bin/llama-server
64
+ ~/llama.cpp/build/bin/llama-server
65
+ --spec-type (n-gram drafting): yes
66
+ n-gram types: ngram-simple, ngram-map-k, ngram-map-k4v, ngram-mod, ngram-cache
67
+ draft size flag: --spec-draft-n-max
68
+ -np (slots): yes
69
+ ```
70
+
71
+ ## Results on an RTX 3090
72
+
73
+ One RTX 3090 (24 GB, power limit 300 W), llama.cpp build 11753 with flash attention, temperature 0, five prompts sent twice each. Replies are 512 tokens on the 7B and the Gemma MoE, and 256 tokens on the 27B and 32B (see the note on heat under [How it measures](#how-it-measures)). Qwen3.8 ran with thinking off. The raw files are in [`results/rtx3090/`](results/rtx3090/).
74
+
75
+ #### qwen25-32b (rtx3090, llamacpp)
76
+
77
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
78
+ |---|---|---|---|---|---|---|---|---|
79
+ | Qwen2.5-32B Q4_K_M | none (baseline) | 37.0 | 1.00x | - | 0.14 | 267 | 19.6 | - |
80
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-0.5B Q8_0 | 62.8 | 1.70x | 76% | 0.24 | 252 | 20.2 | 5/10 |
81
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q4_K_M | 62.4 | 1.69x | 85% | 0.24 | 249 | 20.7 | 5/10 |
82
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q8_0 | 60.9 | 1.65x | 87% | 0.23 | 255 | 21.3 | 5/10 |
83
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-3B Q4_K_M | 54.6 | 1.48x | 84% | 0.22 | 242 | 21.6 | 5/10 |
84
+ | Qwen2.5-32B Q4_K_M | ngram-mod | 43.7 | 1.18x | 70% | 0.16 | 272 | 19.6 | 10/10 |
85
+
86
+ #### qwen25-7b (rtx3090, llamacpp)
87
+
88
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
89
+ |---|---|---|---|---|---|---|---|---|
90
+ | Qwen2.5-7B Q4_K_M | none (baseline) | 140.8 | 1.00x | - | 0.51 | 273 | 4.7 | - |
91
+ | Qwen2.5-7B Q4_K_M | Qwen2.5-0.5B Q8_0 | 170.2 | 1.21x | 80% | 0.59 | 282 | 5.3 | 10/10 |
92
+ | Qwen2.5-7B Q4_K_M | Qwen2.5-1.5B Q4_K_M | 153.2 | 1.09x | 90% | 0.57 | 265 | 5.8 | 10/10 |
93
+ | Qwen2.5-7B Q4_K_M | ngram-mod | 156.2 | 1.11x | 35% | 0.65 | 239 | 4.7 | 10/10 |
94
+
95
+ #### qwen38-27b (rtx3090, llamacpp)
96
+
97
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
98
+ |---|---|---|---|---|---|---|---|---|
99
+ | Qwen3.8-27B Q4_K_M | none (baseline) | 42.1 | 1.00x | - | 0.15 | 263 | 15.6 | - |
100
+ | Qwen3.8-27B Q4_K_M | Qwen3.5-0.8B Q8_0 | 44.6 | 1.06x | 88% | 0.18 | 239 | 16.5 | 6/10 |
101
+ | Qwen3.8-27B Q4_K_M | Qwen3.5-2B Q4_K_M | 44.2 | 1.05x | 89% | 0.17 | 241 | 16.9 | 8/10 |
102
+ | Qwen3.8-27B Q4_K_M | ngram-mod | 49.6 | 1.18x | 63% | 0.18 | 266 | 15.6 | 10/10 |
103
+
104
+ #### gemma4-26b-a4b (rtx3090, llamacpp)
105
+
106
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
107
+ |---|---|---|---|---|---|---|---|---|
108
+ | Gemma-4-26B-A4B Q4_K_M | none (baseline) | 122.3 | 1.00x | - | 0.42 | 282 | 16.6 | - |
109
+ | Gemma-4-26B-A4B Q4_K_M | Gemma-4-E2B Q4_K_M | 92.2 | 0.75x | 71% | 0.34 | 262 | 18.2 | 1/10 |
110
+ | Gemma-4-26B-A4B Q4_K_M | ngram-mod | 122.9 | 1.00x | 35% | 0.45 | 266 | 16.6 | 8/10 |
111
+
112
+ **A draft model gave a 50-80% speedup on this 3090 only for the dense 32B.**
113
+
114
+ - **Qwen2.5-32B Q4_K_M:** a Qwen2.5-0.5B Q8_0 draft took it from 37.0 to 62.8 tok/s (1.70x), and 1.5B Q4_K_M did 1.69x. The 3B draft got a similar share of tokens accepted but costs more to run, so it landed at 1.48x. Energy per token improved along with speed, from 0.14 to 0.24 tok/J.
115
+ - **Qwen2.5-7B Q4_K_M:** the same 0.5B draft gave 1.21x. The 7B already runs at 141 tok/s on its own, and the draft's own cost is a bigger share of each step.
116
+ - **Qwen3.8-27B Q4_K_M with Qwen3.5 drafts:** 1.05x to 1.06x, even though 88-89% of draft tokens were accepted. A separate single request showed the same thing: the server reported 85% acceptance and 3.5 tokens per draft step, and decode stayed at 42.4 tok/s against 42.2 without the draft. I have not found the cause.
117
+ - **Gemma-4-26B-A4B (MoE):** the Gemma-4-E2B draft made it slower, 122.3 down to 92.2 tok/s (0.75x). This MoE only reads about 4B parameters per token, so it is already fast, and running the draft costs more than it saves.
118
+ - **n-gram drafting** (`ngram-mod`, no draft model, no extra VRAM) gave 1.11x to 1.18x on the Qwen targets and 1.00x on Gemma. All of the gain came from the two edit prompts, where the reply copies most of the prompt: 1.5x to 2.0x there, and 1.0x on fresh code, JSON and lists.
119
+
120
+ The per-prompt view for the 32B shows which kinds of reply each draft speeds up:
121
+
122
+ #### qwen25-32b: tok/s per prompt
123
+
124
+ | Target | Draft | code | json | list | edit_code | edit_text |
125
+ |---|---|---|---|---|---|---|
126
+ | Qwen2.5-32B Q4_K_M | none (baseline) | 37 | 37 | 37 | 37 | 37 |
127
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-0.5B Q8_0 | 66 (1.8x) | 71 (1.9x) | 45 (1.2x) | 71 (1.9x) | 74 (2.0x) |
128
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q4_K_M | 63 (1.7x) | 65 (1.8x) | 53 (1.4x) | 64 (1.7x) | 70 (1.9x) |
129
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q8_0 | 64 (1.7x) | 63 (1.7x) | 51 (1.4x) | 62 (1.7x) | 67 (1.8x) |
130
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-3B Q4_K_M | 55 (1.5x) | 56 (1.5x) | 48 (1.3x) | 57 (1.6x) | 60 (1.6x) |
131
+ | Qwen2.5-32B Q4_K_M | ngram-mod | 37 (1.0x) | 37 (1.0x) | 37 (1.0x) | 58 (1.6x) | 73 (2.0x) |
132
+
133
+ `recommend` turns the same files into a pick per card size (24 GB shown):
134
+
135
+ ```
136
+ $ amagi-draftbench recommend results/rtx3090 --budgets 24
137
+ 24 GB card:
138
+ Qwen2.5-32B Q4_K_M: draft Qwen2.5-0.5B Q8_0 -> 62.8 tok/s (1.70x vs 37.0 plain, 76% accepted), 20.2 GiB
139
+ Qwen2.5-7B Q4_K_M: draft Qwen2.5-0.5B Q8_0 -> 170.2 tok/s (1.21x vs 140.8 plain, 80% accepted), 5.3 GiB
140
+ Qwen3.8-27B Q4_K_M: draft ngram-mod -> 49.6 tok/s (1.18x vs 42.1 plain, 63% accepted), 15.6 GiB
141
+ best draft model: Qwen3.5-0.8B Q8_0 -> 44.6 tok/s (1.06x vs 42.1 plain, 88% accepted), 16.5 GiB
142
+ Gemma-4-26B-A4B Q4_K_M: skip drafts (122.3 tok/s, 16.6 GiB) -- no draft that fits is at least 5% faster; run it plain
143
+
144
+ n-gram drafting only pays off when the reply repeats text from the prompt (edits, refactors). Check 'report --by-prompt' before relying on it.
145
+ ```
146
+
147
+ ## FAQ: the six open draftbench issues
148
+
149
+ **#1, GGUF vs MLX.** amagi-draftbench has a `command` backend that runs any server from a shell line, so `mlx_lm.server --draft-model` works through it ([`examples/mlx_command.json`](examples/mlx_command.json)). I have no Apple Silicon results, so there is no GGUF vs MLX comparison here yet.
150
+
151
+ **#2, how do I run a single benchmark?** `amagi-draftbench bench --url ...` against a server you started. See [Usage](#usage).
152
+
153
+ **#3, TPS shows 0.0.** Thinking models (Qwen3, DeepSeek-R1, gpt-oss) stream their reasoning in `delta.reasoning_content`, not `delta.content`. draftbench only counted `content`, so a reply that spent its whole token budget thinking never produced a "first token" and scored 0. Both fields count now. To turn thinking off, add `"extra_body": {"chat_template_kwargs": {"enable_thinking": false}}` to a config, or pass `--no-think` to `bench`.
154
+
155
+ **#4, llama-server autodetection.** Searches PATH (the approach from PR #4 by alxarch), then the usual build folders, including Windows `build/bin/Release/llama-server.exe`. Set `llama_bin` in the config to skip the search.
156
+
157
+ **#5, 400 Bad Request.** draftbench threw the server's error message away, so all you saw was "400". amagi-draftbench prints the message the server sent. It also starts llama-server with one slot (`-np 1`) and a context sized to fit the longest prompt plus `max_tokens`. Recent builds default to several slots that split the context, and a request that does not fit gets a 400. I could not reproduce the 400 with draftbench's own flags on llama.cpp build 11753: all four slots got the full 4096 tokens (unified KV cache) and every request returned 200. Older builds may still behave as the issue describes.
158
+
159
+ **#6, vLLM.** Current vLLM dropped `--speculative-model` in favor of `--speculative-config`. The `vllm` backend uses the new flag for both draft models and n-gram drafting, and reads acceptance from vLLM's `/metrics` counters ([`examples/vllm_qwen3.json`](examples/vllm_qwen3.json)). I have no vLLM results yet; the commands above come from `sweep --dry-run`.
160
+
161
+ ## How it measures
162
+
163
+ - **tok/s** is decode speed. On llama.cpp it is the server's own `timings.predicted_per_second`, summed over all requests as total tokens / total decode time. Elsewhere it is measured on the client from the stream.
164
+ - **Accepted** is draft tokens the target kept divided by draft tokens proposed (`draft_n_accepted / draft_n`), or vLLM's spec-decode counters.
165
+ - **tok/J** is generated tokens divided by GPU energy, a trapezoid integral of `nvidia-smi` power readings taken every 200 ms during each request. Time spent cooling down between requests does not count.
166
+ - **VRAM GiB** is peak `memory.used` during the run minus the idle reading before the server started.
167
+ - **Same output** counts responses whose text hash matches the run without a draft. At temperature 0 a draft should not change the text in theory. In practice the target sees a batch of tokens during verification instead of one at a time, and the floating-point math changes enough to flip a token now and then. Once one token differs, the rest of the reply goes its own way.
168
+ - **N-gram runs start a fresh server for every scored request.** llama-server keeps one n-gram table for the life of the process, shared by every request. In the first sweep each prompt ran twice on one server, and the second pass found its own first answer in the table: the 7B ran edit_text at 1442 tok/s on the second pass against 277 on the first. Those files are in [`results/rtx3090-ngram-warm-table/`](results/rtx3090-ngram-warm-table/). In a long chat or agent session the table does carry over, so repeated content gets that boost for real. A benchmark of one request should not count it, so the sweep doesn't.
169
+
170
+ Hot cards: `--temp-cmd` reads memory temperature (for example a GDDR6X junction reader), `--abort-mem`/`--abort-core` stop the sweep and discard the run in progress, and `--cool-at 92 --cool-to 82` makes it wait before a request until the card cools down. A dense 32B pushed this RTX 3090's memory to 108 C within one 512-token request, which is why the 27B and 32B configs use 256 tokens.
171
+
172
+ ## Config
173
+
174
+ ```json
175
+ {
176
+ "name": "qwen25-32b",
177
+ "hardware": "rtx3090",
178
+ "backend": "llamacpp",
179
+ "targets": [{"label": "Qwen2.5-32B Q4_K_M", "path": "/models/Qwen2.5-32B-Instruct-Q4_K_M.gguf"}],
180
+ "drafts": [
181
+ {"label": "Qwen2.5-0.5B Q8_0", "path": "/models/Qwen2.5-0.5B-Instruct-Q8_0.gguf"},
182
+ {"label": "ngram-mod", "type": "ngram"}
183
+ ],
184
+ "settings": {"runs": 2, "max_tokens": 256, "prompts": "all", "extra_args": ["-fa", "on"]}
185
+ }
186
+ ```
187
+
188
+ `prompts` is `default` (draftbench's code, JSON and list prompts), `edit` (two prompts that hand back given text with a small change, where n-gram drafting does best) or `all`. Other settings: `llama_bin`, `port`, `ctx_size`, `temperature`, `extra_body`, `n_max` per draft, `ngram_cold`. More in [`examples/`](examples/).
189
+
190
+ ## Claude Code skill
191
+
192
+ [`.claude/skills/amagi-draftbench/SKILL.md`](.claude/skills/amagi-draftbench/SKILL.md) teaches Claude Code when to run a sweep, how to read the numbers and what not to claim from them.
193
+
194
+ ## Limits
195
+
196
+ - Results come from one RTX 3090, one llama.cpp build (11753) and Q4_K_M targets. Other cards, quants and builds will differ.
197
+ - The prompts are short, and each reply is 256 or 512 tokens long. Long-context work is not covered.
198
+ - Temperature 0 only. Sampling at higher temperatures lowers acceptance.
199
+ - Power and VRAM come from `nvidia-smi`, so NVIDIA only.
200
+
201
+ ## Star
202
+
203
+ If this saved you a guessing session, a star helps other people find it.
204
+
205
+ ## More from AmagiLabs
206
+
207
+ [amagi-tokbench](https://github.com/amagilabs/amagi-tokbench) measures how fast a local LLM server runs: generation and prompt tok/s, time to first token and peak VRAM. [github.com/amagilabs](https://github.com/amagilabs) has the other small open source dev tools from the same lab.
208
+
209
+ ## Credit
210
+
211
+ Based on draftbench by Alex Ziskind (MIT), github.com/alexziskind1/draftbench
212
+
213
+ The sweep loop, server launcher and config format started from draftbench. The reasoning-token fix, n-gram drafting, power and VRAM sampling, the per-prompt report, the recommendations and the tests are new. The `results/upstream/` files are draftbench's own published results, kept so `report` can read the old format.
214
+
215
+ ## License
216
+
217
+ MIT, see [LICENSE](LICENSE). Copyright (c) 2026 Alex, and Copyright (c) 2026 Amagisolutionsgroup, Inc. (AmagiLabs).
@@ -0,0 +1,197 @@
1
+ # amagi-draftbench
2
+
3
+ Find out which draft model, if any, makes your local LLM faster on your own GPU. amagi-draftbench starts llama-server (or vLLM, or any server you give it) once per target and draft pair, then measures decode tok/s, speedup, draft acceptance rate, tokens per joule and peak VRAM. It also tests n-gram drafting, which needs no draft model at all, and recommends a draft for each VRAM budget.
4
+
5
+ ![amagi-draftbench showing RTX 3090 results and a per-VRAM recommendation](https://raw.githubusercontent.com/amagilabs/amagi-draftbench/main/assets/demo.gif)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pipx install amagi-draftbench
11
+ ```
12
+
13
+ Not on PyPI yet. Until it is, install from a clone with `pipx install .` or `pip install .`
14
+
15
+ Python 3.9 or newer, no other dependencies. You also need a llama.cpp build with `llama-server` (or vLLM) and GGUF models.
16
+
17
+ ## Usage
18
+
19
+ Write a sweep config, run it, then read the results:
20
+
21
+ ```bash
22
+ amagi-draftbench init-config --target ~/models/Qwen2.5-32B-Instruct-Q4_K_M.gguf \
23
+ --draft ~/models/Qwen2.5-0.5B-Instruct-Q8_0.gguf --draft ~/models/Qwen2.5-1.5B-Instruct-Q4_K_M.gguf \
24
+ --ngram --hardware rtx3090 -o configs/q25-32b.json
25
+ amagi-draftbench sweep configs/q25-32b.json
26
+ amagi-draftbench report results/ --by-prompt
27
+ amagi-draftbench recommend results/
28
+ ```
29
+
30
+ `sweep` runs the target alone first, then once with each draft. Every run gets a fresh server, a warm-up request and the same prompts at temperature 0. Results land in `results/<hardware>_<backend>_<name>.json`. If a sweep stops partway, run it again and it carries on from where it stopped.
31
+
32
+ To benchmark one server you started yourself (upstream issue #2):
33
+
34
+ ```bash
35
+ llama-server -m target.gguf -md draft.gguf -ngl 99 -ngld 99 -np 1 --port 8081
36
+ amagi-draftbench bench --url http://127.0.0.1:8081
37
+ amagi-draftbench bench --url http://127.0.0.1:8081 --compare-url http://127.0.0.1:8080 # 8080 runs without a draft
38
+ ```
39
+
40
+ `find-server` shows which `llama-server` it will use and which draft features that build has:
41
+
42
+ ```
43
+ $ amagi-draftbench find-server ~/llama.cpp/build/bin/llama-server
44
+ ~/llama.cpp/build/bin/llama-server
45
+ --spec-type (n-gram drafting): yes
46
+ n-gram types: ngram-simple, ngram-map-k, ngram-map-k4v, ngram-mod, ngram-cache
47
+ draft size flag: --spec-draft-n-max
48
+ -np (slots): yes
49
+ ```
50
+
51
+ ## Results on an RTX 3090
52
+
53
+ One RTX 3090 (24 GB, power limit 300 W), llama.cpp build 11753 with flash attention, temperature 0, five prompts sent twice each. Replies are 512 tokens on the 7B and the Gemma MoE, and 256 tokens on the 27B and 32B (see the note on heat under [How it measures](#how-it-measures)). Qwen3.8 ran with thinking off. The raw files are in [`results/rtx3090/`](results/rtx3090/).
54
+
55
+ #### qwen25-32b (rtx3090, llamacpp)
56
+
57
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
58
+ |---|---|---|---|---|---|---|---|---|
59
+ | Qwen2.5-32B Q4_K_M | none (baseline) | 37.0 | 1.00x | - | 0.14 | 267 | 19.6 | - |
60
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-0.5B Q8_0 | 62.8 | 1.70x | 76% | 0.24 | 252 | 20.2 | 5/10 |
61
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q4_K_M | 62.4 | 1.69x | 85% | 0.24 | 249 | 20.7 | 5/10 |
62
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q8_0 | 60.9 | 1.65x | 87% | 0.23 | 255 | 21.3 | 5/10 |
63
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-3B Q4_K_M | 54.6 | 1.48x | 84% | 0.22 | 242 | 21.6 | 5/10 |
64
+ | Qwen2.5-32B Q4_K_M | ngram-mod | 43.7 | 1.18x | 70% | 0.16 | 272 | 19.6 | 10/10 |
65
+
66
+ #### qwen25-7b (rtx3090, llamacpp)
67
+
68
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
69
+ |---|---|---|---|---|---|---|---|---|
70
+ | Qwen2.5-7B Q4_K_M | none (baseline) | 140.8 | 1.00x | - | 0.51 | 273 | 4.7 | - |
71
+ | Qwen2.5-7B Q4_K_M | Qwen2.5-0.5B Q8_0 | 170.2 | 1.21x | 80% | 0.59 | 282 | 5.3 | 10/10 |
72
+ | Qwen2.5-7B Q4_K_M | Qwen2.5-1.5B Q4_K_M | 153.2 | 1.09x | 90% | 0.57 | 265 | 5.8 | 10/10 |
73
+ | Qwen2.5-7B Q4_K_M | ngram-mod | 156.2 | 1.11x | 35% | 0.65 | 239 | 4.7 | 10/10 |
74
+
75
+ #### qwen38-27b (rtx3090, llamacpp)
76
+
77
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
78
+ |---|---|---|---|---|---|---|---|---|
79
+ | Qwen3.8-27B Q4_K_M | none (baseline) | 42.1 | 1.00x | - | 0.15 | 263 | 15.6 | - |
80
+ | Qwen3.8-27B Q4_K_M | Qwen3.5-0.8B Q8_0 | 44.6 | 1.06x | 88% | 0.18 | 239 | 16.5 | 6/10 |
81
+ | Qwen3.8-27B Q4_K_M | Qwen3.5-2B Q4_K_M | 44.2 | 1.05x | 89% | 0.17 | 241 | 16.9 | 8/10 |
82
+ | Qwen3.8-27B Q4_K_M | ngram-mod | 49.6 | 1.18x | 63% | 0.18 | 266 | 15.6 | 10/10 |
83
+
84
+ #### gemma4-26b-a4b (rtx3090, llamacpp)
85
+
86
+ | Target | Draft | tok/s | Speedup | Accepted | tok/J | Watts | VRAM GiB | Same output |
87
+ |---|---|---|---|---|---|---|---|---|
88
+ | Gemma-4-26B-A4B Q4_K_M | none (baseline) | 122.3 | 1.00x | - | 0.42 | 282 | 16.6 | - |
89
+ | Gemma-4-26B-A4B Q4_K_M | Gemma-4-E2B Q4_K_M | 92.2 | 0.75x | 71% | 0.34 | 262 | 18.2 | 1/10 |
90
+ | Gemma-4-26B-A4B Q4_K_M | ngram-mod | 122.9 | 1.00x | 35% | 0.45 | 266 | 16.6 | 8/10 |
91
+
92
+ **A draft model gave a 50-80% speedup on this 3090 only for the dense 32B.**
93
+
94
+ - **Qwen2.5-32B Q4_K_M:** a Qwen2.5-0.5B Q8_0 draft took it from 37.0 to 62.8 tok/s (1.70x), and 1.5B Q4_K_M did 1.69x. The 3B draft got a similar share of tokens accepted but costs more to run, so it landed at 1.48x. Energy per token improved along with speed, from 0.14 to 0.24 tok/J.
95
+ - **Qwen2.5-7B Q4_K_M:** the same 0.5B draft gave 1.21x. The 7B already runs at 141 tok/s on its own, and the draft's own cost is a bigger share of each step.
96
+ - **Qwen3.8-27B Q4_K_M with Qwen3.5 drafts:** 1.05x to 1.06x, even though 88-89% of draft tokens were accepted. A separate single request showed the same thing: the server reported 85% acceptance and 3.5 tokens per draft step, and decode stayed at 42.4 tok/s against 42.2 without the draft. I have not found the cause.
97
+ - **Gemma-4-26B-A4B (MoE):** the Gemma-4-E2B draft made it slower, 122.3 down to 92.2 tok/s (0.75x). This MoE only reads about 4B parameters per token, so it is already fast, and running the draft costs more than it saves.
98
+ - **n-gram drafting** (`ngram-mod`, no draft model, no extra VRAM) gave 1.11x to 1.18x on the Qwen targets and 1.00x on Gemma. All of the gain came from the two edit prompts, where the reply copies most of the prompt: 1.5x to 2.0x there, and 1.0x on fresh code, JSON and lists.
99
+
100
+ The per-prompt view for the 32B shows which kinds of reply each draft speeds up:
101
+
102
+ #### qwen25-32b: tok/s per prompt
103
+
104
+ | Target | Draft | code | json | list | edit_code | edit_text |
105
+ |---|---|---|---|---|---|---|
106
+ | Qwen2.5-32B Q4_K_M | none (baseline) | 37 | 37 | 37 | 37 | 37 |
107
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-0.5B Q8_0 | 66 (1.8x) | 71 (1.9x) | 45 (1.2x) | 71 (1.9x) | 74 (2.0x) |
108
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q4_K_M | 63 (1.7x) | 65 (1.8x) | 53 (1.4x) | 64 (1.7x) | 70 (1.9x) |
109
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-1.5B Q8_0 | 64 (1.7x) | 63 (1.7x) | 51 (1.4x) | 62 (1.7x) | 67 (1.8x) |
110
+ | Qwen2.5-32B Q4_K_M | Qwen2.5-3B Q4_K_M | 55 (1.5x) | 56 (1.5x) | 48 (1.3x) | 57 (1.6x) | 60 (1.6x) |
111
+ | Qwen2.5-32B Q4_K_M | ngram-mod | 37 (1.0x) | 37 (1.0x) | 37 (1.0x) | 58 (1.6x) | 73 (2.0x) |
112
+
113
+ `recommend` turns the same files into a pick per card size (24 GB shown):
114
+
115
+ ```
116
+ $ amagi-draftbench recommend results/rtx3090 --budgets 24
117
+ 24 GB card:
118
+ Qwen2.5-32B Q4_K_M: draft Qwen2.5-0.5B Q8_0 -> 62.8 tok/s (1.70x vs 37.0 plain, 76% accepted), 20.2 GiB
119
+ Qwen2.5-7B Q4_K_M: draft Qwen2.5-0.5B Q8_0 -> 170.2 tok/s (1.21x vs 140.8 plain, 80% accepted), 5.3 GiB
120
+ Qwen3.8-27B Q4_K_M: draft ngram-mod -> 49.6 tok/s (1.18x vs 42.1 plain, 63% accepted), 15.6 GiB
121
+ best draft model: Qwen3.5-0.8B Q8_0 -> 44.6 tok/s (1.06x vs 42.1 plain, 88% accepted), 16.5 GiB
122
+ Gemma-4-26B-A4B Q4_K_M: skip drafts (122.3 tok/s, 16.6 GiB) -- no draft that fits is at least 5% faster; run it plain
123
+
124
+ n-gram drafting only pays off when the reply repeats text from the prompt (edits, refactors). Check 'report --by-prompt' before relying on it.
125
+ ```
126
+
127
+ ## FAQ: the six open draftbench issues
128
+
129
+ **#1, GGUF vs MLX.** amagi-draftbench has a `command` backend that runs any server from a shell line, so `mlx_lm.server --draft-model` works through it ([`examples/mlx_command.json`](examples/mlx_command.json)). I have no Apple Silicon results, so there is no GGUF vs MLX comparison here yet.
130
+
131
+ **#2, how do I run a single benchmark?** `amagi-draftbench bench --url ...` against a server you started. See [Usage](#usage).
132
+
133
+ **#3, TPS shows 0.0.** Thinking models (Qwen3, DeepSeek-R1, gpt-oss) stream their reasoning in `delta.reasoning_content`, not `delta.content`. draftbench only counted `content`, so a reply that spent its whole token budget thinking never produced a "first token" and scored 0. Both fields count now. To turn thinking off, add `"extra_body": {"chat_template_kwargs": {"enable_thinking": false}}` to a config, or pass `--no-think` to `bench`.
134
+
135
+ **#4, llama-server autodetection.** Searches PATH (the approach from PR #4 by alxarch), then the usual build folders, including Windows `build/bin/Release/llama-server.exe`. Set `llama_bin` in the config to skip the search.
136
+
137
+ **#5, 400 Bad Request.** draftbench threw the server's error message away, so all you saw was "400". amagi-draftbench prints the message the server sent. It also starts llama-server with one slot (`-np 1`) and a context sized to fit the longest prompt plus `max_tokens`. Recent builds default to several slots that split the context, and a request that does not fit gets a 400. I could not reproduce the 400 with draftbench's own flags on llama.cpp build 11753: all four slots got the full 4096 tokens (unified KV cache) and every request returned 200. Older builds may still behave as the issue describes.
138
+
139
+ **#6, vLLM.** Current vLLM dropped `--speculative-model` in favor of `--speculative-config`. The `vllm` backend uses the new flag for both draft models and n-gram drafting, and reads acceptance from vLLM's `/metrics` counters ([`examples/vllm_qwen3.json`](examples/vllm_qwen3.json)). I have no vLLM results yet; the commands above come from `sweep --dry-run`.
140
+
141
+ ## How it measures
142
+
143
+ - **tok/s** is decode speed. On llama.cpp it is the server's own `timings.predicted_per_second`, summed over all requests as total tokens / total decode time. Elsewhere it is measured on the client from the stream.
144
+ - **Accepted** is draft tokens the target kept divided by draft tokens proposed (`draft_n_accepted / draft_n`), or vLLM's spec-decode counters.
145
+ - **tok/J** is generated tokens divided by GPU energy, a trapezoid integral of `nvidia-smi` power readings taken every 200 ms during each request. Time spent cooling down between requests does not count.
146
+ - **VRAM GiB** is peak `memory.used` during the run minus the idle reading before the server started.
147
+ - **Same output** counts responses whose text hash matches the run without a draft. At temperature 0 a draft should not change the text in theory. In practice the target sees a batch of tokens during verification instead of one at a time, and the floating-point math changes enough to flip a token now and then. Once one token differs, the rest of the reply goes its own way.
148
+ - **N-gram runs start a fresh server for every scored request.** llama-server keeps one n-gram table for the life of the process, shared by every request. In the first sweep each prompt ran twice on one server, and the second pass found its own first answer in the table: the 7B ran edit_text at 1442 tok/s on the second pass against 277 on the first. Those files are in [`results/rtx3090-ngram-warm-table/`](results/rtx3090-ngram-warm-table/). In a long chat or agent session the table does carry over, so repeated content gets that boost for real. A benchmark of one request should not count it, so the sweep doesn't.
149
+
150
+ Hot cards: `--temp-cmd` reads memory temperature (for example a GDDR6X junction reader), `--abort-mem`/`--abort-core` stop the sweep and discard the run in progress, and `--cool-at 92 --cool-to 82` makes it wait before a request until the card cools down. A dense 32B pushed this RTX 3090's memory to 108 C within one 512-token request, which is why the 27B and 32B configs use 256 tokens.
151
+
152
+ ## Config
153
+
154
+ ```json
155
+ {
156
+ "name": "qwen25-32b",
157
+ "hardware": "rtx3090",
158
+ "backend": "llamacpp",
159
+ "targets": [{"label": "Qwen2.5-32B Q4_K_M", "path": "/models/Qwen2.5-32B-Instruct-Q4_K_M.gguf"}],
160
+ "drafts": [
161
+ {"label": "Qwen2.5-0.5B Q8_0", "path": "/models/Qwen2.5-0.5B-Instruct-Q8_0.gguf"},
162
+ {"label": "ngram-mod", "type": "ngram"}
163
+ ],
164
+ "settings": {"runs": 2, "max_tokens": 256, "prompts": "all", "extra_args": ["-fa", "on"]}
165
+ }
166
+ ```
167
+
168
+ `prompts` is `default` (draftbench's code, JSON and list prompts), `edit` (two prompts that hand back given text with a small change, where n-gram drafting does best) or `all`. Other settings: `llama_bin`, `port`, `ctx_size`, `temperature`, `extra_body`, `n_max` per draft, `ngram_cold`. More in [`examples/`](examples/).
169
+
170
+ ## Claude Code skill
171
+
172
+ [`.claude/skills/amagi-draftbench/SKILL.md`](.claude/skills/amagi-draftbench/SKILL.md) teaches Claude Code when to run a sweep, how to read the numbers and what not to claim from them.
173
+
174
+ ## Limits
175
+
176
+ - Results come from one RTX 3090, one llama.cpp build (11753) and Q4_K_M targets. Other cards, quants and builds will differ.
177
+ - The prompts are short, and each reply is 256 or 512 tokens long. Long-context work is not covered.
178
+ - Temperature 0 only. Sampling at higher temperatures lowers acceptance.
179
+ - Power and VRAM come from `nvidia-smi`, so NVIDIA only.
180
+
181
+ ## Star
182
+
183
+ If this saved you a guessing session, a star helps other people find it.
184
+
185
+ ## More from AmagiLabs
186
+
187
+ [amagi-tokbench](https://github.com/amagilabs/amagi-tokbench) measures how fast a local LLM server runs: generation and prompt tok/s, time to first token and peak VRAM. [github.com/amagilabs](https://github.com/amagilabs) has the other small open source dev tools from the same lab.
188
+
189
+ ## Credit
190
+
191
+ Based on draftbench by Alex Ziskind (MIT), github.com/alexziskind1/draftbench
192
+
193
+ The sweep loop, server launcher and config format started from draftbench. The reasoning-token fix, n-gram drafting, power and VRAM sampling, the per-prompt report, the recommendations and the tests are new. The `results/upstream/` files are draftbench's own published results, kept so `report` can read the old format.
194
+
195
+ ## License
196
+
197
+ MIT, see [LICENSE](LICENSE). Copyright (c) 2026 Alex, and Copyright (c) 2026 Amagisolutionsgroup, Inc. (AmagiLabs).
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "amagi-draftbench"
7
+ version = "0.1.0"
8
+ description = "Find the draft model (or n-gram lookup) that speeds up your local LLM: speculative-decoding sweeps for llama.cpp and vLLM with tok/s, acceptance rate, tokens per joule and peak VRAM, plus a pick per VRAM budget."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "AmagiLabs (Amagisolutionsgroup, Inc.)", email = "dev@amagisolutionsgroup.com" }]
13
+ requires-python = ">=3.9"
14
+ dependencies = []
15
+ keywords = ["llm", "speculative-decoding", "draft-model", "llama.cpp", "vllm", "benchmark", "gpu", "localllama", "cli"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Operating System :: OS Independent",
19
+ "Environment :: Console",
20
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
21
+ "Topic :: System :: Benchmark",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/amagilabs/amagi-draftbench"
26
+
27
+ [project.scripts]
28
+ amagi-draftbench = "amagi_draftbench.cli:main"
29
+
30
+ [project.optional-dependencies]
31
+ dev = ["pytest>=7.0"]
32
+
33
+ [tool.setuptools.packages.find]
34
+ where = ["src"]
35
+
36
+ [tool.pytest.ini_options]
37
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ """amagi-draftbench: find the draft model (or n-gram lookup) that actually speeds up your local LLM.
2
+
3
+ Fork of draftbench by Alex Ziskind (MIT), github.com/alexziskind1/draftbench.
4
+ """
5
+
6
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())