fix: use prompt token length for advantage group extraction and fix token mask#2176
Conversation
|
/ok to test 628a248 |
628a248 to
7d96ad3
Compare
7d96ad3 to
d5961e5
Compare
|
/ok to test 7d96ad3 |
@macandro96, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test d5961e5 |
d5961e5 to
20adf67
Compare
|
@yfw @HeyyyyyyG could you help to take a review as well? |
20adf67 to
49601f1
Compare
|
LGTM |
|
/ok to test 49601f1 |
|
/ok to test 18a05b0 |
The previous role-based extraction (`_extract_prompt_only_messages`) broke on multi-turn prompts containing assistant messages in the conversation history — it would strip them, corrupting the prompt IDs used for advantage estimation. Replace with `extract_initial_prompt_messages()` which uses the `length` field to identify the original prompt boundary. Applied to both sync and async GRPO paths. Closes #1960 Co-Authored-By: Jiaqi Zeng <jiaqiz@nvidia.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Signed-off-by: Anish Mahishi <amahishi@cw-dfw-cs-001-vscode-02.cm.cluster>
Signed-off-by: Anish Mahishi <amahishi@cw-dfw-cs-001-vscode-02.cm.cluster>
d01bc6c to
8e1c343
Compare
|
/ok to test 8e1c343 |
|
@yuki-97 fixed! can you reapprove please? |
yuki-97
left a comment
There was a problem hiding this comment.
LGTM, thanks @macandro96
@ZhiyuLi-Nvidia could you help to take a check at TQ path?
as I know we'll always have generation_logprobs in rollout, so I think it should be fine to remove setdefault generation_logprobs in TQ path, but better to double check.
Thank you @yuki-97 @macandro96 ! LGTM and thank you for the change and review for data plane coverage as well. Out of scope for this PR, but I have some concerns about the
I think we should eventually move to nested jagged tensors: a single concatenated tensor paired with a sequence-length tensor to mark boundaries. I double-checked, and veRL uses nested jagged tensors as well. Curious if you agree with this direction. |
|
thanks @ZhiyuLi-Nvidia @macandro96 , I've merged but feel free to continue discussing here or in slack. besides, |
…oken mask (#2176) Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com> Signed-off-by: Anish Mahishi <amahishi@cw-dfw-cs-001-vscode-02.cm.cluster> Co-authored-by: Jiaqi Zeng <jiaqiz@nvidia.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Anish Mahishi <amahishi@cw-dfw-cs-001-vscode-02.cm.cluster>
…oken mask (NVIDIA-NeMo#2176) Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com> Signed-off-by: Anish Mahishi <amahishi@cw-dfw-cs-001-vscode-02.cm.cluster> Co-authored-by: Jiaqi Zeng <jiaqiz@nvidia.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Anish Mahishi <amahishi@cw-dfw-cs-001-vscode-02.cm.cluster>
This PR fixes two multi-turn GRPO training issues:
The previous role-based extraction (
_extract_prompt_only_messages) broke on multi-turn prompts containing assistant messages in the conversation history — it would strip them, corrupting the prompt IDs used for advantage estimation.Replace with
extract_initial_prompt_messages()which uses thelengthfield to identify the original prompt boundary. Applied to both sync and async GRPO paths.GRPO token loss masks previously unmasked every message with
role == "assistant". In multi-turn data, assistant messages can be part of the prompt history, not generated rollout output, so those tokens should not contribute to the policy loss. This PR updates masking so only assistant messages produced by generation, identified by existinggeneration_logprobs, are trainable. Missinggeneration_logprobsare still filled with zeros for downstream tensorization.Closes #1960 and #1956
What does this PR do ?
Add a one line overview of what this PR aims to accomplish.
Issues
List issues that this PR closes (syntax):
Usage
# Add a code snippet demonstrating how to use thisBefore your PR is "Ready for review"
Pre checks:
Additional Information