Repository navigation
fix(nemo-gym): honor top-level mask_sample on rollout results - #4489
linj-glitch wants to merge 1 commit into
Conversation
NeMo-Gym's BaseVerifyResponse carries mask_sample as a top-level field of the /run result, and token-id capture also sets it there when a captured chain is unusable. NeMo-RL only read instance_config["mask_sample"], so samples the environment asked to mask were trained as valid. Read both locations through one helper (_env_mask_sample_flag) used by the batched rollout path, the RolloutManager token-capture finalization path, and drop both locations when env.should_mask_flagged_samples is false. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
3cc8704 to
8d8c778
Compare
|
Superseded by #4435. Alexander's PR reads the same two flag locations (first-class #4435 also does two things this PR does not. When the gate is off it drops the flag from a copy, so the Gym result the caller holds is not mutated, and the per-agent metrics still report What moves where:
Closing this PR in favour of #4435. |
What does this PR do ?
Masks a NeMo-Gym rollout when the result carries
mask_sampleat the top level. This is where NeMo-Gym puts it. Before this change, NeMo-RL only readinstance_config["mask_sample"].Issues
None.
Usage
No new configuration.
env.should_mask_flagged_samplesstill gates the flag, and its default is unchanged.Before your PR is "Ready for review"
Pre checks:
Additional Information
Root cause. NeMo-Gym's
BaseVerifyResponsedefinesmask_sampleas a top-level field of the/runresult. A resources server sets it when the environment or its infrastructure failed and the reward is not a valid measurement: a lost session, an unavailable judge, an OOM-killed container. Gym's token-id capture also setsmask_sampleat the top level when a captured chain is broken, ambiguous, or incomplete. NeMo-RL looked only insideinstance_config, which is the convention some agent servers use.How it manifests. Rollouts that Gym flags as invalid are trained as if they were valid. Their reward, often a synthetic 0, gets a real advantage and enters the loss. Nothing is logged; the flag is silently ignored.
Fix. A single helper,
_env_mask_sample_flag, reads both locations. It is used in three places:_mask_sample_flags, which covers the batched NeMo-Gym rollout path (sync and async GRPO) and theRolloutManagerpayload path.RolloutManagertoken-capture finalization path (_record_streamed_completion). This path read onlyinstance_configon its own.env.should_mask_flagged_samples: falsegate inAsyncNemoGymRolloutImpl._results_to_completions, which now drops the flag from both locations through_drop_env_mask_sample_flag. Without this, a top-level flag would survive the gate and still mask the sample.Tests.
tests/unit/experience/test_reward_penalties.py::TestMaskSampleFlags::test_reads_top_level_mask_sampletests/unit/experience/test_rollout_manager.py::test_result_to_completion_top_level_mask_flag_follows_gate(token and receipt results, gate on and off)tests/unit/experience/test_rollout_manager.py::TestGenerateForFinalizationFlow::test_request_carries_top_level_env_mask_flagsCommands run (CPU only):
🤖 Generated with Claude Code