Skip to content

feat(bench): dispatch speculative_bench MTP past Gemma 4 Unified - #1621

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-1613-mtp-bench-dispatch
Sep 4, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-1613-mtp-bench-dispatch

Conversation

@inureyes

@inureyes inureyes commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Summary

run_mtp in src/bin/speculative_bench.rs matched LoadedModel::Gemma4Unified and bailed on every other variant with std::mem::discriminant, so the bench could produce MTP numbers for exactly one checkpoint. Every adapter the other families need already exists and the server burst path already dispatches them, so the harness was the only place pretending the support was absent. This replaces the unwrap with per-variant adapter selection and adds the Qwen 3.8 pairings the restriction was blocking.

What changed

src/bin/speculative_bench.rs: run_mtp now selects the MtpTarget adapter per LoadedModel variant, mirroring src/server/batch/speculative_burst.rs. Gemma 4 text, VLM and Unified wrappers take their gemma4_mtp_target adapter (block-size-armed, because their rotating cache is sized from it); Qwen 3.5 text, MoE and VLM wrappers take their qwen3_5_mtp_target adapter. The drafter is loaded, compat-checked and bound against the LoadedModel enum's own LanguageModel impl, and the per-sequence release goes through the same reference, so only the adapter construction needs a match.

src/bin/speculative_bench.rs: the warm-up burst, the timed generate, the acceptance capture and the sequence release moved into one run_mtp_timed function generic over T: MtpTarget. Each variant arm calls it with its own adapter constructor; the timed body is not copied per variant.

src/bin/speculative_bench.rs: an unsupported variant now fails with a message naming the loaded variant, the target directory and the supported families, rather than printing Discriminant(26). That check runs before the drafter is loaded, the same ordering the burst path uses and for the same reason: without the hoist a validate_target_compat hidden-size mismatch fires first and describes a drafter problem for what is a target problem. The variant name comes from the burst path's own label table, which reports anything outside the speculative-capable set as other, so the message names the target directory too; widening that table is out of scope here.

src/bin/speculative_bench.rs: Qwen 3.5 MTP exactness is Metal-only in the server path, so the bench declines the same way when mlxcel_core::metal_is_available() is false and records the reason as that row's status instead of emitting a number the runtime cannot vouch for. Drafter load failures, validate_target_compat mismatches, missing checkpoints and block_size < 2 all stay per-row statuses and the sweep still completes its remaining rows.

src/bin/speculative_bench.rs: REACHABLE_PAIRINGS gains a qwen3.8-27b-4bit baseline (BenchKind::None) and the same target paired with the qwen3.8-27b-mtp-4bit drafter (BenchKind::Mtp, block_size: Some(4)).

src/server/batch/speculative_burst.rs and src/lib.rs: model_variant_label is pub and re-exported at the crate root. The bench is a separate crate from the library, so pub(crate) would not reach it, and the re-export is what lets the bench reuse the existing table instead of carrying a second copy of it. No other change to speculative_burst.rs.

docs/benchmarks.md: the paragraph claiming the 31B pairing "runs once the checkpoints are present in the model store" was not true before this change, since the target-variant gate rejected the 31B target with both checkpoints on disk. It now records that and the widened family list.

Scope beyond the issue text

resolve_model_dir probed <CARGO_MANIFEST_DIR>/models/<name> and then ../mlxcel-internal/models/<name>. On a host whose checkpoint store is models/mlx/<name> neither probe resolves, so every pairing in a --sweep silently falls through to the "checkpoint missing on disk" skip: the sweep completes, reports no error, and measures nothing. Two models/mlx/<name> probes now run after the existing two (repo-local, then sibling checkout), so no host that resolves today changes behavior. Without this the acceptance criteria below could not be verified at all on this host.

Host substitution

The issue's figures come from an M5 Max sweep. This work was implemented and verified on Apple M1 Ultra 128 GB (Metal), mlxcel 0.7.0-beta.1, MLX pin 9a795735. The dispatch fix and the REACHABLE_PAIRINGS additions are host-independent; the numbers are not. The issue's K=4 figure of 70.9 tok/s for Gemma 4 Unified 12B is an M5 Max reading and is not the M1 Ultra expectation, so nothing here is asserted against it, and the M5 Max table in docs/benchmark_results/model_tests.md is not overwritten with M1 Ultra numbers. The M5 Max re-run against this binary is still pending.

Test plan

  • cargo build --release --features metal,accelerate --bin speculative_bench
  • cargo clippy --bin speculative_bench --features metal,accelerate -- -D warnings (clean)
  • cargo fmt --all -- --check (clean)
  • ./target/release/speculative_bench --target models/mlx/gemma-4-31b-it-4bit --draft models/mlx/gemma-4-31b-it-assistant-bf16 --kind mtp --block-size 4 --max-tokens 128 on M1 Ultra: [bench/mtp] Done: prompt=14 prefill_ms=306.0 decode_ms=5936.1 generated=88 tok/s=14.8 (wall 6.2s) rounds=34 acceptance_rate=0.529 mean_accepted_len=1.59. This pairing fails on the pre-change binary.
  • ./target/release/speculative_bench --target models/mlx/qwen3.8-27b-4bit --draft models/mlx/qwen3.8-27b-mtp-4bit --kind mtp --block-size 4 --max-tokens 128 on M1 Ultra: [bench/mtp] Done: prompt=13 prefill_ms=290.2 decode_ms=7051.4 generated=119 tok/s=16.9 (wall 7.3s) rounds=47 acceptance_rate=0.504 mean_accepted_len=1.51. This pairing did not exist before.
  • ./target/release/speculative_bench --sweep --batch 1 --max-tokens 128 on M1 Ultra: 16 rows, 4 baselines and 9 measured MTP rows across Gemma 4 31B, Gemma 4 Unified 12B and Qwen 3.8 27B at K=2/4/8, 3 DFlash rows still deferred, and no row carrying a status that starts with MTP bench currently supports. Full table recorded on bench/0.7.0-refresh (see below).
  • ./target/release/speculative_bench --target models/mlx/gemma-3-4b-it-4bit --draft models/mlx/gemma-4-12b-it-assistant-4bit --kind mtp reports MTP bench: target <path> loaded as other, which has no MTP target adapter; supported families are Gemma 4 (Gemma4, Gemma4VLM, Gemma4Unified) and Qwen 3.5 (Qwen35, Qwen35Moe, Qwen35VLM, Qwen35MoeVLM) as the row status, without aborting.

Every MTP pairing reads below 1.00x on this host, which is expected rather than a defect: docs/benchmark_results/speculative-decoding-m1ultra-2026-08-19.md measures a block-4 verify round at 2.70 classic decode steps on M1 Ultra against 1.27 on M5 Max, so a mean accepted length near 1.2 cannot clear break-even here. The MLXCEL_ENABLE_MTP_B1 static gate already declines B=1 MTP on this Apple GPU generation for that reason. The numbers are the harness reporting the host it ran on, not a regression.

No unit tests are added: the binary has none today, its behavior is real-checkpoint dispatch, and a synthetic target cannot exercise the adapter selection this change is about.

Where the acceptance criteria are satisfied

This issue splits across two destinations, so this PR closes it while part of its acceptance evidence sits unmerged elsewhere. Satisfied on main by this PR: run_mtp accepts Gemma4, Gemma4VLM, Gemma4Unified, Qwen35, Qwen35Moe, Qwen35VLM and Qwen35MoeVLM and names the loaded variant and the supported families otherwise; the Gemma 4 31B MTP pairing produces numeric tok/s, speedup, acceptance rate and mean accepted length at K=2/4/8 on M1 Ultra (18.4 / 14.9 / 14.9 tok/s, 0.93x / 0.75x / 0.75x against a 19.9 tok/s baseline, acceptance 74.0% / 52.9% / 52.9%, mean accepted length 0.74 / 1.59 / 1.59); the Qwen 3.8 27B baseline row and MTP pairing are in REACHABLE_PAIRINGS and both produce numbers (24.9 tok/s baseline, 22.5 / 17.2 / 9.3 tok/s at K=2/4/8); the Gemma 4 Unified 12B rows still produce numbers (38.4 tok/s baseline, 36.0 / 28.5 / 29.3 tok/s at K=2/4/8, acceptance 54.5% / 39.6% / 39.6%); clippy and fmt are clean.

