| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """MiMo's compact XML parameters contain verbatim string values.""" |
| 4 | |
| 5 | import json |
| 6 | from dataclasses import replace |
| 7 | |
| 8 | from vllm.parser.qwen3 import ( |
| 9 | _PARAM_RE, |
| 10 | _PARTIAL_PARAM_RE, |
| 11 | CHATML_TURN_BOUNDARIES, |
| 12 | Qwen3Parser, |
| 13 | qwen3_config, |
| 14 | ) |
| 15 | |
| 16 | |
| 17 | def _mimo_arg_converter(raw_args: str, partial: bool) -> str: |
| 18 | params = {m.group(1): m.group(2) for m in _PARAM_RE.finditer(raw_args)} |
| 19 | if partial: |
| 20 | match = _PARTIAL_PARAM_RE.search(_PARAM_RE.sub("", raw_args)) |
| 21 | if match and match.group(1): |
| 22 | params[match.group(1)] = match.group(2) |
| 23 | return json.dumps(params, ensure_ascii=False) |
| 24 | |
| 25 | |
| 26 | class MiMoParser(Qwen3Parser): |
| 27 | def __init__(self, tokenizer, tools=None, **kwargs): |
| 28 | thinking = (kwargs.get("chat_template_kwargs") or {}).get( |
| 29 | "enable_thinking", True |
| 30 | ) |
| 31 | kwargs.setdefault( |
| 32 | "parser_engine_config", |
| 33 | replace( |
| 34 | qwen3_config( |
| 35 | thinking=thinking, |
| 36 | name="mimo", |
| 37 | turn_boundary_tokens=CHATML_TURN_BOUNDARIES, |
| 38 | ), |
| 39 | arg_converter=_mimo_arg_converter, |
| 40 | ), |
| 41 | ) |
| 42 | super().__init__(tokenizer, tools, **kwargs) |