speculative: add optional top-k draft acceptance statistics - #28110
Draft
cuhawk wants to merge 1 commit into
Draft
speculative: add optional top-k draft acceptance statistics#28110cuhawk wants to merge 1 commit into
cuhawk wants to merge 1 commit into
Conversation
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.
|
Hi @cuhawk, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
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.
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_pastadvances byn_accepted + 1per verification, so the rejection index is recoverable from consecutivedraft()calls, and the token the target chose at that index arrives asid_laston the next call. Deriving it fromn_pastrather 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
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.