Skip to content

chore: add a serving comparison harness against vLLM and SGLang - #3677

Merged
inureyes merged 9 commits into
mainfrom
feature/issue-3663-serving-compare-harness
Dec 2, 2026
Merged

inureyes merged 9 commits into
mainfrom
feature/issue-3663-serving-compare-harness

Conversation

@inureyes

@inureyes inureyes commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds scripts/bench/serving_compare.py, one command that reproduces the cross-engine serving table of epic #3671. For each --engine mlxcel|vllm|sglang it starts the server from a per-engine command template (or benchmarks a running server with --external URL), waits for the health endpoint, measures every shape and concurrency cell with the same vllm bench serve client, and stops the server. It keeps the raw client JSON per cell, prints the table in the epic's column layout, and appends one CSV row per comparable cell.

What is in it

  • scripts/bench/serving_compare.py: standard-library driver. Default ladder --concurrency 1,8,32, --shapes 512x128,8192x128; per cell one discarded warmup (--num-prompts c), then 16 prompts at c=1 and 4 * c otherwise, --backend openai-chat --endpoint /v1/chat/completions --dataset-name random --ignore-eos, a per-cell client seed derived from --seed (identical for every engine). Server commands are the issue's templates, extendable with --mlxcel-args, --vllm-args, --sglang-args and pointed with --mlxcel-bin, --vllm-venv, --sglang-venv, --client. --dry-run prints every server, health, version, warmup and measured client command without launching anything.
  • Attribution guard (comparability_reason): a cell with any failed request, fewer than num_prompts * output_len output tokens (EOS leaked), or for mlxcel no movement of mlxcel_batch_decode_steps_total in /metrics (or /metrics unavailable) prints NOT COMPARABLE: <reason> and writes no CSV row. A non-zero client exit marks the cell FAILED.
  • Server lifecycle: own process group per server, log in OUT_DIR/<engine>_server.log, --startup-timeout 900 s, port-in-use refusal before launch, SIGTERM to the group then SIGKILL after 30 s, also on Ctrl-C and SIGTERM. The whole group is waited on (vLLM and SGLang children can outlive the leader) and further interrupts are ignored while stopping. A server that exits during a cell aborts that engine with its log tail instead of running the remaining cells against a closed port. An aborted engine or any unreported cell makes the exit status 1.
  • Outputs: raw JSON under --out-dir (default bench_results/serving/<UTC timestamp>/, now gitignored), Markdown table on stdout, rows appended per cell to --csv (default docs/benchmark_results/serving_compare.csv) with the issue's 19 columns. server_args is stored with repo-relative and ~ paths.
  • scripts/bench/serving_compare.md: venv install for vLLM, SGLang and mlx-lm, the single-client rationale, server templates, cells, outputs, guard rules, gpu-lock wrapping.
  • docs/benchmarks.md: new section "Serving claims in CUDA performance PRs" naming the script as the method.
  • Tests: scripts/bench/serving_compare_test.py (guard on synthetic result JSON, command builders, flag override, process-group stop, CSV columns, table layout, dry-run, missing-client error), re-exported by tests/test_bench_serving_compare.py so CI's unittest discover -s tests runs them.

Deviations from the issue text

  • The mlxcel command adds --metrics: mlxcel-server serves /metrics only with that flag, and the guard reads it.
  • Every server gets --host (default 127.0.0.1), so vllm serve does not bind all interfaces.
  • Every cell and every warmup gets its own client seed (cell_seed, from --seed, shape and concurrency), identical for every engine. The random dataset draws prompts in order from the seed and the server stays up across cells, so a single seed would nest prompt sets (c=1's 16 prompts are the first 16 of c=8's, c=8's the first 32 of c=32's, each 8192-token prompt starts with the 512-token prompt at its index) and a warmup on the measured seed would pre-send measured prompts; prefix caches would serve those repeats. Found in the technical-report pass and fixed before merge.
  • Context windows are sized from the requested shapes: vLLM keeps --max-model-len 8192 and mlxcel keeps --ctx-size 65536 when every shape fits, which covers the acceptance command (--shapes 512x128). The default 8192x128 shape does not fit 8192 nor the 2048-token per-slot windows of --parallel 32 --ctx-size 65536, so it raises them to the next power of two (16384 and 524288).
  • A flag repeated in --*-args replaces the template's flag, because mlxcel-server's clap parser rejects a repeated value flag (--ctx-size twice is an error). --host and --port are refused there.
  • The client is missing on most hosts, so a missing vllm executable exits 2 with the install pointer.

Verification (GB10, spark-101)

  • python3 -m py_compile scripts/bench/serving_compare.py: OK.
  • python3 -m unittest scripts/bench/serving_compare_test.py: 19 tests OK; python3 -m unittest discover -s tests -p 'test_bench_serving_compare.py': OK.
  • --dry-run --engine mlxcel --engine vllm --engine sglang --model nvidia/Gemma-4-31B-IT-NVFP4: prints all commands, launches nothing.
  • Client: uv pip install vllm worked on this aarch64 host in an isolated scratchpad venv (vLLM 0.34.0, torch 2.14.0, the same vLLM version as the B200 reference run), and vllm bench serve ran as the client against mlxcel-server. No vLLM or SGLang server was run here.
  • Real run, cargo build --release --features cuda --bin mlxcel-server, then gpu-lock run --tag serving-compare -- python3 scripts/bench/serving_compare.py --engine mlxcel --model models/gemma-4-e2b-it-4bit --concurrency 1,8 --shapes 512x128,8192x128 (exit 0, 4 CSV rows, every cell passed the guard; for example the c=1 512x128 JSON has completed 16, failed 0, total_output_tokens 2048 = 16 x 128):
Engine Shape TPOT c=1 TTFT c=1 output tok/s c=8 TPOT c=8
mlxcel 0.9.0 512x128 12.64 ms 53.4 ms 166.0 46.50 ms
mlxcel 0.9.0 8192x128 14.28 ms 1182.8 ms 58.0 44.05 ms

These are single runs on a shared host and are a functional proof of the driver, not a performance baseline.

  • The final HEAD (2b3c5f4ad) completed a short run on the same host, --concurrency 1 --shapes 512x128 on gemma-4-e2b-it-4bit: exit 0, one CSV row, TPOT 15.11 ms, TTFT 667.4 ms (the host was loaded by unrelated compile jobs).
  • Gemma 4 31B NVFP4 at c=1,8,32 512x128 did not produce a table on this host, and the cause is not established. In the first attempt the host OOM killer took mlxcel-server (oom_score_adj 1000, so it is the victim whoever consumes memory) partway through the c=1 cell, after NVRM ... NV_ERR_NO_MEMORY kernel lines started about a minute earlier; c=1 was running at about 170 ms per token. In the retry it was killed during warmup, with 168 NVRM lines in that window and about 45 GB of anonymous memory held host-wide. Host memory pressure from unrelated jobs and --parallel 32 --ctx-size 65536 not fitting the 31B on GB10 are both open readings. The guard did its job on the first attempt (c=1: NOT COMPARABLE: 3 of 16 requests failed, no CSV rows), and that run is why the driver now aborts an engine whose server dies mid-run; the retry exercised that path (exited with code -9 before it became healthy, exit 1). A third attempt was not made, because repeated NVRM out-of-memory events precede host freezes on GB10. The 31B baseline needs an idle, freshly booted host.

Deferred

  • Acceptance criterion 1 (reproduce the B200 table for mlxcel, vLLM and SGLang within 10%) needs a B200 with vLLM and SGLang servers. Deferred to the B200 follow-up measurement issue.

Closes #3663

Add scripts/bench/serving_compare.py, a standard-library driver that starts mlxcel-server, vLLM or SGLang from per-engine command templates (or uses an already-running server with --external), waits for the health endpoint, measures every shape and concurrency cell with the same `vllm bench serve` client (one discarded warmup, 16 prompts at c=1 and 4*c otherwise, random dataset, --ignore-eos, one seed), and stops the server with SIGTERM then SIGKILL. It keeps the raw client JSON per cell, prints the epic #3671 table layout, and appends one CSV row per comparable cell.

A cell with a failed request, fewer output tokens than num_prompts * output_len, or, for mlxcel, no decode steps in /metrics prints NOT COMPARABLE and writes no row. A missing client is a clear error with exit status 2.

scripts/bench/serving_compare.md documents the isolated venv setup, the server commands and the guard; docs/benchmarks.md names the script as the method for serving claims in CUDA performance PRs; bench_results/ is gitignored. The guard and command builders are covered by scripts/bench/serving_compare_test.py, re-exported from tests/ so CI discovery runs it.

Closes #3663
The guard reads mlxcel's /metrics, which mlxcel-server serves only with --metrics, so the default command now passes it. An explicit --parallel 32 splits --ctx-size 65536 into 2048-token slots, so a shape that does not fit one slot (8192x128) raises --ctx-size to 32 times the next power of two, as vLLM's --max-model-len already was.
@inureyes inureyes added status:in-progress Currently being worked on type:chore Maintenance tasks (build, CI, etc.) priority:high High priority area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) status:review Under review and removed status:in-progress Currently being worked on labels Dec 2, 2026
Review fixes for the serving comparison harness. stop_server now signals and waits on the whole process group, so vLLM and SGLang children that outlive the leader are SIGKILLed, and it ignores further interrupts so a second Ctrl-C cannot skip the SIGKILL. The warmup uses seed + 1 so it does not pre-cache the measured prompts. Every server gets --host, CSV rows are appended per cell with machine paths stripped from server_args, an aborted engine makes the exit status 1, HTTP protocol errors no longer crash a health or metrics probe, and the command tests build expected paths with venv_bin so they pass on Windows.
@inureyes inureyes self-assigned this Dec 2, 2026
mlxcel-server rejects a value flag given twice, so --mlxcel-args could not change --ctx-size or --parallel. A flag set in the *-args options now replaces the template's flag and value; --host and --port stay with the driver, which probes them.
On GB10 the host OOM killer took mlxcel-server during the first 31B cell, and the driver went on to run every remaining cell against a closed port. It now checks the launched server after each cell and aborts that engine with the exit code and the server log tail.
datetime.UTC exists only from Python 3.11; use datetime.timezone.utc so the tests run on older interpreters in CI.
@inureyes inureyes added status:done Completed and removed status:review Under review labels Dec 2, 2026
The random dataset in `vllm bench serve` draws prompts in order from the seed alone, and the harness keeps one server up across cells. With one measured seed per shape, c=1's prompts were the first 16 of c=8's and c=8's the first 32 of c=32's, and each 8192-token prompt began with the 512-token prompt at its index, so prefix caches could serve half of the c=8 and a quarter of the c=32 requests.

`cell_seed` now derives one seed per (shape, concurrency) cell from `--seed`, and the warmup takes the next value. Seeds stay identical across engines. A unit test pins distinct seeds across the ladder; the docs and the technical report describe the change.
@inureyes
inureyes marked this pull request as ready for review December 2, 2026 02:52
@inureyes
inureyes merged commit 6bd1870 into main Dec 2, 2026
1 of 36 checks passed
@inureyes
inureyes deleted the feature/issue-3663-serving-compare-harness branch December 2, 2026 02:52
inureyes added a commit that referenced this pull request Dec 2, 2026
An earlier commit on this branch was taken from a tree that predated #3677 and #3679 and dropped their files and lines; restore them from main so this PR changes only the memory plan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) priority:high High priority status:done Completed type:chore Maintenance tasks (build, CI, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Add a serving benchmark harness against vLLM and SGLang

1 participant