Skip to content

speculative: add optional top-k draft acceptance statistics - #28110

Draft
cuhawk wants to merge 1 commit into
ggml-org:masterfrom
cuhawk:mtp-draft-topk-stats
Draft

speculative: add optional top-k draft acceptance statistics#28110
cuhawk wants to merge 1 commit into
ggml-org:masterfrom
cuhawk:mtp-draft-topk-stats

Conversation

@cuhawk

@cuhawk cuhawk commented Aug 31, 2026

Copy link
Copy Markdown

Optional instrumentation for MTP-style single-head drafting, entirely behind LLAMA_MTP_TOPK_STATS=1. Off by default and inert when unset.

The question it answers

Drafting deeper with a single draft head degrades quickly, because the head is reused off its training distribution past step 1. The open question is whether drafting wider pays instead: when the target rejects a draft token, how often is the token the target actually picked the head's rank-2 candidate? That probability is the per-step gain of widening the draft tree at that position, and it is what you would want to know before implementing tree drafting.

How

It measures this without building a tree. n_past advances by n_accepted + 1 per verification, so the rejection index is recoverable from consecutive draft() calls, and the token the target chose at that index arrives as id_last on the next call. Deriving it from n_past rather than from the accept hook keeps it correct across the different server code paths.

Collected per draft position (up to 16) over the top-8 candidates: rank histogram of the target's choice, acceptance rate, how often the draft reached that position, and the mean rank-2 probability. Reported every N verifications, N settable with LLAMA_MTP_TOPK_STATS_EVERY (default 128).

Status and caveats

  • Additive only: 170 lines, no existing behaviour changed. Every allocation and all bookkeeping is guarded by the flag.
  • Compile-verified against current master; I have not exercised the reporting path on master at runtime. It was written and used against a local MTP branch.
  • This is a research/tuning aid rather than a user-facing feature. If instrumentation of this kind does not belong in common/speculative.cpp, I am happy to drop it or move it behind a build option instead of an environment variable — please say which you would prefer.

Single-head drafting degrades when drafting deeper, because the head is reused
off its training distribution past step 1. Whether drafting wider pays instead
depends on how often the token the target picks is the head rank-2 candidate,
which is the per-step gain of widening the draft tree at that position.

Measure that without building a tree. n_past advances by n_accepted + 1 per
verification, so the rejection index follows from consecutive draft() calls and
the token the target chose arrives as id_last on the next call. Deriving it from
n_past rather than the accept hook keeps it correct on every server code path.

Per draft position, over the top-8 candidates: rank histogram of the target
choice, acceptance rate, reach count, and mean rank-2 probability. Reported
every LLAMA_MTP_TOPK_STATS_EVERY verifications, default 128.

Entirely behind LLAMA_MTP_TOPK_STATS=1; inert and allocation-free when unset.
@cuhawk
cuhawk requested a review from a team as a code owner August 31, 2026 18:20
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

Hi @cuhawk, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 3 open PRs.

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Aug 31, 2026
@github-actions
github-actions Bot marked this pull request as draft August 31, 2026 18:25
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant