Support suppress_tokens / begin_suppress_tokens (HF generation parity)#2207
Draft
Copilot wants to merge 4 commits into
Draft
Support suppress_tokens / begin_suppress_tokens (HF generation parity)#2207Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
Copilot
AI
changed the title
[WIP] Add support for suppress_tokens and begin_suppress_tokens
Support suppress_tokens / begin_suppress_tokens (HF generation parity)
Jun 9, 2026
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.
onnxruntime-genaihad no way to suppress specific token IDs during generation, so output diverged fromtransformers.generate()for models that depend onsuppress_tokens/begin_suppress_tokens(e.g. Whisper, Gemma). These options were neither parsed from config nor applied as logits processors.This adds static per-token suppression mirroring HF's
SuppressTokensLogitsProcessorandSuppressTokensAtBeginLogitsProcessor:config.h/config.cpp): newsuppress_tokens/begin_suppress_tokensint-array fields onConfig::Search, parsed via a newSearch_Element::OnArray.search.h,search.cpp,cuda/search_cuda.cpp): newSearch::ApplySuppressTokensvirtual, implemented for CPU and CUDA, setting targeted logits tofloatlowest — following the existingApplyMinLength/ApplyRepetitionPenaltypattern.generators.cpp,engine/request.cpp):suppress_tokensapplied every step;begin_suppress_tokensonly whencurrent_length == prompt_length. Wired into both the standaloneGeneratorloop and the batchingEnginerequest loop.OgaGeneratorParamsSetSearchTokensArray+ C++ wrapper; Pythonset_search_options(...)now acceptslist[int].builders/base.py,builders/whisper.py): auto-populates both fromgeneration_config.json/ model config via a sharedModel.add_suppress_tokens_to_search_confighelper, so existing HF models work without manual config edits.bad_words_ids(multi-token sequence banning), listed as optional in the issue, is intentionally out of scope here.Note on concurrency
The begin-step is tracked via a per-object length member, mutated non-atomically — consistent with the existing single-threaded-per-
Generator/Requestdesign (cf.computed_logits_,is_prefill_). No synchronization added.