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,661 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import shlex
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Annotated, Optional
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
from rich.table import Table
|
|
10
|
+
|
|
11
|
+
from speculation_benchmark import PACKAGE_NAME, __version__
|
|
12
|
+
from speculation_benchmark.config import (
|
|
13
|
+
DEFAULT_DRAFT_TOKENS,
|
|
14
|
+
DRAFT_TOKEN_PRESETS,
|
|
15
|
+
BenchmarkConfig,
|
|
16
|
+
GenerationConfig,
|
|
17
|
+
ModelSpec,
|
|
18
|
+
OutputConfig,
|
|
19
|
+
ServerConfig,
|
|
20
|
+
SuiteSpec,
|
|
21
|
+
resolve_draft_tokens,
|
|
22
|
+
)
|
|
23
|
+
from speculation_benchmark.hf_jobs import (
|
|
24
|
+
DEFAULT_HF_JOBS_FLAVOR,
|
|
25
|
+
DEFAULT_HF_JOBS_IMAGE,
|
|
26
|
+
DEFAULT_HF_JOBS_TIMEOUT,
|
|
27
|
+
DEFAULT_REMOTE_LLAMA_CMD,
|
|
28
|
+
HFJobOptions,
|
|
29
|
+
submit_hf_job,
|
|
30
|
+
)
|
|
31
|
+
from speculation_benchmark.runner import run_benchmark
|
|
32
|
+
from speculation_benchmark.suites.loaders import SUITE_PRESETS, load_suite
|
|
33
|
+
from speculation_benchmark.visualize import generate_visualizations, load_summary_rows
|
|
34
|
+
|
|
35
|
+
app = typer.Typer(
|
|
36
|
+
name="specbench",
|
|
37
|
+
help="Benchmark llama.cpp speculative decoding token acceptance rates across draft lengths and capabilities.",
|
|
38
|
+
no_args_is_help=True,
|
|
39
|
+
)
|
|
40
|
+
console = Console()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _version_callback(value: bool) -> None:
|
|
44
|
+
if value:
|
|
45
|
+
typer.echo(f"{PACKAGE_NAME} {__version__}")
|
|
46
|
+
raise typer.Exit()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@app.callback()
|
|
50
|
+
def main(
|
|
51
|
+
version: Annotated[
|
|
52
|
+
Optional[bool],
|
|
53
|
+
typer.Option(
|
|
54
|
+
"--version",
|
|
55
|
+
"-V",
|
|
56
|
+
callback=_version_callback,
|
|
57
|
+
is_eager=True,
|
|
58
|
+
help="Show package version and exit.",
|
|
59
|
+
),
|
|
60
|
+
] = None,
|
|
61
|
+
) -> None:
|
|
62
|
+
"""Speculative decoding benchmark CLI for llama.cpp."""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _parse_draft_tokens(raw: str) -> list[int]:
|
|
66
|
+
try:
|
|
67
|
+
values = resolve_draft_tokens(raw)
|
|
68
|
+
except ValueError as exc:
|
|
69
|
+
presets = ", ".join(DRAFT_TOKEN_PRESETS)
|
|
70
|
+
raise typer.BadParameter(
|
|
71
|
+
f"Expected a preset ({presets}) or comma-separated integers, e.g. '0,4,8,12'."
|
|
72
|
+
) from exc
|
|
73
|
+
if not values:
|
|
74
|
+
raise typer.BadParameter("Expected at least one draft token count.")
|
|
75
|
+
return values
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def parse_suite_specs(raw_items: list[str], limit: int = 20) -> list[SuiteSpec]:
|
|
79
|
+
"""Parse `--suite` entries like `coding`, `coding,multimodal`, or `coding=path/to/file.jsonl`."""
|
|
80
|
+
specs: list[SuiteSpec] = []
|
|
81
|
+
for item in raw_items:
|
|
82
|
+
for token in item.split(","):
|
|
83
|
+
token = token.strip()
|
|
84
|
+
if not token:
|
|
85
|
+
continue
|
|
86
|
+
if "=" in token:
|
|
87
|
+
capability, source = token.split("=", 1)
|
|
88
|
+
capability = capability.strip()
|
|
89
|
+
source = source.strip()
|
|
90
|
+
else:
|
|
91
|
+
capability = token
|
|
92
|
+
source = f"preset:{capability.replace('_', '-')}"
|
|
93
|
+
if not capability or not source:
|
|
94
|
+
raise typer.BadParameter(
|
|
95
|
+
f"Invalid --suite entry {token!r}. Use '<capability>' or '<capability>=<source>'."
|
|
96
|
+
)
|
|
97
|
+
specs.append(SuiteSpec(capability=capability, source=source, limit=limit))
|
|
98
|
+
if not specs:
|
|
99
|
+
raise typer.BadParameter("At least one suite must be specified.")
|
|
100
|
+
return specs
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _build_benchmark_config(
|
|
104
|
+
*,
|
|
105
|
+
config_file: Optional[Path],
|
|
106
|
+
model_repo: Optional[str],
|
|
107
|
+
speculator_repo: Optional[str],
|
|
108
|
+
speculator_file: Optional[str],
|
|
109
|
+
spec_type: Optional[str],
|
|
110
|
+
model_quant: Optional[str],
|
|
111
|
+
speculator_quant: Optional[str],
|
|
112
|
+
no_mmproj: bool,
|
|
113
|
+
draft_tokens: Optional[str],
|
|
114
|
+
suite: Optional[list[str]],
|
|
115
|
+
limit: Optional[int],
|
|
116
|
+
max_tokens: Optional[int],
|
|
117
|
+
temperature: Optional[float],
|
|
118
|
+
hf_dataset: Optional[str],
|
|
119
|
+
output_dir: Optional[Path],
|
|
120
|
+
private: bool,
|
|
121
|
+
overwrite: bool,
|
|
122
|
+
dry_run: bool,
|
|
123
|
+
llama_cmd: Optional[str],
|
|
124
|
+
port: Optional[int],
|
|
125
|
+
ctx_size: Optional[int],
|
|
126
|
+
llama_arg: Optional[list[str]],
|
|
127
|
+
run_id: Optional[str],
|
|
128
|
+
) -> BenchmarkConfig:
|
|
129
|
+
if config_file is not None:
|
|
130
|
+
cfg = BenchmarkConfig.from_yaml(config_file)
|
|
131
|
+
else:
|
|
132
|
+
if not model_repo:
|
|
133
|
+
raise typer.BadParameter("Provide either --config or --model-repo.")
|
|
134
|
+
suites = parse_suite_specs(suite or ["coding", "multimodal"], limit=limit or 20)
|
|
135
|
+
cfg = BenchmarkConfig(
|
|
136
|
+
model=ModelSpec(
|
|
137
|
+
model_repo=model_repo,
|
|
138
|
+
speculator_repo=speculator_repo,
|
|
139
|
+
speculator_file=speculator_file,
|
|
140
|
+
spec_type=spec_type,
|
|
141
|
+
model_quant=model_quant,
|
|
142
|
+
speculator_quant=speculator_quant,
|
|
143
|
+
no_mmproj=no_mmproj,
|
|
144
|
+
),
|
|
145
|
+
draft_tokens=_parse_draft_tokens(draft_tokens) if draft_tokens else list(DEFAULT_DRAFT_TOKENS),
|
|
146
|
+
suites=suites,
|
|
147
|
+
server=ServerConfig(),
|
|
148
|
+
generation=GenerationConfig(),
|
|
149
|
+
output=OutputConfig(),
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
if model_repo is not None:
|
|
153
|
+
cfg.model.model_repo = model_repo
|
|
154
|
+
if speculator_repo is not None:
|
|
155
|
+
cfg.model.speculator_repo = speculator_repo
|
|
156
|
+
if speculator_file is not None:
|
|
157
|
+
cfg.model.speculator_file = speculator_file
|
|
158
|
+
if spec_type is not None:
|
|
159
|
+
cfg.model.spec_type = spec_type
|
|
160
|
+
if model_quant is not None:
|
|
161
|
+
cfg.model.model_quant = model_quant
|
|
162
|
+
if speculator_quant is not None:
|
|
163
|
+
cfg.model.speculator_quant = speculator_quant
|
|
164
|
+
if no_mmproj:
|
|
165
|
+
cfg.model.no_mmproj = True
|
|
166
|
+
if draft_tokens is not None:
|
|
167
|
+
cfg.draft_tokens = _parse_draft_tokens(draft_tokens)
|
|
168
|
+
if suite is not None and config_file is not None:
|
|
169
|
+
cfg.suites = parse_suite_specs(suite, limit=limit or 20)
|
|
170
|
+
if limit is not None:
|
|
171
|
+
for s in cfg.suites:
|
|
172
|
+
s.limit = limit
|
|
173
|
+
if max_tokens is not None:
|
|
174
|
+
cfg.generation.max_tokens = max_tokens
|
|
175
|
+
if temperature is not None:
|
|
176
|
+
cfg.generation.temperature = temperature
|
|
177
|
+
if hf_dataset is not None:
|
|
178
|
+
cfg.output.hf_dataset_repo = hf_dataset
|
|
179
|
+
if output_dir is not None:
|
|
180
|
+
cfg.output.output_dir = output_dir
|
|
181
|
+
if private:
|
|
182
|
+
cfg.output.private = True
|
|
183
|
+
if overwrite:
|
|
184
|
+
cfg.output.append = False
|
|
185
|
+
if dry_run:
|
|
186
|
+
cfg.output.dry_run = True
|
|
187
|
+
if llama_cmd is not None:
|
|
188
|
+
cfg.server.llama_cmd = shlex.split(llama_cmd)
|
|
189
|
+
if port is not None:
|
|
190
|
+
cfg.server.port = port
|
|
191
|
+
if ctx_size is not None:
|
|
192
|
+
cfg.server.ctx_size = ctx_size
|
|
193
|
+
if llama_arg:
|
|
194
|
+
cfg.server.extra_args.extend(llama_arg)
|
|
195
|
+
if run_id is not None:
|
|
196
|
+
cfg.run_id = run_id
|
|
197
|
+
|
|
198
|
+
return cfg
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@app.command("run")
|
|
202
|
+
def run_cmd(
|
|
203
|
+
config_file: Annotated[
|
|
204
|
+
Optional[Path],
|
|
205
|
+
typer.Option("--config", "-c", help="Path to a YAML BenchmarkConfig file (CLI flags override file values)."),
|
|
206
|
+
] = None,
|
|
207
|
+
model_repo: Annotated[
|
|
208
|
+
Optional[str],
|
|
209
|
+
typer.Option("--model-repo", "-m", help="Target model HF repo[:quant], e.g. meta-models/Muse-Glimmer-30B-GGUF:Q4_K_M."),
|
|
210
|
+
] = None,
|
|
211
|
+
speculator_repo: Annotated[
|
|
212
|
+
Optional[str],
|
|
213
|
+
typer.Option("--speculator-repo", "-s", help="Optional separate HF repo[:quant] for the speculator. Omit if in the main model repo."),
|
|
214
|
+
] = None,
|
|
215
|
+
speculator_file: Annotated[
|
|
216
|
+
Optional[str],
|
|
217
|
+
typer.Option("--speculator-file", help="Optional draft GGUF filename (defaults to main model repo if --speculator-repo is omitted)."),
|
|
218
|
+
] = None,
|
|
219
|
+
spec_type: Annotated[
|
|
220
|
+
Optional[str],
|
|
221
|
+
typer.Option("--spec-type", help="llama.cpp --spec-type (draft-mtp, draft-simple, draft-eagle3, draft-dflash, ngram-mod, ...)."),
|
|
222
|
+
] = None,
|
|
223
|
+
model_quant: Annotated[
|
|
224
|
+
Optional[str],
|
|
225
|
+
typer.Option("--model-quant", help="Optional target quant label override (auto-inferred from ':quant')."),
|
|
226
|
+
] = None,
|
|
227
|
+
speculator_quant: Annotated[
|
|
228
|
+
Optional[str],
|
|
229
|
+
typer.Option(
|
|
230
|
+
"--speculator-quant",
|
|
231
|
+
help="Optional speculator quant label override (auto-detected from the speculator loaded for --spec-type by default).",
|
|
232
|
+
),
|
|
233
|
+
] = None,
|
|
234
|
+
no_mmproj: Annotated[
|
|
235
|
+
bool,
|
|
236
|
+
typer.Option("--no-mmproj", help="Pass --no-mmproj to llama serve (skip vision encoder for text-only runs)."),
|
|
237
|
+
] = False,
|
|
238
|
+
draft_tokens: Annotated[
|
|
239
|
+
Optional[str],
|
|
240
|
+
typer.Option(
|
|
241
|
+
"--draft-tokens",
|
|
242
|
+
help="Preset ('default'=[0,4,8,12], 'spec-only'=[4,8,12], 'fine') or comma-separated ints.",
|
|
243
|
+
),
|
|
244
|
+
] = None,
|
|
245
|
+
suite: Annotated[
|
|
246
|
+
Optional[list[str]],
|
|
247
|
+
typer.Option(
|
|
248
|
+
"--suite",
|
|
249
|
+
help="Suite(s) to run: '<capability>' or '<capability>=<source>' (repeatable or comma-separated; default: coding,multimodal).",
|
|
250
|
+
),
|
|
251
|
+
] = None,
|
|
252
|
+
limit: Annotated[
|
|
253
|
+
Optional[int],
|
|
254
|
+
typer.Option("--limit", help="Max samples per suite (default: 20)."),
|
|
255
|
+
] = None,
|
|
256
|
+
max_tokens: Annotated[
|
|
257
|
+
Optional[int],
|
|
258
|
+
typer.Option("--max-tokens", help="Max generated tokens per prompt (default: 512)."),
|
|
259
|
+
] = None,
|
|
260
|
+
temperature: Annotated[
|
|
261
|
+
Optional[float],
|
|
262
|
+
typer.Option("--temperature", help="Sampling temperature (default: 0.0)."),
|
|
263
|
+
] = None,
|
|
264
|
+
hf_dataset: Annotated[
|
|
265
|
+
Optional[str],
|
|
266
|
+
typer.Option("--hf-dataset", help="Target HF dataset repo ID (default: merve/drafter-bench)."),
|
|
267
|
+
] = None,
|
|
268
|
+
output_dir: Annotated[
|
|
269
|
+
Optional[Path],
|
|
270
|
+
typer.Option("--output-dir", help="Local directory for checkpoints, logs, and Parquet outputs."),
|
|
271
|
+
] = None,
|
|
272
|
+
private: Annotated[
|
|
273
|
+
bool,
|
|
274
|
+
typer.Option("--private", help="Create/push the HF dataset repo as private."),
|
|
275
|
+
] = False,
|
|
276
|
+
overwrite: Annotated[
|
|
277
|
+
bool,
|
|
278
|
+
typer.Option("--overwrite", help="Replace existing rows on HF Hub instead of appending."),
|
|
279
|
+
] = False,
|
|
280
|
+
dry_run: Annotated[
|
|
281
|
+
bool,
|
|
282
|
+
typer.Option("--dry-run", help="Save Parquet/JSON locally without pushing to Hugging Face Hub."),
|
|
283
|
+
] = False,
|
|
284
|
+
llama_cmd: Annotated[
|
|
285
|
+
Optional[str],
|
|
286
|
+
typer.Option("--llama-cmd", help="Server launch command (default: 'llama serve')."),
|
|
287
|
+
] = None,
|
|
288
|
+
port: Annotated[
|
|
289
|
+
Optional[int],
|
|
290
|
+
typer.Option("--port", help="Local port for llama serve (0 = auto-select free port)."),
|
|
291
|
+
] = None,
|
|
292
|
+
ctx_size: Annotated[
|
|
293
|
+
Optional[int],
|
|
294
|
+
typer.Option("--ctx-size", help="Context size passed to --ctx-size (default: 8192)."),
|
|
295
|
+
] = None,
|
|
296
|
+
llama_arg: Annotated[
|
|
297
|
+
Optional[list[str]],
|
|
298
|
+
typer.Option("--llama-arg", help="Extra raw argument passed to llama serve (repeatable)."),
|
|
299
|
+
] = None,
|
|
300
|
+
run_id: Annotated[
|
|
301
|
+
Optional[str],
|
|
302
|
+
typer.Option("--run-id", help="Optional custom run_id recorded in the dataset."),
|
|
303
|
+
] = None,
|
|
304
|
+
) -> None:
|
|
305
|
+
"""Run a speculative decoding acceptance-rate sweep on local llama.cpp."""
|
|
306
|
+
cfg = _build_benchmark_config(
|
|
307
|
+
config_file=config_file,
|
|
308
|
+
model_repo=model_repo,
|
|
309
|
+
speculator_repo=speculator_repo,
|
|
310
|
+
speculator_file=speculator_file,
|
|
311
|
+
spec_type=spec_type,
|
|
312
|
+
model_quant=model_quant,
|
|
313
|
+
speculator_quant=speculator_quant,
|
|
314
|
+
no_mmproj=no_mmproj,
|
|
315
|
+
draft_tokens=draft_tokens,
|
|
316
|
+
suite=suite,
|
|
317
|
+
limit=limit,
|
|
318
|
+
max_tokens=max_tokens,
|
|
319
|
+
temperature=temperature,
|
|
320
|
+
hf_dataset=hf_dataset,
|
|
321
|
+
output_dir=output_dir,
|
|
322
|
+
private=private,
|
|
323
|
+
overwrite=overwrite,
|
|
324
|
+
dry_run=dry_run,
|
|
325
|
+
llama_cmd=llama_cmd,
|
|
326
|
+
port=port,
|
|
327
|
+
ctx_size=ctx_size,
|
|
328
|
+
llama_arg=llama_arg,
|
|
329
|
+
run_id=run_id,
|
|
330
|
+
)
|
|
331
|
+
run_benchmark(cfg, console=console)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
@app.command("hf-job")
|
|
335
|
+
def hf_job_cmd(
|
|
336
|
+
flavor: Annotated[
|
|
337
|
+
str,
|
|
338
|
+
typer.Option(
|
|
339
|
+
"--flavor",
|
|
340
|
+
help="HF Jobs hardware flavor (run `hf jobs hardware` to list; e.g. l4x1, a10g-large, l40sx1, a100-large, h200).",
|
|
341
|
+
),
|
|
342
|
+
] = DEFAULT_HF_JOBS_FLAVOR,
|
|
343
|
+
timeout: Annotated[
|
|
344
|
+
str,
|
|
345
|
+
typer.Option("--timeout", help="Max Job duration, e.g. '30m', '2h', '4h'."),
|
|
346
|
+
] = DEFAULT_HF_JOBS_TIMEOUT,
|
|
347
|
+
image: Annotated[
|
|
348
|
+
str,
|
|
349
|
+
typer.Option("--image", help="Docker image with CUDA llama-server (default: ghcr.io/ggml-org/llama.cpp:server-cuda)."),
|
|
350
|
+
] = DEFAULT_HF_JOBS_IMAGE,
|
|
351
|
+
remote_llama_cmd: Annotated[
|
|
352
|
+
str,
|
|
353
|
+
typer.Option("--remote-llama-cmd", help="llama-server executable path inside the Job image."),
|
|
354
|
+
] = DEFAULT_REMOTE_LLAMA_CMD,
|
|
355
|
+
package_source: Annotated[
|
|
356
|
+
Optional[str],
|
|
357
|
+
typer.Option(
|
|
358
|
+
"--package-source",
|
|
359
|
+
help="Optional Git URL or PyPI package for `uvx --from` (omit to auto-bundle the local repo).",
|
|
360
|
+
),
|
|
361
|
+
] = None,
|
|
362
|
+
detach: Annotated[
|
|
363
|
+
bool,
|
|
364
|
+
typer.Option("--detach", "-d", help="Submit the Job in the background and print its ID/URL immediately."),
|
|
365
|
+
] = False,
|
|
366
|
+
namespace: Annotated[
|
|
367
|
+
Optional[str],
|
|
368
|
+
typer.Option("--namespace", help="HF user/org namespace to bill and run the Job under."),
|
|
369
|
+
] = None,
|
|
370
|
+
volume: Annotated[
|
|
371
|
+
Optional[list[str]],
|
|
372
|
+
typer.Option("--volume", "-v", help="Mount HF repo/bucket volume, e.g. 'hf://buckets/user/bench:/artifacts' (repeatable)."),
|
|
373
|
+
] = None,
|
|
374
|
+
env: Annotated[
|
|
375
|
+
Optional[list[str]],
|
|
376
|
+
typer.Option("--env", "-e", help="Extra KEY=VALUE environment variable for the Job (repeatable)."),
|
|
377
|
+
] = None,
|
|
378
|
+
label: Annotated[
|
|
379
|
+
Optional[list[str]],
|
|
380
|
+
typer.Option("--label", "-l", help="Extra KEY=VALUE label for `hf jobs ps` filtering (repeatable)."),
|
|
381
|
+
] = None,
|
|
382
|
+
plot_dir: Annotated[
|
|
383
|
+
Optional[str],
|
|
384
|
+
typer.Option("--plot-dir", help="Optional container path (inside a mounted bucket volume) to also save dark-theme charts."),
|
|
385
|
+
] = None,
|
|
386
|
+
print_command: Annotated[
|
|
387
|
+
bool,
|
|
388
|
+
typer.Option("--print-command", help="Print the `hf jobs run` command and exit without launching a Job."),
|
|
389
|
+
] = False,
|
|
390
|
+
allow_dry_run: Annotated[
|
|
391
|
+
bool,
|
|
392
|
+
typer.Option("--allow-dry-run", help="Allow --dry-run inside an ephemeral HF Job container."),
|
|
393
|
+
] = False,
|
|
394
|
+
config_file: Annotated[
|
|
395
|
+
Optional[Path],
|
|
396
|
+
typer.Option("--config", "-c", help="Path to a YAML BenchmarkConfig file (CLI flags override file values)."),
|
|
397
|
+
] = None,
|
|
398
|
+
model_repo: Annotated[
|
|
399
|
+
Optional[str],
|
|
400
|
+
typer.Option("--model-repo", "-m", help="Target model HF repo[:quant], e.g. meta-models/Muse-Glimmer-30B-GGUF:Q4_K_M."),
|
|
401
|
+
] = None,
|
|
402
|
+
speculator_repo: Annotated[
|
|
403
|
+
Optional[str],
|
|
404
|
+
typer.Option("--speculator-repo", "-s", help="Optional separate HF repo[:quant] for the speculator."),
|
|
405
|
+
] = None,
|
|
406
|
+
speculator_file: Annotated[
|
|
407
|
+
Optional[str],
|
|
408
|
+
typer.Option("--speculator-file", help="Optional draft GGUF filename."),
|
|
409
|
+
] = None,
|
|
410
|
+
spec_type: Annotated[
|
|
411
|
+
Optional[str],
|
|
412
|
+
typer.Option("--spec-type", help="llama.cpp --spec-type (draft-dflash, draft-mtp, draft-simple, draft-eagle3, ...)."),
|
|
413
|
+
] = None,
|
|
414
|
+
model_quant: Annotated[
|
|
415
|
+
Optional[str],
|
|
416
|
+
typer.Option("--model-quant", help="Optional target quant label override."),
|
|
417
|
+
] = None,
|
|
418
|
+
speculator_quant: Annotated[
|
|
419
|
+
Optional[str],
|
|
420
|
+
typer.Option("--speculator-quant", help="Optional speculator quant label override."),
|
|
421
|
+
] = None,
|
|
422
|
+
no_mmproj: Annotated[
|
|
423
|
+
bool,
|
|
424
|
+
typer.Option("--no-mmproj", help="Pass --no-mmproj to llama-server."),
|
|
425
|
+
] = False,
|
|
426
|
+
draft_tokens: Annotated[
|
|
427
|
+
Optional[str],
|
|
428
|
+
typer.Option("--draft-tokens", help="Preset ('default'=[0,4,8,12], 'spec-only', 'fine') or comma-separated ints."),
|
|
429
|
+
] = None,
|
|
430
|
+
suite: Annotated[
|
|
431
|
+
Optional[list[str]],
|
|
432
|
+
typer.Option("--suite", help="Suite(s) to run: '<capability>' or '<capability>=<source>'."),
|
|
433
|
+
] = None,
|
|
434
|
+
limit: Annotated[
|
|
435
|
+
Optional[int],
|
|
436
|
+
typer.Option("--limit", help="Max samples per suite (default: 20)."),
|
|
437
|
+
] = None,
|
|
438
|
+
max_tokens: Annotated[
|
|
439
|
+
Optional[int],
|
|
440
|
+
typer.Option("--max-tokens", help="Max generated tokens per prompt (default: 512)."),
|
|
441
|
+
] = None,
|
|
442
|
+
temperature: Annotated[
|
|
443
|
+
Optional[float],
|
|
444
|
+
typer.Option("--temperature", help="Sampling temperature (default: 0.0)."),
|
|
445
|
+
] = None,
|
|
446
|
+
hf_dataset: Annotated[
|
|
447
|
+
Optional[str],
|
|
448
|
+
typer.Option("--hf-dataset", help="Target HF dataset repo ID (default: merve/drafter-bench)."),
|
|
449
|
+
] = None,
|
|
450
|
+
output_dir: Annotated[
|
|
451
|
+
Optional[Path],
|
|
452
|
+
typer.Option("--output-dir", help="Container directory for artifacts (e.g. a mounted bucket path)."),
|
|
453
|
+
] = None,
|
|
454
|
+
private: Annotated[
|
|
455
|
+
bool,
|
|
456
|
+
typer.Option("--private", help="Create/push the HF dataset repo as private."),
|
|
457
|
+
] = False,
|
|
458
|
+
overwrite: Annotated[
|
|
459
|
+
bool,
|
|
460
|
+
typer.Option("--overwrite", help="Replace existing rows on HF Hub instead of appending."),
|
|
461
|
+
] = False,
|
|
462
|
+
dry_run: Annotated[
|
|
463
|
+
bool,
|
|
464
|
+
typer.Option("--dry-run", help="Skip HF Hub push (requires --volume or --allow-dry-run)."),
|
|
465
|
+
] = False,
|
|
466
|
+
ctx_size: Annotated[
|
|
467
|
+
Optional[int],
|
|
468
|
+
typer.Option("--ctx-size", help="Context size passed to --ctx-size (default: 8192)."),
|
|
469
|
+
] = None,
|
|
470
|
+
llama_arg: Annotated[
|
|
471
|
+
Optional[list[str]],
|
|
472
|
+
typer.Option("--llama-arg", help="Extra raw argument passed to llama-server (repeatable)."),
|
|
473
|
+
] = None,
|
|
474
|
+
run_id: Annotated[
|
|
475
|
+
Optional[str],
|
|
476
|
+
typer.Option("--run-id", help="Optional custom run_id recorded in the dataset."),
|
|
477
|
+
] = None,
|
|
478
|
+
) -> None:
|
|
479
|
+
"""Launch a speculative decoding benchmark on a Hugging Face Jobs cloud GPU via `hf jobs run`."""
|
|
480
|
+
cfg = _build_benchmark_config(
|
|
481
|
+
config_file=config_file,
|
|
482
|
+
model_repo=model_repo,
|
|
483
|
+
speculator_repo=speculator_repo,
|
|
484
|
+
speculator_file=speculator_file,
|
|
485
|
+
spec_type=spec_type,
|
|
486
|
+
model_quant=model_quant,
|
|
487
|
+
speculator_quant=speculator_quant,
|
|
488
|
+
no_mmproj=no_mmproj,
|
|
489
|
+
draft_tokens=draft_tokens,
|
|
490
|
+
suite=suite,
|
|
491
|
+
limit=limit,
|
|
492
|
+
max_tokens=max_tokens,
|
|
493
|
+
temperature=temperature,
|
|
494
|
+
hf_dataset=hf_dataset,
|
|
495
|
+
output_dir=output_dir,
|
|
496
|
+
private=private,
|
|
497
|
+
overwrite=overwrite,
|
|
498
|
+
dry_run=dry_run,
|
|
499
|
+
llama_cmd=None,
|
|
500
|
+
port=None,
|
|
501
|
+
ctx_size=ctx_size,
|
|
502
|
+
llama_arg=llama_arg,
|
|
503
|
+
run_id=run_id,
|
|
504
|
+
)
|
|
505
|
+
job = HFJobOptions(
|
|
506
|
+
flavor=flavor,
|
|
507
|
+
timeout=timeout,
|
|
508
|
+
image=image,
|
|
509
|
+
remote_llama_cmd=remote_llama_cmd,
|
|
510
|
+
package_source=package_source,
|
|
511
|
+
detach=detach,
|
|
512
|
+
namespace=namespace,
|
|
513
|
+
volumes=list(volume or []),
|
|
514
|
+
env=list(env or []),
|
|
515
|
+
labels=list(label or []),
|
|
516
|
+
plot_dir=plot_dir,
|
|
517
|
+
allow_dry_run=allow_dry_run,
|
|
518
|
+
)
|
|
519
|
+
try:
|
|
520
|
+
rc = submit_hf_job(cfg, job, print_only=print_command, console=console)
|
|
521
|
+
except (ValueError, FileNotFoundError) as exc:
|
|
522
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
523
|
+
if rc != 0:
|
|
524
|
+
raise typer.Exit(code=rc)
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
@app.command("list-presets")
|
|
528
|
+
def list_presets_cmd() -> None:
|
|
529
|
+
"""List built-in prompt suite and draft-token presets."""
|
|
530
|
+
table = Table(title="Built-in Suite Presets")
|
|
531
|
+
table.add_column("Preset", style="cyan")
|
|
532
|
+
table.add_column("Kind")
|
|
533
|
+
table.add_column("Source")
|
|
534
|
+
table.add_column("Description")
|
|
535
|
+
for preset in SUITE_PRESETS.values():
|
|
536
|
+
table.add_row(f"preset:{preset.name}", preset.kind, preset.target, preset.description)
|
|
537
|
+
console.print(table)
|
|
538
|
+
|
|
539
|
+
dt_table = Table(title="Draft Token Presets (--draft-tokens)")
|
|
540
|
+
dt_table.add_column("Preset", style="cyan")
|
|
541
|
+
dt_table.add_column("Values")
|
|
542
|
+
for name, vals in DRAFT_TOKEN_PRESETS.items():
|
|
543
|
+
dt_table.add_row(name, str(list(vals)))
|
|
544
|
+
console.print(dt_table)
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
@app.command("inspect-suite")
|
|
548
|
+
def inspect_suite_cmd(
|
|
549
|
+
source: Annotated[str, typer.Argument(help="Suite source: local .jsonl, 'preset:<name>', or 'hf:<repo>[?config=...&split=...]'.")],
|
|
550
|
+
capability: Annotated[str, typer.Option("--capability", help="Capability label.")] = "coding",
|
|
551
|
+
limit: Annotated[int, typer.Option("--limit", help="Number of samples to preview.")] = 5,
|
|
552
|
+
hf_config: Annotated[Optional[str], typer.Option("--hf-config")] = None,
|
|
553
|
+
hf_split: Annotated[Optional[str], typer.Option("--hf-split")] = None,
|
|
554
|
+
prompt_column: Annotated[Optional[str], typer.Option("--prompt-column")] = None,
|
|
555
|
+
) -> None:
|
|
556
|
+
"""Load and preview a prompt suite without starting llama serve."""
|
|
557
|
+
spec = SuiteSpec(
|
|
558
|
+
capability=capability,
|
|
559
|
+
source=source,
|
|
560
|
+
limit=limit,
|
|
561
|
+
hf_config=hf_config,
|
|
562
|
+
hf_split=hf_split,
|
|
563
|
+
prompt_column=prompt_column,
|
|
564
|
+
)
|
|
565
|
+
samples = load_suite(spec)
|
|
566
|
+
table = Table(title=f"Suite Preview: {source} ({len(samples)} samples)")
|
|
567
|
+
table.add_column("Sample ID", style="cyan")
|
|
568
|
+
table.add_column("Capability")
|
|
569
|
+
table.add_column("Has Images")
|
|
570
|
+
table.add_column("Prompt Preview")
|
|
571
|
+
for s in samples:
|
|
572
|
+
user_msg = next((m for m in s.messages if m["role"] == "user"), {})
|
|
573
|
+
content = user_msg.get("content", "")
|
|
574
|
+
if isinstance(content, list):
|
|
575
|
+
text_parts = [p.get("text", "") for p in content if p.get("type") == "text"]
|
|
576
|
+
preview = " ".join(text_parts)
|
|
577
|
+
else:
|
|
578
|
+
preview = str(content)
|
|
579
|
+
preview = " ".join(preview.split())[:100]
|
|
580
|
+
table.add_row(s.sample_id, s.capability, str(s.has_images), preview)
|
|
581
|
+
console.print(table)
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
@app.command("plot")
|
|
585
|
+
def plot_cmd(
|
|
586
|
+
source: Annotated[
|
|
587
|
+
str,
|
|
588
|
+
typer.Argument(
|
|
589
|
+
help="Local run dir, summary.parquet, summary.json, or HF dataset repo (default: merve/drafter-bench).",
|
|
590
|
+
),
|
|
591
|
+
] = "merve/drafter-bench",
|
|
592
|
+
output_dir: Annotated[
|
|
593
|
+
Optional[Path],
|
|
594
|
+
typer.Option("--output-dir", "-o", help="Directory to save generated charts (default: <source>/charts or ./charts)."),
|
|
595
|
+
] = None,
|
|
596
|
+
theme: Annotated[
|
|
597
|
+
str,
|
|
598
|
+
typer.Option("--theme", help="Visual theme: 'dark' (default) or 'light'."),
|
|
599
|
+
] = "dark",
|
|
600
|
+
fmt: Annotated[
|
|
601
|
+
str,
|
|
602
|
+
typer.Option("--format", "-f", help="Output image format: 'png' or 'svg'."),
|
|
603
|
+
] = "png",
|
|
604
|
+
model: Annotated[
|
|
605
|
+
Optional[str],
|
|
606
|
+
typer.Option("--model", "-m", help="Filter rows by model repo/quant/spec_type substring."),
|
|
607
|
+
] = None,
|
|
608
|
+
capabilities: Annotated[
|
|
609
|
+
Optional[str],
|
|
610
|
+
typer.Option("--capabilities", help="Comma-separated capabilities to include (e.g. 'coding,knowledge_work')."),
|
|
611
|
+
] = None,
|
|
612
|
+
run_ids: Annotated[
|
|
613
|
+
Optional[str],
|
|
614
|
+
typer.Option("--run-ids", help="Comma-separated run_id values to include."),
|
|
615
|
+
] = None,
|
|
616
|
+
title: Annotated[
|
|
617
|
+
Optional[str],
|
|
618
|
+
typer.Option("--title", help="Optional custom headline title for the charts."),
|
|
619
|
+
] = None,
|
|
620
|
+
) -> None:
|
|
621
|
+
"""Generate polished benchmark charts (dashboard + standalone plots) and save them locally."""
|
|
622
|
+
if theme not in {"light", "dark"}:
|
|
623
|
+
raise typer.BadParameter("--theme must be 'light' or 'dark'.")
|
|
624
|
+
if fmt not in {"png", "svg"}:
|
|
625
|
+
raise typer.BadParameter("--format must be 'png' or 'svg'.")
|
|
626
|
+
|
|
627
|
+
cap_list = [c.strip() for c in capabilities.split(",") if c.strip()] if capabilities else None
|
|
628
|
+
run_list = [r.strip() for r in run_ids.split(",") if r.strip()] if run_ids else None
|
|
629
|
+
|
|
630
|
+
rows = load_summary_rows(
|
|
631
|
+
source,
|
|
632
|
+
model_filter=model,
|
|
633
|
+
capabilities=cap_list,
|
|
634
|
+
run_ids=run_list,
|
|
635
|
+
)
|
|
636
|
+
|
|
637
|
+
if output_dir is None:
|
|
638
|
+
src_path = Path(source)
|
|
639
|
+
if src_path.exists():
|
|
640
|
+
output_dir = (src_path if src_path.is_dir() else src_path.parent) / "charts"
|
|
641
|
+
else:
|
|
642
|
+
output_dir = Path("charts")
|
|
643
|
+
|
|
644
|
+
saved = generate_visualizations(
|
|
645
|
+
rows,
|
|
646
|
+
output_dir,
|
|
647
|
+
theme_name=theme, # type: ignore[arg-type]
|
|
648
|
+
fmt=fmt, # type: ignore[arg-type]
|
|
649
|
+
title=title,
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
table = Table(title=f"Saved Benchmark Visualizations ({len(rows)} summary rows)")
|
|
653
|
+
table.add_column("Chart", style="cyan")
|
|
654
|
+
table.add_column("Path")
|
|
655
|
+
for name, path in saved.items():
|
|
656
|
+
table.add_row(name, str(path))
|
|
657
|
+
console.print(table)
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
if __name__ == "__main__":
|
|
661
|
+
app()
|