Skip to content

feat(sc): support GDPO on the SingleController path - #5301

Open
bg51717 wants to merge 14 commits into
NVIDIA-NeMo:mainfrom
bg51717:feat/sc-gdpo
Open

bg51717 wants to merge 14 commits into
NVIDIA-NeMo:mainfrom
bg51717:feat/sc-gdpo

Conversation

@bg51717

@bg51717 bg51717 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What does this PR do ?

Adds GDPO (grpo.adv_estimator.name: gdpo) to the SingleController path, for multi-reward native environments and for NeMo Gym rollouts with token capture off.

Depends on #5287; until it merges, this diff also shows its commit.

  • The advantage stage finds every reward/<name> column in the step's payload and passes them to the GDPO estimator. It raises if there are fewer than two.
  • NeMo Gym results fill Completion.reward_components from the verifier's reward_components, so native and Gym rollouts write the columns through the same payload code. A sample without components gets zeros, and a verifier whose reward differs from the sum of its components is rejected, both as on the legacy path.
  • Setup rejects GDPO with token capture, with grpo.reward_shaping, with grpo.length_penalty, with reward_penalties, and with env.nemo_gym.effort_levels. The last four adjust only the scalar reward, which GDPO does not read.
  • Adds examples/configs/gdpo_math_1B_megatron_single_controller.yaml, the SingleController variant of gdpo_math_1B.yaml.
  • Moves the Gym GDPO nightly to SingleController and adds a native one, which checks that the mean reward of the last 10 steps is above 2.4. Both have a 30 minute limit, so the nightly GPU hours are unchanged.

Issues

Part of the "GDPO / component-wise reward advantages" item in #5044.

Usage

uv run examples/run_grpo_single_controller.py \
    --config examples/configs/gdpo_math_1B_megatron_single_controller.yaml

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • GDPO on the same task through three paths: SingleController with the native environment, SingleController with NeMo Gym, and the legacy path with the native environment. The task is GSM8K scored on three rewards (math_multi_reward: correctness, integer, format; maximum 3.0), with Qwen2.5-1.5B-Instruct, Megatron, 8 prompts x 8 generations, 50 steps, one run each. train/reward and train/grad_norm:
截屏2026-11-19 12 55 12

NeMo Gym has no environment for this task, so the Gym run used a local resources server that scores a response with the same rules as math_multi_reward. It is not part of this PR.

  • The Gym nightly task (example_tool_call_multireward) on SingleController, 30 steps: mean reward 1.98 to 2.00 of 2.0 throughout. The task is saturated from the first step, so this run shows that the Gym path works, not that it learns.
  • New functional tests pass locally: gdpo_single_controller.sh (native) and gdpo_gym_single_controller.sh (Gym). Both are in L1_Functional_Tests_SingleController_1.sh.
  • Existing functional tests pass locally: grpo_dp_single_controller.sh, ppo_async_single_controller.sh, grpo_async_gym_single_controller.sh.
  • Unit tests cover the Gym component conversion, the advantage stage against the legacy estimator, and the five setup rejections.

@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 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.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 19, 2026
@bg51717 bg51717 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 19, 2026

@bg51717 bg51717 left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GDPO math on SC was checked against the legacy path and matches: it uses the same scale_rewards and the same GDPOAdvantageEstimator. Unit tests pass, 755 across the touched files on CPU.

  1. (C5) The components-vs-scalar check crashes after reward penalties or effort shaping; validate against reward_original.
  2. (C2) Also reject GDPO with reward_penalties and env.nemo_gym.effort_levels.
  3. (C3) Nit: reuse get_gdpo_reward_component_keys instead of copying the reward/ rule.
  4. (C4) Nit: the nightly.txt comment still says the native path is covered elsewhere.

