Handle invalid environment rewards explicitly across environments, rollouts, and GRPO#2207
Draft
taivu1998 wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
Draft
Handle invalid environment rewards explicitly across environments, rollouts, and GRPO#2207taivu1998 wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
taivu1998 wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
Conversation
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.
Summary
This draft PR adds explicit invalid-reward handling for verifier-backed environments instead of overloading
0.0to mean both "valid zero reward" and "reward system failure".It introduces a batched
reward_valid_masksignal onEnvironmentReturn, threads that mask through reward collation and rollout state, and uses it in GRPO advantage/statistics paths so invalid rewards do not contaminate training metrics or policy loss.Addresses #431.
Root Cause
Today, several verifier-backed environments catch internal verification failures and convert them to numeric
0.0rewards. Once that happens, the training stack cannot distinguish:Because the reward path is tensor-based end-to-end, those invalid rewards were then treated as ordinary samples by rollout aggregation, baseline/std computation, logging, and loss masking.
What Changed
Environment contract and reward producers
reward_valid_masktoEnvironmentReturn.math_environment.pycode_jaccard_environment.pyvlm_environment.pyNoneorNaN.HFVerifyWorkerwhere the default verifier implementation was computed but not actually used when the kwarg was omitted.Reward collation and rollout plumbing
calculate_rewards()for backward compatibility.GRPO and advantage computation
grpo.py.Why This Design
This keeps the existing reward tensors intact while introducing a single explicit validity signal that composes cleanly with the existing masking model:
That makes the implementation targeted and low-complexity while solving the ambiguity described in #431.
Tests and Validation
Added and updated focused unit coverage for:
HFVerifyWorkerdefault verifier pathChecks run locally in the isolated worktree:
python3 -m py_compileon touched source and test filesgit diff --checkFull Ray-backed pytest was not runnable in this sandbox because local Ray startup timed out, and the GRPO test module also depends on optional Megatron imports not present in the environment used here.