Repository navigation
Extend probabilistic sampling for DFlash2 drafts - #30663
gaugarg-nv merged 2 commits into
Conversation
|
Adding the performance section as a separate comment for better visibility Performance
RTX 5090Qwen3.8-27B
Muse-Glimmer-30B
DGX SparkQwen3.8-27B
Muse-Glimmer-30B
RTX Pro 6000Qwen3.8-27B
Muse-Glimmer-30B
|
|
@gaugarg-nv, @ruixiang63 can you please take a look at this PR? |
|
The change looks good to me. |
|
I'll revisit #30213 tomorrow, other things came in the way last week. |
|
Do we have DFlash2 model for Muse-Glimmer-30B? @praneshgo |
Yes, there is a DFlash2 model for Muse-Glimmer-30B. I found the drafter model at https://huggingface.co/z-lab/Muse-Glimmer-30B-DFlash2-GGUF and the corresponding target model is at https://huggingface.co/meta-models/Muse-Glimmer-30B-GGUF |
| for (int32_t k = 0; k < top_k; ++k) { | ||
| sum += std::exp(scores[k] - scores[predecessor]); | ||
| probs[k] = std::exp((scores[k] - scores[predecessor]) / temp); | ||
| sum += probs[k]; | ||
| } | ||
| if (1.0f / sum < params.p_min) { | ||
| break; | ||
| } | ||
| for (int32_t k = 0; k < top_k; ++k) { | ||
| probs[k] /= sum; | ||
| } |
There was a problem hiding this comment.
I am thinking about params.p_min here: it still truncates on the draft’s max probability, which was a good proxy for greedy acceptance. Under rejection sampling the expected acceptance is Σ_x min(p(x), q(x)) = 1 − TV(p, q), which doesn’t depend on how peaked q is (draft token probability), so positions cut off by p_min could well have been accepted by the target. Ideally the cutoff would be an estimate of 1 − TV(p, q), but we don’t have p (target verified token probability) at draft time. Should we disable p_min when use rejection sampling?
There was a problem hiding this comment.
Good point, I agree. Under rejection sampling the acceptance at a position is 1 − TV(p, q), and the draft's top probability doesn't say much about that, so p_min can cut tokens the target would have accepted.
For this PR:
- p_min is 0 by default, so it only kicks in when it is set. All the numbers in the PR were measured with it not set.
- draft-simple and draft-mtp already apply p_min the same way in probabilistic mode (top probability of the draft distribution at the target's temperature), so DFlash2 follows the existing behavior.
Instead of changing it for DFlash2 alone here, I think p_min under rejection sampling should be handled for all three drafters together. draft-simple and draft-mtp run one draft forward pass per token, so stopping early also saves draft compute. Dropping the cutoff trades that saving for more tokens the target may accept. Finding out which side wins needs measuring, which I can take up in a follow-up PR.
There was a problem hiding this comment.
Please add a follow-up for this.
There was a problem hiding this comment.
PR #31294 addresses the above discussion.
|
It is approved. Can it be merged now? |
|
@gaugarg-nv can you please help merge this PR if it looks okay? Thank you. |
* spec : add probabilistic sampling for DFlash2 drafts * spec : apply review suggestions --------- Co-authored-by: Pranesh Gonegandla <[email protected]>
--spec-draft-n-short N keeps only the first N drafts of a lattice drafter such as DFlash2 or DSpine unless the expected accepted tokens of the full path, taken from the lattice's own transition probabilities, pay for --spec-draft-long-cost, the relative cost of the longer step. Off by default. b12032 rebase: b12032 has DFlash2 probabilistic drafting (1ab09d6, ggml-org#30663) in the same loop. The keep rule only shortens greedy drafts. It decides from transitions past the drafts it keeps, so on a sampled draft it would keep a token depending on that token's own continuation, while the rejection test assumes the token is distributed as the q handed to the verifier. In a constructed two-candidate lattice, not a model benchmark, with n_short 1 and long_cost 1.44, a token the target puts at 50% came out 75%. A setup warning says so when DFlash2 drafts probabilistically with n_short set. The step probability on a sampled step is the softmax at the argmax with the target's temperature, the value p_min already reads there. Greedy steps use lattice_argmax_prob, unchanged. (cherry picked from commit cf815be)
The lattice walk computed each transition's softmax probability and kept it in path_p even with --spec-draft-p-min 0 and n_short 0, where nothing reads it. It now computes the probability only for p_min or n_short, and reserves and fills path_p only for n_short. b12032 rebase: b12032's DFlash2 sampling (1ab09d6, ggml-org#30663) needs the softmax on every sampled step, so it is computed whenever sampling, and the greedy probability only for p_min or n_short. The keep rule stays off on a sampled draft (see the lattice draft length commit), so keep_p also requires a greedy draft and nothing trims result_q. (cherry picked from commit 1c349c6)
A DFlash2 draft sampled for rejection sampling was cleared when --spec-draft-p-min stopped it before n_min tokens. Where p_min stops depends on the tokens the walk has already sampled, so the cleared drafts were the ones whose sampled tokens lead to an uncertain step, and the drafts that reached the verifier no longer followed the q handed with them. In the test's lattice the first step is A at 70% and B at 30%, and p_min 0.6 stops every draft that starts with B after one token. With n_min 2, A started all 14071 of the 20000 drafts that reached the verifier instead of 70% of them. With a target that also puts A at 70%, a rejection step at the first position emitted A for 90.97% of 200000 drafts before this change and 69.95% after it. A sampled draft now keeps its prefix at any length, and a greedy draft below n_min is still dropped. result_q was only cleared together with a sampled draft, so that clear goes too. test-dspine runs common_speculative_lattice_walk on that lattice: all 20000 sampled drafts must reach the verifier, A must start 70% +- 2% of them, n_short must not shorten one, and the greedy n_min and n_short cases are unchanged. Before this change the n_min case fails. The clear came with DFlash2 probabilistic drafting upstream (1ab09d6, ggml-org#30663) and is unchanged on master at ded522f. Assisted-by: Claude Code Signed-off-by: Guilherme Gallo <[email protected]>
--spec-draft-n-short N keeps only the first N drafts of a lattice drafter such as DFlash2 or DSpine unless the expected accepted tokens of the full path, taken from the lattice's own transition probabilities, pay for --spec-draft-long-cost, the relative cost of the longer step. Off by default. b12032 rebase: b12032 has DFlash2 probabilistic drafting (1ab09d6, ggml-org#30663) in the same loop. The keep rule only shortens greedy drafts. It decides from transitions past the drafts it keeps, so on a sampled draft it would keep a token depending on that token's own continuation, while the rejection test assumes the token is distributed as the q handed to the verifier. In a constructed two-candidate lattice, not a model benchmark, with n_short 1 and long_cost 1.44, a token the target puts at 50% came out 75%. A setup warning says so when DFlash2 drafts probabilistically with n_short set. The step probability on a sampled step is the softmax at the argmax with the target's temperature, the value p_min already reads there. Greedy steps use lattice_argmax_prob, unchanged. (cherry picked from commit cf815be)
The lattice walk computed each transition's softmax probability and kept it in path_p even with --spec-draft-p-min 0 and n_short 0, where nothing reads it. It now computes the probability only for p_min or n_short, and reserves and fills path_p only for n_short. b12032 rebase: b12032's DFlash2 sampling (1ab09d6, ggml-org#30663) needs the softmax on every sampled step, so it is computed whenever sampling, and the greedy probability only for p_min or n_short. The keep rule stays off on a sampled draft (see the lattice draft length commit), so keep_p also requires a greedy draft and nothing trims result_q. (cherry picked from commit 1c349c6)
A DFlash2 draft sampled for rejection sampling was cleared when --spec-draft-p-min stopped it before n_min tokens. Where p_min stops depends on the tokens the walk has already sampled, so the cleared drafts were the ones whose sampled tokens lead to an uncertain step, and the drafts that reached the verifier no longer followed the q handed with them. In the test's lattice the first step is A at 70% and B at 30%, and p_min 0.6 stops every draft that starts with B after one token. With n_min 2, A started all 14071 of the 20000 drafts that reached the verifier instead of 70% of them. With a target that also puts A at 70%, a rejection step at the first position emitted A for 90.97% of 200000 drafts before this change and 69.95% after it. A sampled draft now keeps its prefix at any length, and a greedy draft below n_min is still dropped. result_q was only cleared together with a sampled draft, so that clear goes too. test-dspine runs common_speculative_lattice_walk on that lattice: all 20000 sampled drafts must reach the verifier, A must start 70% +- 2% of them, n_short must not shorten one, and the greedy n_min and n_short cases are unchanged. Before this change the n_min case fails. The clear came with DFlash2 probabilistic drafting upstream (1ab09d6, ggml-org#30663) and is unchanged on master at ded522f. Assisted-by: Claude Code Signed-off-by: Guilherme Gallo <[email protected]>
Overview
This PR is an extension of #27694. This PR adds probabilistic drafter for DFlash2 technique and reuses the same verify-accept-reject logic added in #27694 which is currently on upstream.
Adding some performance data taken over multiple HW running models from different families below:
Performance
RTX 5090
Qwen3.8-27B
Muse-Glimmer-30B
DGX Spark
Qwen3.8-27B
Muse-Glimmer-30B
RTX Pro 6000
Qwen3.8-27B
Muse-Glimmer-30B
Requirements