[Bugfix] Improve GLM4 MoE Reasoning Parser's is_reasoning_end Condition #25355
+219
−3
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.
Purpose
When testing GLM-4.5 in streaming mode with both reasoning and tool calls enabled, it was noticed that after the first assistant response, reasoning was not being parsed and added to the
reasoning_content
properly.This is due to calling
is_reasoning_end
on all the pervious prompt tokens .GLM-4.5's chat template removes the reasoning content, but still appends
<think><\think>
after the assistant token for previous interactions (interactive example). Thus, when checking for just the<\think>
token on all prompt tokens, the check would return true as the previous turn's<\think>
token is present.Thus, we must add the case that if there is an
<|assistant|>
token present, check that there is a<\think>
token after the last<|assistant|>
token. This can equivalently be accomplished by looping backwards over the prompt tokens and returning false upon encountering the<|assistant|>
token or true upon encountering a<\think>
token.Test Plan
Added automated tests (
tests/reasoning/test_glm4_moe_reasoning_parser.py
).Additionally performed manual test with the following curl command:
Test Result
Automated tests pass.
Curl command results:
Main
This PR
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.