[Bugfix][Frontend] Count reasoning tokens for Harmony, DeepSeek-V3 and Step3 parsers (#58626)
Signed-off-by: Samyabrata Maji <116789799+sammaji@users.noreply.github.com> Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
co-authored by
Flora Feng
parent
b3a87b2d04
commit
064bc747ab
@@ -87,3 +87,14 @@ def test_identity_reasoning_parser_basic(tokenizer):
|
||||
delta_token_ids=[],
|
||||
)
|
||||
assert result_none is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("thinking,expected", [(True, 3), (False, 0)])
|
||||
def test_count_reasoning_tokens_delegates(tokenizer, thinking, expected):
|
||||
parser = DeepSeekV3ReasoningParser(
|
||||
tokenizer, chat_template_kwargs={"thinking": thinking}
|
||||
)
|
||||
think = tokenizer.convert_tokens_to_ids(["<think>", "</think>"])
|
||||
token_ids = [think[0], 11, 12, 13, think[1], 14]
|
||||
|
||||
assert parser.count_reasoning_tokens(token_ids) == expected
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm.reasoning import ReasoningParserManager
|
||||
from vllm.tokenizers import get_tokenizer
|
||||
|
||||
pytestmark = pytest.mark.skip_global_cleanup
|
||||
|
||||
REASONING_MODEL_NAME = "stepfun-ai/step3"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def step3_parser():
|
||||
tokenizer = get_tokenizer(tokenizer_name=REASONING_MODEL_NAME)
|
||||
return ReasoningParserManager.get_reasoning_parser("step3")(tokenizer)
|
||||
|
||||
|
||||
def test_count_reasoning_tokens_stops_at_think_end(step3_parser):
|
||||
end = step3_parser.think_end_token_id
|
||||
assert step3_parser.count_reasoning_tokens([11, 12, end, 13]) == 2
|
||||
|
||||
|
||||
def test_count_reasoning_tokens_without_think_end(step3_parser):
|
||||
"""Step3 treats output as reasoning until </think> appears."""
|
||||
assert step3_parser.count_reasoning_tokens([11, 12, 13]) == 3
|
||||
Reference in New Issue
Block a user