Repository navigation
[Generation] Fix target logit mapping in universal speculative decoding with pruned LM head - #50695
Open
aarushdubey wants to merge 2 commits into
Open
aarushdubey wants to merge 2 commits into
aarushdubey wants to merge 2 commits into
Conversation
added 2 commits
November 13, 2026 13:39
…d LM head When the assistant tokenizer vocabulary dictionary order does not match ascending token-ID order, initializing assistant_overlap_token_ids from dict values scrambled logits in get_target_logits. Use torch.where over _assistant_to_target_input_ids to ensure strict ascending token-ID ordering matching target_logits_supported_indices. Add regression test in test_candidate_generator.py. Fixes huggingface#50598. Signed-off-by: Aarush Dubey <120536707+aarushdubey@users.noreply.github.com>
Signed-off-by: Aarush Dubey <120536707+aarushdubey@users.noreply.github.com>
This branch has not been deployed
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?
Fixes #50598
Background & Problem
In universal speculative decoding with assistant LM head pruning enabled (
assistant_prune_lm_head=True),AssistantToTargetTranslatorprunes the assistant LM head usingself.assistant_overlap_token_ids:self.target_to_assistant_input_idsis constructed by iterating throughassistant_vocab.items(). When an assistant tokenizer's dictionary order does not match ascending token-ID order (which frequently occurs with fast tokenizers or serialized tokenizers),self.assistant_overlap_token_idsfollows dictionary key insertion order rather than sorted token ID order.However, in
get_target_logits:target_logits_supported_indicesassumesassistant_logitsis ordered by ascending assistant token ID (torch.where(assistant_indices_mask)[0]).When
self.assistant_overlap_token_idsis ordered by dictionary insertion, the pruned LM head produces logits in dictionary order whileget_target_logitsmaps them as if they were in token ID order, scrambling logits across target tokens. Consequently, candidate verification in speculative decoding evaluates candidate tokens using incorrect probabilities.Fix
Initialize
self.assistant_overlap_token_idsdirectly viatorch.where:This guarantees
self.assistant_overlap_token_idsstrictly follows ascending assistant token IDs, aligning 1:1 withassistant_indices_maskandtarget_logits_supported_indicesregardless of tokenizer vocabulary dictionary order.Changes
self.assistant_overlap_token_idsinitialization inAssistantToTargetTranslator(src/transformers/generation/candidate_generator.py).test_pruned_lm_head_unordered_vocabintests/generation/test_candidate_generator.py.pytest tests/generation/test_candidate_generator.py(14/14 passed),ruff check, andpython utils/check_copies.py.Before submitting