Skip to content

perf(inference): adaptive MTP enable/decline policy from per-pair profiling #333

Closed

Description

@inureyes

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_bench baseline vs MTP for Gemma 4 12B and 31B pairings.
  • Server benchmark with same-length and ragged prompt windows.
  • Confirm temperature=0 byte-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 + ProfileAccumulator in src/server/batch/mtp_policy.rs; profiling window PROFILE_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. (PolicyHint carries 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=0 output 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 in mlxcel_core::speculative::mtp::tests. Real-model temp-0 confirmation on gemma-4-12b is the orchestrator's final pass.
  • speculative_bench and 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

Activity

  1. added
    type:performance
    priority:low
    area:inference
    status:in-progress
    status:review
    status:done
    and removed
    status:in-progress
    status:review
    on Jun 17, 2026
  2. added this to the 0.3 milestone on Jun 21, 2026
  3. self-assigned this
    on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencepriority:lowstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions