[Frontend] Port seed_oss to the streaming parser engine as a Qwen3 subclass (#46314)
Signed-off-by: EazyReal <8047065+EazyReal@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,7 @@ from vllm.parser.glm47_moe import Glm47MoeParser
|
||||
from vllm.parser.minimax_m2 import MinimaxM2Parser
|
||||
from vllm.parser.nemotron_v3 import NemotronV3Parser
|
||||
from vllm.parser.qwen3 import Qwen3Parser
|
||||
from vllm.parser.seed_oss import SeedOssParser
|
||||
|
||||
(
|
||||
MinimaxM2ParserReasoningAdapter,
|
||||
@@ -34,6 +35,11 @@ from vllm.parser.qwen3 import Qwen3Parser
|
||||
Qwen3ParserToolAdapter,
|
||||
) = make_adapters(Qwen3Parser)
|
||||
|
||||
(
|
||||
SeedOssParserReasoningAdapter,
|
||||
SeedOssParserToolAdapter,
|
||||
) = make_adapters(SeedOssParser)
|
||||
|
||||
(
|
||||
Glm47MoeParserReasoningAdapter,
|
||||
Glm47MoeParserToolAdapter,
|
||||
|
||||
+40
-13
@@ -38,6 +38,8 @@ if TYPE_CHECKING:
|
||||
from vllm.tokenizers import TokenizerLike
|
||||
from vllm.tool_parsers.abstract_tool_parser import Tool
|
||||
|
||||
THINK_START = "<think>"
|
||||
THINK_END = "</think>"
|
||||
TOOL_CALL_START = "<tool_call>"
|
||||
TOOL_CALL_END = "</tool_call>"
|
||||
FUNC_PREFIX = "<function="
|
||||
@@ -75,17 +77,25 @@ def _qwen3_arg_converter(raw_args: str, partial: bool) -> str:
|
||||
|
||||
|
||||
@functools.cache
|
||||
def qwen3_config(thinking: bool = True) -> ParserEngineConfig:
|
||||
def qwen3_config(
|
||||
thinking: bool = True,
|
||||
*,
|
||||
name: str = "qwen3",
|
||||
think_start: str = THINK_START,
|
||||
think_end: str = THINK_END,
|
||||
tool_start: str = TOOL_CALL_START,
|
||||
tool_end: str = TOOL_CALL_END,
|
||||
) -> ParserEngineConfig:
|
||||
return ParserEngineConfig(
|
||||
name="qwen3",
|
||||
name=name,
|
||||
initial_state=ParserState.REASONING if thinking else ParserState.CONTENT,
|
||||
terminals={
|
||||
# Reasoning terminals
|
||||
"THINK_START": "<think>",
|
||||
"THINK_END": "</think>",
|
||||
"THINK_START": think_start,
|
||||
"THINK_END": think_end,
|
||||
# Tool call terminals
|
||||
"TOOL_START": TOOL_CALL_START,
|
||||
"TOOL_END": TOOL_CALL_END,
|
||||
"TOOL_START": tool_start,
|
||||
"TOOL_END": tool_end,
|
||||
"FUNC_PREFIX": FUNC_PREFIX,
|
||||
"FUNC_END": FUNC_END,
|
||||
"PARAM_START": PARAM_START,
|
||||
@@ -93,10 +103,10 @@ def qwen3_config(thinking: bool = True) -> ParserEngineConfig:
|
||||
"CLOSE_ANGLE": ">",
|
||||
},
|
||||
token_id_terminals={
|
||||
"THINK_START": "<think>",
|
||||
"THINK_END": "</think>",
|
||||
"TOOL_START": TOOL_CALL_START,
|
||||
"TOOL_END": TOOL_CALL_END,
|
||||
"THINK_START": think_start,
|
||||
"THINK_END": think_end,
|
||||
"TOOL_START": tool_start,
|
||||
"TOOL_END": tool_end,
|
||||
},
|
||||
transitions={
|
||||
# -- Reasoning transitions --
|
||||
@@ -185,8 +195,18 @@ class Qwen3Parser(ParserEngine):
|
||||
|
||||
- ``<tool_call>`` as implicit reasoning end
|
||||
- Unpaired ``<tool_call>`` token ID detection for ``is_reasoning_end``
|
||||
|
||||
Subclasses that share the grammar but differ only in the four wrapper
|
||||
token strings (reasoning + tool-call) override the class attributes
|
||||
below; everything else is inherited unchanged.
|
||||
"""
|
||||
|
||||
CONFIG_NAME = "qwen3"
|
||||
THINK_START = THINK_START
|
||||
THINK_END = THINK_END
|
||||
TOOL_START = TOOL_CALL_START
|
||||
TOOL_END = TOOL_CALL_END
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
tokenizer: TokenizerLike,
|
||||
@@ -197,7 +217,14 @@ class Qwen3Parser(ParserEngine):
|
||||
self.thinking_enabled = chat_kwargs.get("enable_thinking", True)
|
||||
kwargs.setdefault(
|
||||
"parser_engine_config",
|
||||
qwen3_config(thinking=self.thinking_enabled),
|
||||
qwen3_config(
|
||||
thinking=self.thinking_enabled,
|
||||
name=self.CONFIG_NAME,
|
||||
think_start=self.THINK_START,
|
||||
think_end=self.THINK_END,
|
||||
tool_start=self.TOOL_START,
|
||||
tool_end=self.TOOL_END,
|
||||
),
|
||||
)
|
||||
super().__init__(
|
||||
tokenizer,
|
||||
@@ -205,8 +232,8 @@ class Qwen3Parser(ParserEngine):
|
||||
**kwargs,
|
||||
)
|
||||
vocab = self.vocab
|
||||
self._tool_call_token_id: int | None = vocab.get("<tool_call>")
|
||||
self._tool_call_end_token_id: int | None = vocab.get("</tool_call>")
|
||||
self._tool_call_token_id: int | None = vocab.get(self.TOOL_START)
|
||||
self._tool_call_end_token_id: int | None = vocab.get(self.TOOL_END)
|
||||
|
||||
def extract_reasoning(
|
||||
self,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""seed_oss parser for tool calls and reasoning.
|
||||
|
||||
seed_oss shares the Qwen3 XML grammar exactly; only the four wrapper
|
||||
token strings differ::
|
||||
|
||||
<think> -> <seed:think>
|
||||
</think> -> </seed:think>
|
||||
<tool_call> -> <seed:tool_call>
|
||||
</tool_call> -> </seed:tool_call>
|
||||
|
||||
``<function=...>`` and ``<parameter=...>`` are byte-identical, so the
|
||||
entire transition table and ``_qwen3_arg_converter`` are inherited from
|
||||
:class:`Qwen3Parser` unchanged.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from vllm.parser.qwen3 import Qwen3Parser
|
||||
|
||||
|
||||
class SeedOssParser(Qwen3Parser):
|
||||
CONFIG_NAME = "seed_oss"
|
||||
THINK_START = "<seed:think>"
|
||||
THINK_END = "</seed:think>"
|
||||
TOOL_START = "<seed:tool_call>"
|
||||
TOOL_END = "</seed:tool_call>"
|
||||
Reference in New Issue
Block a user