A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 12, 01:00 UTC
[Bugfix] Fix the issue with interleaved thinking when using streaming (#30033)
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com> Signed-off-by: Chauncey <chaunceyjiang@gmail.com> Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
Chauncey committed
Dec 4, 2025 at 19:11 UTC
6796ce8bdbf29f5624fcdc03792626574c919b41
2 files changed
+19
-2
tests/reasoning/test_base_thinking_reasoning_parser.py
+11
-1
@@ -112,7 +112,7 @@ class TestBaseThinkingReasoningParserMethods:
112
"""Test the is_reasoning_end method."""
113
parser = TestThinkingReasoningParser(test_tokenizer)
114
end_token_id = parser.end_token_id
115
-
115
+ start_token_id = parser.start_token_id
116
# Test with end token present
117
assert parser.is_reasoning_end([1, 2, end_token_id, 4]) is True
118
@@ -122,6 +122,16 @@ class TestBaseThinkingReasoningParserMethods:
122
# Test with empty list
123
assert parser.is_reasoning_end([]) is False
124
125
+ # Test with interleaved thinking
126
+ assert parser.is_reasoning_end([1, start_token_id, 2, end_token_id]) is True
127
+ assert parser.is_reasoning_end([1, start_token_id, 2, 3]) is False
128
+ assert (
129
+ parser.is_reasoning_end(
130
+ [1, start_token_id, 2, end_token_id, 2, 2, start_token_id]
131
+ )
132
+ is False
133
+ )
134
+
135
def test_extract_content_ids(self, test_tokenizer):
136
"""Test the extract_content_ids method."""
137
parser = TestThinkingReasoningParser(test_tokenizer)
vllm/reasoning/basic_parsers.py
+8
-1
@@ -64,8 +64,15 @@ class BaseThinkingReasoningParser(ReasoningParser):
64
)
65
66
def is_reasoning_end(self, input_ids: list[int]) -> bool:
67
+ start_token_id = self.start_token_id
68
end_token_id = self.end_token_id
68
- return any(input_id == end_token_id for input_id in reversed(input_ids))
69
+
70
+ for i in range(len(input_ids) - 1, -1, -1):
71
+ if input_ids[i] == start_token_id:
72
+ return False
73
+ if input_ids[i] == end_token_id:
74
+ return True
75
+ return False
76
77
def extract_content_ids(self, input_ids: list[int]) -> list[int]:
78
"""