[Bugfix] Ensure special tokens are properly filtered out for guided structured output with MistralTokenizer #10363
+17
−6
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.
This PR improves the support of the vllm
MistralTokenizer
with the guided structured output functionalities.In particular:
lm-format-enforcer
is bumped to the latest version, so it includes the support of the vllm MistralTokenizer (feat: add support for vLLM Mistral Tokenizer noamgat/lm-format-enforcer#142)MistralTokenizer
methods leveraged by the structured output libraries are now properly populated so that the list of possible tokens generated based on the chosen grammar/constraints (e.g.:json
output) correctly filters out the special tokens. Note that this problem was present before, but masked by the fact that the special tokens were automatically filtered out of the conversion from ids to string: the recent vllm support for automatic mistral tool parsing allowed to reveal the bug (also see this comment #10333). As a benefit, this should also make the structured output generation by Mistral models more reliable.cc: @patrickvonplaten
Example: code that would break without this PR but passes with it