Skip to content

fix: preserve advantage statistics across filtering and batch splitting - #5216

Merged
terrykong merged 6 commits into
mainfrom
terryk/guard-advantage-mask-equivalence
Nov 17, 2026
Merged

terrykong merged 6 commits into
mainfrom
terryk/guard-advantage-mask-equivalence

Conversation

@terrykong

@terrykong terrykong commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Prevent advantage statistics from changing when sequence-error filtering moves into the loss, a step streams in chunks, or advantage actors split its batch.

Configuration Behavior
GRPO masked_reward_policy=exclude + seq_logprob_error_in_loss=true Reject. Use include, or filter before computing advantages.
PPO normalized advantages + in-loss sequence filtering Reject. Disable normalization, or filter before computing advantages.
Any estimator with requires_global_batch=true + streaming Reject. Wait for the complete prompt batch or choose estimator settings without global statistics.
Any estimator with requires_global_batch=true + multiple advantage actors Send the complete batch to one actor.

Turning off seq_logprob_error_in_loss keeps the threshold enabled and restores the separate policy-logprob pass. Full-batch chunks use async_rl.min_groups_for_streaming_train == <algorithm>.num_prompts_per_step.

One requirement for streaming and sharding

Each estimator implements the required requires_global_batch property. Validation and actor dispatch read that property from the same estimator factory used for computation, replacing the name-based sharding list and separate streaming checks.

  • GRPO: false; prompt groups must stay intact.
  • Reinforce++ and GDPO: true. GDPO remains unsupported on SingleController because component rewards are unavailable.
  • PPO estimators: the value of normalize_advantages.
  • OPD/TROPD: the value of subtract_global_baseline.

This fixes an additional OPD bug even with streaming disabled. For six prompt groups with four identical one-token rollouts each, teacher–student logprob gaps [1, 3, 5, 9, 11, 13] should be centered on 7, giving [-6, -4, -2, 2, 4, 6]. Two actors instead centered their shards on 3 and 11, giving [-2, 0, 2, -2, 0, 2]. The property now keeps that batch together. OPD without a global baseline can still shard. Unnormalized PPO can also shard; its advantages and value targets are checked numerically.

The shared streaming32 PPO recipe disables advantage normalization; its split-critic variant inherits this setting. The full-batch recipe keeps normalization enabled. The PPO mask branch remains necessary because GAE normalizes using its token mask. The GRPO late-filter guard rejects exactly exclude, allowing #4968's proposed exclude_infra policy to compose when it lands.

Regression coverage and validation

  • The six original configuration-rejection cases failed before the guards with DID NOT RAISE.
  • The focused OPD regression passed locally and with one actor, then failed with two actors before the dispatch fix. Its expected values and assertions were unchanged for the passing run.
  • PPO numerical checks cover normalization on/off, controller-local computation, and multiple actors. A property override checks that streaming validation follows the estimator requirement rather than its name.
  • Earlier batching-change CPU suite: 641 passed, 10 optional Megatron-backend cases deselected, across estimator, participation-mask, advantage-stage, setup and configuration tests. The isolated macOS run uses --noconftest to omit unrelated global Ray/GPU-monitor startup; it mocks actor transport and storage while running the real estimators and dispatcher.
  • Another 20 focused tests passed for estimator factories and existing single-forward/in-loss behavior, including the six-sample OPD numbers used in the explainer.
  • Self-review fixes: 284 CPU tests passed. The L1 streaming smoke's inherited YAML plus both scripts' CLI overrides was rejected before the normalization override and accepted afterward; bash -n passes. The GPU smoke itself was not run locally.
  • Pinned ruff 0.9.9 checks and formatting pass. Pinned pyrefly 0.24.2 reports zero errors in the estimator module. Comparing the estimator and SingleController configuration modules against the previous head removes all six new bad-override diagnostics, adds none, and leaves 28 pre-existing configuration diagnostics in this local environment. The earlier zero-error report used a newer pyrefly version.
  • compute_advantage is declared as a ClassVar[Callable[...]]; requires_global_batch remains the only abstract member. The streaming error names the relevant settings and prints both chunk and step sizes.
  • GPU validation: both streaming nightlies and two matched full-batch controls passed. Measured results and plots. No broad comparison matrix was added.

GPU validation

Results, plots, run links, and tested revisions. All four targeted runs passed their nightly checks after 40 steps, including 10 critic-only warmup steps.

Mean reward over the final 10 steps was 0.7363 with normalization and 0.7473 without it in the full-batch controls; streaming32 and streaming32-split scored 0.7174 and 0.7254. The reward curves look similar over these 30 policy updates. This single-seed comparison does not establish equal final convergence.

Every update consumed one chunk of 256 prompt groups, including the minimum-32 recipes. These GPU runs therefore do not validate convergence with multiple chunks per update. The CPU regressions separately check advantage equivalence across chunks and actor shards.

Follows #4160, #5080 and #5130; related to #4968, #4326 and #4357.

Pre checks

  • Followed contributor guidelines.
  • Observed regression failures before applying their fixes.
  • Updated guides and recipe comments.
  • GPU CI validation: both streaming nightlies and matched full-batch controls passed (see results above).

@copy-pr-bot

copy-pr-bot Bot commented Nov 13, 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 13, 2026
@terrykong
terrykong marked this pull request as ready for review November 13, 2026 23:25
@terrykong

Copy link
Copy Markdown
Collaborator Author

/ok to test 041c5a2

@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.

No correctness defects found in the guards, estimator/controller paths, regression assertions or recipe inheritance.

Suggestions

  1. (C1) Add convergence evidence for the streaming recipe's switch to unnormalized advantages. This is a non-blocking validation gap, not a demonstrated training regression.

I inspected all 12 changed files and their directly affected paths. One delegated report wasn't delivered, so I independently covered its setup-validation scope. This review was static: I didn't execute tests or linters, inspect live CI, or independently verify the author-reported results.

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

@terrykong

Copy link
Copy Markdown
Collaborator Author

/ok to test 581a71d

@terrykong terrykong changed the title fix: preserve advantage statistics across filtering and streaming fix: preserve advantage statistics across filtering and batch splitting Nov 14, 2026
@terrykong

Copy link
Copy Markdown
Collaborator Author

/ok to test a062161

@terrykong

Copy link
Copy Markdown
Collaborator Author

/ok to test 7fd61d9

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Self-review of my own PR, run with the review team, at 7fd61d9. The redesign in a062161 is the right shape: each estimator now declares requires_global_batch from its own settings, and the streaming guard and advantage-actor sharding both read it through one create_advantage_estimator(). That replaces three separate name/setting checks. It also fixes a bug already on main: OPD with subtract_global_baseline: true was split across advantage actors, so with 2+ actors each part was centered on its own mean instead of the step's. Worth a line in the PR description. No bugs found in the guards; the new tests pass on CPU, and the unit-test results match the previous head.

Two CI breaks to fix before merge:

  1. (C1) The L1 PPO streaming smoke test now fails at setup; one-line override fix.
  2. (C4) The abstract compute_advantage fails the pinned pyrefly lint.

Also:
3. (C5) The new streaming error prints the whole config; name the setting instead.
4. (C3) Reply on the convergence-run thread: wrong baseline, and the run plan.

Not run: GPU/functional tests.

Generated by Claude Code

@terrykong

Copy link
Copy Markdown
Collaborator Author

/ok to test 1105fab

@yuki-97 yuki-97 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.

Merge blockers — please rebase on main and resolve conflicts.

LGTM, and thanks for addressing the feedback and for the self-review.

Scope: full static review at 7fd61d9, plus the single-commit update to 1105fab and verification of the existing requests.

Checked:

Waiting for nightly run results before merge.

nit

  • Document the shared factory's arguments and return value.

Not blocking merge.

Generated by Codex (#4999 version)

@terrykong
terrykong force-pushed the terryk/guard-advantage-mask-equivalence branch from 1105fab to df4edf2 Compare November 16, 2026 22:39
@terrykong

Copy link
Copy Markdown
Collaborator Author

/ok to test df4edf2

@github-actions

Copy link
Copy Markdown

❌ Submodule Fast-Forward Check Failed

Check based on commit: df4edf2 (PR #5216 from terryk/guard-advantage-mask-equivalence)

❌ Submodules that need attention:

Gym: ❌ PR branch is BEHIND main branch
TARGET (main branch): https://github.com/NVIDIA-NeMo/Gym/commits/23557b7c2a48c60975c7719ee25cb6adb42963b7/
CURRENT (PR #5216 from terryk/guard-advantage-mask-equivalence): https://github.com/NVIDIA-NeMo/Gym/commits/5911d628c744d0bf43fe1d9ddf3bda72d59b0f9a/

Please ensure all submodule commits are fast-forwards of the main branch before merging.

@terrykong terrykong added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 16, 2026
@terrykong
terrykong force-pushed the terryk/guard-advantage-mask-equivalence branch from df4edf2 to 303d240 Compare November 16, 2026 22:51
@terrykong

Copy link
Copy Markdown
Collaborator Author

/ok to test 303d240

@terrykong

Copy link
Copy Markdown
Collaborator Author

@yuki-97 — the two streaming nightlies and both matched full-batch controls passed. The short-run reward curves look similar. Disabling normalization did not reduce the final-10-step mean reward in the full-batch comparison, but these runs do not establish equal final convergence.

Run Nightly checks Mean reward, steps 31–40 Mean policy gradient norm, steps 11–40
Full batch, normalization on Passed 0.7363 0.6528
Full batch, normalization off Passed 0.7473 0.3122
streaming32, normalization off Passed 0.7174 0.3111
streaming32-split, normalization off Passed 0.7254 0.3081

Every update consumed one chunk of 256 prompt groups, including the minimum-32 recipes. The minimum permits smaller chunks but does not require them. These runs therefore do not validate convergence with multiple chunks per update, or a meaningful split-versus-whole-batch critic difference. The CPU regressions separately check advantage equivalence across chunks and actor shards.

Measured reward, policy gradient norm, and actual chunk counts for four matched PPO runs

Plotted values, including warmup (CSV). Reward is shown as faint individual values and a bold trailing five-update mean. All 40 steps and every plotted metric were checked against the original driver logs.

Settings, tested revisions, and run links

All four runs used Qwen2.5-1.5B-Instruct on GSM8K, 16 H100 GPUs, configured seed 42, 256 prompt groups, 40 training steps with 10 critic-only warmup steps, one policy epoch and four critic epochs. Policy learning rate was 1e-6; critic learning rate was 1e-5. This is one run per setting and only 30 policy updates. Asynchronous execution is not bitwise deterministic.

The full-batch controls change only the chunk minimum (256) and normalization setting relative to streaming32. streaming32-split additionally uses split critic training. All four passed the same 12 metric checks: update counts, finite losses/rewards, probability-ratio limits, and data integrity. Those checks do not impose a reward target.

The experiment uses PR revision df4edf20cd. Temporary control configs/scripts were added in 7dc9731be0; the controls ran at cd88def57b, which only adds executable permissions to the two control scripts. These temporary files are not part of the PR. The later rebase to PR head 303d24016c brings upstream Gym changes; the PPO/advantage/controller code and these PPO recipes are unchanged. The current PR's regular CI checks also pass.

Initial Slurm submission timeouts were retried. The first control attempts stopped before training because their temporary wrappers lacked executable permissions; those were fixed before the measured control runs. No metric checks were weakened.

W&B: full batch, normalized · full batch, unnormalized · streaming32 · streaming32-split.

@terrykong
terrykong enabled auto-merge (squash) November 17, 2026 02:44
@terrykong
terrykong merged commit 6c6c329 into main Nov 17, 2026
99 checks passed
@terrykong
terrykong deleted the terryk/guard-advantage-mask-equivalence branch November 17, 2026 04:12
yfw added a commit that referenced this pull request Nov 21, 2026
…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]>
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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants