fix: pair --log-correct-samples rewards with the DP-local samples - #2234
Open
keepkeen wants to merge 1 commit into
Open
fix: pair --log-correct-samples rewards with the DP-local samples#2234keepkeen wants to merge 1 commit into
keepkeen wants to merge 1 commit into
Conversation
`RolloutManager._split_train_data_by_dp` ships `raw_reward` whole while every
per-sample field next to it is already sliced down to the samples this DP rank
owns. `process_rollout_data` re-splits `total_lengths` but leaves `raw_reward`
global, so the `--log-correct-samples` block in `log_rollout_data` indexes this
rank's `response_lengths` / `total_lengths` / `loss_masks` / `log_probs` with
global sample indices:
IndexError: list index out of range
correct_response_lengths.append(response_lengths[i])
Before it runs off the end it is also silently wrong — sample i's reward is
attributed to whichever sample happens to sit at local position i. That affects
dp_size == 1 too, because first-fit packing returns a permuted partition.
`raw_reward` has to stay global: `log_passrate` reshapes it into
[rollout_batch_size, n_samples_per_prompt] groups, which only works on the full
rollout batch. So keep it, and add `local_raw_reward` — the DP-local view — for
the metrics that pair rewards with per-sample tensors.
Fixes THUDM#1784
keepkeen
force-pushed
the
fix/log-correct-samples-dp-partition
branch
from
July 26, 2026 10:08
c70b17f to
718f558
Compare
Author
|
Hi @zhuzilin, could you please take a look when you have time? This fixes #1784 while preserving the global |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
--log-correct-samplescrashes withIndexErroron DP > 1, and produces wrong numbers before it crashes. Fixes #1784.Root cause
RolloutManager._split_train_data_by_dpships two kinds of fields to the trainer:process_rollout_datathen re-splitstotal_lengthsbut leavesraw_rewardglobal. So inlog_rollout_data, the--log-correct-samplesblock walks the global reward list while indexing this rank's local lists:Two failure modes:
IndexErroronceipasses the end of this rank's lists — the traceback in [Bug] IndexError in log_rollout_data when --log-correct-samples enabled with DP > 1 #1784.i's reward is attributed to whichever sample happens to sit at local positioni. This also affectsdp_size == 1, because first-fit packing returns a permutedpartition, not the identity.Why not just partition
raw_rewardraw_rewardhas to stay global —log_passratereshapes it into[rollout_batch_size, n_samples_per_prompt]groups, which only works on the full rollout batch. So this keepsraw_rewardas-is and addslocal_raw_reward, the DP-local view, for the metrics that pair a reward with per-sample tensors.Reproduction
Driving the real
process_rollout_datawith the partition layout_split_train_data_by_dpproduces (8 samples, dp_size=2, odd samples correct):Test
New CPU unit test
tests/test_process_rollout_data.py, registered in thecpu-unittestCI job. It pins the three-way contract (total_lengthsDP-local,raw_rewardglobal,local_raw_rewardDP-local and positionally aligned) and replays the--log-correct-samplesselection loop across dp1-permuted / dp2 / dp4 partitions. It fails onmain(6 of 8 cases) and passes with this change.ray.getis monkeypatched to the identity so the test stays single-process —process_rollout_dataonly uses Ray to deref the per-rankBox.Note for maintainers (not addressed here)
While tracing this I noticed the same block computes
correct_response_lengths/correct_length/p*/correct_entropyand stores them intorollout_dataafter the onlygather_log_data("rollout", ...)call inlog_rollout_data, and never callsgather_log_dataitself (unlike its siblingslog_multi_turn_data/log_passrate). Its locallog_dictis unused. So those metrics appear to never be emitted anywhere. That has been true since the block was introduced in #1192, and reducing them across ranks needs(sum, count)weighting because each rank has a different number of correct samples — a behaviour change I left out of this crash fix. Happy to send a follow-up PR if you'd like it fixed.