[data] Filter Overlonged Prompts in tool_agent_loop#6079
[data] Filter Overlonged Prompts in tool_agent_loop#6079HwCARI wants to merge 1 commit intoverl-project:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a length check for prompt IDs in the agent loop to prevent runtime errors from overlong prompts by terminating the state early. Feedback suggests that this approach may result in blank samples being passed to the trainer, recommending the use of specific metric flags or default rewards for filtered samples and the inclusion of request IDs in logs for improved observability.
| if len(prompt_ids) > self.prompt_length: | ||
| logger.warning( | ||
| f"Prompt length {len(prompt_ids)} exceeds prompt_length {self.prompt_length}. " | ||
| "Filtering out this sample." | ||
| ) | ||
| return AgentState.TERMINATED |
There was a problem hiding this comment.
While this check correctly prevents the RuntimeError during batching by terminating early for overlong prompts, returning AgentState.TERMINATED at this stage leaves agent_data.prompt_ids as an empty list. This results in a "blank" sample (all padding) being passed to the trainer.
To improve observability and ensure the trainer handles the filtered sample correctly, consider setting a default reward or a specific metric flag indicating the sample was filtered due to length constraints. Additionally, including the request_id in the warning log would significantly aid in debugging specific failed samples in large-scale runs.
What does this PR do?
Fixes #2069.
filter_overlong_promptswas silently skipped in the multiturn setting inverl/verl/experimental/agent_loop/tool_agent_loop.py, causing prompts exceedingdata.max_prompt_lengthto pass through unfiltered. This resulted in tensor size mismatches downstream when batching sequences:This PR ensures the overlong prompt filter is applied consistently regardless of whether multiturn tool use is enabled.
Fix
Apply
filter_overlong_promptsinverl/verl/experimental/agent_loop/tool_agent_loop.py.Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,veomni,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,cfg,reward,fully_async,one_step_off,like[megatron, fsdp, doc]{type}is infeat,fix,refactor,chore,test[BREAKING]to the beginning of the title.[BREAKING][fsdp, megatron] feat: dynamic batchingTest
API and Usage Example
# Add code snippet or script demonstrating how to use thisDesign & Code Changes
Checklist Before Submitting
Important
Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=alwaysci-requestchannel in theverlSlack workspace. (If not accessible, please try the Feishu group (飞书群).)recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main.