Repository navigation
feat(grpo): per-environment GRPO settings (grpo.agent_overrides) - #5321
Conversation
7b2eeb0 to
0e6266f
Compare
yfw
left a comment
There was a problem hiding this comment.
Thank you for this PR. It adds grpo.agent_overrides, which sets overlong_filtering and normalize_rewards per environment on SingleController. The per-row normalize_rows input on the estimator is a clean place for this. With agent_overrides unset, the code passes exactly the same arguments as before.
The key is the row's attribution key, the same key as grpo.length_penalty.agent_overrides. That works for per-environment settings, also when one harness agent serves many environments, because taskset rows key by taskset. C6 only asks to say this in the text and the docs.
Findings, most severe first:
- (C1) CI blocker: the reference
grpo_math_1B.yamlis missing the new default. - (C2) Without token capture, SingleController ignores the overrides with no error. The legacy raise also runs after
Logger(...)(which opens the W&B run when W&B logging is on),CheckpointManagerand the dataloaders. - (C3) Dynamic sampling under
masked_reward_policy: excludekeeps or drops groups by the run-wideoverlong_filtering. - (C4) Test gaps in the advantage stage and the Forest owner path.
- (C5) Wiring tests for
stamp_agent_names, a shared tag constant, and a wrong code comment. - (C6) Key wording and user docs.
After the fixes, please do one short SingleController run with token capture and two environments, one of them overridden. Please use a run without Forest (Forest does not log these metrics) and share that num_rows_without_agent_tag is 0, and that with an overlong_filtering: true override on an environment whose rows get truncated, num_masked_seqs_by_overlong_filtering/<key> is above 0. The unit tests cannot cover the real Ray actor hand-off. Convergence curves are not needed, because the feature is opt-in and the unset path does not change.
Local CPU results: the PR's new tests pass, and test_config_v2_same_as_v1 fails as C1 describes. The two test_rollout_reassembler.py failures that the PR body lists also fail on main here, because the venv has no megatron-core. pre-commit (ruff, ruff-format) passes on the 9 files. CI did not run on this head yet.
Generated by Claude Code
|
Thanks for the thorough review. All six are addressed in c0b77a6:
The CPU suites are in the updated PR body. The only failures are the same two reassembler failures that I'll follow up with the SingleController smoke run: token capture on, no Forest, two environments with one overridden, reporting |
|
Smoke run done: SingleController with token capture, no Forest, two NeMo-Gym environments (flat rows), one of them overridden. Setup (1 node, 4 GPUs: 2 vLLM + 2 Megatron, Qwen3-0.6B, 6 steps × 4 prompts × 4 generations): grpo:
overlong_filtering: false # run-wide
adv_estimator: {normalize_rewards: true} # run-wide
agent_overrides:
mcqa_simple_agent: {overlong_filtering: true, normalize_rewards: false}
token_capture: {enabled: true}
env.nemo_gym.config_paths: [vllm_model_for_training, mcqa, string_match]
policy.max_total_sequence_length: 512 # small context so long answers truncateThe data is the two example sets interleaved ( Result (every step, from the step metrics):
One caveat on the base. The cluster I ran on only has the internal post-training container (vLLM 0.29), and |
c0b77a6 to
6ed240b
Compare
Multi-environment runs mix pass/fail environments with judge-graded ones,
which need different settings. grpo.agent_overrides maps a NeMo-Gym agent
name to settings that replace the run-wide value for that agent's rows;
unset fields inherit the run:
grpo:
agent_overrides:
rubric_judge_agent:
overlong_filtering: true # truncated rows leave the loss
normalize_rewards: false # no division by the group reward std
- The rollout finalizer stamps each published row's tag with its rollout's
agent (agent_name) when overrides are configured.
- The SingleController advantage stage turns the tags into per-row switches:
_apply_async_sample_masks accepts a per-row overlong_filtering tensor and
GRPOAdvantageEstimator.compute_advantage a per-row normalize_rows tensor.
- Metrics: num_masked_seqs_by_overlong_filtering/<agent> per configured agent
and num_rows_without_agent_tag (rows that fell back to run-wide values).
- Validation: at least one agent, every override sets something,
normalize_rewards overrides need the grpo estimator; the legacy setup()
raises (SingleController path only).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tuomas Rintamaki <[email protected]>
- Add the agent_overrides default to grpo_math_1B.yaml (exemplar + reference). - Reject agent_overrides on SingleController without token capture, and move the legacy setup() raise before the Logger and checkpoint manager. - Reject an overlong_filtering override that differs from the run-wide value under dynamic sampling with masked_reward_policy 'exclude'. - Move AGENT_NAME_TAG to data_plane/schema.py; drop a stale getattr in setup. - Say 'attribution key' (agent name for flat rows, task_id.taskset for task rows) in docstrings, errors and the new docs section. - Tests: opposite run-wide settings, per-agent counts, Forest owners, finalizer wiring (setup and actor), the legacy raise, the two new guards. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tuomas Rintamaki <[email protected]>
6ed240b to
33f611a
Compare
|
/ok to test 33f611a |
…kind-advantages Brings in 69 commits, including per-environment GRPO settings (grpo.agent_overrides, #5321) and the advantage statistics fix across filtering and batch splitting (#5216). Two conflict blocks, both resolved by keeping both sides: - grpo.py: DEFAULT_POLICY_FAILURE_KINDS next to main's AgentOverrideConfig. - test_rollout_reassembler.py: this PR's infra-failure weight test next to main's agent-name stamping tests. One more change keeps this PR's test working: the sync-trainer case of test_trainers_infra_masked_reward_never_moves_valid_siblings sets data_plane.backend, which grpo_train_sync now reads (#5151 made the same change to main's tests). exclude_infra needs no change for agent_overrides: its voters do not depend on overlong_filtering, so main's dynamic-sampling check stays limited to masked_reward_policy "exclude". Main's ledger schema is still 8, so failure_kind stays in schema 9. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
What
grpo.agent_overridessets GRPO options per environment in multi-environment NeMo-Gym runs on the SingleController path with token capture. Each entry is keyed by the rows' attribution key, the same key asgrpo.length_penalty.agent_overrides: the Gym agent name for flat rows, thetask_id.tasksetfor materialized task rows. Set fields replace the run-wide value for that agent's rows; unset fields inherit it.overlong_filteringgrpo.overlong_filteringnormalize_rewardsgrpo.adv_estimator.normalize_rewardsWith
agent_overridesunset nothing changes: rows are not tagged, and the mask helper and the estimator get the same arguments as before.Why
Multi-environment runs mix pass/fail environments with judge-graded ones. A rubric-graded reward (for example the share of criteria passed) often differs little between the answers of one group. Dividing those advantages by the group's std turns small judge disagreements (0.80 vs 0.85 of criteria) into full-size advantages, which suits binary rewards but not graded ones. Cut-off handling has the same issue: some environments want truncated rows penalised, others masked. Both settings are run-wide today.
How
rollout_reassembler.py): when overrides are configured, each published row's tag getsAGENT_NAME_TAG(data_plane/schema.py), by rollout slot. Rows without a reward context, such as Forest execution padding, take their group's agent.advantage_stage.py):agent_override_rowsturns the tags into per-row switches._apply_async_sample_masksaccepts a per-rowoverlong_filteringtensor.GRPOAdvantageEstimator.compute_advantageaccepts an optional per-rownormalize_rowstensor.num_masked_seqs_by_overlong_filtering/<agent>for each configured agent, andnum_rows_without_agent_tag(rows that fell back to the run-wide values).normalize_rewardsoverrides need thegrpoestimator;overlong_filteringoverride must equal the run-wide value under dynamic sampling withmasked_reward_policy: exclude, because dynamic sampling votes with the run-wide flag;token_capture.enabled(only the token-capture finalizer tags rows);setup()path raises before the Logger and checkpoint manager start.docs/guides/grpo.md, plus one line each insingle-controller.mdandnemo-gym-integration.md.Tests
CPU run in the
rl-nt4container, this branch againstmain492e1b7:tests/unit/algorithms/test_grpo_agent_overrides.py(new)tests/unit/test_config_v2.pytests/unit/single_controller/test_advantage_stage.pytests/unit/single_controller/test_setup.pytests/unit/single_controller/test_logical_advantage.pytests/unit/experience/test_rollout_reassembler_actor.pytest_advantage_estimator.py,test_advantage_validity.py,test_grpo_group_identity.pytests/unit/algorithms/test_grpo.py -k "mask or overlong or config"tests/unit/algorithms/test_grpo.py -k "agent_overrides or router_replay_before_side_effects"tests/unit/data_plane/test_rollout_reassembler.py --nemo-gym-onlyThe two finalizer failures (
test_finalize_group_publishes_minf_routes_staged_through_the_stager,test_megatron_capture_two_turn_media_finalizes_to_the_engine_pixels) fail the same way onmainin this environment.The stage tests check, in both directions (run-wide off/on, override flipping both fields), that each key's rows come out exactly as a run with that key's settings applied run-wide, on the ordinary and the Forest owner paths, and that untagged rows keep the run-wide settings.
ruff checkandruff format(0.9.9) are clean.Not yet exercised in a full training run.
Checklist
🤖 Generated with Claude Code