What changes when SingleController PPO drops bad rows inside the loss instead of before it

PR #5130 · follows #5080 (the same flag for SingleController GRPO) · permalinks pinned to ef9cc6c2

Before
SingleController refused loss_fn.seq_logprob_error_in_loss: true for PPO at startup, so PPO always ran a separate policy-logprob forward just to find the bad rows.
This PR
Removes that refusal for SingleController PPO with ppo.ppo_epochs: 1. No runtime code changes: setup, loss and workers already handled PPO. The legacy PPO trainer still refuses the flag.
Status
New option added by this PR. Open (C3): with the flag on, the critic trains on rows the policy rejected; with it off, it doesn't. Also open (C2): two GRPO-only messages that PPO runs can now hit.
Background. Each prompt gets several answers, called rows. A row is rejected when the trainer's log-probability of the whole answer differs too much from the one the generator reported (ppo.seq_logprob_error_threshold). Rejected rows get no policy gradient. PPO also trains a critic: a second model that predicts the future reward at each token. GAE uses those predictions to compute advantages. Dotted words have a short explanation: hover or tap them.

With the flag off, SingleController runs an extra policy forward, finds rejected rows, and zeroes them in sample_mask before computing advantages (advantage_stage.py). Every later stage reads that mask: advantage normalization, the policy loss, and the critic's loss (MseValueLossFn). With the flag on, logprob_passes_required turns the extra forward off, and only the policy loss drops the row, from the training forward it already runs (loss_functions.py). So the policy gradient is the same, but the stages before and after the policy loss now see the rejected row.

Same 4 rows, both ways

One batch of 4 rows with 6, 5, 7 and 8 answer tokens (26 total). Row 1's sequence error is 2.9, over the 2.0 threshold.

flag off — separate pass flag on — this PR 1 · rollout + critic predicts values rows 0..3, tokens [6, 5, 7, 8] → 26 gen logprobs + critic values per token rows 0..3, tokens [6, 5, 7, 8] → 26 gen logprobs + critic values per token 2 · find rejected rows extra policy forward (2.45 s/step in the PR's run) seq error [0.3, 2.9, 0.1, 0.6] sample_mask → [1, 0, 1, 1] skipped: logprob_passes_required → False sample_mask stays [1, 1, 1, 1] config.py#L1019 3 · GAE advantages, then normalize (if normalize_advantages) GAE per row from rewards + values mean/std over rows {0, 2, 3} advantage_stage.py#L526 GAE per row from rewards + values mean/std over rows {0, 1, 2, 3} row 1 shifts the other rows' advantages a little 4 · policy training forward + loss loss over rows {0, 2, 3} kept tokens from sample_mask: 21 gradient = S / 21 loss checks seq error [0.3, 2.9, 0.1, 0.6] drops row 1, reports kept tokens: 21 gradient = S / 21 (same) 5 · critic training (value loss) value loss over rows {0, 2, 3} mask = token_mask × sample_mask loss_functions.py#L2168 value loss over rows {0, 1, 2, 3} critic learns from row 1 too open: C3 asks to drop row 1 here too 6 · checks at startup any ppo_epochs, any ratio mode (flag off: nothing extra to check) force_on_policy_ratio, token_level_loss, ppo_epochs = 1, Megatron, no KL-in-reward grpo.py#L626 rejected row / the extra pass where the lanes differ (PPO only) this PR's path; same policy gradient

The policy gradient is the same in both lanes: S / 21, the sum over kept tokens divided by the number of kept tokens. Two PPO stages differ, because they run outside the policy loss and read only sample_mask:

StageFlag offFlag onCan it match?
Advantage normalizationrows {0, 2, 3}rows {0, 1, 2, 3}No: it runs before the loss sees row 1
Critic trainingrows {0, 2, 3}rows {0, 1, 2, 3}Yes: it runs after the policy step. Asked in C3.
Critic training, warmup stepsrows {0, 2, 3}rows {0, 1, 2, 3}Yes: run the separate pass on those steps. Asked in C3.

The PR documents both in grpo.md. Normalization can't match without the extra pass, so a doc note is enough there. GRPO has the same kind of gap: a rejected row still counts in its group's average reward. The critic can match: it trains after the policy step (_value_train_epochs), when row 1's rejection is already known. A flag that only skips a pass shouldn't change what the critic learns from, so C3 asks the PR to hand the rejection to the critic. Critic warmup (ppo.policy_training_start_step > 0) needs one more piece: those steps skip policy training, so with the flag on nothing ever rejects row 1. With the flag off, the separate pass still runs then. C3 asks to run it on warmup steps too. That costs one forward pass on warmup steps only; policy-training steps keep the speedup.

Review comment: C3 · critic trains on rejected rows — grpo.md:695

Why one policy epoch

This mode needs force_on_policy_ratio: true: the ratio between the new and old policy is set to 1, so no old logprobs are needed. That is exact only for the first optimizer step on a batch, before the weights move. SingleController already maps one PPO epoch to one optimizer step (config.py#L1829), so ppo.ppo_epochs: 1 is the whole condition. Two checks reject more than one epoch, one for each reason: the existing force_on_policy_ratio rule (config.py#L1567) and the PR's new in-loss check (grpo.py#L654).

Review comment: C2 · GRPO-only texts PPO now hits — grpo.py:637

So what. In the PR's run (1.5B dense model, 512 rows per step, one node), skipping the extra pass cut step time from 25.7 s to 22.6 s (−12%). Reward, grad norm, entropy and critic loss stayed within one step-to-step standard deviation, on one seed per arm. Use it when you already run one policy epoch with a forced ratio; expect normalization to count the few rejected rows, and the critic to train on them until C3 is fixed.