Repository navigation
[Spec Decode] Add draft-model distributions for probabilistic sampling - #1373
Draft
POWEHI2023 wants to merge 1 commit into
Draft
POWEHI2023 wants to merge 1 commit into
POWEHI2023 wants to merge 1 commit into
Conversation
POWEHI2023
force-pushed
the
feat/lossless-speculative-sampling
branch
from
November 19, 2026 10:17
9d2f57c to
3aa3eea
Compare
Sample draft tokens from processed distributions and verify them against target probabilities with residual resampling. Preserve per-request draft distributions and RNG state across scheduler handoff. Return draft IDs and optional probabilities through one proposer interface. Signed-off-by: POWEHI2023 <zxe6b885@163.com>
POWEHI2023
force-pushed
the
feat/lossless-speculative-sampling
branch
from
November 19, 2026 12:16
25f952b to
77eae6a
Compare
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.
Motivation
The MLX draft-model proposer previously returned only greedy token IDs. Requests using a nonzero temperature or top-k/top-p sampling could not use draft-model speculation, so serving a model with its normal sampling settings fell back to target-only decoding. This draft PR works toward distribution-correct speculative sampling for that use case.
Design
MetalProposer.propose()to return(DraftTokenIds | None, dict[str, PendingDraftProbs] | None). Other proposers returnNonefor the distribution result; this version implements probabilistic proposals only forDraftModelProposer.ProposeContext. Proposal and verification consume successive draws from the same stream. The runner hands sampled draft IDs to the scheduler and retains the distributions for the next verification step.xwith probabilitymin(1, p(x)/q(x)); on rejection, sample from the normalized positive residualmax(p-q, 0). If all drafts are accepted, sample a bonus token from the target distribution.Relation to #1278
#1278 samples each target verification row with
sample_from_logits, using the request's output history plus earlier draft tokens, then compares the sampled target token with an argmax draft ID. This PR records the draft model's full proposal distribution and uses probability-ratio acceptance plus residual resampling. For a deterministic draft distribution, the two acceptance rules have the same distribution. If sampled draft IDs were simply fed into #1278's equality check, acceptance would besum_x p(x)q(x)rather than thesum_x min(p(x),q(x))of probability-ratio verification; whenp=q, this PR can accept every draft.Integration plan if #1278 merges
sample_from_logitsreturns sampled IDs, which are insufficient for thep/qacceptance test and residual distribution. Do not draw a target token for every proposal row in the probability-ratio path.verifypath for ID-only proposers. RoutePendingDraftProbsfrom the draft-model proposer toverify_probabilistic, while preserving the common packed-row metadata and scheduler handoff checks in the runner.can_drafteligibility and preflight checks by verifier capability: ID-only drafts may use [Spec Decode] Verify drafts of sampled requests #1278's sampled-target path; distribution-bearing drafts must have matching processedpandq. On rebase, resolve [Spec Decode] Verify drafts of sampled requests #1278'sverify_greedy-to-verifyrename without duplicating sampling or eligibility logic. Add parity tests for deterministic drafts and distribution/acceptance tests for stochastic drafts.#1278 remains an open draft PR. This PR can proceed independently as a draft and will rebase on its final interface if it lands first.
Current draft status
77eae6a.propose()interface. Probabilistic verification and RNG lifecycle regression tests will be added during the next development pass. Real-checkpoint baseline comparison, acceptance measurements, and B=1/B>1 serving benchmarks remain pending. No speedup claim is made.Validation so far
pytest -q tests/test_spec_decode_metadata.py tests/test_draft_model_proposer.py tests/test_sampling.py: 180 passed on77eae6a. These tests do not exercise the new probabilistic verifier.scripts/lint.sh: shellcheck, Ruff lint and format, and mypy passed on77eae6a.Before marking ready