Satisfied on bench/0.7.0-refresh (PR #1617), not on main: the docs/benchmark_results/model_tests.md edits that drop the unsupported-target limitation and record the new rows with their host named, and the M1 Ultra sweep CSV under benchmarks/. Those files are benchmark artifacts and that branch is the repository's benchmark-refresh PR, which is deliberately staying open until the M1 Ultra, M3 Ultra and GB10 sweeps land in it. Do not read this PR merging as those doc edits reaching main.

Closes #1613

@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:inference Generation, sampling, decoding (incl. speculative, DRY) status:review Under review labels Sep 4, 2026
`run_mtp` matched `LoadedModel::Gemma4Unified` and bailed on every other variant with `std::mem::discriminant`, so the bench could produce MTP numbers for exactly one checkpoint. The adapters for the other families already exist and the server burst path already dispatches them, so the harness was the only place pretending the support was absent.

The variant match now mirrors `src/server/batch/speculative_burst.rs`: Gemma 4 text, VLM and Unified wrappers take their `gemma4_mtp_target` adapter, Qwen 3.5 text, MoE and VLM wrappers take their `qwen3_5_mtp_target` adapter, and any other variant fails with a message naming the loaded variant and the supported families instead of a discriminant. The drafter is loaded, compat-checked and bound against the `LoadedModel` enum's own `LanguageModel` impl, and the per-sequence release goes through the same reference, so only the `MtpTarget` construction is variant-specific.

`MtpGenerator` is generic over `MtpTarget`, so the warm-up burst, the timed generate, the acceptance capture and the sequence release moved into one `run_mtp_timed` function generic over `T: MtpTarget` that every arm calls with its own adapter constructor. The body is not copied per variant.

Qwen 3.5 MTP exactness is Metal-only in the server path, so the bench declines the same way when `metal_is_available()` is false and records the reason as the row's status rather than emitting a number the runtime cannot vouch for. Every other failure (drafter load, compat mismatch, missing checkpoint, `block_size < 2`) stays a per-row status and the sweep still completes its remaining rows.

`REACHABLE_PAIRINGS` gains a `qwen3.8-27b-4bit` baseline and the same target paired with the `qwen3.8-27b-mtp-4bit` head at `block_size: Some(4)`.

Beyond the issue text: `resolve_model_dir` probed `<manifest>/models/<name>` and `../mlxcel-internal/models/<name>` only. A host whose checkpoint store is `models/mlx/<name>` resolved nothing, so every sweep row fell through to the "checkpoint missing on disk" skip and the sweep measured nothing while reporting no error. Two `models/mlx/<name>` probes now run after the existing two, so no host that resolves today changes behavior.

`model_variant_label` is `pub` and re-exported at the crate root. The bench is a separate crate from the library, so `pub(crate)` would not reach it, and the re-export is what lets the bench reuse the table instead of carrying a second copy.

The unsupported-variant check runs before the drafter is loaded, the same ordering the burst path uses. Without the hoist a `validate_target_compat` hidden-size mismatch fires first and reports a drafter problem for what is a target problem. The message names the target directory as well as the variant label, because the shared label table reports anything outside the speculative-capable set as `other`.

Validated on Apple M1 Ultra 128 GB (Metal), mlxcel 0.7.0-beta.1, MLX pin 9a795735, `--kind mtp --block-size 4 --max-tokens 128`: `gemma-4-31b-it-4bit` + `gemma-4-31b-it-assistant-bf16` at 14.8 tok/s, acceptance 52.9%, mean accepted length 1.59 over 34 rounds; `qwen3.8-27b-4bit` + `qwen3.8-27b-mtp-4bit` at 16.9 tok/s, acceptance 50.4%, mean accepted length 1.51 over 47 rounds. Both fail on the pre-change binary. The full `--sweep --batch 1 --max-tokens 128` completes 16 rows with 9 measured MTP rows and no row carrying an unsupported-target status; `gemma-3-4b-it-4bit` under `--kind mtp` reports the loaded variant, the target directory and the supported families as a row status rather than aborting the sweep. `cargo clippy --bin speculative_bench --features metal,accelerate -- -D warnings` and `cargo fmt --all -- --check` are clean.

Refs #1613
@inureyes
inureyes force-pushed the feature/issue-1613-mtp-bench-dispatch branch from f0281ae to a74348f Compare September 4, 2026 03:27
Project convention forbids em dashes in prose, code comments included. Comment text only; the pairing entries are untouched.

Refs #1613
@inureyes inureyes added status:done Completed and removed status:review Under review labels Sep 4, 2026
@inureyes
inureyes merged commit bf1cdb7 into main Sep 4, 2026
12 checks passed
@inureyes
inureyes deleted the feature/issue-1613-mtp-bench-dispatch branch September 4, 2026 03:43
inureyes added a commit that referenced this pull request Sep 6, 2026
Full re-benchmark at `a50ff440`: text (176 dirs, 147 measured), VLM (71), speculative, batched serving, embeddings. First sweep on the fixed interval 3a746ea introduced, so the tables are not comparable to earlier ones and the doc now says where.

- Prefill is not comparable across the boundary: the prompt went 6 to 512 tokens, so ratios against 2026-09-03 run 2.5x to 27x purely from amortizing fixed per-call overhead. Decode carries about -1.8% (median 0.982) from the larger KV cache.
- The `vs M1 Ultra` column is blanked to `n/a` across 203 rows. That reference is the 2026-07-12 old-condition sweep, and a ratio spanning both a version and a condition change is not a hardware comparison. It returns when M1 Ultra is re-swept at pp512/tg128.
- Seven Qwen VL checkpoints read 15-26% low and are not a regression: re-running the old condition on this build reproduces the old numbers within 1%, with two controls. It does expose that Qwen VL decode loses ~26% between a 6-token and a 512-token context where a plain Qwen decoder loses ~2%.
- Speculative gains the Gemma 4 31B rows for the first time here after #1621 (1.90x at K=4), with Gemma 4 Unified reproducing 2026-09-04 as a control. Qwen 3.8 27B goes net negative at K=8 (0.78x, acceptance 22.4%).
- The mlx-lm section keeps its old-condition numbers behind a note; both sides were taken at that condition, so refreshing it is a Python baseline re-run.

All 12 models down more than 10% were re-measured in isolation and reproduced within 3%; per-model CSVs are included as the audit trail. Two rows measured during host storage work read 2-3% low and are replaced by their isolated runs.
@inureyes inureyes added this to the 0.7 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: extend speculative_bench MTP path past Gemma 4 Unified

1 participant