Generated by Claude Code (#4999 version)

Comment thread tests/test_suites/nightly.txt Resolved
Comment thread nemo_rl/experience/rollout_manager.py Resolved
@bg51717

bg51717 commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

/ok to test 06dd112

@bg51717

bg51717 commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

/ok to test 2ad441e

@bg51717
bg51717 marked this pull request as ready for review November 19, 2026 13:16

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main correctness issue is C6: missing Gym reward components are zero-filled within a prompt group, but not across the groups selected for one GDPO batch. That can make the advantage-stage fetch fail. C7 corrects the new field contract; C8 adds the required header to the new nightly script.

I verified the earlier fixes in the current source: setup rejects scalar-only penalties and shaping, component discovery uses the shared helper, validation checks the verifier's original reward, and the stale nightly comment is gone.

Static review only. I did not run tests or lint, and CI results were unavailable. The Gym submodule source was not populated, so external Gym behavior could not be checked. Two delegated reports were unavailable; I inspected their estimation/setup and recipe/test assignments directly.

Generated by Codex

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

)
# A sample without components gets zeros, as on the legacy path, so a
# verify result that omits them does not fail the group's payload.
component_columns = build_reward_component_columns(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C6 · 1 action item. TL;DR — correctness bug: group-local zero-filling leaves valid GDPO batches with missing component columns.

This is PR-introduced. Consider one step containing two two-response Gym groups. Group A returns components [{"a": 1, "b": 1}, None] and scalar rewards [2, 0]; group B returns no components and scalar zero on both responses. This conversion gives A both columns but gives B none. The payload helper omits component columns for B, selection concatenates the groups, and metadata concatenation unions their field names. The advantage stage requests both components for every selected row, which reaches the adapter's missing-column KeyError. B should receive zeros under the missing-component fallback.

AI-1

Normalize component coverage before selection merges the individual group metadata. Use each group's fields to identify missing components, write float32 zeros for those rows, and update the metadata through a replay-buffer helper under its checkpoint mutation barrier. The invariant is that every selected row has every component in the selected union. Do not use an intersection, overwrite existing values, or invent component names for an entirely scalar batch. This crosses batch assembly and replay-buffer writes, so the exact helper placement needs implementation verification rather than a one-region patch.

Acceptance, proposed and not run: publish and select the two groups above, then run the advantage stage. Both component columns should be [1, 0, 0, 0], fetching should succeed, and advantages should match the estimator given those complete columns. Keep the within-group zero-fill assertions, all-scalar omission behavior, and genuine verifier-mismatch rejection.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 837fbb3. TQReplayBuffer.claim_for_training now zero-fills the reward/<name> columns a claimed group lacks, so every built-in sampler is covered. Added TestTQReplayBufferRewardComponentFill with the two-group case from this comment.

Comment thread nemo_rl/experience/interfaces.py Outdated
# dynamic sampling filters on. ``None`` means nothing rewrote ``reward``.
reward_original: Optional[float] = None
# Per-component rewards of a multi-reward environment, keyed by the
# environment's component names and summing to ``reward``. ``None`` for a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C7 · 1 action item. TL;DR — documentation: components need not sum to the completion's adjusted scalar reward.

This new contract contradicts the supported GRPO penalty path. The new regression explicitly expects scalar reward zero while keeping components summing to one. The component keys are also payload keys with the reward/ prefix, not unprefixed verifier names.

AI-1

Replace this comment line so the declaration describes the raw values without promising equality after scalar-only adjustments:

Suggested change
# environment's component names and summing to ``reward``. ``None`` for a
# ``reward/<name>`` keys, before scalar-only adjustments. ``None`` for a

Acceptance, static check: read the resulting field comment as describing prefixed, unadjusted component values. Keep the penalty regression's zero scalar and unchanged component assertions; do not change runtime behavior to satisfy the old comment. The suggestion has not been executed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9bf3f0e. The comment now says the keys are reward/<name> and that effort shaping and reward penalties change reward but not the components.

@@ -0,0 +1,38 @@
#!/bin/bash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C8 · 1 action item. TL;DR — guideline: the new nightly script is missing the required NVIDIA copyright header.

This is a new shell script, so the protected copyright rule applies. This finding does not cover the renamed Gym script's pre-existing header omission.

AI-1

Keep the shebang first and insert the notice immediately after it:

Suggested change
#!/bin/bash
#!/bin/bash
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Acceptance, static check: the script starts with the shebang and complete notice; executable statements, the 30-minute allocation, and the reward assertion stay unchanged. This is a comment-only suggestion, not an executed validation result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 61e0553. Added the header after the shebang.

AsyncRolloutImpl accumulates a dict of rewards per component, keeps their sum as the completion reward, and the rollout payload writes one reward/<name> column per component.

Signed-off-by: bg51717 <[email protected]>
Reward shaping adjusts only total_reward, which GDPO does not read, so the run would silently skip the shaping. Reject the combination at setup, and name gdpo in the full-batch error.

Signed-off-by: bg51717 <[email protected]>
The recipe now inherits the SingleController exemplar (Megatron trainer, non-colocated vLLM, sync in_order sampler) and its script runs examples/run_grpo_single_controller.py.

Signed-off-by: bg51717 <[email protected]>
grpo.length_penalty adjusts only the scalar reward after the Gym results become completions, and GDPO reads only the reward components, so the penalty would be silently skipped.

Signed-off-by: bg51717 <[email protected]>
Adds the SingleController variant of gdpo_math_1B.yaml and a functional test that runs it, and registers both SingleController GDPO functional tests in the L1 list.

Signed-off-by: bg51717 <[email protected]>
Both change only the scalar reward, which GDPO does not read, so the run
would silently skip them.

Signed-off-by: bg51717 <[email protected]>
A prompt group writes only the reward/<name> columns its own completions
carry, but a train step fetches the columns of all its groups from every
row. A GDPO step that mixed a group with components and a group without
them failed in the advantage stage with a missing-column KeyError.

claim_for_training now writes float32 zeros for the columns a claimed
group lacks and adds them to its metadata, inside the claim's mutation
section. Existing values are kept and a claim without any component
column writes nothing.

Signed-off-by: bg51717 <[email protected]>
@bg51717

bg51717 commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

/ok to test 837fbb3

@RayenTian RayenTian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding GDPO support to the single-controller path! The test coverage is thorough. I left a few comments inline.

)
# Check the verifier's own reward: effort shaping and the penalties
# above rewrite full_result["reward"] but not its components.
validate_reward_components_match_scalar(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C9 · 1 action item. TL;DR — Could the new sum check reject a correct MCQA answer when both grading rules give it full credit?

In boxed_and_normalized mode, the answer \boxed{B} with gold label B gets strict_boxed=1.0 and normalized=1.0. MCQA uses the strict score as its scalar reward, so it returns 1.0. The previous SC path accepted that result. This check raises ValueError because the scores sum to 2.0, even with shaping and penalties disabled. MCQA scoring code

AI-1

Should the SC Gym path accept this result and preserve both the verifier’s scalar reward and its named scores?

"preserve. Set token_capture.enabled=false to use GDPO."
)

