Repository navigation
BaseChatTemplateParser strips every TokenConfig string from message content to block control-token injection. For Qwen that set included tool_start_token ("\n<tool_call>\n") and tool_end_token ("\n</tool_call>"), which are ordinary text in tool-use system prompts and in assistant tool-call turns. Stripping them removed the <tool_call> wrapper from the function-calling format example that the Qwen3.5 chat template writes into the system prompt, so the model emitted bare <function=...> blocks and often failed to end its turn. In agentic RL on DeepSWE with Qwen3.5-35B-A3B, about a fifth of rollouts degenerated into repeated </function> until they hit the response-length cap, which more than doubled step time. - #2820
Merged
Merged
Conversation
copybara-service
Bot
requested review from
abheesht17,
hgao327,
jiangyangmu,
lc5211,
s-noghabi,
sizhit2,
tianshub and
wang2yn84
as code owners
October 11, 2026 18:41
copybara-service
Bot
force-pushed
the
test_997511662
branch
from
October 11, 2026 22:12
7d40b98 to
554f5a2
Compare
…ge content to block control-token injection. For Qwen that set included `tool_start_token` (`"\n<tool_call>\n"`) and `tool_end_token` (`"\n</tool_call>"`), which are ordinary text in tool-use system prompts and in assistant tool-call turns. Stripping them removed the `<tool_call>` wrapper from the function-calling format example that the Qwen3.5 chat template writes into the system prompt, so the model emitted bare `<function=...>` blocks and often failed to end its turn. In agentic RL on DeepSWE with Qwen3.5-35B-A3B, about a fifth of rollouts degenerated into repeated `</function>` until they hit the response-length cap, which more than doubled step time. Exclude `tool_start_token` and `tool_end_token` from sanitization. The exclusion is in the base class, so Gemma4 now also keeps its `<|tool_call>` / `<tool_call|>` markup and Llama no longer strips its tool header from content; turn terminators such as `<|im_end|>` and `<|eot_id|>` are still stripped. Also render runs of consecutive tool messages the way the Qwen chat template does, as a single user turn with one `<tool_response>` block per message, which changes the token layout for turns with several tool calls. `QwenChatTemplateParser.preprocess_messages` marks such runs so that `tokenize_and_generate_masks`, which renders one message at a time, produces the same text as `parse`. PiperOrigin-RevId: 997567041
copybara-service
Bot
force-pushed
the
test_997511662
branch
from
October 11, 2026 22:33
554f5a2 to
8dcf606
Compare
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
BaseChatTemplateParserstrips everyTokenConfigstring from message content to block control-token injection. For Qwen that set includedtool_start_token("\n<tool_call>\n") andtool_end_token("\n</tool_call>"), which are ordinary text in tool-use system prompts and in assistant tool-call turns. Stripping them removed the<tool_call>wrapper from the function-calling format example that the Qwen3.5 chat template writes into the system prompt, so the model emitted bare<function=...>blocks and often failed to end its turn. In agentic RL on DeepSWE with Qwen3.5-35B-A3B, about a fifth of rollouts degenerated into repeated</function>until they hit the response-length cap, which more than doubled step time.Exclude
tool_start_tokenandtool_end_tokenfrom sanitization. The exclusion is in the base class, so Gemma4 now also keeps its<|tool_call>/<tool_call|>markup and Llama no longer strips its tool header from content; turn terminators such as<|im_end|>and<|eot_id|>are still stripped.Also render runs of consecutive tool messages the way the Qwen chat template does, as a single user turn with one
<tool_response>block per message, which changes the token layout for turns with several tool calls.QwenChatTemplateParser.preprocess_messagesmarks such runs so thattokenize_and_generate_masks, which renders one message at a time, produces the same text asparse.