Repository navigation
[rl] TrainingSampleBuilder drops only the rollout it can't train, and counts it by reason (4/4) - #6204
Conversation
5659b20 to
d33b84d
Compare
d33b84d to
249f6c9
Compare
|
@claude review |
|
Claude finished @felipemello1's task in 2m 29s —— View job Approve (please address the items before merging): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The builder now has one place that decides which rollouts train, and it counts every drop by reason. Stock recipes train exactly the same samples. A maintainer still needs to review.
What this PR does. _select_rollouts_to_train runs once per group, before the zero-std check. It drops each rollout separately, as untrainable, empty_turn or no_advantage, and the drops are counted in training_sample_builder/num_rollouts_dropped/<reason>. Before, the builder handled these cases three ways: drop the whole group, drop the rollout inside the loop, or raise inside rollout_to_training_samples. That last check is now removed. The PR also adds zero_advantage_frac, and the policy-version metrics now read only the samples that are kept.
Example. One group, sibling 0 broken, the others fine:
sibling 0 turns base (3/4) this PR
[] (no turn) whole group dropped drop 0, count empty_turn
[[], [4]] ValueError, run stops drop 0, count empty_turn
[[4], []] drop 0, count drop 0, count empty_turn
COMPLETED, adv=None ValueError, run stops drop 0, count no_advantage
Both stock workers already turn an empty completion or an empty turn list into ERROR_INFRA (token_env.py:251, verifiers/rollouter.py:375). So these rows only happen with custom rollouters, and the "no loss change" claim holds for in-repo recipes.
Must fix
- PR description: "Summary (human-written)" is empty. The author needs to fill it in.
Should consider
training_sample_builder.py:106-116: anempty_turnrollout was already scored, so its reward went into its siblings' advantages. Dropping only that rollout trains the siblings on biased advantages. It's cleaner to mark such a rollout untrainable inmake_scored_groupbefore scoring. See the inline comment.training_sample_builder.py:223-225: thereward is not Nonefilter can quietly change the zero-std decision. Remove it or count it as a drop reason.training_sample_builder.py:285-291: the comment says "trained rollouts", but the metric also covers selected rollouts that end up with no sample.1e-9needs a reason.
Questions
- Turning
no_advantageandempty_turnfrom a raise into warn-and-drop goes against the repo's "errors over warnings" rule (CLAUDE.mdprinciples 8 and "assert for programmer error"). The PR explains its reason: one buggy rollout shouldn't stop the run. The batcher's consecutive-untrainable limit (batcher.py:355) still stops a run where every group is broken. Can a maintainer confirm that counting plus a warning per rollout is the policy they want for rollouter bugs?
Details
rollout_to_training_samplesis documented as the extension point to override. It no longer guards against empty turns, so callers depend on the builder's pre-filter. If it is called directly with an empty turn, it builds a prompt-only sample, which_has_valid_loss_tokenthen drops. Nothing crashes.- Its
advantage is Noneraise can no longer be hit frombuild_from_group. It still narrows the type for direct callers, so keeping it is fine. - Empty-list metrics (
Mean,Min,Max,SummaryStats.from_list([])) handle 0 items, so a group where every rollout is dropped anddrop_zero_std_reward_groups=Falsestill logs safely. - Removed metric keys (
num_groups_dropped_untrainable,num_rollouts_dropped_empty_completion) have no other in-repo readers.
Not verified: I did not run the unit tests.
| # Sanity check: filter a rollout with no turn, or a turn with no completion. | ||
| if not rollout.turns or any( | ||
| len(turn.completion_token_ids) == 0 for turn in rollout.turns | ||
| ): | ||
| logger.warning( | ||
| "rollout %s/rollout=%d has no turn, or a turn with no completion; dropping it", | ||
| rollout.group_id, | ||
| rollout.rollout_id, | ||
| ) | ||
| num_rollouts_dropped["empty_turn"] += 1 | ||
| continue |
There was a problem hiding this comment.
An empty_turn rollout has a trainable status, so make_scored_group (rollouter.py:412-422) already scored it and fed its reward into the advantage estimator. Dropping it here keeps its siblings, but their advantages are still centered on a reward that never trains. For example, rewards [1 (empty turn), 1, 0, 0] have mean 0.5. The siblings train with advantages [+0.5, -0.5, -0.5], which sum to -0.5, where the kept rollouts alone would have mean 1/3. The zero-std check below then runs on the kept rewards, which doesn't match how the advantages were computed.
The old code had the same problem for an empty later turn. For an empty turn 0 or no turn, it dropped the whole group, which kept the advantages clean. This PR's "drop only that rollout" rule makes that case biased too.
Both stock workers go through make_scored_group, so the clean fix is in that layer. Mark an empty-turn or no-turn rollout untrainable before scoring, so it never enters the advantage, the same way TokenEnv and the Verifiers rollouter already make it ERROR_INFRA. Then this branch is only a sanity check for rollouters that skip make_scored_group. If you'd rather keep this PR small, at least drop the group for empty_turn here, since only no_advantage rollouts are known to be outside the estimator.
| rewards = [ | ||
| rollout.reward for rollout in rollouts_to_train if rollout.reward is not None | ||
| ] |
There was a problem hiding this comment.
Every rollout here is trainable and has an advantage, and make_scored_group sets reward on the same rollouts it gives an advantage. So reward is None can only come from a rollouter bug. When that happens, this filter quietly changes the zero-std decision: it uses fewer rewards, and a group can fall below 2 rewards and be dropped. Nothing gets counted. That's the kind of just-in-case check CLAUDE.md principle 8 asks us not to add.
Either remove the filter, or check reward is None together with advantage is None in _select_rollouts_to_train (e.g. no_score) so it is counted like the other drops.
| # Share of trained rollouts whose advantage is 0: they add nothing to the gradient, only | ||
| # tokens to the loss's token count. | ||
| m.Metric( | ||
| "training_sample_builder/zero_advantage_frac", | ||
| m.Mean.from_list( | ||
| [ | ||
| float(math.isclose(advantage, 0.0, abs_tol=1e-9)) |
There was a problem hiding this comment.
Two small points.
- "Share of trained rollouts" isn't quite right.
advantagescovers every rollout inrollouts_to_train, including ones whose samples were all dropped by_has_valid_loss_tokenabove, which therefore train nothing. Either say "rollouts selected to train" or compute the fraction over rollouts that kept at least one sample. abs_tol=1e-9needs a one-line reason, e.g. that it absorbs float rounding in the mean/std estimator. The rules ask for a comment on magic constants.
249f6c9 to
be71e9f
Compare
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 1s —— View job Approve (the diff is the same as at my last review, and its items are still open): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The force-push to be71e9f only rebases this PR onto the updated (3/4). The diff in training_sample_builder.py and in both test files is the same as at 249f6c9, so every item from the earlier review is still open. A maintainer still needs to review.
What this PR does. _select_rollouts_to_train runs once per group. It drops each rollout on its own, as untrainable, empty_turn or no_advantage, and counts each drop in training_sample_builder/num_rollouts_dropped/<reason>. It also adds zero_advantage_frac.
Example. One group, sibling 0 broken, the others fine:
sibling 0 base (3/4) this PR
turns=[] whole group dropped drop 0, count empty_turn
turns=[[], [4]] ValueError drop 0, count empty_turn
COMPLETED, adv=None ValueError drop 0, count no_advantage
I checked this against the rebased base. TokenEnv.step (token_env.py:251) still turns an empty completion into ERROR_INFRA. TRUNCATED_PROMPT_TOO_LONG (token_env.py:383-391) is trainable, but it adds no empty-completion turn. So stock recipes never reach empty_turn, and the claim that no loss changes still holds for in-repo recipes.
Must fix
- PR description: "Summary (human-written)" is still empty.
Should consider (still open, see the earlier inline comments)
training_sample_builder.py:106-116:make_scored_group(rollouter.py:412-435) scores anempty_turnrollout and includes its reward in its siblings' advantages. Dropping only that rollout then trains its siblings on biased advantages. The fix: mark such a rollout untrainable before scoring, or drop the whole group forempty_turn.training_sample_builder.py:223-225: thereward is not Nonefilter changes the zero-std decision without counting anything. Remove it, or make it a counted drop reason.training_sample_builder.py:285-294: the comment says "trained rollouts", butadvantagescovers every selected rollout, including ones whose samples_has_valid_loss_tokenremoves. Also,abs_tol=1e-9needs a one-line reason.
Questions
- The PR changes rollouter bugs (
no_advantage,empty_turn) from raising to warning and dropping. Can a maintainer confirm that this is the policy they want? The batcher's consecutive-untrainable limit still stops a run where every group is broken.
Not verified: I did not run the unit tests.
be71e9f to
4f0548a
Compare
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 2s —— View job Approve (the rebase onto the updated (3/4) left this PR's changes the same, so the earlier items are still open): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The force-push to 4f0548a rebases this PR again, this time onto the updated (3/4) at 2784265. This PR's own changes are the same as at be71e9f: same hunks, same +163/-104. So the items from the earlier reviews are still open. tianyu-l has approved. Their review has no comments, so no maintainer comment is waiting on a reply.
What this PR does. _select_rollouts_to_train drops each rollout on its own and gives a reason: untrainable, empty_turn or no_advantage. Each drop is counted in training_sample_builder/num_rollouts_dropped/<reason>. The PR also adds zero_advantage_frac and removes the empty-turn checks from rollout_to_training_samples.
Example. One group where sibling 0 is broken and the others are fine:
sibling 0 base (3/4) this PR
turns=[] whole group dropped drop 0, count empty_turn
turns=[[], [4]] ValueError drop 0, count empty_turn
COMPLETED, adv=None ValueError drop 0, count no_advantage
make_scored_group (rollouter.py:402-449) still skips only rollouts that aren't is_trainable(). The Verifiers rollouter still marks a trainable rollout with no turns as ERROR_INFRA (verifiers/rollouter.py:373). So stock recipes never reach empty_turn, and the "no loss change" claim still holds.
Must fix
- PR description: "Summary (human-written)" is still empty.
Should consider (still open, see the earlier inline comments)
training_sample_builder.py:105-115: anempty_turnrollout was already scored bymake_scored_group, so its reward went into its siblings' advantages. Dropping only that rollout trains the siblings on biased advantages. Either mark it untrainable before scoring, or drop the whole group forempty_turn.training_sample_builder.py:220-222: thereward is not Nonefilter changes the zero-std decision and counts nothing. Remove it, or make it a counted drop reason.training_sample_builder.py:282-291: the comment says "trained rollouts", butadvantagescovers every selected rollout, including ones whose samples_has_valid_loss_tokenremoves. Also,abs_tol=1e-9needs a one-line reason.
Details
- The rebased (3/4) removed the TODO above the rollout pick: "a group left with 10 of 16 rollouts gives its prompt about 10/16 of a full group's weight". This PR doesn't touch that line. Still,
empty_turnandno_advantagenow drop one rollout where the base dropped the group or raised, so partial groups are more common. If the caveat still applies, it may be worth putting the TODO back. - tianyu-l's approval settles the earlier question of whether to warn and drop or to raise on rollouter bugs.
Not verified: I did not run the unit tests.
1dbfecb to
22d2d2c
Compare
… counts it by reason _select_rollouts_to_train drops a rollout that can't train and counts it in training_sample_builder/num_rollouts_dropped/<reason>: untrainable (a status such as ERROR_INFRA), empty_turn (no turn, or a turn with no completion tokens) or no_advantage (a trainable rollout with no advantage, which used to raise). A rollout with no completion token no longer drops its whole group. training_sample_builder/zero_advantage_frac logs the share of trained rollouts whose advantage is 0. The zero-std group drop is unchanged: a group with no empty turn and no missing advantage trains the same samples, with the same loss, as before.
22d2d2c to
cd9b3d0
Compare
Summary (human-written)
Agent details
TLDR: The builder drops a rollout it can't train on its own, never its siblings, and counts each drop by reason in
training_sample_builder/num_rollouts_dropped/<reason>. A trainable rollout with no advantage is dropped and counted instead of stopping the run. A new metric,training_sample_builder/zero_advantage_frac, logs the share of trained rollouts whose advantage is 0. This PR changes no loss numbers: the zero-std group drop is as before. Fourth of 4, on top of the Verifiers PR (3/4).Problem
ERROR_INFRA, and the builder skips it.num_groups_dropped_untrainablecounts groups, andnum_rollouts_dropped_empty_completioncounts only empty later turns.Solution
_select_rollouts_to_trainruns first. It drops a rollout for the first reason that matches:untrainable(a status that never trains),empty_turn(no turn, or a turn with no completion tokens),no_advantage(a trainable rollout with no advantage). It logs a warning for the last two.training_sample_builder/num_rollouts_dropped/<reason>. It replacestraining_sample_builder/num_groups_dropped_untrainableandtraining_sample_builder/num_rollouts_dropped_empty_completion.training_sample_builder/zero_advantage_frac: the share of trained rollouts whose advantage is 0 (within 1e-9).rollout_to_training_samplesno longer checks for empty turns: the builder drops those rollouts first.rollout/min_policy_versionandrollout/max_policy_versionread only the training samples that are kept.drop_zero_std_reward_groups), its metrics (num_groups_dropped_zero_std,rollout_reward/group_zero_std_frac) and its rule from (1/4). It reads the rewards of the rollouts that_select_rollouts_to_trainkeeps. A group with no empty turn and no missing advantage trains the same samples, with the same loss.You may ask: why drop a rollout with no advantage, not raise? A rollouter bug in one rollout shouldn't stop the run. The drop is logged and counted in
num_rollouts_dropped/no_advantage.You may ask: why not drop the zero-advantage rollouts too? With partial rewards, e.g. [1, 0, 0.5], the 0.5 rollout has advantage 0. Dropping it leaves the same gradient divided by fewer loss tokens, a larger step.
zero_advantage_fracmeasures how often that happens first.New W&B keys:
training_sample_builder/num_rollouts_dropped/untrainable,.../empty_turn,.../no_advantage,training_sample_builder/zero_advantage_frac.Removed W&B keys:
training_sample_builder/num_groups_dropped_untrainable,training_sample_builder/num_rollouts_dropped_empty_completion.Test plan
pre-commitpasses.pyreflyskipstorchtitan/rlandtests(project-excludesinpyproject.toml), so it checks none of this PR's files.Each of these tests fails on the builder of (3/4):
test_build_from_group_drops_a_rollout_with_an_empty_completion: an empty later turn, an empty turn 0, no turn.test_build_from_group_trains_a_zero_advantage_rollout_and_counts_it: rewards [1, 0, 0.5]; all 3 train,zero_advantage_frac= 1/3.test_build_from_group_skips_an_unscored_rollout_but_trains_its_siblings: gains ano_advantagecase, and checks the count for each reason.Changed:
test_batcher_actor_returns_the_in_process_batchtriggers its builder error with a badprompt_prefix_len("reuses 99 tokens"), since a missing advantage no longer raises.Deleted:
test_empty_completion_on_a_later_turn_raisesandtest_empty_completion_on_first_turn_is_skipped(the checks they pinned are gone),test_build_from_group_drops_a_rollout_with_an_empty_later_completion(now a case of the first test).