Repository navigation
feat(single-controller): support reward_scaling on the SC path - #4878
Conversation
|
/ok to test 483b6f9 |
483b6f9 to
317c9d5
Compare
|
/ok to test 709b8de |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
Reviewed all eight changed files across three independent topics: runtime reward handling, setup/configuration contracts, and tests/fixtures. The shared scaling helper is applied before advantage and reward-metric consumers, while DataPlane rewards remain unchanged. The clamping tests make omitted scaling observable, and the PPO fixture change retains its GAE writeback assertions.
One correctness issue and two low-severity guideline suggestions remain:
- (C1) Enabled scaling accepts non-finite bounds that can produce NaN rewards.
- (C2) New test helpers and setup tests lack required type annotations.
- (C3) Two added in-function comment blocks exceed the pinned review guidance.
The supplied training comparisons provide quantitative parity evidence. This review was static: tests, linters, and training runs were not executed.
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.
709b8de to
ff51bdb
Compare
|
/ok to test ff51bdb |
ff51bdb to
482754f
Compare
|
/ok to test 482754f |
mehraakash
left a comment
There was a problem hiding this comment.
Please rebase first. docs/guides/single-controller.md conflicts with main (the same feature-gap paragraphs were edited there since this branch was cut). The seven code and test files merge cleanly.
Verdict: nothing blocks merge. The change does what it says: the scale is applied once, right after the stage reads the rewards and before the baseline, the logged reward and the training dump see them, mirroring v1's order in grpo.py and ppo.py. The DataPlane column stays raw. Five agents found no PR-introduced bug. The 24 new tests and the whole advantage-stage file pass on CPU; the parity run is the right shape of evidence, since a non-clamping remap cannot move std-normalised GRPO advantages and the logged-reward minimum of −0.5625 shows the scale reached the metric.
Design calls that look right and should stay: the inline call with a one-key wrapper (a shared v1/SC transform helper would be over-abstraction; the reward_shaping PR can slot in after truncated is read at L397-399 and keep scale-then-shape), removing the entry from the unsupported list rather than adding a second list, and PPOConfig.model_construct() for the PPO stub.
Inline: one low-severity test ask (PPO/GAE path), one optional design suggestion, one doc clause. One more nit for the rebase, no thread: main now flags in-function comment blocks of three or more lines (skills/contributing/references/comments-docstrings-and-docs.md); the two new blocks at advantage_stage.py:385-387 and test_single_controller_actor.py:4208-4210 are exactly three lines.
Generated by Claude Code
482754f to
ab0ae95
Compare
|
/ok to test ab0ae95 |
The SingleController path rejected reward_scaling at setup rather than silently skipping it. Apply it instead, in the advantage stage. scale_rewards is reused from the v1 path rather than reimplemented, and is called where v1 calls it: ahead of the baseline, the logged reward, and masked_correct_pct. The map is per-row, so a shard produces the same numbers as the whole batch and the stage stays shardable. The DataPlane column keeps the env's raw reward; only the stage's view is scaled. Setup now rejects an enabled block whose source_min >= source_max. The remap divides by that interval, so an empty or inverted one surfaces as inf/nan or sign-flipped advantages a whole rollout later, naming nothing. reward_shaping and use_dynamic_sampling are still rejected. The fixture's rewards are 0/1 and GRPO normalizes by the group std, so an affine remap leaves the advantages untouched; the tests use a clamping source interval, which is the observable part of the map. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: ruit <[email protected]>
…_setup
They went into test_ppo_setup.py because that is where the rejection
test they replaced lived. But the class is TestPPOValidation in a file
documented as "the PPO half of the setup path", and these cover a GRPO
config -- the file already had that mismatch and this was making it
worse.
test_setup.py is the right home: it already exercises
validate_single_controller_config, and TestOPDFullValidation next door
is the same kind of test, rejecting at startup rather than once the
cluster is up.
test_ppo_setup.py keeps only the one change it owes this branch:
reward_scaling leaves the unsupported-knob parametrization, since setup
no longer raises NotImplementedError for it.
Two changes on the way over, so this is not a pure move:
- dropped the grpo/ppo parametrization. The check reads the
reward_scaling block off whichever algorithm block is present, so
the surrounding one cannot affect it and GRPO alone covers it.
- renamed the accepting test after what it covers, the [0, 1] ->
[-1, 1] interval every dapo-* recipe sets.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: ruit <[email protected]>
L0_Unit_Tests_Other caught what the local runs could not:
advantage_stage.py:355, in run
rewards = scale_rewards(
BatchedDataDict({"total_reward": rewards}), cfg.algo.reward_scaling
AttributeError: 'types.SimpleNamespace' object has no attribute
'reward_scaling'
test_advantage_stage_writes_gae_returns_alongside_advantages built the PPO
algo block as a SimpleNamespace listing only the three fields it cared about,
so reading a fourth off it raised. The stage is right to read the field
unconditionally -- PPOConfig and GRPOConfig both declare it, and a getattr
fallback there would hide a genuinely missing config.
Use PPOConfig.model_construct() instead. It fills every default, including
default_factory ones, and still skips validation, so the next field added to
the block does not break this test again. Its defaults are already the three
the test wanted: adv_estimator.name "gae", overlong_filtering False,
seq_logprob_error_threshold None. The file builds its other PPO stub the same
way at line 2914.
The GRPOConfig.model_construct stubs were never affected, for the same reason
the fix works.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: ruit <[email protected]>
Run the sharding test with the recipe interval so the logged reward moves and a shard-dependent scale bug is caught, fix the "scaling block" docstring, and update the SC PPO exemplar yaml comment that still said SC implements neither reward knob. Co-Authored-By: Claude Code <[email protected]> Signed-off-by: ruit <[email protected]>
An infinite bound ordered fine against the existing source-interval check and then made the remap divide inf by inf; a nan bound compared False against every comparison and slipped through the same way. Both reached training and turned every finite reward into inf/nan, a whole rollout later and naming no config key -- scale_rewards(0.5) returns nan under source_min=-inf, and inf under target_max=inf. Check math.isfinite on all four bounds ahead of the interval check, and name the offending ones in the error. Target bounds are still not required to increase: a constant [1, 1] or reversed [1, -1] target is a legal remap. Both checks now share one `enabled` guard. Cover the four bounds against nan and both infinities, the two finite target intervals, a disabled block with an infinite bound, and the PPO block through algo_config. Also annotate the five signatures the review flagged and shorten the two over-long in-function comments. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: ruit <[email protected]>
Signed-off-by: ruit <[email protected]>
Signed-off-by: ruit <[email protected]>
ab0ae95 to
af8f145
Compare
|
/ok to test e8c94a7 |
mehraakash
left a comment
There was a problem hiding this comment.
Approving. All three of my threads are fixed in 3375579 and verified at e8c94a7: the PPO test fails when scale_rewards is stubbed to the identity, the shared RewardScalingConfig validator rejects inverted and non-finite bounds for both v1 and SC entry points, and the docs match the code. CI is green on this head.
One note for @aroshanghias-nvd: this PR removes grpo.reward_scaling.enabled from the validate_forest_objective unsupported table (#4878 (comment)), so reward scaling is now allowed under token_capture.forest_training. The scale runs on the physical rows before the logical-owner baseline, with a regression test in test_logical_advantage.py (test_forest_reward_scaling_before_owner_baseline) and Forest GPU runs off/on linked in that thread. Flagging in case you want to look at it, since the Forest objective rules are yours.
Generated by Claude Code
|
Thanks for flagging this, @mehraakash. I checked the forest path: valid segments of a rollout receive the same finalized reward, so scaling each row before computing the logical-owner baseline is consistent with our current design. The multi-segment regression coverage looks good. I also noticed that scaling can hide a mismatch from the existing segment-reward consistency check if both values get clamped. This is a defensive-check gap; I haven’t found a normal path that produces mismatched segment rewards. |
What does this PR do ?
Applies
reward_scalingon the SingleController path, which until now rejected it at setup.The knob has always existed on the v1 path (
grpo.scale_rewards). SC listed itin
_validate_algo_settings'unsupportedset and raised, so any recipecarrying it — every
dapo-*recipe does — could not run on SC at all.Where it is applied, and why there
scale_rewardsis reused rather than reimplemented, and is called where v1calls it: in the advantage stage, ahead of every other reader of
rewards—the baseline, the logged
train/reward, andmasked_correct_pct. Thatordering is what makes the two paths produce the same numbers.
The map is per-row, so a shard produces the same result as the whole batch and
the stage stays shardable. The DataPlane column keeps the environment's raw
reward; only the stage's view of it is scaled, so a replayed or re-read row is
never scaled twice.
One new setup check
An enabled block with
source_min >= source_maxis now rejected at setup. Theremap divides by that interval, so an empty or inverted one surfaces as inf/nan
or sign-flipped advantages a whole rollout later, with nothing naming the
config key that caused it.
reward_shapinganduse_dynamic_samplingare still rejected — they aretracked separately.
Issues
Closes the
reward_scalinghalf of the SC feature gap tracked in thePrimeRL-vs-NeMo-RL comparison (row 13: "V2 only, already supported in V1").
Usage
[0,1] -> [-1,1]is what everydapo-*recipe inexamples/configs/recipes/llmsets.Testing
Unit
TestRewardScalingintests/unit/single_controller/test_advantage_stage.pyand
TestRewardScalingValidationintest_setup.py.One thing worth flagging for review: a naive test here passes whether or not
the scaling ran. The fixture's rewards are 0/1 and GRPO normalizes by the
group std, so
(r - mean) / stdis invariant under any positive affine remap —a test written on
target_min=-1would prove nothing. The tests therefore usea source interval that clamps, which is the only non-affine part of the map
and so the only observable one.
Three-arm 100-step run on 4x4 GB200 (nanov3-30BA3B, DAPOMath17K)
Forest Test
PPO
Because of that same invariance, the on-cluster check is a parity test: the
pass condition is a non-difference in the learning dynamics, with a difference
only in the reported reward.
train/rewardtrain/losstrain/grad_normtrain/advantages/maxtrain/advantages/minConverting the scaled arms back with
acc = (reward + 1) / 2:6400 rollouts per arm. The difference sits inside the sampling noise, and its
sign flipped as the sample grew (-0.021 at 6 steps, +0.009 at 20, -0.002 at 57,
-0.007 at 100) rather than settling on a non-zero value. The v1 arm landing
between the two SC arms is the cross-path check: this is not just SC agreeing
with itself.
min(train/reward)on the scaled arms is -0.5625, which[0,1] -> [0,1]cannot produce — direct evidence the scale reached the logged reward.
A sharper signal showed up partway through: at 57 steps both SC arms reported
advantages/{max,min}of±2.47487, agreeing to six significant figures. Thatvalue is the advantage of the single correct completion in an 8-generation
group,
(1 - 1/8) / 0.35355; under the scaled reward the same group gives(1 - (-0.75)) / 0.70711, the identical number. The residual is ~1e-6, thesize of the
epsiloninadvantage_estimator.py. That is the affineinvariance showing up directly in the metrics.
Before your PR is "Ready for review"
Pre checks:
Additional Information
reward_shapingPR. Both touch theunsupportedlistin
config.pyand the same block inadvantage_stage.py. Whichever mergessecond must take the union of the two deletions from the list, and must
keep the order scale first, then shape — the overlong penalty's magnitude
is only meaningful against the scaled reward's range, which is how v1 orders
them (
grpo.py).test_single_controller_actor.pybuilds the PPO advantage-stage stub withPPOConfig.model_construct()instead of aSimpleNamespacelisting threefields. Reading a fourth field off that namespace raised
AttributeError;model_constructfills every default and still skips validation, so adding afield to the block will not break it again.