Skip to content

feat(sc): support in-loss sequence filtering for PPO - #5130

Merged
terrykong merged 3 commits into
mainfrom
sc-inloss-ppo
Nov 11, 2026
Merged

terrykong merged 3 commits into
mainfrom
sc-inloss-ppo

Conversation

@snivertynv

@snivertynv snivertynv commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

SingleController rejected loss_fn.seq_logprob_error_in_loss for PPO, but its setup, loss and workers already handle the PPO case: the threshold is passed to the loss from the PPO config, and the policy-logprob pass is skipped for any algorithm. Only validation blocked it.

  • Drop the SingleController "requires GRPO" rejection.
  • The shared validator reads the threshold from the ppo or grpo block, keeps the grpo-estimator rule for GRPO only, and requires ppo.ppo_epochs=1 for PPO: the forced ratio in-loss filtering needs is exact only for the first optimizer step on a batch. KL-in-reward stays rejected because GAE would have no policy logprobs for it.
  • The legacy PPO trainer still rejects the option and now points to the SingleController trainer.

The rejection is decided inside the policy loss, so for PPO the critic still trains on rejected rows and normalize_advantages statistics include them. Both are documented.

What does this PR do ?

Allows loss_fn.seq_logprob_error_in_loss for SingleController PPO with ppo.ppo_epochs: 1, streaming or full-batch. Follows #5080, which added it for SingleController GRPO. The legacy PPO trainer still rejects it.

SingleController setup, loss and workers already handle PPO: the threshold reaches the loss from the ppo block, the policy-logprob pass is skipped for any algorithm, and finish_train_step divides by the survivor counts. Only validation blocked it.

Changes

  • validate_single_controller_config: drop the "requires GRPO" rejection.
  • _validate_seq_logprob_error_in_loss (shared by both trainers):
    • reads the threshold from the ppo or grpo block;
    • keeps the grpo advantage-estimator rule for GRPO only;
    • requires ppo.ppo_epochs=1 for PPO, because the forced ratio this mode needs is exact only for the first optimizer step on a batch;
    • still rejects KL-in-reward: with the policy-logprob pass skipped, GAE would have no policy logprobs for it.
  • Critic rows: the policy loss returns its per-row keep mask (a reserved, non-metric key); the policy worker maps it back to the batch's row order and writes the filtered sample_mask to the data plane. The critic reads that column after policy training in every mode, so it trains on the same rows as with the separate pass. On the non-streaming trainer the mask is dropped.
  • Critic warmup (ppo.policy_training_start_step > 0): those steps skip policy training, so nothing would decide rejections. With in-loss filtering they run the separate policy-logprob pass, and a per-call override makes the advantage stage apply the threshold as it does with the flag off.
  • Legacy PPO trainer: the rejection message now points to the SingleController trainer.
  • The empty-update error and the field comment name the ppo block too.
  • Docs and config comments describe PPO support.

PPO-specific behavior

The rejection is decided inside the policy loss, after GAE has run. The critic still skips rejected rows (see above), but with normalize_advantages the normalization statistics include them, which the separate pass avoids. This is documented in grpo.md.

Validation

Single-node SingleController PPO on a 1.5B dense model (math RL), full-batch (not streaming), 32 prompts × 16 generations per step, ppo_epochs=1, force_on_policy_ratio=true, threshold 1.03 (rejects 0–9 of 512 sequences per step). Two arms identical except seq_logprob_error_in_loss. Steps 2–40, mean (step-to-step stdev), one seed per arm:

Metric Separate pass In-loss Δ
reward 0.291 (0.063) 0.297 (0.063) +1.9%
grad norm 0.1226 (0.0117) 0.1228 (0.0122) +0.1%
approx entropy 0.398 (0.084) 0.394 (0.085) −1.1%
critic loss 0.1706 (0.060) 0.1706 (0.059) 0.0%
critic grad norm 2.53 (1.06) 2.53 (1.05) −0.1%
generation length (tokens) 817 (43) 812 (44) −0.6%
sequences rejected / step 1.4 (1.9) 1.6 (1.9)
policy-logprob pass + prep 2.45 s 0 −100%
policy training 5.52 s 5.66 s +2.5%
step time 25.7 s 22.6 s −12%

Learning and critic metrics stay within one step-to-step standard deviation. The policy loss differs as expected: with the separate pass, advantages are normalized over survivors only, so the mean policy loss is ~0 (−9e-10); in-loss normalization includes rejected rows, leaving a small nonzero mean (−2.4e-5). This is the normalize_advantages difference documented above. The run rejected about 1.5 of 512 rows per step, so it barely exercises the PPO-specific differences; runs with a high reject rate should validate them separately. The run predates the critic-masking change, so in its in-loss arm the critic also trained on the ~1.5 rejected rows per step.

Tests

  • test_ppo_setup.py: SingleController PPO with in-loss filtering is accepted with ppo_epochs=1 (streaming and full-batch) and skips the policy-logprob pass; rejected with ppo_epochs=4 and with KL-in-reward.
  • test_resiliency_config.py: removes the old "PPO rejected" test.
  • test_single_forward_grpo.py: on a batch with one row over the threshold, the loss's keep mask applied to sample_mask equals the separate pass's sample_mask; packed sequences join their keep masks in row order.
  • test_split_api_wrappers.py: the worker writes rejections in the batch's original row order after a packing reorder, and fails loudly on a size mismatch.
  • test_advantage_stage.py: the per-call override masks exactly the over-threshold row.
  • test_single_controller_actor.py: with in-loss filtering, the policy-logprob pass and the override run only on critic-warmup steps.

@snivertynv snivertynv self-assigned this Nov 9, 2026
@snivertynv snivertynv added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 9, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 9, 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 9, 2026
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test d8f0483

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 539381c

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test ef9cc6c

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. The reasoning holds up: SingleController PPO already skipped the policy-logprob pass whenever force_on_policy_ratio was on without a threshold (skips_policy_logprob_pass), the loss already gets the threshold from the ppo block (setup.py#L2298), and the worker's survivor count does not depend on the algorithm. So the "requires GRPO" check really was the only thing in the way.

  1. (C2) Two GRPO-only texts that PPO can now reach: the "no rows left" error and the field comment.
  2. (C3) With the flag on, the critic trains on rows the policy rejected; with it off, it doesn't. The two modes should give the critic the same rows.

On the A/B table (not needed for merge): could you add to the description whether it ran streaming or full-batch, since the PR enables both? Also, it rejected about 1.5 of 512 rows per step, so the PPO differences between the two modes (C3, and normalize_advantages counting rejected rows) were barely exercised. A sentence saying so would help anyone planning a run with a high reject rate.

CPU unit tests (test_ppo_setup.py, test_resiliency_config.py) pass locally at ef9cc6c. ruff and ruff-format pass on the changed files.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5130-sc-ppo-in-loss-filter.html

Generated by Claude Code

Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread docs/guides/grpo.md Resolved
SingleController rejected loss_fn.seq_logprob_error_in_loss for PPO, but
its setup, loss and workers already handle the PPO case: the threshold is
passed to the loss from the PPO config, and the policy-logprob pass is
skipped for any algorithm. Only validation blocked it.

- Drop the SingleController "requires GRPO" rejection.
- The shared validator reads the threshold from the ppo or grpo block,
  keeps the grpo-estimator rule for GRPO only, and requires
  ppo.ppo_epochs=1 for PPO: the forced ratio in-loss filtering needs is
  exact only for the first optimizer step on a batch. KL-in-reward stays
  rejected because GAE would have no policy logprobs for it.
- The legacy PPO trainer still rejects the option and now points to the
  SingleController trainer.

The rejection is decided inside the policy loss, so for PPO the critic
still trains on rejected rows and normalize_advantages statistics include
them. Both are documented.

Signed-off-by: Sriharsha Niverty <[email protected]>
PPO can now reach the empty-update error and the field comment, which pointed only at grpo.seq_logprob_error_threshold.

Signed-off-by: Sriharsha Niverty <[email protected]>
The separate policy-logprob pass zeroes rejected rows' sample_mask before training, so the critic skips them. With in-loss filtering the rejection was only known inside the policy loss, so the critic trained on every row.

- The loss returns its per-row keep mask under SEQ_LOGPROB_KEEP_MASK_KEY; the packing wrapper joins it per sequence and workers pop it before metric reduction.
- train_microbatch_presharded maps it back to meta row order (undoing local repacking) and writes the filtered sample_mask, which the critic reads after policy training.
- PPO critic-warmup steps skip policy training, so with in-loss filtering they run the separate pass and the advantage stage applies the threshold through a per-request override.

Signed-off-by: Sriharsha Niverty <[email protected]>
@snivertynv

Copy link
Copy Markdown
Contributor Author

Thanks for this. The reasoning holds up: SingleController PPO already skipped the policy-logprob pass whenever force_on_policy_ratio was on without a threshold (skips_policy_logprob_pass), the loss already gets the threshold from the ppo block (setup.py#L2298), and the worker's survivor count does not depend on the algorithm. So the "requires GRPO" check really was the only thing in the way.

  1. (C2) Two GRPO-only texts that PPO can now reach: the "no rows left" error and the field comment.
  2. (C3) With the flag on, the critic trains on rows the policy rejected; with it off, it doesn't. The two modes should give the critic the same rows.

On the A/B table (not needed for merge): could you add to the description whether it ran streaming or full-batch, since the PR enables both? Also, it rejected about 1.5 of 512 rows per step, so the PPO differences between the two modes (C3, and normalize_advantages counting rejected rows) were barely exercised. A sentence saying so would help anyone planning a run with a high reject rate.

CPU unit tests (test_ppo_setup.py, test_resiliency_config.py) pass locally at ef9cc6c. ruff and ruff-format pass on the changed files.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5130-sc-ppo-in-loss-filter.html

Generated by Claude Code

Thanks. Addressed (rebased on main as d83dbb8):

  • C2: the empty-update error now says "seq_logprob_error_threshold in the grpo or ppo block", and the field comment lists SingleController PPO with ppo_epochs=1.
  • C3 AI-1: the policy loss returns its per-row keep mask; the worker maps it back to the batch's row order (undoing local packing) and writes the filtered sample_mask, which the critic reads after policy training. The grpo.md sentence now only keeps the normalize_advantages difference.
  • C3 AI-2: with in-loss filtering, critic-warmup steps run the separate policy-logprob pass, and a per-call override makes the advantage stage apply the threshold as with the flag off.
  • C3 AI-3: tests that the loss's keep mask applied to sample_mask equals the separate pass's mask on a batch with one rejected row, that the worker writes it in meta order after a packing reorder, that the stage override masks the same row, and that the logprob pass runs only on warmup steps.
  • Description: the A/B was full-batch; added a note that ~1.5 of 512 rows were rejected per step and that the run predates the critic masking.

Generated by Claude Code

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test d83dbb8

@terrykong
terrykong enabled auto-merge (squash) November 11, 2026 19:17
@terrykong
terrykong merged commit 27fac5f into main Nov 11, 2026
164 of 170 checks passed
@terrykong
terrykong deleted the sc-inloss-ppo branch November 11, 2026 22:18
jthomson04 added a commit to jthomson04/RL that referenced this pull request Nov 12, 2026
Brings NVIDIA-NeMo#3726 (DSpark tiled objectives), NVIDIA-NeMo#4882 (reward_shaping on the
SingleController path) and NVIDIA-NeMo#5130 (in-loss sequence filtering for PPO).
No conflicts.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[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.

2 participants