Skip to content

fix(sc): apply reward scaling before advantage estimation - #3787

Closed
tianyi-zhang-02 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
tianyi-zhang-02:fix/sc-grpo-knob-parity
Closed

tianyi-zhang-02 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
tianyi-zhang-02:fix/sc-grpo-knob-parity

Conversation

@tianyi-zhang-02

@tianyi-zhang-02 tianyi-zhang-02 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes Single Controller apply the existing grpo.reward_scaling setting before advantage estimation, using the shared scale_rewards helper.

This PR is intentionally limited to reward scaling. Current main already provides advantage clipping, overlong filtering, and environment sample masking. Reward shaping and message-level penalties remain out of scope because Single Controller does not yet carry the response-length/message fields they need.

The shipped default remains a no-op, and algorithms without a reward-scaling block remain unchanged.

Validation

Current head 90d294e9df9376dec52d71d94488d814a8d20b72, rebased onto upstream main at 90a2a212d503455d8590be5c8de3cb989d3425b0.

  • full tests/unit/single_controller/test_single_controller_actor.py: 61 passed
  • caller-level coverage verifies scaling happens before advantage estimation and that logged rewards use the scaled values
  • Ruff check, Ruff format check, and git diff --check: passed

An earlier pre-refresh head completed a real 2×H100 SC run with Qwen3-0.6B, Megatron policy/reference, vLLM, and TQ. With scaling enabled, rewards were mapped from 0..1 to -1..1; training completed with loss 0.1040 and grad norm 2.6518. The current head was shrunk against main and rerun through the full SC actor suite; the 2-GPU functional run was not repeated after that refresh.

@tianyi-zhang-02
tianyi-zhang-02 requested review from a team as code owners August 24, 2026 04:40
@copy-pr-bot

copy-pr-bot Bot commented Aug 24, 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.

@tianyi-zhang-02
tianyi-zhang-02 requested review from a team as code owners August 26, 2026 07:05
@tianyi-zhang-02
tianyi-zhang-02 force-pushed the fix/sc-grpo-knob-parity branch from fbed880 to 93c2551 Compare August 26, 2026 07:44
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Aug 26, 2026
tianyi-zhang-02 added a commit to tianyi-zhang-02/RL that referenced this pull request Aug 26, 2026
…ity PRs

NVIDIA-NeMo#3786 and NVIDIA-NeMo#3787 each rewrote this comment to name the knob they removed, so
they conflicted on nothing but the prose -- the tuple entries merged fine.
Stating the rule once, without naming a knob, lets the two auto-merge in
either order.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
tianyi-zhang-02 added a commit to tianyi-zhang-02/RL that referenced this pull request Aug 26, 2026
…ity PRs

NVIDIA-NeMo#3786 and NVIDIA-NeMo#3787 each rewrote this comment to name the knob they removed, so
they conflicted on nothing but the prose -- the tuple entries merged fine.
Stating the rule once, without naming a knob, lets the two auto-merge in
either order.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
@tianyi-zhang-02

Copy link
Copy Markdown
Contributor Author

Heads-up on merge order, with the resolution written out.

Four of my open PRs edit the same twelve-line block — the unsupported knob list in _validate_algo_settings:

I checked every pair by actually merging them. #3786 × #3787 is clean now — they only ever conflicted on the comment wording and on both adding a test before the same anchor, and both are fixed. The remaining four pairs are a genuine textual conflict on that block, and no restructuring avoids it: extracting or reordering the list conflicts just as hard.

So rather than force a stack, here is the resolution. Whichever order they land in, this is the merged form:

    # An enabled one here describes shaping this run does not do. An entry
    # leaves this list when the SC path starts implementing it -- rejecting a
    # knob is only right while nobody honours it.
    #
    # DistillationConfig defines none of them: there is no reward to shape or
    # filter on, so the list cannot even be evaluated on that path.
    unsupported = (
        []
        if is_distillation_run(master_config)
        else [
            name
            for name, enabled in (
                ("use_dynamic_sampling", algo_cfg.use_dynamic_sampling),
                ("reward_scaling", algo_cfg.reward_scaling.enabled),
                ("reward_shaping", algo_cfg.reward_shaping.enabled),
            )
            if enabled
        ]
    )

I built that merge locally and ran the SC and config suites against it — 1084 passed. Happy to rebase whichever ones are left once the first lands; just say which order you want.

tianyi-zhang-02 added a commit to tianyi-zhang-02/RL that referenced this pull request Aug 26, 2026
The guard used to wrap that list in a conditional, which put this PR on the
same twelve lines as NVIDIA-NeMo#3786 and NVIDIA-NeMo#3787 -- each of those removes an entry from
it. Four pairwise conflicts on nothing but placement.

Returns early instead. DistillationConfig defines none of the knobs the list
names, so the check does not apply and the comprehension could not be
evaluated anyway; everything after it is PPO-specific and returns early on
this path already. The colocated requirement is the one thing that does
apply, so it moves into a helper and the guard calls it directly rather than
falling through.

The list itself is now untouched by this PR, so all four conflicts go away
and none of the three needs to land before the others.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
tianyi-zhang-02 added a commit to tianyi-zhang-02/RL that referenced this pull request Aug 26, 2026
The guard used to wrap that list in a conditional, which put this PR on the
same twelve lines as NVIDIA-NeMo#3786 and NVIDIA-NeMo#3787 -- each of those removes an entry from
it. Four pairwise conflicts on nothing but placement.

Returns early instead. DistillationConfig defines none of the knobs the list
names, so the check does not apply and the comprehension could not be
evaluated anyway; everything after it is PPO-specific and returns early on
this path already. The colocated requirement is the one thing that does
apply, so it moves into a helper and the guard calls it directly rather than
falling through.

The list itself is now untouched by this PR, so all four conflicts go away
and none of the three needs to land before the others.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
tianyi-zhang-02 added a commit to tianyi-zhang-02/RL that referenced this pull request Aug 26, 2026
The guard used to wrap that list in a conditional, which put this PR on the
same twelve lines as NVIDIA-NeMo#3786 and NVIDIA-NeMo#3787 -- each of those removes an entry from
it. Four pairwise conflicts on nothing but placement.

Returns early instead. DistillationConfig defines none of the knobs the list
names, so the check does not apply and the comprehension could not be
evaluated anyway; everything after it is PPO-specific and returns early on
this path already. The colocated requirement is the one thing that does
apply, so it moves into a helper and the guard calls it directly rather than
falling through.

The list itself is now untouched by this PR, so all four conflicts go away
and none of the three needs to land before the others.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
tianyi-zhang-02 added a commit to tianyi-zhang-02/RL that referenced this pull request Aug 26, 2026
The guard used to wrap that list in a conditional, which put this PR on the
same twelve lines as NVIDIA-NeMo#3786 and NVIDIA-NeMo#3787 -- each of those removes an entry from
it. Four pairwise conflicts on nothing but placement.

Returns early instead. DistillationConfig defines none of the knobs the list
names, so the check does not apply and the comprehension could not be
evaluated anyway; everything after it is PPO-specific and returns early on
this path already. The colocated requirement is the one thing that does
apply, so it moves into a helper and the guard calls it directly rather than
falling through.

The list itself is now untouched by this PR, so all four conflicts go away
and none of the three needs to land before the others.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Aug 27, 2026
@tianyi-zhang-02
tianyi-zhang-02 force-pushed the fix/sc-grpo-knob-parity branch 2 times, most recently from 9e3cfc4 to 6535295 Compare August 27, 2026 02:56
@tianyi-zhang-02
tianyi-zhang-02 requested a review from a team as a code owner August 28, 2026 17:29
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 28, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Aug 29, 2026
@tianyi-zhang-02 tianyi-zhang-02 changed the title fix(sc): apply advantage clipping and reward scaling in the advantage stage fix(sc): apply reward scaling before advantage estimation Sep 4, 2026
Scale rewards before advantage estimation on the Single Controller path, using the same helper and configuration semantics as legacy GRPO. Preserve current-main filtering and clipping behavior, and keep non-GRPO algorithms unchanged when the setting is absent.

Signed-off-by: Tianyi Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants