Repository navigation
Closed
Labels
area:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:lowLow prioritystatus:doneCompletedtype:performancePerformance improvements
Milestone
Description
Summary
Replace the static environment gates for MTP speculative decode with an adaptive policy that profiles the first few requests for a target/drafter pair and auto-enables or declines MTP per pair and per hardware class.
Source: idea.md "7. Adaptive MTP Policy" (P2, expected payoff pair-dependent, risk medium).
Current state
- The benchmark doc shows Gemma 4 12B + 4-bit assistant around 1.87x faster with MTP, while the 31B + bf16 assistant is pairing-dependent (
docs/benchmarks.md, around lines 82 / 99). - The scheduler already gates B=1 and B>1 MTP because some cases regress: B=1 can regress on pre-M5 hardware, and B>1 31B MTP is not consistently faster than classic batched decode (
src/server/batch/scheduler.rs, around lines 2850 / 2872).
Proposal
- Add an adaptive policy that profiles the first few requests for a target/drafter pair and records acceptance length, verify latency, drafter latency, batch size, and prompt-shape compatibility.
- Auto-enable or decline MTP per pair and per hardware class instead of relying only on static environment gates.
- Persist only coarse local hints, NOT prompt data.
Validation
speculative_benchbaseline vs MTP for Gemma 4 12B and 31B pairings.- Server benchmark with same-length and ragged prompt windows.
- Confirm
temperature=0byte-identical output against classic decode.
Acceptance criteria
- Per-pair and per-hardware profiling records acceptance length, verify latency, drafter latency, batch size, and prompt-shape compatibility over the first few requests. (
MtpBurstProfile+ProfileAccumulatorinsrc/server/batch/mtp_policy.rs; profiling windowPROFILE_SAMPLE_TARGET.) - MTP is auto-enabled or declined from the measured profile, overriding the static gates where the profile is favorable or unfavorable. (
estimate_speedup+classify_speedup+resolve_verdict; ambiguous defers to the static per-hardware default.) - Only coarse local hints persisted; no prompt data stored. (
PolicyHintcarries verdict + coarse acceptance rate + sample count only;${MLXCEL_CACHE_DIR:-$HOME/.cache/mlxcel}/mtp-policy/<key-hash>.json; unit test asserts the field set.) -
temperature=0output byte-identical to classic decode (MTP must stay exact speculative decode). Preserved by design (policy is decision-only; generator change is purely additive) and covered by the in-repo greedy-parity gate inmlxcel_core::speculative::mtp::tests. Real-model temp-0 confirmation on gemma-4-12b is the orchestrator's final pass. -
speculative_benchand server numbers recorded for Gemma 4 12B and 31B pairings; no regression vs the static-gate baseline. (Requires real-model runs; pending the orchestrator's release-build validation.)
Risk and priority
idea.md priority P2; risk medium. MTP has large upside for some pairs; fixed gates leave performance on the table when a new hardware/model pair is favorable.
References
- idea.md "7. Adaptive MTP Policy".
- Code:
src/server/batch/scheduler.rs(MTP B=1 and B>1 gates),docs/benchmarks.md. - Related MTP issues: feat: wire MTP speculative decoding into the offline
mlxcel generatepath #166, perf: validate B=1 MTP default-on on lower-bandwidth Apple Silicon (M1/M2) #165, perf: harden ragged B>1 MTP batching (NaN-safe masked rows, per-row valid-length verify mask) #163, perf: support variable-length prompts in B>1 batched MTP speculative bursts #161, perf: enable B=1 MTP speculative decoding by default for gemma4_unified (re-calibrate the singleton-window decline guard) #158.
Metadata
Metadata
Assignees
Labels
area:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:lowLow prioritystatus:doneCompletedtype:performancePerformance improvements
Activity
perf(server): adaptive B=1 MTP enable/decline policy from profiling (#…
perf(server): tick-cooperative speculative decoding to remove the bur…
fix(server): re-check the B=1 verdict and budget at slice grant promo…
feat(mtp-policy): expose the settled verdict at /v1/internal/mtp-poli…
perf(server): adaptive B=1 MTP enable/decline policy from profiling (l…
perf(server): tick-cooperative speculative decoding to remove the bur…
feat(mtp-policy): expose the settled verdict at /v1/internal/mtp-poli…