Fix guided generation: include <|endoftext|> as stop token#117
Merged
Conversation
stikves
force-pushed
the
fix/endoftext-stop-token
branch
from
July 20, 2026 18:41
e46255c to
0af57a8
Compare
stikves
marked this pull request as ready for review
July 21, 2026 19:27
stikves
requested review from
alejandro-isaza,
carinapeng,
kevchengcodes and
tjia1818
and removed request for
alejandro-isaza
July 21, 2026 19:27
…xt|> Two fixes for the same bug (defense in depth): 1. When the grammar session terminates (isTerminated), return nil immediately instead of emitting the terminal token's decoded text. This prevents ANY special token from leaking into structured output, regardless of whether it's in the stop sequences list. 2. Add 'endoftext' to turnEndPatterns so <|endoftext|> (token 151643) is picked up from added_tokens_decoder as an additional stop token. Qwen3 declares eos_token as <|im_end|> (151645) but xgrammar can also produce <|endoftext|> as a valid grammar terminal.
stikves
force-pushed
the
fix/endoftext-stop-token
branch
from
July 21, 2026 19:30
fe08dc7 to
30ec088
Compare
alejandro-isaza
approved these changes
Jul 21, 2026
kevchengcodes
approved these changes
Jul 21, 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.
Qwen3 models declare
eos_tokenas<|im_end|>(151645) but the grammar (xgrammar) can also produce<|endoftext|>(151643) as a valid terminal. Since 151643 wasn't in the stop sequences, it passed through to the output as literal text, corrupting structured generation results.Add 'endoftext' to the turnEndPatterns so it's picked up from
added_tokens_decoderalongsideim_end,end_of_turn, andeot_id.