if algo_cfg.adv_estimator.name == "gdpo" and algo_cfg.reward_shaping.enabled:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C10 · 1 action item, 1 follow-up. TL;DR — Could SC reject reward-side KL for GDPO when the coefficient is nonzero? The configuration currently passes setup but silently drops the penalty.

This behavior predates this PR and also affects standard GRPO. With loss_fn.use_kl_in_reward=true and loss_fn.reference_policy_kl_penalty=0.01, the shared loss sets its own KL coefficient to zero, expecting the estimator to apply the penalty. Neither the standard GRPO nor the legacy GDPO estimator does so. This PR makes that combination reachable for GDPO on SingleController. Existing loss behavior · Existing GRPO and GDPO estimators

AI-1

Could we reject that GDPO combination here at setup and point users to use_kl_in_reward=false to keep the penalty in the loss? A regression test could check that the same nonzero coefficient is rejected with the flag on and accepted with it off.

Follow-up

Could we track reward-side KL support for both GRPO and GDPO in a separate issue, so the legacy and SingleController paths can share the implementation?

input_fields = cfg.input_fields()
repeated_batch_fields = list(adv_cfg.repeated_batch_fields)
if not cfg.is_ppo and cfg.algo.adv_estimator.name == "gdpo":
component_fields = get_gdpo_reward_component_keys(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C11 · 1 action item. TL;DR — Could a run mixing Gym environments silently apply the same weight to different reward objectives across steps?

This behavior predates this PR. Legacy GDPO sorts the component names present in each batch and pairs them with reward_weights by position. Suppose one step contains only an environment scoring correctness and format, and the next contains only one scoring latency and safety. With reward_weights=[1, 0], both steps pass the length check, but the nonzero weight moves from correctness to latency. Legacy GDPO estimator

AI-1

Can this happen in a supported multi-environment Gym run? If so, should GDPO check that the component names associated with explicit, nonuniform weights stay consistent across steps?

cd $PROJECT_ROOT
uv run --group test coverage run -a --data-file=$PROJECT_ROOT/tests/.coverage --source=$PROJECT_ROOT/nemo_rl \
$PROJECT_ROOT/examples/run_grpo_single_controller.py \
--config $PROJECT_ROOT/examples/configs/gdpo_math_1B_megatron_single_controller.yaml \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C12 · Optional suggestion (non-blocking). TL;DR — Would it be useful to run the native SC GDPO functional test with AutoModel?

The SC GDPO functional and nightly tests added here all use Megatron. GDPO computes advantages before the policy update, so switching this functional test to AutoModel would exercise the same multi-reward training path with a second training backend. The Gym functional test and both nightlies would still cover Megatron.

Once this branch is up to date with main, would you consider adapting this test to the existing AutoModel SC full-batch smoke configuration?

@@ -56,7 +55,4 @@ uv run tests/json_dump_tb_logs.py $LOG_DIR --output_path $JSON_METRICS
if [[ $(jq 'to_entries | .[] | select(.key == "train/loss") | .value | keys | map(tonumber) | max' $JSON_METRICS) -ge $MAX_STEPS ]]; then
uv run tests/check_metrics.py $JSON_METRICS \
'max(data["train/reward"]) > 0.0'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this check be too lenient for a nightly? A positive reward on the first step would let the run pass even if the reward stays at zero for every remaining step. Is that sufficient for this Gym recipe?

This branch has not been deployed

No deployments
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.

4 participants