Repository navigation
[rl] Rollouts that fail outside the policy are recorded, not trained - #5520
felipemello1 wants to merge 1 commit into
Conversation
70a1b3a to
a3f5b24
Compare
c209ac3 to
6f03cfb
Compare
6f03cfb to
59c038c
Compare
1bd02b5 to
060dbe7
Compare
59c038c to
4653f41
Compare
|
Reply from claude: @claude review |
|
Claude finished @felipemello1's task in 3m 46s —— View job Approve -- please address the items below before merging (the Verifiers 4xx rule counts some infra failures as policy errors; a maintainer still needs to review): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. Moving infra failures out of scoring, the advantage and training is the right layer for this fix. One rule in the Verifiers classifier is too broad: it still trains some infra failures as policy errors. This PR touches core RL code (training_sample_builder.py, advantage.py, rollouter.py), so a maintainer still needs to review it.
What this PR does. It adds RolloutStatus.ERROR_SYSTEM for rollouts that fail for a reason outside the policy. Native rollouts that raise and Verifiers rollouts that raise (via rollouts_from_gather) become ERROR_SYSTEM instead of failing their group. So do Verifiers traces with a recorded infra error (rollout_status). These rollouts stay in their group for logs and the recorder, but scoring, the advantage estimator and TrainingSampleBuilder skip them. The remaining rollouts are centered on their own mean.
Example. One group of 3 rollouts. The generator is unreachable for rollout 0, and the rubric gives rewards 2 and 3 to the other two:
before: rollout 0 is ERROR with no turns -> "untrainable" filter drops all 3
after: rollout 0 is ERROR_SYSTEM, reward/advantage None, not trained
rollouts 1, 2 get advantages -0.5, +0.5 (mean 2.5) and train
rollout/system_error_rate = 1/3
Must fix
torchtitan/rl/examples/verifiers/rollouter.py:415-- the rule treats any generator 4xx as the policy's error. The in-repo generation server also returns 400 for harness/integration bugs (missing session header, badsampling_params, missing group id). Those rollouts geterror_rewardand their partial turns train. Match the context-length message instead (inline suggestion).
Questions
rollouter.py:413-- Does Verifiers raiseHarnessErrorafter the first turn only when the agent exits on its own? If a harness process or sandbox crash mid-rollout is also aHarnessError, those rollouts train as policy errors.
Details
- I checked the callers of the new status.
Rubric._score_single_rollout'serror_rewardshort-circuit usesis_error(), butERROR_SYSTEMrollouts never reach the rubric.compute_rollout_metricsandKeepExtremeRewardsFilteralready skipNonerewards.AdvantageEstimatornow returns[]for an empty group, and both group functions zip withstrict=Trueover the samescoredlist. TokenEnv's step timeout returnsERROR_TIMEOUTinstead of raising (token_env.py:226), so moving native exceptions toERROR_SYSTEMdoesn't reclassify timeouts.CancelledErroris aBaseException, sorollouts_from_gatherstill re-raises it.- Changing the zero-std check from
len(rewards) > 1tolen(rollout_group.rollouts) > 1keeps group_size=1 groups trainable as before, and drops groups that have one rollout left. - A Verifiers 400 at 0 turns is still
ERRORwith no turns, so the "untrainable" filter drops the whole group. That matches the intent (a data problem) and the behavior before this PR.
Not verified: I couldn't inspect the installed Verifiers package, so I don't know whether Error.type records the concrete subclass name. If it does, a subclass of ProviderError or HarnessError wouldn't match __name__, and those rollouts would fall through to ERROR_SYSTEM.
|
Reply from claude: @claude review again |
|
Claude finished @felipemello1's task in 1m 11s —— View job Approve -- the earlier must-fix item and question are resolved, and the new commits add no new problems (a maintainer still needs to review): review |
There was a problem hiding this comment.
Verdict: Approve -- the earlier must-fix item and question are resolved, and the new commits (9044219, 1dfba47, f99803e) add no new problems. This PR touches core RL code (training_sample_builder.py, advantage.py, rollout/rollouter.py), so a maintainer still needs to review it.
What changed since the last review. rollout_status (torchtitan/rl/examples/verifiers/rollouter.py:425-432) now counts only two recorded errors as the policy's:
- a
ProviderErrorwhose message contains_CONTEXT_OVERFLOW_TEXT; - a
HarnessErrorafter the first turn whose message matches_AGENT_EXIT_PATTERN(harness '<id>' exited <code>:).
The first-prompt check at line 375 uses the same constant.
Example.
first recorded error turns before this round now
ProviderError 400 "maximum context length ..." 0/1 ERROR ERROR
ProviderError 400 "missing X-Session-ID header" 1 ERROR (trained) ERROR_SYSTEM
HarnessError "harness 'terminus' exited 1: ..." 1 ERROR ERROR
HarnessError "harness 'terminus' metric: KeyError" 1 ERROR (trained) ERROR_SYSTEM
HarnessError "harness 'terminus': ... tmux exited 1" 1 ERROR (trained) ERROR_SYSTEM
HarnessError (any) 0 ERROR_SYSTEM ERROR_SYSTEM
Earlier items
- Must fix,
rollouter.py:415(any generator 4xx counted as the policy's): resolved. Only the context-length wording counts now, and the parametrized cases cover a non-context 400. - Question,
HarnessErrorafter the first turn: resolved. The match is now on the agent-exit message and anchored withre.match. The pattern requires the quoted id, so a nested "... exited 1" inside a harness-code error doesn't match (there's a test case for that). A harness process that crashes on its own after the first turn still counts as the policy's, and the comment at 416-417 now says so.
Details
- At 0 turns, a context-overflow
ProviderErrorreturnsERROR, so lines 372-391 still flag the first prompt as a data problem and the "untrainable" filter drops the group, same as before. A non-context 400 at 0 turns is nowERROR_SYSTEM, so its siblings train. That's the intended change. - Since the last review, the PR diff only changed
rollouter.pyandtest_verifiers.py. The merge commits only bring in the base branch.
Not verified: I couldn't import the installed Verifiers 0.4.0, so I didn't confirm its exact HarnessError exit wording or that Error.type is type(error).__name__. That relies on the author's reply.
674cf32 to
b3c83d3
Compare
08eb8a5 to
99ef19d
Compare
5a833dd to
ed02d71
Compare
99ef19d to
0ecfb1f
Compare
|
Reply from claude: @claude please review. This push puts the stack on a draft copy of the look-aside router PR, rebased onto main (row 0, DO NOT REVIEW; it closes when the original lands). The generate answer now comes from the generator, so the docs and bodies say so; each body says not to merge while row 0 is under the stack. |
|
Claude finished @felipemello1's task in 1m 39s —— View job Approve -- please address the items below before merging: the rebase onto row 0 leaves this PR's diff unchanged in substance, and failed rollouts still release their router reservation. The "Summary (human-written)" section is still empty, and a maintainer still needs to review. Review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. Rebasing onto row 0 (look-aside routing) leaves this PR's diff unchanged in substance, and the failed-rollout path still composes with the new generate path. This PR touches core RL code (rollout/rollouter.py, rollout/types.py, rollout/token_env.py, trainer/training_sample_builder.py), so a maintainer still needs to review it.
What changed since the last review. Only the base changed. The PR's 19 files and hunks match what I approved last round. Row 0 changes what a rollout's generate_fn does: the controller's generate (controller.py:668-691) reserves a generator from the router, calls that generator directly, and releases the reservation in a finally.
Example. One rollout's generate call fails under look-aside routing:
generate_fn: router.reserve -> generator.generate raises ConnectionError -> finally: release_reservation
_run_single_rollout: except Exception -> ERROR_INFRA, logs["error"]="ConnectionError(...)"
then release_session_fn(routing_session_id) runs as before
run_group: gather(return_exceptions=True) waits for every sibling -> make_scored_group
controller: generator_router.release_groups([group_id]) (controller.py:1206), no sibling still generating
Must fix
- PR description: the "Summary (human-written)" section is still empty. The author has to fill it in (CLAUDE.md, PR expectations #2).
Questions
- Still open from earlier rounds:
token_env.pyre-renders the policy's owncompletion_message(bridge_to_next_turn, thenrender_ids). If either can raise on content the model produced, the rule of thumb says that rollout should train, but today it ends asERROR_INFRA. Can that happen with the renderers in use?
Details
- Reservation accounting:
generate'sfinallyreleases the reservation whethergenerator.generatereturns or raises, so a rollout that becomesERROR_INFRAleaves no reserved load on the router. The TODO atcontroller.py:676-678about cancelled callers is row 0's and unchanged by this PR. This PR's gather never cancels a sibling. make_scored_group's docstring ("the controller releases the group on the generators next") still holds: the release now goes throughgenerator_router.release_groups, which reaches the generators.GenerateFnstill returnsCompletion | None(types.py:178). ANonewould makeTokenEnv.stepraise oncompletion.finish_reason, so it ends asERROR_INFRA. The controller'sgeneratenever returnsNone(the generator endpoint returnsCompletion).- Callers after the rebase: no
TokenEnv.Config()without a cap and no_alphabet_sort_rollouter_config()without arguments remain. EveryRolloutWorker.Config(...)builder (alphabet_sort, dapo_math, search_r1, geometry3k, theRollouterdocstring, the RL README) passestoken_env.
Not verified: I didn't run the CPU unit tests.
d9bb1eb to
029993d
Compare
81c0bb2 to
6f766d0
Compare
029993d to
ddd4639
Compare
91343c6 to
3abf31c
Compare
|
Reply from claude: @claude please review. The bottom PR renamed the stock |
|
Claude finished @felipemello1's task in 1m 10s —— View job Approve -- please address the items below before merging: the rebase onto the |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The rebase onto the MessageEnvRolloutWorker rename is clean and the logic is the same as what I approved last round. This PR touches core RL code (rollout/rollouter.py, rollout/types.py, rollout/token_env.py, trainer/training_sample_builder.py), so a maintainer still needs to review it.
What changed since the last review. Only names and one docstring:
- Every reference this PR adds or edits now uses
MessageEnvRolloutWorker/BaseRolloutWorker: theRolloutStatusdocstring, theTokenEnvdeadline comment, the recipes (alphabet_sort, geometry3k, the CI alphabet_sort configs), the RL README and the tests. Nothing in the tree or the diff still says bareRolloutWorker. MessageEnvRolloutWorker.run_group(rollouter.py:502) keeps the bottom PR's one-line docstring ("... then score them and fill their advantages"). That still matches the body: scoring and advantages happen inmake_scored_group, whichrun_groupreturns. The detailed contract (gather withreturn_exceptions=True, pass the results tomake_scored_group) is onBaseRolloutWorker.run_group, where an override would look for it.
Example. The same group as before, under the new class name:
MessageEnvRolloutWorker.run_group, group of 3; rollout 0's generate call raises ConnectionError;
the rubric gives rollouts 1 and 2 rewards 2 and 3
gather(return_exceptions=True) -> [ConnectionError(...), Rollout(1), Rollout(2)]
BaseRolloutWorker.make_scored_group:
rollout 0 -> ERROR_INFRA, reward/advantage None, logs["error"]="ConnectionError(...)"
rollouts 1, 2 -> advantages -0.5, +0.5, trained
Must fix
- PR description: the "Summary (human-written)" section is still empty. The author has to fill it in (CLAUDE.md, PR expectations #2).
Questions
- Still open from earlier rounds:
token_env.pyre-renders the policy's owncompletion_message(bridge_to_next_turn, thenrender_ids). If either one can raise on content the model produced, the rule of thumb says that rollout should train, but today it ends asERROR_INFRA. Can that happen with the renderers in use?
Details
- Rename coverage: a word-boundary search for
RolloutWorkerover the checkout and overgh pr diff 5520finds no matches. So no recipe, test or doc this PR touches depends on an alias the bottom PR removed. MessageEnvRolloutWorker.Config.token_envhas no default. EveryMessageEnvRolloutWorker.Config(...)builder (alphabet_sort through_alphabet_sort_rollouter_config(max_rollout_tokens=seq_len), geometry3k, theRollouterdocstring, the RL README) passestoken_env.Rollouter.run_group_rollouts(rollouter.py:239-243) still says "Thenscore_groupfills each reward". This PR doesn't touch it, and the sentence is still true.- Outside the rename, the diff matches what I approved last round:
make_scored_grouponBaseRolloutWorker,_NOT_TRAINABLE = {"error_abort", "error_infra"}, the abort check before parsing, theasyncio.timeoutdeadline check, a requiredmax_rollout_tokens, and the builder filtering onreward is not None.
Not verified: I didn't run the CPU unit tests.
|
Reply from claude: @claude please review. The stack is reordered: Verifiers groups in workers, then Verifiers 0.4.1, then worker placement come first (the stack table shows the new rows). It is also rebuilt with three reviewed passes: a code-style pass over every changed file, the rewritten placement docs (the |
|
Claude finished @felipemello1's task in 1m 4s —— View job Approve: the logic at 0442e23 is unchanged after the reorder, and the human-written summary is now filled in. A maintainer still needs to review: review |
There was a problem hiding this comment.
Verdict: Approve. I re-read the diff at 0442e23 after the reorder and the rebuild. Its logic is the same as what I approved last round, and the "Summary (human-written)" section is now filled in, so the one remaining must-fix item is resolved. This PR touches core RL code (rollout/rollouter.py, rollout/types.py, rollout/token_env.py, trainer/training_sample_builder.py), so a maintainer still needs to review it.
What this PR does. A rollout whose code raises now ends as ERROR_INFRA, with the error in logs["error"]. That covers a raise inside _run_single_rollout and a sibling that raised past it, which BaseRolloutWorker.make_scored_group catches. score_group and the advantage estimator see only is_trainable() rollouts. ERROR_ABORT and ERROR_INFRA are never scored or trained. TrainingSampleBuilder skips any rollout whose reward is None. max_rollout_tokens is required. Only the TokenEnv step deadline gives ERROR_TIMEOUT.
Example.
group of 3; rollout 0's generate call raises ConnectionError; the rubric gives rollouts 1 and 2 rewards 2 and 3
base: rollout 0 is ERROR with no turns -> the "untrainable" filter drops all 3
HEAD: rollout 0 is ERROR_INFRA, reward/advantage None, not trained
rollouts 1, 2 get advantages -0.5, +0.5 and train
rollout/status_rate/error_infra = 1/3, rollout/unscored_rate = 1/3
Questions
- Still open from earlier rounds, not blocking:
token_env.pyre-renders the policy's owncompletion_message(bridge_to_next_turn, thenrender_ids). If either one can raise on content the model produced, the rule of thumb says that rollout should train, but today it ends as an untrainedERROR_INFRA.
Details
- Diff at HEAD (19 files, +540/-138): the same hunks as last round. Those are
make_scored_grouponBaseRolloutWorker,_NOT_TRAINABLE = {"error_abort", "error_infra"}, the abort check before parsing, theasyncio.timeout+deadline.expired()check, a requiredmax_rollout_tokens/token_env, the builder'sreward is not Nonefilter, and the zero-std check onlen(rollout_group.rollouts) > 1. The Verifiers worker'srun_groupreturnsmake_scored_group(results, ...). - Callers after the rebuild: nothing in the tree builds
TokenEnv.Config()without a cap or calls_alphabet_sort_rollouter_config()with no arguments. EveryMessageEnvRolloutWorker.Config(...)passestoken_env: alphabet_sort, geometry3k, dapo_math, search_r1, theRollouterdocstring and the RL README. run_groupimplementations:MessageEnvRolloutWorkerandVerifiersRolloutWorkerboth go throughmake_scored_group. The MonarchRolloutWorkerActor.run_grouponly delegates to them. No other subclass in the tree overrides it.
Not verified: I didn't run the CPU unit tests.
|
Reply from claude: @claude please review. The stack is rebased onto main (the look-aside router PR merged), and the PRs below this one are updated. |
|
Claude finished @felipemello1's task in 1m 4s —— View job Approve: the logic at 9e0e9e6 is unchanged after the rebase onto main, and main's new |
There was a problem hiding this comment.
Verdict: Approve -- after the rebase onto main (look-aside router merged), the diff at 9e0e9e6 has the same logic I approved last round, and the one new caller from main (slake.py) already sets max_rollout_tokens. This PR touches core RL code (rollout/rollouter.py, rollout/types.py, rollout/token_env.py, trainer/training_sample_builder.py), so a maintainer still needs to review it.
What this PR does. A rollout whose code raises ends as ERROR_INFRA, with the error in logs["error"]. That covers a raise inside _run_single_rollout, and a sibling that raised past it, which BaseRolloutWorker.make_scored_group catches. ERROR_ABORT and ERROR_INFRA are not is_trainable(), so score_group and the advantage estimator never see them. TrainingSampleBuilder skips any rollout whose reward is None. max_rollout_tokens is now required, and only the TokenEnv step deadline gives ERROR_TIMEOUT.
Example.
group of 3; rollout 0's generate call raises ConnectionError; the rubric gives rollouts 1 and 2 rewards 2 and 3
base: rollout 0 is ERROR with no turns -> the "untrainable" filter drops all 3
HEAD: rollout 0 is ERROR_INFRA, reward/advantage None, not trained
rollouts 1, 2 get advantages -0.5, +0.5 and train
rollout/status_rate/error_infra = 1/3, rollout/unscored_rate = 1/3
Questions
- Still open from earlier rounds, not blocking:
token_env.pyre-renders the policy's owncompletion_message(bridge_to_next_turn, thenrender_ids). If either one can raise on content the model produced, the rule of thumb says that rollout should train. Today it ends as an untrainedERROR_INFRA.
Details
- Diff at HEAD: the same 19 files and +540/-138 as last round. The logic hunks are unchanged:
make_scored_grouponBaseRolloutWorker,_NOT_TRAINABLE = {"error_abort", "error_infra"}, the abort check before parsing,asyncio.timeout+deadline.expired(), a requiredmax_rollout_tokens/token_env, the builder'sreward is not Nonefilter, and the zero-std check onlen(rollout_group.rollouts) > 1. - New from main:
torchtitan_recipes/rl/slake.py:166buildsTokenEnv.Config(max_rollout_tokens=max_total_tokens, max_num_turns=1), so the required field doesn't break it. NoTokenEnv.Config()without a cap, and noMessageEnvRolloutWorker.Config(...)withouttoken_env, is left in the tree (alphabet_sort, dapo_math, geometry3k, search_r1, slake, theRollouterdocstring, the RL README). run_groupimplementations:MessageEnvRolloutWorkerandVerifiersRolloutWorkerboth returnmake_scored_group(...). The MonarchRolloutWorkerActor.run_grouponly delegates to them.- Code that reads a reward (the recorder ranking,
compute_rollout_metrics, the builder) filters out None.AdvantageEstimatoronly getsrollouts_to_center.ERROR_ABORTis still produced in one place,token_env.py:235.
Not verified: I didn't run the CPU unit tests.
|
Reply from claude: Correction: it can raise. The first version of this comment had it wrong.
Follow-up: a separate bug-fix PR on main that converts the tool calls to the |
| async def make_scored_group( | ||
| self, results: list[Rollout | BaseException], sample: object, *, group_id: int | ||
| ) -> RolloutGroup: | ||
| """Turn a group's `gather(..., return_exceptions=True)` results into one scored group. |
There was a problem hiding this comment.
this doesnt make sense. the gather(..., return_exceptions=True) provides no context
There was a problem hiding this comment.
Reply from claude: Rewritten: "Score one group and fill its advantages. A sibling that raised becomes ERROR_INFRA." Then an example table. The return_exceptions reason moved next to the callers' gather: every sibling must end before the controller frees the group's KV cache.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| Example, group 7, rewards from `score_group`: | ||
|
|
||
| results [Rollout(0, COMPLETED), ConnectionError(...), Rollout(2, ERROR)] | ||
| rollouts [Rollout(0), Rollout(1, ERROR_INFRA, logs={"error": ...}), Rollout(2)] | ||
| rewards [1.0, None, 0.0] score_group sees rollouts 0 and 2 (`is_trainable()`) | ||
| advantages [0.5, None, -0.5] None: not trained | ||
| results [Rollout(0), CancelledError()] -> raises the CancelledError |
There was a problem hiding this comment.
this can be done better.
There was a problem hiding this comment.
Reply from claude: The loop no longer rebinds its variable. Each branch appends one rollout, and the names say what each list holds: rollouts_or_errors, then rollouts, then rollouts_to_score.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| advantages [0.5, None, -0.5] None: not trained | ||
| results [Rollout(0), CancelledError()] -> raises the CancelledError | ||
|
|
||
| A reward None from `score_group` (e.g. a judge that failed) also keeps a rollout out of |
There was a problem hiding this comment.
i believe reading somewhere that when theres an error, verifiers returns score 0, instead of None. Is there a contradiction here?
There was a problem hiding this comment.
Reply from claude: No contradiction. Verifiers' Trace.reward sums the rewards that exist, so it reads 0.0 for a trace nobody graded. TitanRL decides by status: the Verifiers worker gives every failed rollout reward None (score_group), whatever its status. So no Verifiers rollout trains on a 0.0 it didn't earn.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| rollout for rollout in rollouts if rollout.status.is_trainable() | ||
| ] | ||
| if rollouts_to_score: | ||
| outputs = await self.score_group(rollouts_to_score, sample) |
There was a problem hiding this comment.
lets try to be literal and informative in our variable names. E.g. "scored_outputs"? Maybe not that literally.
There was a problem hiding this comment.
Reply from claude: Renamed to rubric_outputs.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| One scored `RolloutGroup`. | ||
| """ | ||
|
|
||
| async def make_scored_group( |
There was a problem hiding this comment.
is make_scored_group the best name here? Maybe "score_rollouts"? But even that is not right, because we also compute advantages. I am ok with the name staying like that, i just wonder if theres something better.
There was a problem hiding this comment.
Reply from claude: I kept it. It takes a group's raw results and returns a RolloutGroup with rewards and advantages; score_group, the rubric step, is one part of it. I found nothing clearer.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| # subclassed, and metrics list `RolloutStatus` members. One way: keep these kinds fixed and add a | ||
| # free-form reason string on `Rollout` that metrics key on. To stop training more rollouts today, | ||
| # override `BaseRolloutWorker.score_group` to return reward None. | ||
| class RolloutStatus(StrEnum): |
There was a problem hiding this comment.
docstring here is very bad. We should only give a general guidance of what each means. It can be written as 1-2 lines underneath each option. It shouldnt say what rewards do, because thats up to the rubric function to define. As a rule of thumb, a function shouldnt say what another function is doing, because this can become stale.
There was a problem hiding this comment.
Reply from claude: Rewritten. The class docstring is the rule of thumb in 2 lines. Each status has a 1-line docstring that says when it happens, not what other code does with it.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| reward: float | None = None | ||
| """Final weighted reward, filled by the rubric.""" | ||
| """Final weighted reward, filled by the rubric. None if the rollout wasn't scored (its status | ||
| isn't `is_trainable()`) or the rubric gave no reward: it then gets no advantage and isn't | ||
| trained.""" |
There was a problem hiding this comment.
Lets add a TODO that this should become per token.
There was a problem hiding this comment.
Reply from claude: Added: # TODO: make it per token.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| """Final weighted reward, filled by the rubric. None if the rollout wasn't scored (its status | ||
| isn't `is_trainable()`) or the rubric gave no reward: it then gets no advantage and isn't | ||
| trained.""" |
There was a problem hiding this comment.
| """Final weighted reward, filled by the rubric. None if the rollout wasn't scored (its status | |
| isn't `is_trainable()`) or the rubric gave no reward: it then gets no advantage and isn't | |
| trained.""" | |
| """Final weighted reward, filled by the rubric. None if the rollout wasn't scored.""" |
There was a problem hiding this comment.
Reply from claude: Applied.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| """ | ||
| metrics: list[m.Metric] = list(rollout_group.metrics) | ||
| # A rollout with reward None wasn't scored (see `BaseRolloutWorker.make_scored_group`): skip | ||
| # it, not its group. A group left with 10 of 16 trains those 10, centered on their 10 rewards. |
There was a problem hiding this comment.
| # it, not its group. A group left with 10 of 16 trains those 10, centered on their 10 rewards. | |
| # it, not its group. A group left with 10/16 trains those 10, centered on their 10 rewards. |
Lets put a TODO somewhere that we should investigate if we want to reweight these 10 or change the trainer to count the number of rollouts -- not the number of groups.
There was a problem hiding this comment.
Reply from claude: Applied, reworded to drop the "X, not Y" (code-style): "A rollout with reward None wasn't scored: drop only that rollout. E.g. a group left with 10 of 16 rollouts trains those 10, centered on their 10 rewards." The TODO is yours: "investigate reweighting those 10, or making the trainer count the rollouts it trains."
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| metrics: list[m.Metric] = list(rollout_group.metrics) | ||
| # A rollout with reward None wasn't scored (see `BaseRolloutWorker.make_scored_group`): skip | ||
| # it, not its group. A group left with 10 of 16 trains those 10, centered on their 10 rewards. | ||
| rollouts = [ |
There was a problem hiding this comment.
should we qualify, e.g. non_zero_rollouts, rollouts_with_reward? you can think of a better name.
There was a problem hiding this comment.
Reply from claude: Renamed to rollouts_with_reward.
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
|
Reply from claude: answers to the comments on this PR that have no inline thread.
Still true, and outside this stack: it's a renderer bug on main. The proposed fix stays a separate PR. |
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 59s —— View job Approve: every comment from the 2026-11-13 maintainer round is fixed at d1200ff, and removing |
There was a problem hiding this comment.
Verdict: Approve. Every comment from the 2026-11-13 maintainer round is fixed at d1200ff, and removing ERROR_ABORT is consistent everywhere in the tree. This PR changes core RL code (rollout/rollouter.py, rollout/types.py, rollout/token_env.py, trainer/training_sample_builder.py), so a maintainer still needs to review it.
What changed since the last review.
ERROR_ABORTis gone.TokenEnv.step(token_env.py:236-242) now checks the finish reason before it parses. A finish reason of"abort"or vLLM's"error"returnsERROR_INFRAwith nocompletion_message, so the rollout is never scored or trained._NOT_TRAINABLEis just{"error_infra"}.- There is a new
{prefix}_reward_allmetric. It is the mean over all rollouts, with an unscored rollout counted as 0, so a rising failure rate can't inflate{prefix}_reward. - The maintainer's suggestions are applied:
- the
RolloutStatusdocstrings are one line per status, plus the rule of thumb; - the
make_scored_groupdocstring and its example table are rewritten; - renames:
rollouts_or_errors,rubric_outputs,rollouts_with_reward; - new TODOs: the per-token reward, reweighting a partial group, and the shorter TODO on
RolloutStatus.
- the
- The reason for
return_exceptionsnow sits next to thegatherinrun_group(rollouter.py:504-505).
Example. A group of 3. On turn 2, rollout 0's completion comes back with finish_reason="abort" and tokens that don't parse. The rubric gives rollouts 1 and 2 rewards 2 and 3:
main: parse first -> ERROR_PARSE, scored (error_reward or reward fns), enters the mean, trains
HEAD: cut-short check first -> ERROR_INFRA, reward/advantage None, not trained
rollouts 1, 2 -> advantages -0.5, +0.5
rollout_reward mean 2.5, rollout_reward_all mean 5/3, status_rate/error_infra 1/3
Details
- 2026-11-13 maintainer comments, checked at HEAD: all are fixed in code or answered, and none got further pushback. The replies on the Verifiers threads point at later PRs in the stack. On this base,
VerifiersRollouter.run_group_rollouts(examples/verifiers/rollouter.py:250) still runs its own gather/score path. This PR doesn't touch it, and that path never produces a None reward. ERROR_ABORTremoval:- No reference to
ERROR_ABORTorerror_abortis left in the tree. - The SGLang engine still reports
finish_reason="abort"for a request it has already admitted (generator/sglang/engine.py:746-760,:809). That now ends asERROR_INFRA, which matches the rule of thumb. - An abort during admission still raises
ValueError(engine.py:572) and also ends asERROR_INFRA.
- No reference to
- Callers: every
TokenEnv.Config(...)in recipes and tests passesmax_rollout_tokens:- dapo_math, search_r1 and slake set it on the next line;
- alphabet_sort and geometry3k pass
seq_len; _configure_cino longer overrides it.
- Deadline:
deadline = asyncio.timeout(timeout)is created before thetry, sodeadline.expired()can always be read in theexcept.asyncio.timeout(None)never expires. - Open question from earlier rounds: a tool call in the history can make the full re-render raise. The author confirmed this, and it is on main too. It is deferred to a separate renderer bug-fix PR, so it doesn't block this one.
Not verified: I didn't run the CPU unit tests, and I didn't check what makes SGLang abort a request it already admitted (the description says only invalid requests do).
| # Over every rollout, an unscored one counted as 0: `_reward` leaves the unscored ones | ||
| # out, so it reads higher as more rollouts fail. Example: 8 rollouts at 1.0 and 2 | ||
| # unscored: `_reward` 1.0, `_reward_all` 0.8. | ||
| m.Metric(f"{prefix}_reward_all", m.Mean.from_list(all_rewards)), |
There was a problem hiding this comment.
| # Over every rollout, an unscored one counted as 0: `_reward` leaves the unscored ones | |
| # out, so it reads higher as more rollouts fail. Example: 8 rollouts at 1.0 and 2 | |
| # unscored: `_reward` 1.0, `_reward_all` 0.8. | |
| m.Metric(f"{prefix}_reward_all", m.Mean.from_list(all_rewards)), |
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| out.extend( | ||
| m.Metric( | ||
| f"{prefix}/status_rate/{status.value}", | ||
| m.Mean.from_list([float(rollout.status is status) for rollout in rollouts]), | ||
| ) | ||
| for status in RolloutStatus | ||
| if status.is_terminal() | ||
| ) |
There was a problem hiding this comment.
there must be a more efficient way of doing this. Maybe "Counter" or something like that and divide by the sum and log that?
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
| self._num_turns += 1 | ||
|
|
||
| # Parse first, so a truncated / aborted response still carries its message | ||
| if completion.finish_reason in _CUT_SHORT_FINISH_REASONS: |
There was a problem hiding this comment.
Lets add a TODO here to also add some log with it, so we are not bling on the reason. Do we already support carrying on logs? if so, maybe its easy to just fix it, no todo?
There was a problem hiding this comment.
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one.
|
Reply from claude: This PR is replaced by a fresh draft on a new branch, with the same title: "[rl] Rollouts that fail outside the policy are recorded, not trained". The comments here were read when planning it. Closing this one. |
Summary (human-written)
If a rollout fails because of infra, we shouldnt add it to the training data. Today we cancel the entire group. Now we cancel only that rollout. The other make into training.
Agent details
TLDR: A rollout that failed outside the policy (a dead generator, a crashed env) is now
ERROR_INFRA: recorded,counted, never trained. The rest of its group still trains.
Stack (15 PRs, bottom first; merging a PR also merges every PR below it; this PR in bold)
Alone on main, not in this stack: "Validation reads each prompt at most once; ValidationConfig.steps defaults to -1" and "Terminal-Bench 35B-A3B recipe: Dist-MoE in both roles, FULL CUDA graph generators, DAPO loss".
Problem
ERROR(_run_single_rollout'sexcept Exception), soinfra damage trains toward the error reward as if the policy had failed.
ERROR_ABORT, which also trains toward the error reward, though the policy did nothingwrong.
Solution
RolloutStatus.ERROR_INFRAmarks a failure outside the policy.is_trainable()is False only for it.ERROR_INFRA. The MessageEnv worker marks it in_run_single_rolloutand keeps itsturns. A sibling that raises out of
run_group's gather gets the same status inmake_scored_group, which thenscores and centers the rest of its group. The Verifiers worker (PR 1) passes its gather results to
make_scored_grouptoo, so a Verifiers rollout that raises no longer fails its whole group.ERROR_INFRAwithout parsing.ERROR_ABORTis deleted.rollout/status_rate/<status>reports each status's share every step.rollout/unscored_rateis the share withno reward.
rollout_rewardaverages the scored rollouts;rollout_reward_allaverages all of them, an unscoredone as 0 (8 at 1.0 and 2 unscored: 1.0 and 0.8).
RolloutStatus: the status says who failed.ERROR_INFRAnever trains; a policy failuretrains unless the worker gives it no reward (
score_group).You may ask: why no retry for an aborted request? TitanRL's vLLM engine never aborts one, and the SGLang engine
aborts only invalid requests, which a retry wouldn't fix.
TODOs in this PR: group postprocessors as an ordered list; user-added statuses; per-token reward and advantage;
reweighting a partial group.
Test plan
pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/components/test_renderer.py tests/unit_tests/cpu/config # 965 passed, 1 skipped, 14 warningsNew:
test_a_response_the_generator_cut_short_is_error_infra_even_if_it_fails_to_parse[abort|error];test_compute_rollout_metrics_records_a_rate_per_statusalso checksrollout_reward_all;test_a_failing_rollout_is_error_infra_once_every_sibling_finished(the Verifiers worker).