[Frontend] Support strict MiMo-V2.6 tool calling (#58019)
Co-authored-by: Codex <noreply@openai.com> Co-authored-by: yuchuan <yuchuan.7streams@gmail.com> Co-authored-by: Bugen Zhao <i@bugenzhao.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Ubospica <ubospica@gmail.com> Signed-off-by: yuchuan <yuchuan.7streams@gmail.com> Signed-off-by: Bugen Zhao <i@bugenzhao.com>
This commit is contained in:
co-authored by
Codex
yuchuan
Bugen Zhao
Claude Opus 5.5
parent
79a0307d74
commit
dfc8e0f3e2
@@ -17,6 +17,7 @@ from vllm.parser.granite import GraniteParser
|
||||
from vllm.parser.granite_thinking import GraniteThinkingParser
|
||||
from vllm.parser.inkling import InklingParser
|
||||
from vllm.parser.kimi_k2 import KimiK2Parser
|
||||
from vllm.parser.mimo import MiMoParser
|
||||
from vllm.parser.minimax_m2 import MinimaxM2Parser
|
||||
from vllm.parser.mistral import MistralParser
|
||||
from vllm.parser.nemotron_v3 import NemotronV3Parser
|
||||
@@ -69,6 +70,11 @@ from vllm.parser.seed_oss import SeedOssParser
|
||||
Qwen3ParserToolAdapter,
|
||||
) = make_adapters(Qwen3Parser)
|
||||
|
||||
(
|
||||
MiMoParserReasoningAdapter,
|
||||
MiMoParserToolAdapter,
|
||||
) = make_adapters(MiMoParser)
|
||||
|
||||
(
|
||||
SeedOssParserReasoningAdapter,
|
||||
SeedOssParserToolAdapter,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""MiMo's compact XML parameters contain verbatim string values."""
|
||||
|
||||
import json
|
||||
from dataclasses import replace
|
||||
|
||||
from vllm.parser.qwen3 import (
|
||||
_PARAM_RE,
|
||||
_PARTIAL_PARAM_RE,
|
||||
CHATML_TURN_BOUNDARIES,
|
||||
Qwen3Parser,
|
||||
qwen3_config,
|
||||
)
|
||||
|
||||
|
||||
def _mimo_arg_converter(raw_args: str, partial: bool) -> str:
|
||||
params = {m.group(1): m.group(2) for m in _PARAM_RE.finditer(raw_args)}
|
||||
if partial:
|
||||
match = _PARTIAL_PARAM_RE.search(_PARAM_RE.sub("", raw_args))
|
||||
if match and match.group(1):
|
||||
params[match.group(1)] = match.group(2)
|
||||
return json.dumps(params, ensure_ascii=False)
|
||||
|
||||
|
||||
class MiMoParser(Qwen3Parser):
|
||||
def __init__(self, tokenizer, tools=None, **kwargs):
|
||||
thinking = (kwargs.get("chat_template_kwargs") or {}).get(
|
||||
"enable_thinking", True
|
||||
)
|
||||
kwargs.setdefault(
|
||||
"parser_engine_config",
|
||||
replace(
|
||||
qwen3_config(
|
||||
thinking=thinking,
|
||||
name="mimo",
|
||||
turn_boundary_tokens=CHATML_TURN_BOUNDARIES,
|
||||
),
|
||||
arg_converter=_mimo_arg_converter,
|
||||
),
|
||||
)
|
||||
super().__init__(tokenizer, tools, **kwargs)
|
||||
@@ -109,8 +109,8 @@ _REASONING_PARSERS_TO_REGISTER = {
|
||||
"K2HorizonReasoningParser",
|
||||
),
|
||||
"mimo": (
|
||||
"qwen3_engine_reasoning_parser",
|
||||
"Qwen3ParserReasoningAdapter",
|
||||
"mimo_engine_reasoning_parser",
|
||||
"MiMoParserReasoningAdapter",
|
||||
),
|
||||
"minimax_m2": (
|
||||
"minimax_m2_reasoning_parser",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from vllm.parser.engine.registered_adapters import MiMoParserReasoningAdapter
|
||||
|
||||
__all__ = ["MiMoParserReasoningAdapter"]
|
||||
@@ -143,8 +143,8 @@ _TOOL_PARSERS_TO_REGISTER = {
|
||||
"LongcatFlashToolParser",
|
||||
),
|
||||
"mimo": (
|
||||
"qwen3_engine_tool_parser",
|
||||
"Qwen3EngineToolParser",
|
||||
"mimo_tool_parser",
|
||||
"MiMoToolParser",
|
||||
),
|
||||
"minimax_m2": (
|
||||
"minimax_m2_tool_parser",
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from xgrammar.structural_tag import TriggeredTagsFormat
|
||||
|
||||
from vllm.parser.engine.registered_adapters import MiMoParserToolAdapter
|
||||
from vllm.tool_parsers.tool_strict_level import ToolStrictLevel
|
||||
|
||||
|
||||
class MiMoToolParser(MiMoParserToolAdapter): # type: ignore[valid-type, misc]
|
||||
structural_tag_model = "mimo"
|
||||
|
||||
def get_structural_tag(
|
||||
self, request, *, reasoning=False, strict_level=ToolStrictLevel.AUTO
|
||||
):
|
||||
tag = super().get_structural_tag(
|
||||
request, reasoning=reasoning, strict_level=strict_level
|
||||
)
|
||||
if (
|
||||
tag is not None
|
||||
and request.parallel_tool_calls is False
|
||||
and isinstance(tag.format, TriggeredTagsFormat)
|
||||
):
|
||||
tag.format.stop_after_first = True
|
||||
return tag
|
||||
@@ -66,6 +66,7 @@ XGRAMMAR_BUILTIN_STRUCTURAL_TAG_MODELS = frozenset(
|
||||
"deepseek_v3_1",
|
||||
"qwen_3_5",
|
||||
"qwen_3_coder",
|
||||
"mimo",
|
||||
"qwen_3",
|
||||
"deepseek_v3_2",
|
||||
"glm_4_7",
|
||||
|
||||
Reference in New Issue
Block a user