Skip to content

fix(grpo): group env-reward baseline by prompt group ids - #4620

Merged
ZhiyuLi-Nvidia merged 1 commit into
mainfrom
zhiyul/fix-grpo-env-baseline
Oct 9, 2026
Merged

ZhiyuLi-Nvidia merged 1 commit into
mainfrom
zhiyul/fix-grpo-env-baseline

Conversation

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

What

main fails Lint check at 39eeee7eb (#4553):

nemo_rl/algorithms/grpo.py:3509:33: F821 Undefined name `input_ids`

This is a semantic conflict between two PRs that merged back to back:

Besides failing lint, that path raises NameError whenever env_reward is set.

Fix (2 lines)

  • grpo.py: the env-reward baseline groups by repeated_batch[PROMPT_GROUP_IDS_KEY], the same key as the main baseline just above it.
  • grpo_sync.py: the same baseline used driver_carry["prompt_ids_for_adv"] (prompt token ids). It now uses prompt_group_ids, which the main baseline and dynamic sampling already use, so all three group rows the same way.

ruff check passes on both files. This also unblocks lint on PRs based on current main (e.g. #4618).

🤖 Generated with Claude Code

#3882 switched calculate_baseline_and_std_per_prompt to group by
prompt_group_ids and removed input_ids from _grpo_train_impl; #4553,
merged right after, added the env-reward baseline call still passing
input_ids. On main that is an undefined name (ruff F821, failing Lint
check) and a NameError whenever grpo.length_penalty sets env_reward.

Use repeated_batch[PROMPT_GROUP_IDS_KEY] there, and prompt_group_ids
(instead of prompt token ids) for the same baseline in grpo_sync, so the
env-reward baseline groups rows exactly like the main baseline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
@ZhiyuLi-Nvidia ZhiyuLi-Nvidia added the CI:L0 Run doctests and unit tests label Oct 9, 2026
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 5328e0c

@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L0 Run doctests and unit tests labels Oct 9, 2026
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia enabled auto-merge (squash) October 9, 2026 04:44
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia merged commit a3deb1a into main Oct 9, 2026
73 checks passed
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia deleted the zhiyul/fix-grpo-env-baseline branch October 9, 2026 08:43
alexandery-nvidia added a commit that referenced this pull request Oct 10, 2026
…lit baselines

GRPO's baselines key on the explicit prompt-group ids since #3882 and #4620,
so a per-rollout string in the harness prompt no longer splits a group into
singleton baselines. The comment and the warning now say what the condition
does mean: the rollouts of a group do not share a prompt prefix, so the
engine's prefix cache and anything keyed on first-prompt tokens see one
group per rollout. The test asserts the new wording.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 12, 2026
…lit baselines

GRPO's baselines key on the explicit prompt-group ids since #3882 and #4620,
so a per-rollout string in the harness prompt no longer splits a group into
singleton baselines. The comment and the warning now say what the condition
does mean: the rollouts of a group do not share a prompt prefix, so the
engine's prefix cache and anything keyed on first-prompt tokens see one
group per rollout. The test asserts the new wording.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
linj-glitch added a commit to linj-glitch/RL that referenced this pull request Oct 13, 2026
main grew a fourth all-ones valid-mask site after NVIDIA-NeMo#4553/NVIDIA-NeMo#4620: the
env_baseline that grpo.length_penalty keeps for the pct_* diagnostics.
Pass the same participation mask there, so a masked row's env reward
does not vote in its siblings' env baseline either.

State the two rules the mask follows in the helper docstring and at
both call sites. Participation is binary: a nonzero fractional
loss_multiplier still counts as one vote, and the training loss
weights are never changed. Truncated rollouts keep voting under
overlong_filtering because the mask is taken before that rewrite,
which is what docs/guides/grpo.md documents for these loops; the
SingleController advantage_stage folds truncated rows into its
valid_mask instead, and reconciling the two is left to the
configurable policy work rather than decided here.

Tests: fractional-nonzero versus zero loss weight, the truncated-row
call-order rule, one driver test asserting the trivial check, the
baseline/std and the env baseline all receive the mask (and that the
env baseline of the real rows ignores the masked reward), a fractional
case for the sync/async forwarding test plus an assertion that the
forwarded sample_mask keeps the original weight, and a sync/async test
that a truncated row votes in the baseline while overlong filtering
removes it from the loss.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lin Jia <[email protected]>
linj-glitch added a commit to linj-glitch/RL that referenced this pull request Oct 23, 2026
main grew a fourth all-ones valid-mask site after NVIDIA-NeMo#4553/NVIDIA-NeMo#4620: the
env_baseline that grpo.length_penalty keeps for the pct_* diagnostics.
Pass the same participation mask there, so a masked row's env reward
does not vote in its siblings' env baseline either.

State the two rules the mask follows in the helper docstring and at
both call sites. Participation is binary: a nonzero fractional
loss_multiplier still counts as one vote, and the training loss
weights are never changed. Truncated rollouts keep voting under
overlong_filtering because the mask is taken before that rewrite,
which is what docs/guides/grpo.md documents for these loops; the
SingleController advantage_stage folds truncated rows into its
valid_mask instead, and reconciling the two is left to the
configurable policy work rather than decided here.

Tests: fractional-nonzero versus zero loss weight, the truncated-row
call-order rule, one driver test asserting the trivial check, the
baseline/std and the env baseline all receive the mask (and that the
env baseline of the real rows ignores the masked reward), a fractional
case for the sync/async forwarding test plus an assertion that the
forwarded sample_mask keeps the original weight, and a sync/async test
that a truncated row votes in the baseline while overlong filtering
removes it from the loss.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lin Jia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants