[Bugfix] Support MistralCommonBackend tokenizers in structured output (#52720)

Signed-off-by: Thanh Phan <thanhphantuan1110@gmail.com>
This commit is contained in:
Thanh Phan
2026-08-20 19:08:50 +01:00
committed by GitHub
parent 7c8b68b9ce
commit d56bbf3995
3 changed files with 118 additions and 2 deletions
+13
View File
@@ -14,6 +14,7 @@ from typing import TYPE_CHECKING, TypeVar
import regex as re
import torch
from cachetools import LRUCache
from transformers import MistralCommonBackend
import vllm.envs as envs
from vllm.logger import init_logger
@@ -305,6 +306,18 @@ re_llama_byte_token = re.compile(r"^<0x[0-9A-F]{2}>$")
re_replacement_seq = re.compile(r"^.{0,6}�+.{0,6}$")
def maybe_wrap_mistral_common_tokenizer(tokenizer: TokenizerLike) -> TokenizerLike:
"""The grammar backends cannot consume a `MistralCommonBackend` directly."""
if not isinstance(tokenizer, MistralCommonBackend):
return tokenizer
# Deferred: `vllm.tokenizers.mistral` pulls in a large dependency tree, and
# this module is imported by `vllm.v1.worker.gpu_model_runner`.
from vllm.tokenizers.mistral import MistralTokenizer
return MistralTokenizer(tokenizer)
def _reduced_vocabulary(tokenizer: TokenizerLike) -> dict[bytes, list[int]]:
"""Create a map from vocabulary tokens to lists of equivalent token ids.