fix(search-r1): stop generation at </search> and </answer> - #2036
Merged
Merged
Conversation
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.
Contributor
Author
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.

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 newQuestion:s).The example only trims that via
postprocess_responses(string split), which is disabled whenreturn_logprob=True(needed to keep token/logp aligned for TIS). So with logprob collection on, the trailing junk:loss_mask=1), andis_valid_sequence(content after</answer>→ format invalid → lower reward).Fix
Pass
stop=["</search>", "</answer>"]insampling_params. slime already setsno_stop_trim=True, so the closing tag is kept and token/logp stay aligned natively — no string post-processing needed, and it works whetherreturn_logprobis on or off.