[Bugfix] Avoid mutating chat_template_kwargs in HYV3ReasoningParser initialization (#40713)

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Bugen Zhao
2026-04-24 13:08:58 +08:00
committed by GitHub
parent 100c7b65e7
commit c662b4359e
2 changed files with 37 additions and 2 deletions
@@ -4,6 +4,7 @@ import pytest
from tests.reasoning.utils import run_reasoning_extraction
from vllm.reasoning import ReasoningParser, ReasoningParserManager
from vllm.reasoning.hy_v3_reasoning_parser import HYV3ReasoningParser
from vllm.tokenizers import get_tokenizer
parser_name = "hy_v3"
@@ -241,3 +242,33 @@ def test_is_reasoning_end_full_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
def test_constructor_does_not_mutate_shared_chat_template_kwargs(hy_v3_tokenizer):
parser_cls = ReasoningParserManager.get_reasoning_parser(parser_name)
chat_template_kwargs = {"reasoning_effort": "low"}
first_parser: ReasoningParser = parser_cls(
hy_v3_tokenizer,
chat_template_kwargs=chat_template_kwargs,
)
second_parser: ReasoningParser = parser_cls(
hy_v3_tokenizer,
chat_template_kwargs=chat_template_kwargs,
)
assert chat_template_kwargs == {"reasoning_effort": "low"}
assert isinstance(first_parser, HYV3ReasoningParser)
assert isinstance(second_parser, HYV3ReasoningParser)
assert first_parser._identity_parser is None
assert second_parser._identity_parser is None
def test_constructor_falls_back_to_outer_reasoning_effort(hy_v3_tokenizer):
parser: ReasoningParser = ReasoningParserManager.get_reasoning_parser(parser_name)(
hy_v3_tokenizer,
reasoning_effort="low",
)
assert isinstance(parser, HYV3ReasoningParser)
assert parser._identity_parser is None
+6 -2
View File
@@ -34,8 +34,12 @@ class HYV3ReasoningParser(BaseThinkingReasoningParser):
# at the outer level of the chat message.
# Otherwise, If both are empty, assign "no_think".
chat_kwargs = kwargs.pop("chat_template_kwargs", {}) or {}
reasoning_effort = chat_kwargs.pop("reasoning_effort", "no_think")
chat_kwargs = kwargs.get("chat_template_kwargs", {}) or {}
reasoning_effort = (
chat_kwargs.get("reasoning_effort")
or kwargs.get("reasoning_effort")
or "no_think"
)
logger.debug("reasoning_effort for choosing parser: %s", reasoning_effort)