Repository navigation
feat(sc): support in-loss sequence filtering for PPO - #5130
Conversation
|
/ok to test d8f0483 |
|
/ok to test 539381c |
|
/ok to test ef9cc6c |
terrykong
left a comment
There was a problem hiding this comment.
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.
- (C2) Two GRPO-only texts that PPO can now reach: the "no rows left" error and the field comment.
- (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
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]>
ef9cc6c to
d83dbb8
Compare
Thanks. Addressed (rebased on main as d83dbb8):
Generated by Claude Code |
|
/ok to test d83dbb8 |
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]>
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.
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_lossfor SingleController PPO withppo.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
ppoblock, the policy-logprob pass is skipped for any algorithm, andfinish_train_stepdivides 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):ppoorgrpoblock;grpoadvantage-estimator rule for GRPO only;ppo.ppo_epochs=1for PPO, because the forced ratio this mode needs is exact only for the first optimizer step on a batch;sample_maskto 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.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.ppoblock too.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_advantagesthe normalization statistics include them, which the separate pass avoids. This is documented ingrpo.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 exceptseq_logprob_error_in_loss. Steps 2–40, mean (step-to-step stdev), one seed per arm: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_advantagesdifference 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 withppo_epochs=1(streaming and full-batch) and skips the policy-logprob pass; rejected withppo_epochs=4and 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 tosample_maskequals the separate pass'ssample_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.