-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
[Bugfix] Fix and add tests for GptOss reasoning parser #28000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yeqcharlotte
merged 6 commits into
vllm-project:main
from
CentML:bugfix-gptoss-reasoning-parser
Nov 7, 2025
+151
−7
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d4ad04
fix bug in gpt oss reasoning parser
benchislett 409ad03
add max length limit for performance and robustness
benchislett 3b67cf6
Merge branch 'main' into bugfix-gptoss-reasoning-parser
benchislett 97d0a9b
add more coverage and update tests
benchislett 251bebd
Merge branch 'main' into bugfix-gptoss-reasoning-parser
benchislett 0fff9bb
Merge branch 'main' into bugfix-gptoss-reasoning-parser
benchislett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import pytest | ||
| from transformers import AutoTokenizer | ||
|
|
||
| from vllm.reasoning import ReasoningParser | ||
| from vllm.reasoning.gptoss_reasoning_parser import GptOssReasoningParser | ||
|
|
||
| REASONING_MODEL_NAME = "openai/gpt-oss-120b" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def gpt_oss_tokenizer(): | ||
| return AutoTokenizer.from_pretrained(REASONING_MODEL_NAME) | ||
|
|
||
|
|
||
| USER_MESSAGE_START = "<|start|>user<|message|>" | ||
| REASONING_SECTION_START = "<|end|><|start|>assistant<|channel|>analysis<|message|>" | ||
| ASSISTANT_CONTENT_START_PREFIX = "<|end|><|start|>assistant<|channel|>final" | ||
| ASSISTANT_CONTENT_START_SUFFIX = "<|message|>" | ||
| ASSISTANT_CONTENT_START = ( | ||
| ASSISTANT_CONTENT_START_PREFIX + ASSISTANT_CONTENT_START_SUFFIX | ||
| ) | ||
|
|
||
| BASIC_CONTENT = { | ||
| "output": REASONING_SECTION_START | ||
| + "This is reasoning" | ||
| + ASSISTANT_CONTENT_START | ||
| + "This is the rest", | ||
| "is_reasoning_end": True, | ||
| } | ||
|
|
||
| BASIC_REASONING_ONLY = { | ||
| "output": REASONING_SECTION_START + "This is reasoning" + "<|end|>", | ||
| "is_reasoning_end": False, | ||
| } | ||
| BASIC_NO_REASONING_NO_ASSISTANT = { | ||
| "output": USER_MESSAGE_START + "This is a user message", | ||
| "is_reasoning_end": False, | ||
| } | ||
|
|
||
| # Edge-case where the model omits the assistant tag entirely. | ||
| BASIC_NO_REASONING_ASSISTANT = { | ||
| "output": USER_MESSAGE_START + "This is a user message<|end|><|channel|>final", | ||
| "is_reasoning_end": True, | ||
| } | ||
|
|
||
| COMPLEX_CONTENT_INCOMPLETE_PREFIX_ONLY = { | ||
| "output": REASONING_SECTION_START | ||
| + "This is reasoning" | ||
| + ASSISTANT_CONTENT_START_PREFIX, | ||
| "is_reasoning_end": False, | ||
| } | ||
|
|
||
| COMPLEX_CONTENT_SUFFIX_ONLY = { | ||
| "output": REASONING_SECTION_START | ||
| + "This is reasoning" | ||
| + ASSISTANT_CONTENT_START_SUFFIX, | ||
| "is_reasoning_end": False, | ||
| } | ||
|
|
||
| COMPLEX_CONTENT_1_NO_SUFFIX = { | ||
| "output": REASONING_SECTION_START | ||
| + "This is reasoning" | ||
| + ASSISTANT_CONTENT_START_PREFIX | ||
| + "<|constrain|> JSON ", | ||
| "is_reasoning_end": False, | ||
| } | ||
|
|
||
| COMPLEX_CONTENT_1 = { | ||
| "output": REASONING_SECTION_START | ||
| + "This is reasoning" | ||
| + ASSISTANT_CONTENT_START_PREFIX | ||
| + "<|constrain|> JSON " | ||
| + ASSISTANT_CONTENT_START_SUFFIX, | ||
| "is_reasoning_end": True, | ||
| } | ||
|
|
||
| COMPLEX_CONTENT_1_WITH_CONTENT = { | ||
| "output": REASONING_SECTION_START | ||
| + "This is reasoning" | ||
| + ASSISTANT_CONTENT_START_PREFIX | ||
| + "<|constrain|> JSON " | ||
| + ASSISTANT_CONTENT_START_SUFFIX | ||
| + "This is the rest", | ||
| "is_reasoning_end": True, | ||
| } | ||
|
|
||
| COMPLEX_CONTENT_2 = { | ||
| "output": REASONING_SECTION_START | ||
| + "This is reasoning" | ||
| + ASSISTANT_CONTENT_START_PREFIX | ||
| + "<|constrain|>ReplyAction " | ||
| + ASSISTANT_CONTENT_START_SUFFIX | ||
| + "This is the rest", | ||
| "is_reasoning_end": True, | ||
| } | ||
|
|
||
| TEST_CASES = [ | ||
| BASIC_CONTENT, | ||
| BASIC_REASONING_ONLY, | ||
| COMPLEX_CONTENT_INCOMPLETE_PREFIX_ONLY, | ||
| COMPLEX_CONTENT_SUFFIX_ONLY, | ||
| COMPLEX_CONTENT_1_NO_SUFFIX, | ||
| COMPLEX_CONTENT_1, | ||
| COMPLEX_CONTENT_1_WITH_CONTENT, | ||
| COMPLEX_CONTENT_2, | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "output, is_reasoning_end", | ||
| [(t["output"], t["is_reasoning_end"]) for t in TEST_CASES], | ||
| ) | ||
| def test_gptoss_is_reasoning_end( | ||
| output, | ||
| is_reasoning_end, | ||
| gpt_oss_tokenizer, | ||
| ): | ||
| output = gpt_oss_tokenizer.tokenize(output) | ||
| parser: ReasoningParser = GptOssReasoningParser(gpt_oss_tokenizer) | ||
|
|
||
| # Test is_reasoning_end | ||
| output_ids = gpt_oss_tokenizer.convert_tokens_to_ids(output) | ||
| actual_is_reasoning_end = parser.is_reasoning_end(output_ids) | ||
| assert is_reasoning_end == actual_is_reasoning_end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.