Skip to content

MTP: implement --spec-draft-p-min (probabilistic accept threshold) #38

Description

@pekkah

Background

llama.cpp's --spec-draft-p-min (default 0.75) is the minimum acceptance probability for a drafted token. Today sharpi's MTP path uses pure greedy verification: a draft is accepted iff `argmax(target_logits) == draft` (probability threshold = 1.0 on argmax). This means we reject more drafts than necessary on close calls where the draft is a plausible alternative.

llama.cpp accepts a draft whenever `softmax(target_logits)[draft] >= p_min` — i.e. as long as the draft is a reasonably probable continuation. This raises the acceptance rate at the cost of slight output divergence vs the no-MTP baseline.

Scope

  1. Add `SamplingParams.SpecDraftPMin` (default 1.0 = current behavior, exact argmax match).
  2. Add `--spec-draft-p-min ` to `src/SharpInference.Cli/RunCommand.cs`.
  3. In `MtpDecoder.Decode`, swap the current `argmax` comparison for a softmax + threshold check:
    • Compute `p_draft = softmax(target_logits)[draft]`.
    • Accept iff `p_draft >= sp.SpecDraftPMin`; reject otherwise and re-emit `argmax(target_logits)` as the correction.
  4. Document the parity trade-off: `p_min < 1.0` means sharpi will not match the greedy MTP-disabled baseline token-for-token. This is the same divergence llama.cpp accepts in exchange for higher decode throughput.

Notes

  • Requires a partial softmax (only the verifier value at `draft` is needed; can short-circuit by computing `exp(logits[draft]) / sum(exp(logits))` with the standard log-sum-exp trick — or just normalize the top-K). Per-step cost is tiny (`O(V)` reductions; vocab fits in cache).
  • Sensible default in llama.cpp is 0.75. Sharpi should keep the default at 1.0 so existing test parity (MtpDecoder_GreedyParity, etc.) holds; users opt into the looser threshold explicitly.
  • File: `src/SharpInference.Engine/Sampler.cs` (SamplingParams), `src/SharpInference.Cli/RunCommand.cs` (CLI flag), `src/SharpInference.Engine/MtpDecoder.cs` (acceptance check).

Acceptance

  • `p_min == 1.0` reproduces today's MtpDecoder output bit-for-bit.
  • `p_min == 0.75` raises acceptance rate on Qwen3.6-27B-MTP (verify via `SHARPI_TRACE_MTP=1`) without breaking decode-coherence asserts in tests.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions