Skip to content

fix: hide unverified draft tokens from logits processors - #2399

Open
Syedmudassir1604 wants to merge 1 commit into
abetlen:mainfrom
Syedmudassir1604:cursor/fix-speculative-logits-processor-35a4
Open

Syedmudassir1604 wants to merge 1 commit into
abetlen:mainfrom
Syedmudassir1604:cursor/fix-speculative-logits-processor-35a4

Conversation

@Syedmudassir1604

Copy link
Copy Markdown

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 (including MinTokensLogitsProcessor) 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_processor is omitted.

Fixes #2393

Test plan

  • make lint (ruff 0.17.3, 88 columns)
  • pytest tests/test_speculative_logits_processor.py tests/test_llama_speculative.py
  • pytest tests/test_llama.py::test_llama_cpp_version tests/test_llama.py::test_llama_cpp_tokenization
  • Issue Logits processors receive unverified draft tokens in input_ids when a draft_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.
  • Full make test (remaining cases need larger GGUF downloads)

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logits processors receive unverified draft tokens in input_ids when a draft_model (prompt lookup) is used

2 participants