Fix tau-bench token deltas for reasoning templates#2213
Draft
DongzhuoranZhou wants to merge 1 commit into
Draft
Conversation
DongzhuoranZhou
force-pushed
the
codex/fix-qwen3-thinking-token-delta
branch
from
July 16, 2026 09:11
43827e7 to
0c40ed5
Compare
Co-authored-by: Yuki <70699639+Y-L-LIU@users.noreply.github.com>
DongzhuoranZhou
force-pushed
the
codex/fix-qwen3-thinking-token-delta
branch
from
July 16, 2026 09:12
0c40ed5 to
55e6d33
Compare
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.
Summary
Root cause
The tau-bench example computed each newly appended message with:
This assumes the newly rendered conversation always starts with the previous rendering. Qwen3 reasoning templates violate that assumption: after a new real user message arrives, the template removes the preceding assistant reasoning from
curr. Slicingcurratlen(prev)therefore starts inside, or after, the new user message. The resulting GRPOsample.tokenscan omit user context while its remaining mask lengths still align.Fix
When
curr.startswith(prev), behavior is unchanged. When the latest message is a user message and history was rewritten, render that user message independently and verify that it is exactly the suffix ofcurrbefore tokenizing it. Other unexpected rewrite patterns raise an error instead of silently producing corrupt training data.This does not change whether prior reasoning is retained in the accumulated GRPO training context; it only prevents new user messages from being truncated.
Validation
pytest -q tests/test_tau_bench_token_delta.py— 2 passedpy_compileon the helper and tau-bench agent — passedQwen3-4B-Thinking-2507tokenizer over five assistant/user turns: