Skip to content

[rl] Send each rollout group to the worker with the fewest rollouts in flight - #6114

Draft
felipemello1 wants to merge 1 commit into
felipemello1/verifiers-041/5-shared-folderfrom
felipemello1/distribute/3-least-loaded
Draft

felipemello1 wants to merge 1 commit into
felipemello1/verifiers-041/5-shared-folderfrom
felipemello1/distribute/3-least-loaded

Conversation

@felipemello1

@felipemello1 felipemello1 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Agent details

TLDR: Each rollout group now goes to the worker with the fewest rollouts in flight, picked by LeastLoadedRoutingStrategy, the class both generator routers use to place new sessions. In a placement simulation at Terminal-Bench 9B's shape (48 groups of 32 on 12 workers), the busiest worker runs 1.9x the mean load instead of 2.4x with random placement, and 2.8x instead of 4.0x at p99. The simulation is not part of this PR. On real runs, two gauges read the busiest worker's count and the mean count once per step.

With the unit test's 3 rollout workers, a random pick can leave one worker idle while another runs 6 rollouts, but this PR sends each group to the worker with the fewest rollouts in flight (a tie goes to the worker picked longest ago), and a simulation at Terminal-Bench 9B's shape puts the busiest worker at 1.91x the mean load instead of 2.36x.

# before
random.choice(self._workers.by_worker).run_group.call_one(...)
# after
worker = self._worker_strategy.choose(RoutingContext(), self._worker_loads)
worker.actor.run_group.call_one(...)

Problem

  1. Each group goes to a worker picked at random.
  2. The pick ignores load, so workers are even only over many groups.
  3. A group stays on its worker until its slowest rollout ends, so some workers pile up groups while others idle.
  4. In the placement simulation at Terminal-Bench 9B's shape, the busiest worker runs 2.4x the mean load.

Solution

  1. The Rollouter keeps one _RolloutWorkerLoad per worker: a RoutingCandidate whose reserved_load is the worker's rollouts in flight.
  2. Each group goes to the lowest count through LeastLoadedRoutingStrategy. A tie goes to the worker chosen longest ago.
  3. The count rises by the group size only after the call is sent. If the send raises, the callback that lowers the count is never added, so a count added first would never come down. It drops when the call ends, also for a cancelled caller.
  4. Rollouter.metrics() adds rollout_worker/num_rollouts_in_flight_max and rollout_worker/num_rollouts_in_flight_mean to each training step's metrics, next to the rollout buffer's gauges. They count whole groups until they return, so they read higher than the table's running rollouts below. A Rollouter subclass that overrides setup_async may spawn no workers: then metrics() returns nothing. Rollouter.metrics()'s docstring says how to read them: a max well above the mean means the load is uneven.
  5. Unchanged: whole groups, the pool size, the hosts.
  6. The RL README's "Rollout workers on more than one host" says that a host whose groups fail at once gets most new groups.

Results

busiest worker / mean running rollouts, time-averaged (p99), modelled rollout times, 128 rollouts per worker
shape (workers)                random        this PR       count per rollout (TODO)
alphabet_sort 32x8 (2)         1.17 (1.72)   1.10 (1.46)   1.04 (1.34)
dapo_math 4B 40x16 (5)         1.59 (2.56)   1.37 (1.95)   1.14 (1.48)
Terminal-Bench 9B 48x32 (12)   2.36 (3.95)   1.91 (2.81)   1.36 (1.74)
Terminal-Bench 35B 40x32 (10)  2.22 (3.86)   1.84 (2.77)   1.36 (1.77)
dapo_math 30B-A3B 160x16 (20)  1.98 (2.82)   1.61 (2.10)   1.16 (1.34)

The table comes from a placement simulation outside this PR, not from runs. Rollout times: lognormal, a per-task factor times per-rollout noise, median 6 minutes, 3,000 simulated minutes. The simulation copies LeastLoadedRoutingStrategy.choose; a first-index tie-break gives the same numbers, because ties happen only at the start.

You may ask:

  • Why reuse LeastLoadedRoutingStrategy? It already picks the least loaded target, with a tie-break that spreads idle starts: the generator router and the DP-rank router place new sessions with it (the sticky strategy's fallback). One way to do it in titan.
  • Why not lower the count as each rollout ends (the last column)? Each worker would have to report each rollout's end to the controller: a new callback in every worker's run_group, the Verifiers worker's included. A TODO marks it.
  • Why test a send that fails? call_one raises before sending when an argument can't be pickled, e.g. a dataset sample that holds a lock. The count must not rise for a group that never left.
  • Can a worker go over rollouts_per_worker (R)? Counted the way the gauges count (whole groups until they return), and with no validation group in flight, a worker holds at most ceil(R / S) x S training rollouts, where S is the group size. That is R when S divides R, as in every recipe. A validation burst can push a worker past it.

NOTE:

  • Validation groups count too, with their own group size, so a validation burst pushes training groups to other workers.
  • A worker whose groups fail right away (e.g. its env can't start, or its host misses an image file or a task's tests/) is back at 0 at once and gets most new groups, where random placement sent it about 1 in N. The RL README says so too. A rollout that fails ends as ERROR_INFRA with 0 turns, so rollout/num_turns (mean) drops; only a run_group that raises counts in rollout/group_failures. A TODO at the pick says to retire such a worker.
  • An open PR that adds retries to run_group_rollouts edits the same lines. Whichever lands second rebases, and a retry must count the group on the worker it retries on.

Follow up / TODO (each is a # TODO in the code):

  • Balance the workers better: lower a worker's count as each of its rollouts ends. Today it drops only when the whole group returns. In the simulation, Terminal-Bench 9B's busiest worker drops from 1.9x to 1.4x the mean load. It needs each worker to report each rollout's end to the controller.
  • Retire a worker whose groups keep failing (e.g. its env can't start). It needs a rule for "broken", e.g. 3 failed groups in a row.

Test plan

python -m pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/components/test_renderer.py tests/unit_tests/cpu/config -q
# 1003 passed, 7 skipped (6 need Verifiers, 1 skipped on main)
# The same command with Verifiers 0.4.1 installed:
# 1110 passed, 1 skipped (skipped on main)

New or changed in test_rollouter_pool.py: test_each_group_goes_to_the_worker_with_the_fewest_rollouts_in_flight (with a tie that the least recently chosen worker wins, which a first-index tie-break fails; and metrics() with no workers returns nothing, which max([]) fails), test_a_run_group_that_fails_to_send_leaves_its_worker_count_unchanged, and test_close_waits_for_run_group_of_cancelled_caller (the count stays 2 after the cancel, and is 0 once the group returns). pre-commit and pyrefly check pass.

@felipemello1
felipemello1 added this pull request to stack #6115 November 16, 2026 06:53
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review

@claude

claude Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 42s —— View job


Approve -- please address the items before merging (the human-written summary is empty, and one should-consider about a fast-failing worker attracting most groups) -- review ·

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. The change is small and correct (+29/-5 logic) and replaces random placement with a least-loaded pick, but the human-written summary is empty.

What this PR does. Rollouter keeps _num_rollouts_in_flight, one count per entry of by_worker. run_group_rollouts sends each group to the worker with the lowest count, and the first index wins a tie. The count goes up by group_size only after call_one returns, so a send that fails to pickle never counts. It goes down in the done callback, which also runs when the caller was cancelled, because the call is shielded.

Example. 3 workers, all idle.

dispatch g0(size 4), g1(2), g2(2), g3(1)
before: each group goes to random.choice(by_worker); several can land on one worker
after:  g0->w0, g1->w1, g2->w2, g3->w1 (w1 and w2 tie at 2; first wins)   counts [4, 3, 2]
g0 returns -> counts [0, 3, 2] -> the next group goes to w0

Must fix

  1. The PR description's "Summary (human-written)" section is empty. Please fill it in (CONTRIBUTING.md, "AI-assisted contributions").

Should consider

  • torchtitan/rl/rollout/rollouter.py:279 -- a worker whose run_group fails fast attracts nearly every group under least-loaded, where random placement sent it about 1/N. At minimum, write the behavior down (see the inline comment).
Details
  • Necessity: placement used to ignore load, and a group holds its worker until its slowest rollout ends. That makes a least-loaded pick a reasonable fix at the right layer, the Rollouter. The evidence is a simulation, which the PR says plainly. The change is small enough that no end-to-end measurement is needed to land it.
  • Atomicity: nothing is awaited between min and +=, and all callers share one event loop. Concurrent run_group_rollouts calls, such as the validation gather in controller.py:903 and the training _rollout_loop, therefore can't both read a stale minimum.
  • Ordering: add_done_callback on a pending task schedules its callback with call_soon, so the decrement can never run before the increment. The same holds if call_one returns a future that is already done.
  • Callsites: setup_async initializes the counts, so the object.__new__ helper in test_verifiers.py:300, which skips __init__ but calls setup_async, keeps working. test_shutdown.py calls by_worker[i].run_group.call_one directly and is unaffected.
  • Tests: the send-failure test guards the ordering invariant, which would otherwise fail silently (a leaked count would steer every later group away from that worker). It is a cheap CPU test that extends the existing fakes.
  • Overlap: #6099 changes the run_group_rollouts arguments in this same function. Expect a rebase conflict, but no design conflict.

Not verified: the simulation numbers in the description.

Comment thread torchtitan/rl/rollout/rollouter.py Outdated
Comment on lines +279 to +284
# The worker with the fewest rollouts in flight; the first one on a tie.
# TODO: lower a worker's count as each rollout ends, not when its whole group returns
# (simulated busiest worker: 2.6x -> 1.8x the mean). It needs the worker to report each end.
worker_index = self._num_rollouts_in_flight.index(
min(self._num_rollouts_in_flight)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Least-loaded makes a worker that fails fast attract most groups. Picture a worker whose run_group raises within milliseconds, for example because its host has no Docker daemon, or a 127.0.0.1 service is missing after workers_on_controller_host=False from the base PR. Its count drops back to 0 almost at once. The healthy workers stay above 0, so this worker wins nearly every pick. _rollout_loop then logs "rollout group N failed; dropping" for nearly every group. With random placement only about 1/N of groups would fail.

The failure is loud (rollout/group_failures), so this doesn't block the PR. Still, it is worth a NOTE/TODO here and a line in the description. A cheap fix is to skip the refund in _on_run_group_call_done when call.exception() is not None, so a failing worker keeps its load. The catch is that a worker with occasional transient failures then drifts upward forever. Either way, please write the chosen behavior down.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: Fixed in 6eb7975: the refund stays. A 2-line # TODO: at the pick names the fast-failing worker and the fix (keep a failed group's count) with its cost (transient failures pile up). The description's NOTE says it too.

@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from 9a478ef to 6eb7975 Compare November 16, 2026 07:26
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: Fixed in 6eb7975 (TODO at the pick, NOTE line in the description). @claude please review

@claude

claude Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 36s —— View job


Approve -- please address the item before merging (the fast-failing-worker TODO is resolved; the human-written summary is still empty) -- review ·

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the item below before merging. The fast-failing-worker concern is now written down in code and in the description. The only open item is the empty human-written summary.

Re-review of 6eb7975

  • Resolved: the should-consider at torchtitan/rl/rollout/rollouter.py:282. A # TODO at the pick now names the fast-failing worker, the fix (keep a failed group's count), and its cost (transient failures pile up). The description's NOTE and follow-up list say the same.
  • Still open: the "Summary (human-written)" section of the PR description is still just the template placeholder.

Must fix

  1. The PR description's "Summary (human-written)" section is empty. The author has to write it (CONTRIBUTING.md, "AI-assisted contributions").
Details
  • No new problems in the new commit. The diff only differs from the last review by the added TODO.
  • The earlier analysis still holds at HEAD. Nothing is awaited between min(...) and += group_size, so concurrent run_group_rollouts calls on the one event loop can't read a stale minimum. The done callback is scheduled with call_soon, so the decrement always runs after the increment. The increment comes after call_one, so a send that fails to pickle never leaks a count, and test_a_run_group_that_fails_to_send_leaves_its_worker_count_unchanged guards that.

Not verified: the simulation numbers in the description. This touches only RL rollout code, but a maintainer still needs to review.

@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from 6eb7975 to dfc5649 Compare November 16, 2026 14:00
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: Rebased on the new default in the PR below (dfc5649, same patch). @claude please review

@claude

claude Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 59s —— View job


Approve -- please address the item before merging (rebase leaves the patch unchanged with no new problems; the human-written summary is still empty) -- review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the item below before merging. The rebase onto the base PR's new default (workers_on_controller_host=False) leaves the patch unchanged and adds no new problems. The only open item is still the empty human-written summary.

Re-review of dfc5649

  • Unchanged: the diff against the new base matches 6eb7975. That covers the least-loaded pick, the increment after call_one, the decrement in the done callback, both TODOs, and the three tests.
  • Still open: the "Summary (human-written)" section of the description is still the template placeholder.

Must fix

  1. The PR description's "Summary (human-written)" section is empty. The author has to write it (CONTRIBUTING.md, "AI-assisted contributions").
Details
  • The new default makes the fast-failing-worker TODO (torchtitan/rl/rollout/rollouter.py:284) more likely to apply. An env that needs a 127.0.0.1 service now runs off the controller host by default. If that service is missing, run_group fails fast on those workers. That case is already written down in the TODO and the description's NOTE, and the failures still show up loudly in rollout/group_failures, so no new action is needed.
  • Tie-break and host order: by_worker is host-major ([A0, A1, B0, B1, C0], torchtitan/rl/actors/monarch/system.py:221). Ties go to the first index, so when fewer groups are in flight than there are workers, host A's workers fill first. This only happens under light load: under normal sizing (rollouts_per_worker), there are at least as many groups in flight as workers, and the first round already puts one group on every worker. Not a finding. If per-host load ever matters (say, Docker containers per host), rotating the tie-break would be a one-line change.
  • The analysis from the earlier reviews still holds at HEAD. Nothing is awaited between min(...) and += group_size. The done callback is scheduled with call_soon, so it always runs after the increment. A send that fails to pickle never leaks a count, and test_a_run_group_that_fails_to_send_leaves_its_worker_count_unchanged guards that.

Not verified: the simulation numbers in the description. This touches only RL rollout code, but a maintainer still needs to review.

@felipemello1 felipemello1 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks ok and i would approve it as is, but i wonder what the lift is to actually do this by rollout

Comment thread torchtitan/rl/rollout/rollouter.py Outdated
Comment on lines +284 to +285
# TODO: a worker whose `run_group` fails fast drops back to 0 and draws most groups. Keeping a
# failed group's count on its worker would stop that, but transient failures would then pile up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont understand this todo. Please clarify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: rewritten with an example. Today a worker's count drops only when its whole group returns, so a
group of 8 with 7 rollouts done still counts 8, and new groups avoid that worker. The second TODO: a worker that fails
every group at once (e.g. its env can't start) is back at 0 right away, so it keeps drawing new groups.

)
self._inflight_run_group_calls.add(call)
call.add_done_callback(self._on_run_group_call_done)
call.add_done_callback(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets maybe add a 1 or 2 liner comment here with a hint, e.g. "update inflight count". Maybe we need to rename _on_run_group_call_done? not sure if we should keep generic. Maybe we should, if the function is doing multiple things.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: kept the name. It does three things: lowers the count, forgets the call, reads the error. The new
comment above add_done_callback says so: "When run_group ends: lower this worker's count, forget the call and read
its error."

Comment thread torchtitan/rl/rollout/rollouter.py Outdated
on_controller_host=self._config.workers_on_controller_host,
**(worker_kwargs or {}),
)
self._num_rollouts_in_flight = [0] * len(self._workers.by_worker)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets also add a one liner hint here on why we need this, e.g. "Keep count to help with load balancing"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: done: "Every worker on every host, with its rollouts in flight: each new group goes to the least
loaded."

Comment thread torchtitan/rl/rollout/rollouter.py Outdated
# (simulated busiest worker: 2.6x -> 1.8x the mean). It needs the worker to report each end.
# TODO: a worker whose `run_group` fails fast drops back to 0 and draws most groups. Keeping a
# failed group's count on its worker would stop that, but transient failures would then pile up.
worker_index = self._num_rollouts_in_flight.index(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need you to refresh my mind: do we have 1 rollouter in the controller, on multiple?

In other words: is this selecting across ALL workers in ALL nodes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: one. The controller builds one Rollouter (controller.py:635), and it runs in the controller's
process. Its handle lists every worker on every host (by_worker), so each pick is across all workers on all nodes.
The comment above the counts says so now.

@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from dfc5649 to f4e05c0 Compare November 16, 2026 19:21
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: on your review,

this looks ok and i would approve it as is, but i wonder what the lift is to actually do this by rollout

two readings.

  • Send each rollout to its own worker: a big lift. A verifier that scores the whole group needs all of its rollouts in
    one place, and the worker computes the group's advantages. Splitting groups moves both to the controller.
  • Count each rollout's end, still sending whole groups: ~90 lines in 5 files, plus ~60 lines of tests. Each worker
    must report each rollout's end. A Monarch Port does that; a probe got 3 rollout ends before the group returned.
    The cost is a new callback in every worker's run_group, and an ActorSystem method to open the channel. Gain in
    this PR's simulation, at Terminal-Bench 9B's shape (48 groups of 32 on 12 workers): busiest worker 1.9x -> 1.4x the
    mean.

I'd do the second after the Verifiers-env-in-worker stack lands, since it rewrites the Verifiers worker. The new
rollout_worker/rollouts_in_flight_max vs _mean gauges will show on real runs whether it's worth it.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review.

The code at this head answers the maintainer review (replies are in each thread). Follow-up work, not in this push:

  • Section banners in functions with clear phases. A comment-only commit is coming in this stack.
  • Per-rollout counting: lower a worker's count as each rollout ends, not only when its group returns. In this PR's simulation (48 groups of 32 on 12 workers), the busiest worker would drop from 1.91x to 1.36x the mean. A draft is being built on top of this PR and parked as a separate draft; it lands after the Verifiers stack, which rewrites the Verifiers worker's run_group.

@claude

claude Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 29s —— View job


Approve -- please address the item before merging (all maintainer comments are addressed and the move to LeastLoadedRoutingStrategy adds no new problems; the human-written summary is still empty) -- review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the item below before merging. All four of the maintainer's inline comments are handled at f4e05c0, and moving the pick to LeastLoadedRoutingStrategy introduces no new problems. The only open item is still the empty human-written summary.

Re-review of f4e05c0

  • Changed since the last review: the hand-rolled _num_rollouts_in_flight.index(min(...)) is gone. In its place is one _RolloutWorkerLoad(RoutingCandidate) per worker, picked by LeastLoadedRoutingStrategy (torchtitan/rl/rollout/rollouter.py:305). A tie now goes to the least recently chosen worker, not the first index, which fixes the host-A-fills-first point from the last review. The PR also adds Rollouter.metrics() (rollout_worker/rollouts_in_flight_max / _mean), wired into _trainer_loop (controller.py:1492).
  • Maintainer comments (felipemello1), all addressed in code:
    • "i dont understand this todo": both TODOs now give an example (a group of 8 with 7 rollouts done still counts 8; a worker whose env can't start is back at 0 right away).
    • Hint at the done callback: there is now a one-line comment above add_done_callback, and the name stays.
    • Hint at the counts: added at rollouter.py:216.
    • "1 rollouter or multiple?": answered. There is one, in the controller, and it picks across every worker on every host.
    • The top-level question about the lift of per-rollout counting is answered in the thread and tracked as a TODO.
  • Still open: the human-written summary.

Example. 3 workers, all idle:

send g0(4), g1(2), g2(2), g3(1)  -> [[g0], [g1, g3], [g2]]   loads [4, 3, 2]
  (g3: w1 and w2 tie at 2; w1 was chosen earlier, so it wins)
g0 returns                       -> loads [0, 3, 2]
send g4(2), g5(1)                -> g4->w0; w0 and w2 tie at 2, w2 chosen longer ago -> g5->w2
first-index tie-break would send g5 to w0; the test catches that

Must fix

  1. The PR description's "Summary (human-written)" section is still the template placeholder. The author has to write it (CONTRIBUTING.md, "AI-assisted contributions").
Details
  • Reuse: _RolloutWorkerLoad follows the same pattern as _DPRankHandle and _GeneratorHandle (a kw_only, slots dataclass whose reserved_load: int = 0 field overrides the abstract property). LeastLoadedRoutingStrategy keys its recency map on id(candidate). That works here because the candidates are built once in setup_async and live as long as the Rollouter, which the updated comment in strategies.py:102 states.
  • Ordering holds at HEAD. Nothing is awaited between choose and reserved_load += group_size, so concurrent run_group_rollouts calls (the validation gather and _rollout_loop) can't both pick a stale minimum. The done callback is scheduled with call_soon, so it runs after the increment, also when call_one returns a future that is already done. The increment comes after call_one, so a send that fails to pickle leaves the count unchanged, and the new test guards that.
  • Cancel paths: close() cancels pending calls after the drain timeout. Cancelling still fires the done callback, so the counts return to 0. The cancelled-caller test checks 2 -> 0.
  • metrics(): max(loads) would raise on an empty list, but num_rollout_workers is a ceil of a positive value, and _trainer_loop runs after setup_async. test_verifiers.py:291 builds the rollouter with object.__new__ and skips __init__, so it has no _worker_strategy. That is safe because the test only calls setup_async/close and never run_group_rollouts.
  • Gauges: they are snapshots taken once per training step, not peaks or time averages. That is enough for the stated purpose (deciding whether per-rollout counting is worth it) over many steps, but one step's value can be noisy.

Not verified: the simulation numbers in the description. This touches only RL rollout code, but a maintainer still needs to review.

@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from f4e05c0 to a46408c Compare November 17, 2026 00:09
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review. Since your last review: metrics() returns [] when no workers were spawned (a Rollouter subclass may override setup_async), names and TODOs rewritten. The human-written Summary is still empty on purpose.

@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 8s —— View job


Approve -- please address the item before merging (no new problems at a46408c; the human-written summary is still empty) -- review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the item below before merging. The changes since f4e05c0 (the empty-workers guard in metrics(), plus rewritten names and TODOs) add no correctness problems. The only open item is still the empty human-written summary.

Re-review of a46408c

  • Changed: metrics() returns [] when _worker_loads is empty (torchtitan/rl/rollout/rollouter.py:358). The test checks this before setup_async.
  • Changed: both TODOs at the pick (rollouter.py:300-310) are rewritten. Each now gives an example, its blocker or cost, and a link to #6118 (open; it rewrites the Verifiers worker). Their numbers (1.9x -> 1.4x) match the description.
  • Unchanged and still correct: the least-loaded pick through LeastLoadedRoutingStrategy, the increment after call_one, the decrement in the done callback, and the three tests.
  • Still open: the "Summary (human-written)" section. The author says it is empty on purpose, but it still has to be filled in before merge.

Must fix

  1. The PR description's "Summary (human-written)" section is still the template placeholder. The author has to write it (CONTRIBUTING.md, "AI-assisted contributions").

Should consider

  • torchtitan/rl/rollout/rollouter.py:357 -- no in-repo caller reaches the empty-workers guard (see the inline comment).
Details
  • VerifiersRollouter is the only Rollouter subclass, and its setup_async calls super().setup_async(...) (torchtitan/rl/examples/verifiers/rollouter.py:172). So _worker_loads is never empty when _trainer_loop (controller.py:1495) calls metrics().
  • test_verifiers.py:291 builds a VerifiersRollouter with object.__new__, which skips __init__, so _worker_loads and _strategy are never set. The test only calls setup_async and close, and both work without those fields. If a future test there calls metrics() or run_group_rollouts, it will hit an AttributeError.
  • The earlier ordering analysis still holds. Nothing is awaited between choose and reserved_load += group_size. The done callback runs on a later loop step, so the decrement always follows the increment. A send that fails to pickle never leaks a count.

Not verified: the simulation numbers in the description. This touches only RL rollout code, but a maintainer still needs to review.

Comment on lines +357 to +359
# A Rollouter subclass that overrides `setup_async` may spawn no workers.
if not self._worker_loads:
return []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in the repo reaches this branch. The only subclass, VerifiersRollouter.setup_async (torchtitan/rl/examples/verifiers/rollouter.py:172), calls super().setup_async, so it always spawns workers. num_rollout_workers is a ceil of a positive value, and _trainer_loop runs only after setup_async succeeds. The only consumer is the new assert rollouter.metrics() == [] in the test. Per design.md ("every new symbol/branch needs a current consumer"), consider dropping the guard and that assert. A future subclass that spawns no workers would then fail loudly at max([]), and it would fail on choose([]) in run_group_rollouts anyway. This is small, so keeping it is also fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: keeping it. The class docstring (rollouter.py:99-101, from main) tells a subclass that runs its own orchestration to override run_group_rollouts and also setup_async, so no pool spawns. That subclass never reaches choose([]), but the controller still calls metrics() at every step log, and max([]) would crash it there.

@felipemello1
felipemello1 removed this pull request from stack #6115 November 17, 2026 00:20
@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from 4dd856a to b1e99fc Compare November 18, 2026 17:28
@felipemello1
felipemello1 removed this pull request from stack #6185 November 18, 2026 20:42
@felipemello1
felipemello1 added this pull request to stack #6190 November 18, 2026 20:43
@felipemello1
felipemello1 removed this pull request from stack #6190 November 19, 2026 01:49
@felipemello1
felipemello1 added this pull request to stack #6205 November 19, 2026 01:49
@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from b1e99fc to 1bfa4eb Compare November 20, 2026 05:47
@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from 1bfa4eb to fdbc666 Compare November 22, 2026 09:03
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review

@claude

claude Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 54s —— View job


Approve -- please address the item before merging (no new problems at fdbc666; the human-written summary is still empty) -- review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the item below before merging. At fdbc666 the patch's logic is the same as at e287806, and I found no new problems. The only open item is still the empty human-written summary.

Re-review of fdbc666 (since e287806)

  • Unchanged:
    • the pick through LeastLoadedRoutingStrategy (torchtitan/rl/rollout/rollouter.py:400)
    • the increment right after call_one (:413), then the decrement in the done callback (:433)
    • the empty-workers guard in metrics(), and both TODOs
    • the README paragraph, which still names the TODO "retire a worker whose groups keep failing" with the exact wording used in the code
    • the docstring updates in routing/strategies.py and routing/types.py, and the three tests
  • Callsites: torchtitan/rl/examples/verifiers/rollouter.py defines the Verifiers rollout worker, not a Rollouter subclass. It never touches _worker_loads. The only bare-constructed Rollouter that reaches run_group_rollouts/metrics() is _rollouter_without_datasets in test_rollouter_pool.py, and it sets both new fields.
  • Still open: the "Summary (human-written)" section.

Example. 3 workers, all idle:

send g0(4), g1(2), g2(2), g3(1) -> [[g0], [g1, g3], [g2]]   loads [4, 3, 2]
  (g3: w1 and w2 tie at 2; w1 was chosen longer ago)
g0 returns                      -> loads [0, 3, 2]; the next group goes to w0

Must fix

  1. The "Summary (human-written)" section of the PR description is still the template placeholder. The author has to write it (CONTRIBUTING.md, "AI-assisted contributions").

Not verified: the simulation numbers in the description. I also couldn't fetch e287806 in this shallow checkout, so "unchanged" means I compared HEAD against the earlier reviews' descriptions of the patch, not against an actual diff of the two commits. This touches only RL rollout code, but a maintainer still needs to review.

@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from fdbc666 to 5936533 Compare November 22, 2026 12:45
@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch 7 times, most recently from 40d13b7 to 4e43438 Compare November 23, 2026 20:12
@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch 2 times, most recently from 24e9435 to c64fc36 Compare November 24, 2026 02:29
…n flight

The Rollouter keeps one _RolloutWorkerLoad (a RoutingCandidate) per worker and picks with
LeastLoadedRoutingStrategy: the lowest count of rollouts in flight, the one chosen longest ago on a
tie. The count rises by the group size once the call is sent and drops when the call ends.
Rollouter.metrics() adds rollout_worker/num_rollouts_in_flight_max and _mean to each step's metrics.

The RL README's "Rollout workers on more than one host" says why a host whose groups fail at once
gets most new groups.
@felipemello1
felipemello1 force-pushed the felipemello1/distribute/3-least-loaded branch from c64fc36 to 388e05b Compare November 24, 2026 02:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant