Skip to content

feat(gym): apply effort-level reward shaping in the SingleController - #3770

Merged
yuki-97 merged 4 commits into
mainfrom
ruit/v2_2770_effort_level_gym
Aug 25, 2026
Merged

yuki-97 merged 4 commits into
mainfrom
ruit/v2_2770_effort_level_gym

Conversation

@RayenTian

@RayenTian RayenTian commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

PR #2770 only wired length-based effort reward shaping into the run_grpo.py (v1) synchronous paths. The SingleController (v2) path runs its own NeMo-Gym rollout via RolloutManager/AsyncNemoGymRolloutImpl, which never applied it.

  • Thread EffortLevelsConfig through RolloutManager into AsyncNemoGymRolloutImpl and call the shared _apply_effort_shaping before completions are built, so the shaped reward flows into Completion.reward.
  • Fold the effort length/reward metrics into _compute_rollout_metrics.
  • setup.py resolves the config via the shared _get_effort_config helper.

No behaviour change when env.nemo_gym.effort_levels is unset (_get_effort_config returns None -> shaping is a no-op).

result

image image

Issues

List issues that this PR closes (syntax):

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

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

  • ...

@copy-pr-bot

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

@RayenTian
RayenTian force-pushed the ruit/v2_2770_effort_level_gym branch from 31960c0 to 316182c Compare August 23, 2026 03:41
@RayenTian RayenTian added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Aug 23, 2026
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test 316182c

@RayenTian
RayenTian marked this pull request as ready for review August 23, 2026 05:21
@RayenTian
RayenTian requested review from a team as code owners August 23, 2026 05:21
@RayenTian
RayenTian requested review from terrykong, yfw and yuki-97 August 23, 2026 12:37
Comment thread nemo_rl/experience/rollout_manager.py Resolved
Comment thread nemo_rl/experience/rollouts.py Resolved
RayenTian and others added 4 commits August 24, 2026 23:40
…ller rollout path

PR #2770 only wired length-based effort reward shaping into the run_grpo.py
(v1) synchronous paths. The SingleController (v2) path runs its own NeMo-Gym
rollout via RolloutManager/AsyncNemoGymRolloutImpl, which never applied it.

- Thread EffortLevelsConfig through RolloutManager into AsyncNemoGymRolloutImpl
  and call the shared _apply_effort_shaping before completions are built, so the
  shaped reward flows into Completion.reward.
- Fold the effort length/reward metrics into _compute_rollout_metrics.
- setup.py resolves the config via the shared _get_effort_config helper.

No behaviour change when env.nemo_gym.effort_levels is unset (_get_effort_config
returns None -> shaping is a no-op).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: ruit <[email protected]>
Applying effort shaping in the SingleController path broke four unit tests
in the L0_Unit_Tests_Other shard, in two independent ways:

  - `_run_rollouts` reads `self._effort_config` unconditionally, but
    `test_rollout_generation_failures._make_gym_impl` and the stand-in in
    `test_rollouts` build the impl via `object.__new__` and never set it
    -> AttributeError.
  - `_compute_rollout_metrics` gained a required third positional param,
    while the monkeypatched stub in `test_rollouts` still took two
    -> TypeError.

Extract the shared `_effort_shaping_metrics` helper in rollouts.py and have
both the batched v1 path and the rollout manager `update` from it. The SC
metric block was a line-by-line copy of the v1 one, so this removes the
duplication and, because the caller now updates the dict itself,
`_compute_rollout_metrics` keeps its original two-argument signature -- the
TypeError disappears with no test change. The impl stand-ins get an explicit
`_effort_config = None`.

Verified the helper is equivalent to the inline blocks it replaces over 500
randomized inputs, including the empty case.

Also add the wiring coverage this path never had: the existing
test_effort_shaping cases only exercised `_apply_effort_shaping` as a pure
function. The new cases drive the real `_run_rollouts` so they pin down that
shaping happens before `_result_to_completion` -- otherwise `Completion.reward`,
which becomes `total_reward` in the train batch, keeps the env's raw reward --
plus `_get_effort_config` resolution through `setup_single_controller`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: ruit <[email protected]>
Co-authored-by: Yuki Huang <[email protected]>
Signed-off-by: Rayen <[email protected]>
Signed-off-by: ruit <[email protected]>
@RayenTian
RayenTian force-pushed the ruit/v2_2770_effort_level_gym branch from 58d4e9f to bbc8191 Compare August 25, 2026 06:40
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test bbc8191

@yuki-97
yuki-97 enabled auto-merge (squash) August 25, 2026 11:58
@yuki-97
yuki-97 merged commit 32bb7a3 into main Aug 25, 2026
94 checks passed
@yuki-97
yuki-97 deleted the ruit/v2_2770_effort_level_gym branch August 25, 2026 11:58
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.

2 participants