[Generation] Add static ensemble verification for lossy speculative decoding#45979
Open
kasakh wants to merge 2 commits into
Open
[Generation] Add static ensemble verification for lossy speculative decoding#45979kasakh wants to merge 2 commits into
kasakh wants to merge 2 commits into
Conversation
added 2 commits
May 14, 2026 07:40
…ive decoding Add assistant_ensemble_weight parameter to GenerationConfig that enables static ensemble verification, a training-free method that increases draft token acceptance rates by relaxing the verification distribution. The verification distribution becomes v(x) = w * p(x) + (1-w) * q(x), where w is the ensemble weight. This provably achieves the Pareto-optimal tradeoff between acceptance rate and distributional bias. Changes: - Add assistant_ensemble_weight to GenerationConfig - Modify _speculative_sampling to use ensemble acceptance ratio - Support greedy decoding with argmax(v) in Case 2 - Add error for incompatible candidate generators (no logits) - Add numerical stability guard for fallback distribution Reference: Wang & Kasa et al., "DIVERSED: Relaxed Speculative Decoding via Dynamic Ensemble Verification", AISTATS 2026. https://arxiv.org/abs/2604.07622 Fixes huggingface#45865
Add 8 fast synthetic tests covering: - w=None/w=1.0 equivalence (backward compatibility) - Deterministic acceptance ratio test (w=0.7 accepts where w=1.0 rejects) - Fallback distribution is finite and normalized - Numerical stability with near-zero residual (p approx q) - Greedy ensemble: argmax(v) accepts where argmax(p) rejects - ValueError for missing candidate logits - GenerationConfig round-trip serialization - Default value is None Add documentation section to assisted_decoding.md with usage example.
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45979&sha=6ad3ef |
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.
What does this PR do?
Adds support for static ensemble verification in speculative decoding (assisted generation), a training-free method that increases draft token acceptance rates by relaxing the verification distribution.
Fixes #45865
Motivation
Standard speculative decoding rejects many plausible tokens because it strictly enforces that the output distribution matches the target model. Static ensemble verification blends the target and draft distributions during verification:
This provably achieves the Pareto-optimal tradeoff between acceptance rate and distributional bias (Proposition 1 in the paper). The acceptance probability increases from
1 - TV(q,p)to1 - w*TV(q,p).Changes
assistant_ensemble_weightparameter toGenerationConfig(float in (0, 1], defaultNone= lossless)_speculative_samplingto use ensemble acceptance ratio:v(x)/q(x) = 1 - w + w*(p(x)/q(x))do_sample=False) by comparing againstargmax(v)instead ofargmax(p)assisted_decoding.mdUsage
Design decisions
[v-q]+ = w*[p-q]+normalizes to the same distribution as[p-q]+, we compute the standard fallback directly for numerical stability.1 - w + w*(p_i/q_i)which is algebraically equivalent tov_i/q_ibut avoids constructing the full ensemble distribution.p(target) rather thanv, sinceqat position N+1 is unavailable. This is conservative and documented.do_sample=False, compares draft tokens againstargmax(v)— "greedy under the ensemble verifier."Tests
8 fast synthetic tests (all pass, ~0.15s total):
w=None/w=1.0equivalence (backward compatibility)argmax(v)accepts whereargmax(p)rejectsResults (from the paper)
On CNN/DailyMail with Llama-3.1-8B-Instruct (target) + Llama-3.2-1B-Instruct (draft), temperature=0:
References
cc @Cyrilvallez