[Model] Support Hy3 preview (#40681)

Signed-off-by: stevenkuang <stevenkuang@tencent.com>
Co-authored-by: Jee Jee Li <pandaleefree@gmail.com>
This commit is contained in:
stevenkuang
2026-04-23 22:08:26 +08:00
committed by GitHub
co-authored by Jee Jee Li
parent 424033f4fc
commit d0009ddb0b
16 changed files with 2696 additions and 0 deletions
+5
View File
@@ -324,6 +324,7 @@ _TEXT_GENERATION_EXAMPLE_MODELS = {
"HunYuanMoEV1ForCausalLM": _HfExamplesInfo(
"tencent/Hunyuan-A13B-Instruct", trust_remote_code=True
),
"HYV3ForCausalLM": _HfExamplesInfo("tencent/Hy3-preview", trust_remote_code=True),
"HyperCLOVAXForCausalLM": _HfExamplesInfo(
"naver-hyperclovax/HyperCLOVAX-SEED-Think-14B",
trust_remote_code=True,
@@ -1516,6 +1517,10 @@ _SPECULATIVE_DECODING_EXAMPLE_MODELS = {
is_available_online=False,
min_transformers_version="5.1.0",
),
"HYV3MTPModel": _HfExamplesInfo(
"tencent/Hy3-preview",
speculative_model="tencent/Hy3-preview",
),
"LongCatFlashMTPModel": _HfExamplesInfo(
"meituan-longcat/LongCat-Flash-Chat",
trust_remote_code=True,
@@ -0,0 +1,243 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
from tests.reasoning.utils import run_reasoning_extraction
from vllm.reasoning import ReasoningParser, ReasoningParserManager
from vllm.tokenizers import get_tokenizer
parser_name = "hy_v3"
MODEL = "tencent/Hy3-preview"
@pytest.fixture(scope="module")
def hy_v3_tokenizer():
return get_tokenizer(tokenizer_name=MODEL)
WITH_THINK = {
"output": "This is a reasoning section</think>This is the rest",
"reasoning": "This is a reasoning section",
"content": "This is the rest",
"is_reasoning_end": True,
"reasoning_effort": "high",
}
WITH_THINK_STREAM = {
"output": "This is a reasoning section</think>This is the rest",
"reasoning": "This is a reasoning section",
"content": "This is the rest",
"is_reasoning_end": True,
"reasoning_effort": "high",
}
WITHOUT_THINK = {
"output": "This is the rest",
"reasoning": None,
"content": "This is the rest",
"is_reasoning_end": True,
"reasoning_effort": "no_think",
}
WITHOUT_THINK_STREAM = {
"output": "This is the rest",
"reasoning": None,
"content": "This is the rest",
"is_reasoning_end": True,
"reasoning_effort": "no_think",
}
WITH_REASONING_EFFORT_NONE = {
"output": "This is the rest",
"reasoning": None,
"content": "This is the rest",
"is_reasoning_end": True,
}
WITH_REASONING_EFFORT_NONE_STREAM = {
"output": "This is the rest",
"reasoning": None,
"content": "This is the rest",
"is_reasoning_end": True,
}
COMPLETE_REASONING = {
"output": "This is a reasoning section</think>",
"reasoning": "This is a reasoning section",
"content": None,
"is_reasoning_end": True,
"reasoning_effort": "high",
}
MULTILINE_REASONING = {
"output": "This is a reasoning\nsection</think>This is the rest\nThat",
"reasoning": "This is a reasoning\nsection",
"content": "This is the rest\nThat",
"is_reasoning_end": True,
"reasoning_effort": "high",
}
ONLY_OPEN_TAG = {
"output": "This is a reasoning section",
"reasoning": "This is a reasoning section",
"content": None,
"is_reasoning_end": False,
"reasoning_effort": "high",
}
ONLY_OPEN_TAG_STREAM = {
"output": "This is a reasoning section",
"reasoning": "This is a reasoning section",
"content": None,
"is_reasoning_end": False,
"reasoning_effort": "high",
}
TEST_CASES = [
pytest.param(
False,
WITH_THINK,
id="with_think",
),
pytest.param(
True,
WITH_THINK_STREAM,
id="with_think_stream",
),
pytest.param(
False,
WITHOUT_THINK,
id="without_think",
),
pytest.param(
True,
WITHOUT_THINK_STREAM,
id="without_think_stream",
),
pytest.param(
False,
WITH_REASONING_EFFORT_NONE,
id="with_reasoning_effort_none",
),
pytest.param(
True,
WITH_REASONING_EFFORT_NONE_STREAM,
id="with_reasoning_effort_none_stream",
),
pytest.param(
False,
COMPLETE_REASONING,
id="complete_reasoning",
),
pytest.param(
True,
COMPLETE_REASONING,
id="complete_reasoning_stream",
),
pytest.param(
False,
MULTILINE_REASONING,
id="multiline_reasoning",
),
pytest.param(
True,
MULTILINE_REASONING,
id="multiline_reasoning_stream",
),
pytest.param(
False,
ONLY_OPEN_TAG,
id="only_open_tag",
),
pytest.param(
True,
ONLY_OPEN_TAG_STREAM,
id="only_open_tag_stream",
),
]
STILL_REASONING_PROMPT = """<|hy_begin▁of▁sentence|>
You are a helpful assistant.
<|reasoning_mode|>reasoning_effort:high<|hy_User|>
What is the capital of France?<|hy_Assistant|>
<think>The user is asking for the capital of"""
DONE_REASONING_PROMPT = """<|hy_begin▁of▁sentence|>
You are a helpful assistant.
<|reasoning_mode|>reasoning_effort:high<|hy_User|>
What is the capital of France?<|hy_Assistant|>
<think>The user is asking for the capital of France.</think>
The capital of France is Paris."""
MULTI_TURN_STILL_REASONING_PROMPT = """<|hy_begin▁of▁sentence|>
You are a helpful assistant.
<|reasoning_mode|>reasoning_effort:high<|hy_User|>
What is the capital of France?<|hy_Assistant|
><think></think>The capital of France is Paris.<eos:6124c78e>
<|hy_User|>What about Chile?<|hy_Assistant|>
<think>The user is asking for the capital of"""
MULTI_TURN_DONE_REASONING_PROMPT = """<|hy_begin▁of▁sentence|>
You are a helpful assistant.
<|reasoning_mode|>reasoning_effort:high<|hy_User|>
What is the capital of France?<|hy_Assistant|
><think></think>The capital of France is Paris.<eos:6124c78e>
<|hy_User|>What about Chile?<|hy_Assistant|>
<think>The user is asking for the capital of Chile.</think>
The capital of Chile is Santiago."""
REASONING_END_TEST_CASES = [
pytest.param(STILL_REASONING_PROMPT, False, id="still_reasoning"),
pytest.param(DONE_REASONING_PROMPT, True, id="done_reasoning"),
pytest.param(
MULTI_TURN_STILL_REASONING_PROMPT, False, id="multi_turn_still_reasoning"
),
pytest.param(
MULTI_TURN_DONE_REASONING_PROMPT, True, id="multi_turn_done_reasoning"
),
]
@pytest.mark.parametrize("streaming, param_dict", TEST_CASES)
def test_reasoning(
streaming: bool,
param_dict: dict,
hy_v3_tokenizer,
):
output = hy_v3_tokenizer.tokenize(param_dict["output"])
output_tokens: list[str] = [
hy_v3_tokenizer.convert_tokens_to_string([token]) for token in output
]
parser_kwargs = {}
if "reasoning_effort" in param_dict:
parser_kwargs["chat_template_kwargs"] = {
"reasoning_effort": param_dict["reasoning_effort"]
}
parser: ReasoningParser = ReasoningParserManager.get_reasoning_parser(parser_name)(
hy_v3_tokenizer,
**parser_kwargs,
)
reasoning, content = run_reasoning_extraction(
parser, output_tokens, streaming=streaming
)
assert reasoning == param_dict["reasoning"]
assert content == param_dict["content"]
output_ids = hy_v3_tokenizer.convert_tokens_to_ids(output)
is_reasoning_end = parser.is_reasoning_end(output_ids)
assert is_reasoning_end == param_dict["is_reasoning_end"]
@pytest.mark.parametrize("prompt, is_reasoning_end", REASONING_END_TEST_CASES)
def test_is_reasoning_end_full_prompt(
prompt: str, is_reasoning_end: bool, hy_v3_tokenizer
):
parser: ReasoningParser = ReasoningParserManager.get_reasoning_parser(parser_name)(
hy_v3_tokenizer,
chat_template_kwargs={"reasoning_effort": "high"},
)
tokens = hy_v3_tokenizer.tokenize(prompt)
token_ids = hy_v3_tokenizer.convert_tokens_to_ids(tokens)
check_is_reasoning_end = parser.is_reasoning_end(token_ids)
assert check_is_reasoning_end == is_reasoning_end
@@ -0,0 +1,274 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
# ruff: noqa: E501
"""Tests for the HYV3 tool call parser."""
import json
from unittest.mock import Mock
import pytest
from vllm.entrypoints.openai.chat_completion.protocol import (
ChatCompletionRequest,
ChatCompletionToolsParam,
FunctionDefinition,
)
from vllm.entrypoints.openai.engine.protocol import DeltaMessage
from vllm.tokenizers import get_tokenizer
from vllm.tool_parsers.hy_v3_tool_parser import HYV3ToolParser
parser_name = "hy_v3"
MODEL = "tencent/Hy3-preview"
@pytest.fixture(scope="module")
def hy_v3_tokenizer():
return get_tokenizer(tokenizer_name=MODEL)
@pytest.fixture
def hy_v3_tool_parser(hy_v3_tokenizer):
return HYV3ToolParser(hy_v3_tokenizer)
@pytest.fixture
def mock_request() -> ChatCompletionRequest:
request = Mock(spec=ChatCompletionRequest)
request.tools = [
ChatCompletionToolsParam(
function=FunctionDefinition(name="get_current_date", parameters={}),
),
ChatCompletionToolsParam(
function=FunctionDefinition(
name="get_weather",
parameters={
"type": "object",
"properties": {
"city": {"type": "string"},
"date": {"type": "string"},
},
},
),
),
]
request.tool_choice = "auto"
return request
class TestHYV3ExtractToolCalls:
def test_no_tool_call(self, hy_v3_tool_parser, mock_request):
out = "This is a plain response."
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert not r.tools_called
assert r.content == out
def test_zero_arg_inline(self, hy_v3_tool_parser, mock_request):
out = (
"<tool_calls><tool_call>get_current_date<tool_sep></tool_call></tool_calls>"
)
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert r.tools_called
assert r.tool_calls[0].function.name == "get_current_date"
assert json.loads(r.tool_calls[0].function.arguments) == {}
assert r.content is None
def test_zero_arg_newline(self, hy_v3_tool_parser, mock_request):
out = "<tool_calls>\n<tool_call>get_current_date<tool_sep>\n</tool_call>\n</tool_calls>"
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert r.tools_called
assert r.tool_calls[0].function.name == "get_current_date"
def test_args_same_line(self, hy_v3_tool_parser, mock_request):
out = (
"<tool_calls><tool_call>get_weather<tool_sep><arg_key>city</arg_key><arg_value>Beijing"
"</arg_value><arg_key>date</arg_key><arg_value>2026-03-30</arg_value></tool_call></tool_calls>"
)
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert r.tools_called
assert json.loads(r.tool_calls[0].function.arguments) == {
"city": "Beijing",
"date": "2026-03-30",
}
def test_args_with_newlines(self, hy_v3_tool_parser, mock_request):
out = (
"<tool_calls>\n<tool_call>get_weather<tool_sep>\n<arg_key>city</arg_key>\n<arg_value>Beijing"
"</arg_value>\n<arg_key>date</arg_key>\n<arg_value>2026-03-30</arg_value>\n</tool_call>\n</tool_calls>"
)
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert r.tools_called
assert json.loads(r.tool_calls[0].function.arguments) == {
"city": "Beijing",
"date": "2026-03-30",
}
def test_content_before(self, hy_v3_tool_parser, mock_request):
out = "Checking.<tool_calls>\n<tool_call>get_current_date<tool_sep>\n</tool_call>\n</tool_calls>"
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert r.tools_called
assert r.content == "Checking."
def test_multiple(self, hy_v3_tool_parser, mock_request):
out = (
"<tool_calls>\n<tool_call>get_weather<tool_sep>\n<arg_key>city</arg_key>\n<arg_value>Beijing"
"</arg_value>\n<arg_key>date</arg_key>\n<arg_value>2026-03-30</arg_value>\n</tool_call>\n"
"<tool_call>get_weather<tool_sep>\n<arg_key>city</arg_key>\n<arg_value>Hangzhou</arg_value>\n"
"<arg_key>date</arg_key>\n<arg_value>2026-03-30</arg_value>\n</tool_call>\n</tool_calls>"
)
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert len(r.tool_calls) == 2
def test_empty_content_none(self, hy_v3_tool_parser, mock_request):
out = "<tool_calls>\n<tool_call>get_current_date<tool_sep>\n</tool_call>\n</tool_calls>"
r = hy_v3_tool_parser.extract_tool_calls(out, request=mock_request)
assert r.content is None
def _simulate_streaming(
parser: HYV3ToolParser,
deltas: list[str],
request: ChatCompletionRequest,
) -> list[DeltaMessage | None]:
results: list[DeltaMessage | None] = []
previous_text = ""
previous_token_ids: list[int] = []
vocab = parser.vocab
for delta_text in deltas:
current_text = previous_text + delta_text
delta_token_ids = [tid for tok, tid in vocab.items() if tok in delta_text]
current_token_ids = previous_token_ids + delta_token_ids
result = parser.extract_tool_calls_streaming(
previous_text=previous_text,
current_text=current_text,
delta_text=delta_text,
previous_token_ids=previous_token_ids,
current_token_ids=current_token_ids,
delta_token_ids=delta_token_ids,
request=request,
)
results.append(result)
previous_text = current_text
previous_token_ids = current_token_ids
return results
def _collect_streaming_tool_calls(results: list[DeltaMessage | None]) -> list[dict]:
tool_calls: dict[int, dict] = {}
for result in results:
if result is None or not result.tool_calls:
continue
for tc in result.tool_calls:
idx = tc.index
if idx not in tool_calls:
tool_calls[idx] = {
"name": tc.function.name or "",
"arguments": tc.function.arguments or "",
}
else:
if tc.function.name:
tool_calls[idx]["name"] += tc.function.name
if tc.function.arguments:
tool_calls[idx]["arguments"] += tc.function.arguments
return [tool_calls[i] for i in sorted(tool_calls.keys())]
def _collect_streaming_content(results: list[DeltaMessage | None]) -> str:
parts = []
for result in results:
if result is not None and result.content:
parts.append(result.content)
return "".join(parts)
class TestHYV3ExtractToolCallsStreaming:
def test_no_tool_call_streaming(self, hy_v3_tool_parser, mock_request):
deltas = ["This is ", "a plain ", "response."]
results = _simulate_streaming(hy_v3_tool_parser, deltas, mock_request)
content = _collect_streaming_content(results)
assert content == "This is a plain response."
assert len(_collect_streaming_tool_calls(results)) == 0
def test_zero_arg_streaming(self, hy_v3_tool_parser, mock_request):
deltas = [
"<tool_calls>",
"\n<tool_call>",
"get_current_date",
"<tool_sep>",
"\n</tool_call>",
"\n</tool_calls>",
]
results = _simulate_streaming(hy_v3_tool_parser, deltas, mock_request)
tc = _collect_streaming_tool_calls(results)
assert len(tc) == 1
assert tc[0]["name"] == "get_current_date"
assert json.loads(tc[0]["arguments"]) == {}
def test_args_streaming(self, hy_v3_tool_parser, mock_request):
deltas = [
"<tool_calls>",
"\n<tool_call>",
"get_weather",
"<tool_sep>",
"\n<arg_key>city</arg_key>",
"\n<arg_value>Beijing</arg_value>",
"\n<arg_key>date</arg_key>",
"\n<arg_value>2026-03-30</arg_value>",
"\n</tool_call>",
"\n</tool_calls>",
]
results = _simulate_streaming(hy_v3_tool_parser, deltas, mock_request)
tc = _collect_streaming_tool_calls(results)
assert len(tc) == 1 and tc[0]["name"] == "get_weather"
assert json.loads(tc[0]["arguments"]) == {
"city": "Beijing",
"date": "2026-03-30",
}
def test_content_before_streaming(self, hy_v3_tool_parser, mock_request):
deltas = [
"Checking.",
"<tool_calls>",
"\n<tool_call>",
"get_current_date",
"<tool_sep>",
"\n</tool_call>",
"\n</tool_calls>",
]
results = _simulate_streaming(hy_v3_tool_parser, deltas, mock_request)
assert "Checking." in _collect_streaming_content(results)
tc = _collect_streaming_tool_calls(results)
assert len(tc) == 1 and tc[0]["name"] == "get_current_date"
def test_multiple_streaming(self, hy_v3_tool_parser, mock_request):
deltas = [
"<tool_calls>",
"\n<tool_call>",
"get_weather",
"<tool_sep>",
"\n<arg_key>city</arg_key>",
"\n<arg_value>Beijing</arg_value>",
"\n<arg_key>date</arg_key>",
"\n<arg_value>2026-03-30</arg_value>",
"\n</tool_call>",
"\n<tool_call>",
"get_weather",
"<tool_sep>",
"\n<arg_key>city</arg_key>",
"\n<arg_value>Hangzhou</arg_value>",
"\n<arg_key>date</arg_key>",
"\n<arg_value>2026-03-30</arg_value>",
"\n</tool_call>",
"\n</tool_calls>",
]
results = _simulate_streaming(hy_v3_tool_parser, deltas, mock_request)
tc = _collect_streaming_tool_calls(results)
assert len(tc) == 2
assert json.loads(tc[0]["arguments"])["city"] == "Beijing"
assert json.loads(tc[1]["arguments"])["city"] == "Hangzhou"
def test_all_in_one_delta_streaming(self, hy_v3_tool_parser, mock_request):
out = "<tool_calls>\n<tool_call>get_current_date<tool_sep>\n</tool_call>\n</tool_calls>"
results = _simulate_streaming(hy_v3_tool_parser, [out], mock_request)
tc = _collect_streaming_tool_calls(results)
assert len(tc) == 1 and tc[0]["name"] == "get_current_date"
assert json.loads(tc[0]["arguments"]) == {}