Support Hy4-preview (#36805)

Co-authored-by: BBuf <1182563586@qq.com>
Co-authored-by: alphabetc1 <2508695655@qq.com>
This commit is contained in:
Xinyuan Tong
2026-09-04 18:03:49 -07:00
committed by GitHub
co-authored by BBuf alphabetc1
parent 85da5457de
commit 55bf3380e0
47 changed files with 3387 additions and 103 deletions
@@ -0,0 +1,43 @@
import sys
import pytest
from sglang.srt.entrypoints.openai.protocol import ChatCompletionRequest
from sglang.srt.parser.hunyuan_reasoning import normalize_hunyuan_reasoning_effort
from sglang.srt.parser.template_detection import ReasoningToggleConfig
from sglang.test.ci.ci_register import register_cpu_ci
register_cpu_ci(est_time=1, suite="base-a-test-cpu")
@pytest.mark.parametrize(
("effort", "normalized"),
[
(None, "high"),
("none", "no_think"),
("minimal", "low"),
("low", "low"),
("medium", "high"),
("high", "high"),
("xhigh", "high"),
("max", "high"),
],
)
def test_hunyuan_reasoning_effort_normalization(effort, normalized):
request = ChatCompletionRequest(
model="x",
messages=[{"role": "user", "content": "hi"}],
reasoning_effort=effort,
)
normalize_hunyuan_reasoning_effort(
request,
reasoning_parser="hunyuan",
reasoning_config=ReasoningToggleConfig(special_case="hunyuan_effort"),
)
assert request.reasoning_effort == normalized
if __name__ == "__main__":
sys.exit(pytest.main([__file__]))
@@ -269,6 +269,42 @@ class TestTemplateManagerReasoningDetection(unittest.TestCase):
_, _, parser = self._detect(template, ["<minimax:tool_call>"])
self.assertEqual(parser, "minimax")
HYV4_TEMPLATE = (
"{%- set reasoning_mode_token = '<|reasoning_mode:opensource|>' %}\n"
"{%- if not reasoning_effort is defined %}\n"
" {%- set reasoning_effort = 'high' %}\n"
"{%- elif reasoning_effort not in ['high', 'low', 'no_think'] %}\n"
"{%- endif %}\n"
"<tool_call:opensource>{{ name }}<arg_key:opensource>{{ k }}</arg_key:opensource>"
)
HYV4_VOCAB = [
"<tool_calls:opensource>",
"<tool_call:opensource>",
"<arg_key:opensource>",
"<arg_value:opensource>",
]
def test_hyv4_effort_template_detected_with_special_case(self):
# Hy4 drops <tool_sep>; detection must key on the effort-mode template
# signature plus the suffixed arg tokens instead.
force, config, parser = self._detect(self.HYV4_TEMPLATE, self.HYV4_VOCAB)
self.assertEqual(config, ReasoningToggleConfig(special_case="hunyuan_effort"))
self.assertEqual(parser, "hunyuan")
self.assertEqual(
detect_tool_call_parser(
self.HYV4_TEMPLATE, _DummyTokenizer(self.HYV4_VOCAB), config, force
),
"hunyuan",
)
def test_hyv4_template_without_arg_tokens_not_hunyuan(self):
_, config, parser = self._detect(self.HYV4_TEMPLATE, ["<tool_call:opensource>"])
self.assertEqual(config, ReasoningToggleConfig(special_case="hunyuan_effort"))
self.assertNotEqual(parser, "hunyuan")
class TestTemplateDetectionRuleMatrix(unittest.TestCase):
"""Table-driven tests for REASONING_PARSER_RULES and REASONING_MODE_RULES."""