[reward] feat: expose valid_response_length and max_resp_len in extra_info - #7063
[reward] feat: expose valid_response_length and max_resp_len in extra_info#7063Secbone wants to merge 5 commits into
Conversation
…_info Add valid_response_length and max_resp_len to extra_info dict in DAPORewardManager so downstream consumers have access to per-sample response lengths for logging and analysis. These values were already computed internally but not exposed. Co-authored-by: Claude Signed-off-by: Secbone <secbone@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request adds valid_response_length and max_resp_len to extra_info in the DAPO reward manager. However, modifying extra_info in-place is problematic because it may not write back to the batch and will be lost in distributed environments due to Ray actor isolation. It is recommended to append these metrics to reward_extra_info instead.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| extra_info["valid_response_length"] = valid_response_length | ||
| extra_info["max_resp_len"] = self.max_resp_len |
There was a problem hiding this comment.
Modifying extra_info in-place here has two major issues that prevent downstream consumers from accessing these values:
- No Write-Back:
extra_infois retrieved viadata_item.non_tensor_batch.get("extra_info", {}). If"extra_info"is not present innon_tensor_batch, a new dictionary is created. Modifying this dictionary in-place does not write it back todata_item.non_tensor_batch. - Ray Actor Isolation: In a distributed training setup,
DAPORewardManagertypically runs as a Ray actor. Since arguments and return values are serialized/deserialized (passed by value), any in-place modifications todataordata_iteminside the actor are lost and not propagated back to the caller.
To correctly expose these metrics to downstream consumers (e.g., for logging), they should be appended to reward_extra_info, which is returned to the caller when return_dict=True.
| extra_info["valid_response_length"] = valid_response_length | |
| extra_info["max_resp_len"] = self.max_resp_len | |
| reward_extra_info["valid_response_length"].append(valid_response_length) | |
| reward_extra_info["max_resp_len"].append(self.max_resp_len) |
…d of extra_info extra_info from non_tensor_batch.get() may not persist across Ray serialization boundaries. reward_extra_info is explicitly returned to the caller, making it the correct channel for per-sample metrics. Co-authored-by: Claude Signed-off-by: Secbone <secbone@gmail.com>
d65e64c to
26e08c7
Compare
…ward_extra_info Co-authored-by: Claude Signed-off-by: Secbone <secbone@gmail.com>
What does this PR do?
Expose
valid_response_lengthandmax_resp_lenin thereward_extra_infodict ofDAPORewardManager. These values were already computed internally but were not written to the batch output, making them inaccessible to downstream consumers for logging and analysis.Checklist Before Starting
gh pr list --search "extra_info valid_response_length"— no duplicates found.[{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
Unit test verifies that
valid_response_lengthandmax_resp_lenappear inreward_extra_infowhenreturn_dict=True.API and Usage Example
Design & Code Changes
verl/workers/reward_manager/dapo.py: 2 lines changed — writevalid_response_lengthandmax_resp_lentoreward_extra_info(which is explicitly returned to the caller) instead of the non-persistentextra_infodict.tests/workers/reward_manager/test_dapo_on_cpu.py: Add unit test verifying the new keys appear inreward_extra_info.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=alwaystests/workers/reward_manager/test_dapo_on_cpu.py.ci-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.