How SingleController skips the extra logprob pass when the loss drops the bad rows itself

PR #5080 · related: #4171 (the same flag for the regular trainer), #5079 (ready_first + forced ratio) · permalinks pinned to 8cb3b94a

Before
SingleController refused loss_fn.seq_logprob_error_in_loss: true at startup, so it always ran a separate policy-logprob forward just to find the bad rows.
This PR
Allows the flag for SingleController GRPO, skips that forward, and divides the gradient by the number of tokens the loss kept.
Status
New path added by this PR. The review found no bug in the gradient or metric math. Four smaller review comments are open (a test that can't fail, a doc sentence, a missing L1 run, shared code).
Background. In GRPO, 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 (grpo.seq_logprob_error_threshold). Rejected rows get no gradient. The baseline is the group's average reward that each row's reward is compared with. Dotted words have a short explanation: hover or tap them.

With the flag off, SingleController runs a separate forward pass to get the trainer's logprobs, finds the rejected rows, and zeroes them in sample_mask before computing advantages (advantage_stage.py). With the flag on, logprob_passes_required turns that pass off. The loss makes the same check from the training forward it already runs, zeroes the rejected rows, and reports how many tokens it kept (loss_functions.py). The Megatron worker adds those counts up over all chunks and all DP ranks, then divides the gradient by them (_finish_train_step_body).

Same 4 rows, both ways

One group 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 rows 0..3, tokens [6, 5, 7, 8] → 26 gen logprobs from the generator rows 0..3, tokens [6, 5, 7, 8] → 26 gen logprobs from the generator 2 · find rejected rows extra policy forward (74 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#L1008 3 · advantage baseline (group average) exclude: average over rows {0, 2, 3} include: average over rows {0, 1, 2, 3} advantage_stage.py#L536 exclude: average over rows {0, 1, 2, 3} include: average over rows {0, 1, 2, 3} row 1 still votes (same as regular trainer) 4 · training forward + loss (one chunk at a time) loss over rows {0, 2, 3} backward: raw sum S (no division yet) kept-token count from sample_mask: 21 loss checks seq error [0.3, 2.9, 0.1, 0.6] drops row 1, backward: raw sum S reports valid_tokens 21, valid_seqs 3 5 · finish step: sum over chunks + DP ranks, divide N = 21 (from sample_mask) gradient = S / 21 N = 21 (from the loss's counts) gradient = S / 21 · if N = 0 → RuntimeError megatron_policy_worker.py#L2333 rejected row / the extra pass where the two lanes differ new in this PR; ends at the same gradient

The two lanes end at the same gradient, S / 21: the sum over kept tokens divided by the number of kept tokens. That is the same result as dropping row 1 before training (why, for the regular trainer). They differ in one place. Under masked_reward_policy: exclude, row 1 still counts in the group average when the flag is on, because the baseline is set before the loss sees the row. The regular trainer does the same thing with the flag on, so the PR keeps the two trainers in step.

What the PR blocks, and what changes in the logs

validate_single_controller_config rejects the flag for PPO and for forest training, then reuses the regular trainer's checks (threshold set, token-level loss, no MTP, draft, KL-in-reward, or distillation). With the flag on, the controller's own seq-error range metrics are gone; the count of rejected rows comes from the loss as num_masked_seqs_by_logprob_error, as in the regular trainer.

Review comments: C2 · exclude sentence — grpo.md:695 C4 · shared survivor-count helper — megatron_policy_worker.py:2333 C5 · one "skip the extra forward?" rule — config.py:1009 C6 · error on an unlisted metric — loss/utils.py:44

So what. In the PR's run (multi-node MoE, 8,192 rows per step), skipping the extra pass cut step time from 354 s to 284 s (−20%), with reward, loss and entropy inside normal step-to-step noise. The gain shows up only when steps are training-bound. One thing to check before relying on it: that run used ready_first with a forced ratio, which this branch alone still rejects unless CISPO is on; #5079 lifts that.