Repository navigation
feat(bench): dispatch speculative_bench MTP past Gemma 4 Unified - #1621
Merged
Merged
Conversation
`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
force-pushed
the
feature/issue-1613-mtp-bench-dispatch
branch
from
September 4, 2026 03:27
f0281ae to
a74348f
Compare
6 tasks done
Project convention forbids em dashes in prose, code comments included. Comment text only; the pairing entries are untouched. Refs #1613
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
run_mtpinsrc/bin/speculative_bench.rsmatchedLoadedModel::Gemma4Unifiedand bailed on every other variant withstd::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_mtpnow selects theMtpTargetadapter perLoadedModelvariant, mirroringsrc/server/batch/speculative_burst.rs. Gemma 4 text, VLM and Unified wrappers take theirgemma4_mtp_targetadapter (block-size-armed, because their rotating cache is sized from it); Qwen 3.5 text, MoE and VLM wrappers take theirqwen3_5_mtp_targetadapter. The drafter is loaded, compat-checked and bound against theLoadedModelenum's ownLanguageModelimpl, 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 onerun_mtp_timedfunction generic overT: 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 printingDiscriminant(26). That check runs before the drafter is loaded, the same ordering the burst path uses and for the same reason: without the hoist avalidate_target_compathidden-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 asother, 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 whenmlxcel_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_compatmismatches, missing checkpoints andblock_size < 2all stay per-row statuses and the sweep still completes its remaining rows.src/bin/speculative_bench.rs:REACHABLE_PAIRINGSgains aqwen3.8-27b-4bitbaseline (BenchKind::None) and the same target paired with theqwen3.8-27b-mtp-4bitdrafter (BenchKind::Mtp,block_size: Some(4)).src/server/batch/speculative_burst.rsandsrc/lib.rs:model_variant_labelispuband re-exported at the crate root. The bench is a separate crate from the library, sopub(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 tospeculative_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_dirprobed<CARGO_MANIFEST_DIR>/models/<name>and then../mlxcel-internal/models/<name>. On a host whose checkpoint store ismodels/mlx/<name>neither probe resolves, so every pairing in a--sweepsilently falls through to the "checkpoint missing on disk" skip: the sweep completes, reports no error, and measures nothing. Twomodels/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 theREACHABLE_PAIRINGSadditions 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 indocs/benchmark_results/model_tests.mdis 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_benchcargo 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 128on 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 128on 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 128on 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 withMTP bench currently supports. Full table recorded onbench/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 mtpreportsMTP 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.mdmeasures 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. TheMLXCEL_ENABLE_MTP_B1static 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
mainby this PR:run_mtpacceptsGemma4,Gemma4VLM,Gemma4Unified,Qwen35,Qwen35Moe,Qwen35VLMandQwen35MoeVLMand 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 inREACHABLE_PAIRINGSand 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 onmain: thedocs/benchmark_results/model_tests.mdedits that drop the unsupported-target limitation and record the new rows with their host named, and the M1 Ultra sweep CSV underbenchmarks/. 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 reachingmain.Closes #1613