Skip to content

fix(tau-bench): train on sampled token ids instead of retokenized chat text - #2467

Open
PlanckChang wants to merge 1 commit into
THUDM:mainfrom
PlanckChang:fix/tau-bench-token-exact
Open

PlanckChang wants to merge 1 commit into
THUDM:mainfrom
PlanckChang:fix/tau-bench-token-exact

Conversation

@PlanckChang

@PlanckChang PlanckChang commented Oct 12, 2026 •

Copy link
Copy Markdown

Summary

Tau-bench multi-turn RL was training on a retokenized chat-template rendering, not on the tokens SGLang sampled. The loss mask for that rendering was also wrong whenever the template inserted text the model did not generate.

What was wrong

Each turn sent the full conversation as text. The sampled token ids were discarded. Training targets came from apply_chat_template plus encode. BPE does not round-trip, so encode(decode(ids)) is often a different sequence. Qwen3-style templates can also rewrite earlier <think> blocks when a new user turn arrives, so the next inference context and the training tokens diverged.

The assistant span was then labeled with one mask bit per retokenized id:

  • The model text had its trailing <|im_end|> stripped, and the template appended <|im_end|>\n again. That closer and the following newline were all loss_mask=1. The newline is not a sampled token.
  • From the second assistant turn on, <|im_start|>assistant (and a generation prompt such as <think>\n) was supposed to be masked. The mask length was len(encode(prefix)), measured separately from encode(prefix + content). If BPE merges across that boundary, template tokens fall inside the loss.

Tool and user turns were already loss_mask=0. The bug was the assistant span.

What this does

  • Tokenize the first prompt once. Later requests send that exact input_ids prefix and return_logprob=true.
  • Keep SGLang output_token_logprobs as the assistant tokens (loss_mask=1), including a sampled <|im_end|>. Decode them only to parse the tool call.
  • Append the chat-template tail after that end token for the tool/user observation and, when the episode continues, the next generation prompt. That tail is loss_mask=0. If the sample did not emit the end token, insert one copy and leave it masked.
  • Stop the episode when a turn hits the length limit instead of closing a partial assistant message with template tokens.
  • Skip transient git lock files when the image-baseline patch test copies a repository. git maintenance was removing objects/maintenance.lock during shutil.copytree.

Test plan

  • python tests/test_tau_bench_token_delta.py
  • python tests/test_agent/test_swe_workspace_diff.py
  • Sampled ids that do not survive encode(decode(ids)) stay intact in the training sequence
  • <|im_start|>assistant, the newline after <|im_end|>, and tool/user text are loss_mask=0
  • A template end token the model did not sample is inserted once and masked
  • A BPE merge across <|im_end|> stays in the masked suffix

…t text

Multi-turn rollouts discarded SGLang ids and rebuilt the loss mask from the chat template, so BPE merges and template rewrites trained on tokens the model did not generate.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant