Metadata-Version: 2.5
Name: specbench-cli
Version: 0.1.0
Summary: Benchmark llama.cpp speculative decoding token acceptance rates, speedup, and memory overhead across draft lengths and task suites.
Project-URL: Homepage, https://github.com/merveenoyan/specbench
Project-URL: Repository, https://github.com/merveenoyan/specbench
Project-URL: Issues, https://github.com/merveenoyan/specbench/issues
Author-email: Merve Noyan <merveenoyan@gmail.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: benchmark,dflash,eagle,gguf,huggingface,llama.cpp,llm,mtp,speculative-decoding
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Requires-Dist: datasets>=3.0.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: huggingface-hub>=0.27.0
Requires-Dist: matplotlib>=3.9.0
Requires-Dist: pillow>=10.0.0
Requires-Dist: pydantic>=2.8.0
Requires-Dist: pyyaml>=6.0.2
Requires-Dist: rich>=13.9.0
Requires-Dist: typer>=0.12.5
Description-Content-Type: text/markdown

# `specbench`

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.

https://github.com/user-attachments/assets/771ae1b8-5b28-4af5-a71e-c80f75fcf209


![Muse-Glimmer-30B speculative decoding benchmark dashboard](https://raw.githubusercontent.com/merveenoyan/specbench/main/assets/muse-glimmer-30b-dashboard.png)

## What It Measures

For every `(model, speculator, capability, draft_n_max)` run:

- **Acceptance rate** — pooled and per-sample token acceptance straight from `llama-server` timings.
- **Real speedup** — decode/prefill throughput (`tok/s`), latency, and `speedup_vs_baseline` vs. `draft_n_max = 0`.
- **Memory overhead** — peak GPU VRAM and extra memory added by the drafter (works on discrete NVIDIA GPUs and unified-memory systems like DGX Spark).
- **Effective draft length & quant metadata** — tracks requested vs. clamped `effective_draft_n_max` (e.g., DFlash block size) plus target and drafter quantizations.

## Installation

Requires **`llama.cpp`** (`llama serve` or `llama-server` on `PATH`) and **Python 3.11+**.

```bash
# Install from PyPI (provides the `specbench` CLI)
pip install specbench-cli

# Or install globally with uv
uv tool install specbench-cli

# Or run without installing
uvx --from specbench-cli specbench --help

# Needed for gated models or pushing results to Hugging Face Hub
hf auth login
```

<details>
<summary>Install from source (for development)</summary>

```bash
git clone https://github.com/merveenoyan/specbench.git
cd specbench
uv sync
uv run specbench --help
```

</details>

## Quick Start

### Single HF repo (auto-discovered drafter: DFlash, MTP, EAGLE-3, DSpark)

Modern `llama.cpp` automatically picks up `dflash-*`, `mtp-*`, `eagle3-*`, and `dspark-*` sidecar GGUFs from the same repo based on `--spec-type`:

```bash
# 1) Benchmark Q4_K_M with its matched Q4_K_M DFlash drafter
specbench run \
  -m meta-models/Muse-Glimmer-30B-GGUF:Q4_K_M \
  --spec-type draft-dflash \
  --suite coding,multimodal,knowledge_work \
  --ctx-size 32768 \
  --max-tokens 2048 \
  --hf-dataset merve/drafter-bench

# 2) Benchmark Q4_K_XL reusing the same Q4_K_M DFlash drafter from the repo
specbench run \
  -m meta-models/Muse-Glimmer-30B-GGUF:Q4_K_XL \
  --spec-type draft-dflash \
  --suite coding,multimodal,knowledge_work \
  --ctx-size 32768 \
  --max-tokens 2048 \
  --hf-dataset merve/drafter-bench
```

> **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.

### Separate target & drafter repos

```bash
specbench run \
  -m unsloth/Qwen3-32B-GGUF:Q4_K_M \
  -s unsloth/Qwen3-0.6B-GGUF:Q8_0 \
  --spec-type draft-simple \
  --suite coding,multimodal \
  --hf-dataset <your-username/drafter-bench>
```

### YAML config

```bash
specbench run --config config.example.yaml
```

## Prompt Suites

Select built-in suites with `--suite` (comma-separated or repeated; defaults to 20 samples via `--limit 20`):

| Flag | Dataset | Focus |
| --- | --- | --- |
| `coding` | [`ArtificialAnalysis/SWE-Atlas-QnA-AA`](https://huggingface.co/datasets/ArtificialAnalysis/SWE-Atlas-QnA-AA) | Software engineering Q&A (Go/Python/C/TS) |
| `multimodal` | [`MMMU/MMMU_Pro`](https://huggingface.co/datasets/MMMU/MMMU_Pro) | Image + question reasoning |
| `knowledge_work` | [`ArtificialAnalysis/AA-Briefcase-Lite`](https://huggingface.co/datasets/ArtificialAnalysis/AA-Briefcase-Lite) | Long-context commercial due diligence |
| `coding=preset:livecodebench` | [`livecodebench/code_generation_lite`](https://huggingface.co/datasets/livecodebench/code_generation_lite) | Competitive coding (v6) |
| `coding=preset:smoke-coding` | Bundled offline smoke suite | Fast offline check (`preset:smoke-multimodal` also included) |

### Bring your own dataset

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:

```bash
# Zero-config HF dataset
specbench run -m <repo:quant> --suite math=hf:org/my-math-prompts

# Optional overrides for multi-config datasets or custom columns
specbench run -m <repo:quant> \
  --suite math="hf:openai/gsm8k?config=main&split=test&prompt_column=question"

# Local JSONL (supports optional "images": ["relative/path.png"])
specbench run -m <repo:quant> --suite coding=./my_prompts.jsonl
```

Preview any suite before launching a server:

```bash
specbench inspect-suite preset:coding --capability coding --limit 5
```

## Draft Token Sweeps

By default, `specbench` sweeps `--draft-tokens default` = **`[0, 4, 8, 12]`** (including `0` computes baseline speedup and memory delta automatically).

- `--draft-tokens spec-only` → `[4, 8, 12]`
- `--draft-tokens fine` → `[0, 1, 2, 4, 8, 12, 16]`
- `--draft-tokens 0,2,6,10,15` → custom list

<details>
<summary>How <code>llama.cpp</code> block-size clamping is handled</summary>

Some speculators cap the maximum draft length internally:

- **DFlash (`draft-dflash`)** clamps to `dflash.block_size - 1` (e.g., `block_size=16` caps at `15`).
- **Chained multi-head MTP (`draft-mtp`)** clamps to `n_mtp_layers`.
- **`ngram-cache`** is fixed at `8` tokens.
- **Standalone draft (`draft-simple`) & EAGLE-3 (`draft-eagle3`)** accept arbitrary lengths.

When `llama.cpp` clamps a value, `specbench` logs a warning and records both `draft_n_max` (requested) and `effective_draft_n_max` (actual).

</details>

## Plotting Results

Generate the 2×2 dashboard (`dashboard.png`) plus standalone charts from a HF Hub dataset or local `results/<run_id>` folder:

```bash
specbench plot merve/drafter-bench --output-dir ./charts
specbench plot merve/drafter-bench --model Muse-Glimmer --theme light --format svg
```

## Cloud GPUs via Hugging Face Jobs

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:

```bash
specbench hf-job \
  --flavor l40sx1 \
  --timeout 2h \
  --detach \
  -m meta-models/Muse-Glimmer-30B-GGUF:Q4_K_M \
  --spec-type draft-dflash \
  --suite coding,multimodal,knowledge_work \
  --limit 15 \
  --ctx-size 32768 \
  --hf-dataset <your-username/drafter-bench>
```

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`.

## Dataset Output

Runs write local Parquet + JSON checkpoints to `results/<run_id>/` and append to two HF dataset configs (`summary` and `samples`):

```python
from datasets import load_dataset

summary = load_dataset("merve/drafter-bench", "summary", split="train")
samples = load_dataset("merve/drafter-bench", "samples", split="train")
```

<details>
<summary>Full schema columns</summary>

- **`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`.
- **`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.

</details>

## Custom `llama-server` & Tests

Point to a custom `llama-server` binary with `--llama-cmd /path/to/llama-server`, list presets with `specbench list-presets`, and run tests with:

```bash
uv run pytest -v
```
