Repository navigation
fix: hide unverified draft tokens from logits processors - #2399
Open
Syedmudassir1604 wants to merge 1 commit into
Open
Syedmudassir1604 wants to merge 1 commit into
Syedmudassir1604 wants to merge 1 commit into
Conversation
Speculative decoding evaluates draft tokens before they are accepted, so custom logits processors observed those tokens in input_ids. Pass only the prompt plus tokens up to the position being sampled. With no draft model the prefix is still the full evaluated sequence, and the processor receives that same array. Co-authored-by: Syed Mudassir <Syedmudassir1604@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.
Summary
Logits processors used during speculative decoding received unverified draft tokens inside
input_ids.generate()evaluates the accepted token and the draft block together, and the custom sampler passed that whole buffer through on every position. Processors that depend on position or prefix (includingMinTokensLogitsProcessor) therefore disagreed with greedy decoding without a draft model. Reported in #2393.The sampler callback now sees the prompt plus tokens up to and including the position being sampled. When that prefix is already the full evaluated sequence, the processor receives that same array. No callback is installed when
logits_processoris omitted.Fixes #2393
Test plan
make lint(ruff 0.17.3, 88 columns)pytest tests/test_speculative_logits_processor.py tests/test_llama_speculative.pypytest tests/test_llama.py::test_llama_cpp_version tests/test_llama.py::test_llama_cpp_tokenizationinput_idswhen adraft_model(prompt lookup) is used #2393 repro on CPU, Python 3.12.3, gcc 13.3.0,stories260K.gguf: with prompt lookup, processor calls whose prefix differed from the prompt plus accepted tokens went from 25 to 0, rule violations from 3 to 0, and greedy outputs match the no-draft run. The no-processor control still matches.make test(remaining cases need larger GGUF downloads)