Benchmarking inference serving
specforge benchmark measures an SGLang server on one or more tasks and reports output throughput, acceptance length, and, for scored tasks, accuracy. It can measure a server you already started, or launch one server per speculative-decoding configuration and sweep a matrix.
Quick start
Measure a running server:
specforge benchmark \
--model Qwen/Qwen3-8B \
--base-url http://127.0.0.1:30000 \
--task gsm8k:200 --task mtbench \
--concurrency 16Sweep target-only and speculative configurations from a config file (see examples/benchmarks/eagle3_matrix.yaml for EAGLE3 and examples/benchmarks/dflash_matrix.yaml for DFlash/DFlash2/DSpark):
specforge benchmark --config examples/benchmarks/eagle3_matrix.yaml
specforge benchmark --config examples/benchmarks/dflash_matrix.yaml \
draft_model=/path/to/exported-dflash-draftEvery run prints a summary table and writes a JSON report to output.dir/<output.name>_<timestamp>.json.
config task samples failed tokens tok/s accept_macro accept_micro accuracy
----------------------------------------------------------------------------------------------------------------
baseline gsm8k 200 0 61234 812.3 - - 92.5%
eagle3-s3-k1-d4 gsm8k 200 0 61102 2154.7 3.485 3.412 92.0%Configuration
A benchmark is one validated config. Load it from YAML or JSON with --config, set the common fields with flags, and adjust anything else with dotted section.field=value overrides; later sources win in that order.
model: meta-llama/Llama-3.1-8B-Instruct
draft_model: /path/to/exported-draft
tasks:
- name: mtbench
- name: gsm8k
num_samples: 200
- name: ceval
num_samples: 50
subset: [accountant, law]
server:
launch: true
base_url: http://127.0.0.1:30000
args: [--tp-size, "1", --mem-fraction-static, "0.8", --attention-backend, fa3]
matrix:
- {label: baseline}
- {steps: 3, topk: 1, draft_tokens: 4}
- {steps: 5, topk: 4, draft_tokens: 8, batch_size: 8}
sampling:
temperature: 0.0
max_new_tokens: 2048
concurrency: 1
output:
dir: ./benchmark_results
name: llama3.1-8b-eagle3| Section | Fields |
|---|---|
| top level | model (tokenizer, chat template, served model), draft_model, concurrency, warmup, enable_thinking, trust_remote_code, seed, plugins |
tasks[] | name, num_samples, subset, max_new_tokens, path (for jsonl / file-backed tasks), options (task-specific kwargs) |
server | base_url, launch, launch_timeout_seconds, request_timeout_seconds, args (verbatim sglang.launch_server flags), env |
matrix[] | label, batch_size, algorithm (EAGLE, EAGLE3, DFLASH, DSPARK), draft_model (per-entry override), steps, topk, draft_tokens (EAGLE-family), block_size (DFlash/DSpark), args (per-entry SGLang flags); an entry without algorithm/steps is the target-only baseline |
sampling | temperature, top_p, top_k (default -1, disabled; 1 is greedy at any temperature), max_new_tokens (global override replacing each task's default when set; per-task tasks[].max_new_tokens still wins) |
output | dir, name |
matrix requires server.launch: true (setting matrix with server.launch: false is rejected). A running server is measured as-is and its rows are labeled server; the benchmark never changes a server it did not start.
On the command line, --task NAME[:N[:SUBSET,...]] is repeatable and replaces the file's task list, so --task ceval:50:accountant,law is the same as the YAML entry above. --list-tasks prints the registry.
Tasks
| Task | Dataset | Scored |
|---|---|---|
gsm8k | openai/gsm8k test | final number |
math500 | HuggingFaceH4/MATH-500 | boxed answer |
aime | Maxwell-Jia/AIME_2024 (32k-token cap) | integer answer |
humaneval | openai/openai_humaneval | runs the unit tests |
mbpp | google-research-datasets/mbpp sanitized | runs the asserts |
ceval | ceval/ceval-exam test, subset = subjects | choice letter |
mmlu | cais/mmlu test, subset = HF config names | choice letter |
gpqa | Idavidrein/gpqa main, seeded choice order | choice letter |
mmstar | Lin-Chen/MMStar val (image input) | choice letter |
mtbench | HuggingFaceH4/mt_bench_prompts, two turns | no |
simpleqa | basicv8vc/SimpleQA | no |
financeqa | AfterQuery/FinanceQA | no |
livecodebench | livecodebench/code_generation | no |
jsonl | local .jsonl file (path, single-turn or multi-turn) | no |
Prompts are rendered client-side with the target tokenizer's chat template and sent to /generate, the endpoint that returns speculative-decoding telemetry. Multi-turn tasks replay each assistant reply into the next turn. mmstar emits multimodal {"type": "image"} content blocks for vision-language chat templates and passes the image path as image_data.
Benchmarking a local JSONL file
Use name: jsonl with path to benchmark local single-turn prompts (prompt, question, text), user turn lists (turns), or OpenAI / ShareGPT multi-turn conversations (messages or conversations):
tasks:
- name: jsonl
path: /path/to/conversations.jsonl
num_samples: 100
options:
history_mode: auto # auto | recorded | liveWith history_mode: auto (default), rows containing recorded assistant or tool turns replay the recorded message prefix before each assistant turn (preserving multi-turn and tool-call context); rows with only user turns (or history_mode: live) feed the model's live replies into subsequent turns.
Adding a task
Subclass BenchmarkTask, yield Sample objects from load, optionally implement score, and register the class. Built-in tasks live in specforge/benchmarks/tasks/; external ones are imported through plugins.
from specforge.benchmarks.tasks import TASKS, BenchmarkTask, Sample
from specforge.benchmarks.tasks.answers import extract_final_number, numbers_equal
@TASKS.register
class MyMathTask(BenchmarkTask):
name = "mymath"
description = "in-house math set"
max_new_tokens = 4096
def load(self):
for row in self.limit(load_my_rows()):
yield Sample(turns=[row["question"]], label=row["answer"])
def score(self, output, label):
return numbers_equal(extract_final_number(output), label)plugins: [my_package.benchmarks]
tasks:
- name: mymathMetrics
- tok/s is output tokens divided by the wall-clock time of the timed phase. With
warmup: true(the default) one concurrency-sized batch runs first, untimed, and the prefix cache is flushed before measuring. - accept_macro is the request-level mean acceptance length: the unweighted average of each
/generaterequest's mean acceptance length (mean_i(tau_i)) across requests that underwent at least one verification (for multi-turn tasks, each generation turn is one request). - accept_micro is the step-level mean acceptance length: total accepted length divided by total verification rounds (
sum_i(L_i) / sum_i(R_i)=sum_i(R_i * tau_i) / sum_i(R_i)) across requests withspec_verify_ct > 0. Both fields are blank when the server reports no speculation. - accuracy is the fraction of scored samples the task marked correct.
- failed counts samples whose request errored or timed out. They are left out of tokens, acceptance and accuracy, so a row with failures describes only the samples that succeeded. The report is still written and the command exits with status 1.
Comparing results
Measure target-only and speculative decoding with the same target revision, tokenizer and chat template, tasks, sampling parameters, output cap, hardware, tensor parallelism, and concurrency. A matrix run guarantees this by construction; for separately started servers, keep the config identical apart from server.base_url.
Safety
humaneval and mbpp execute model-generated Python in a subprocess with a timeout. That isolates the benchmark from hangs, not from malicious code. Run scored code tasks only in an isolated environment without credentials or production data.