[trainer, perf] fix: count old_logprobs mismatches with a masked sum instead of boolean indexing #8663
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 592 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.382
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8663"
general
weight: 0.35
jialei777
What does this PR do?
actor/old_logprobs_mismatch_count, added in #8026, is computed inppo_losswith boolean-mask indexing:The indexed tensor has one element per valid response token of the micro-batch, so its shape changes with every micro-batch. On TPU (torch_tpu compiles
nonzerofor every new input length and every new number of nonzeros, google-pytorch/torch_tpu#5085), each micro-batch then compiles new programs for thenonzero/ index and for the multiply / sum that follows, before the metric's.item()returns. This PR computes the same count with a masked sum, whose shape does not depend on the mask contents:response_maskis boolean here, so the count is unchanged; the FP32 comparison, thedp_sizescaling andAggregationType.SUMstay as they are. The loss and the gradients do not use this value.Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI)Test
pytest -q tests/workers/test_old_logprobs_mismatch_on_cpu.py: 5 passed (CPU). The addedtest_masked_out_tokens_are_not_countedpasses before and after this change: it checks that the counting semantics are kept with a partially valid mask (the existing tests all use fully valid masks); it does not check the shape behaviour.- Profile of one actor update before this change (41.0 s, 2 micro-batches): 4 compiles inside the update, 29.1 s in total (
nonzero/ index andmul, 6–9 s each, two per micro-batch). The TensorCores were idle for 80% of the update, and 71% of the actor thread's Python stack samples were on the two lines of this metric. After this change the profiled update has a TensorCore duty cycle of 87.8% (19.5% before).- Same batch and same initial weights (step 1 replayed from a saved batch), before vs. after: rank-0
train_batch54.5 s → 21.0 s (both include step-1 one-time costs). Exactly equal: the per-token log-probs on ranks 0 and 31, the 37 actor metrics on each of those ranks (includingpg_lossandgrad_norm), the per-rank update statistics of all 853 parameters on all 32 ranks, and the full updates of 39 rank-0 tensors (52.5 M elements; full updates of other ranks were not saved).- Steps with the same number of micro-batches, rank-0 forward/backward time: 40.3–52.0 s → 8.4–8.5 s with 2 micro-batches; 65.5 s → 12.1–19.3 s with 3. The two 8-step runs differ in their micro-batch counts per step, so their mean step times (110.46 s → 69.07 s) are not a paired comparison.
API and Usage Example
No API or config change.
Design & Code Changes
verl/workers/utils/losses.py: masked sum instead of boolean indexing, with a two-line comment on why (+3 / −1).tests/workers/test_old_logprobs_mismatch_on_cpu.py:_metrics()takes an optionalresponse_mask; newtest_masked_out_tokens_are_not_counted(+13 / −2).Checklist Before Submitting
pre-commit run --files verl/workers/utils/losses.py tests/workers/test_old_logprobs_mismatch_on_cpu.py: all hooks passed (ruff, ruff format, mypy, config generation, license and the other repo checks).tests/workers/test_old_logprobs_mismatch_on_cpu.py(CPU).ci-requestchannel in theverlSlack workspace.recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main. Not related.