[Grammar][Fix] Pass in stop tokens to xgrammar TokenizerInfo #642
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.
Prior to this PR, using models such as SmolLM, which has
<|endoftext|>
as an unk token and<|im_end|>
as a stop token, runs into issues with XGrammar. This is because XGrammar has a builtin set of stop tokens, which includes<|endoftext|>
but not<|im_end|>
. This results in, at the end of a structured generation,<|endoftext|>
is forced to be generated (as it is the only stop token recognized), but since it is not an actual stop token, the generation of the model does not stop.This PR explicitly passes in the stop tokens (recognized from
mlc-chat-config.json
) tocreateTokenizerInfo()
so we do not use the built-in set of stop tokens. In the case above,<|im_end|>
will be the only stop token used by XGrammar, fixing the issue. It achieves a similar goal to XGrammar's PR mlc-ai/xgrammar#96