Skip to content

fix(search-r1): stop generation at </search> and </answer> - #2036

Merged
zhuzilin merged 1 commit into
THUDM:mainfrom
yichuan-w:search-r1-stop-token-fix
Jun 13, 2026
Merged

zhuzilin merged 1 commit into
THUDM:mainfrom
yichuan-w:search-r1-stop-token-fix

Conversation

@yichuan-w

@yichuan-w yichuan-w commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Problem

In examples/search-r1/generate_with_search.py, the multi-turn rollout never tells the inference engine to stop at the tool/answer boundary. So the model keeps generating after </search> / </answer> (junk, sometimes fabricating new Question:s).

The example only trims that via postprocess_responses (string split), which is disabled when return_logprob=True (needed to keep token/logp aligned for TIS). So with logprob collection on, the trailing junk:

  • stays in the trajectory and is trained on (loss_mask=1), and
  • breaks is_valid_sequence (content after </answer> → format invalid → lower reward).

Fix

Pass stop=["</search>", "</answer>"] in sampling_params. slime already sets no_stop_trim=True, so the closing tag is kept and token/logp stay aligned natively — no string post-processing needed, and it works whether return_logprob is on or off.

The multi-turn rollout never told the inference engine to stop at the tool/answer
boundary, so the model kept generating after </search> / </answer> (junk, even
fabricated new "Question:"s). The example only trimmed that via
postprocess_responses, which is disabled when return_logprob=True (to keep
token/logp aligned for TIS) — so with logprob collection on, the trailing junk
stayed in the trajectory, got trained on (loss_mask=1), and broke
is_valid_sequence (content after </answer> -> format invalid -> lower reward).

Fix: pass stop=["</search>", "</answer>"] in sampling_params. slime already
sets no_stop_trim=True, so the closing tag is kept and token/logp stay aligned
natively — no string post-processing needed, works with return_logprob on or off.
@yichuan-w

Copy link
Copy Markdown
Contributor Author
image compare two curve, the fix one is much better

@zhuzilin
zhuzilin merged commit 5d7296a into THUDM:main Jun 13, 2026
35 checks passed
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.

2 participants