Repository navigation
[rl] Run Verifiers groups in rollout workers - #5511
Conversation
ee23f54 to
740beed
Compare
740beed to
c81435b
Compare
|
A general comment: A theme in this stack is on how to manage the the serialization cost. We should look into the lazy deserialization pattern, so we can bundle passthrough fields into a lazy object, and only deserialize them when we have to. Monarch already has zero-copy optimization on pickling bytes, and potentially could do more. So this is a area we could make it quite optimal. |
c81435b to
bb79416
Compare
|
reply from claude: agreed, worth a follow-up. The token payload is already cheap here: the |
bb79416 to
67abd3e
Compare
67abd3e to
e77d87d
Compare
5669e3b to
4bfb9e3
Compare
|
Reply from claude: @claude review. This PR was rewritten: Verifiers groups now run in rollout workers without the HTTP generation PRs, so the code and the body changed. |
|
Claude finished @felipemello1's task in 3m 40s —— View job Approve -- please address the items before merging (empty human-written summary; a fixed |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. Verifiers groups now go through the stock worker pool, which removes the controller-side generation server, the env client and the special cases in Rollouter. The two remaining items are small, local edits. A maintainer still needs to review, because the PR touches torchtitan/rl/rollout/rollouter.py.
What this PR does. It splits VerifiersRollouter in two. VerifiersRolloutWorker(RolloutWorker) runs in each pool process and owns:
- the env client
- a loopback
GenerationServer - the trace decode, scoring and advantages
VerifiersRollouter now only starts the env server, spawns the workers with the env server's address, and stops the env server before the workers drain. Groups go through Rollouter.run_group_rollouts, so cancel_group and the shutdown drain apply to them. In the recipes, rubric, generation_server and connection_timeout_sec move under worker=VerifiersRolloutWorker.Config(...).
Example.
before: controller: VerifiersRollouter.run_group_rollouts
-> env client -> env server -> HTTP -> controller GenerationServer -> router
after: controller: Rollouter.run_group_rollouts -> run_group.choose(...) on worker k
worker k: env client -> env server -> HTTP 127.0.0.1:<port_k> -> worker k GenerationServer
-> tracked generate_fn -> router; worker k returns a scored RolloutGroup
close: env server stopped -> Rollouter.close drains run_group and generate calls -> workers stopped
Must fix
- The "Summary (human-written)" section is empty. The author needs to fill it in; agents leave the placeholder.
torchtitan/rl/examples/verifiers/rollouter.py:494: every worker binds its ownGenerationServerfrom one config. A non-zerogeneration_server.portwithworker_pool_size > 1(now 4 by default) fails at setup with EADDRINUSE. Either delete the unusedportfield, or raise in__post_init__(see the inline comment).
Should consider
torchtitan/rl/rollout/rollouter.py:170: the newworker_configparameter on the sharedsetup_asynchas a single consumer. The subclass can build the replaced config before it callssuper(), which keeps the core diff at zero (see the inline comment).assets/images/rl_verifiers_integration_architecture.svg: the box is renamed toVerifiersRolloutWorker, but its "start" arrow to the EnvServer stays. The controller-sideVerifiersRollouterstarts the env server now, and the diagram has no controller box for it.
Questions
- The description says
cancel_group"stops Verifiers groups too". CancellingVerifiersEnvClient.runstops the worker-side task. Does it also stop the episode in the env server? If not, a cancelled episode keeps making model calls to that worker'sGenerationServer. Those calls go through whatevergenerate_fnwas set last (the TODO at L196 covers the metrics prefix). They also leave entries ingeneration_metadatathat nothing pops. The base branch behaves the same way, but the claim should say which of these happens. - With W workers, the env server now receives W
TrainClientConfigs that differ only inbase_url. Does Verifiers key its renderer pool by client config? If so, the env server builds W times as many renderers, each with its own tokenizer, as before.
Not verified: the questions above, because I couldn't inspect the Verifiers package source here. I also couldn't confirm that the env server's renderer and process pool behave the same under four clients as under one.
|
|
||
| def __post_init__(self) -> None: | ||
| Rollouter.Config.__post_init__(self) | ||
| if self.worker.env_server_address is not None: |
There was a problem hiding this comment.
Every rollout worker now builds its own GenerationServer from the same worker.generation_server config. So a non-zero GenerationServer.Config.port with worker_pool_size > 1 (now 4 by default) makes the second worker fail TCPSite bind with EADDRINUSE during setup_async, after the env server and the worker processes are already up. Before this PR, a fixed port worked because the controller ran a single server.
No in-repo caller sets port. The smallest fix is to delete port from GenerationServer.Config and always bind port 0, since each worker needs its own ephemeral port anyway. If you'd rather keep the field, reject the combination here:
if self.worker.generation_server.port != 0 and self.worker_pool_size > 1:
raise ValueError(
"worker.generation_server.port must be 0 when worker_pool_size > 1: "
"each rollout worker binds its own generation server"
)| tokenizer_config: HuggingFaceTokenizer.Config, | ||
| renderer_config: RendererConfig, | ||
| hf_assets_path: str, | ||
| worker_config: RolloutWorker.Config | None = None, |
There was a problem hiding this comment.
(should consider) This adds a parameter to the shared Rollouter.setup_async that only VerifiersRollouter passes. Principle 4 asks us not to add hooks to shared code for one consumer, and the class docstring's "Customization" section doesn't mention the new parameter. The subclass can do the same thing without any core change, by building the replaced config before it calls super():
# VerifiersRollouter.setup_async
env_server_address = await self._verifiers_env_server.start()
self._config = replace(
self._config,
worker=replace(self._config.worker, env_server_address=env_server_address),
)
await super().setup_async(actor_system=..., tokenizer_config=..., renderer_config=..., hf_assets_path=...)This builds a new config and doesn't mutate the original. It does rebind a base attribute, which is the trade-off the PR description mentions. Since the core diff then drops to zero, a maintainer should decide which version they prefer.
|
Reply from claude:
|
|
Reply from claude: An update on "against main": the refactor PR and this one now sit on a draft copy of your look-aside router PR, rebased onto main ("[DO NOT REVIEW] Look-aside generator routing"), so the whole stack runs on look-aside. They depend on nothing else in the stack. When your PR lands, the stack rebases onto main and the copy closes; nothing in this stack should merge before that. |
|
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 36s —— View job Approve -- please address the item before merging (the human-written summary is still empty; the docs and SVG match the look-aside path at d9bb1eb): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. The docs, the SVG and the class docstring now draw the look-aside path that is in the base: the worker reserves a generator from the router, then calls that generator. I found no new code problems at d9bb1eb. A maintainer still needs to review, because the PR touches torchtitan/rl/rollout/rollouter.py. Per the body, nothing in the stack should merge while the row-0 copy is under it.
What this PR does. VerifiersRolloutWorker(BaseRolloutWorker) runs one Verifiers group per run_group call inside a rollout worker process. Each worker has its own env client, its own loopback GenerationServer on port 0, and does the trace decode and scoring itself. VerifiersRollouter starts the env server, spawns the workers with Rollouter.setup_async(worker_config=replace(worker, env_server_address=addr)), and on close stops the workers first and the env server last.
Example. One model call at this head, checked against the code:
agent -> env server -> HTTP 127.0.0.1:<port_k> -> worker k GenerationServer._handle_generate_request
-> generate_fn (Controller._make_generate_fn, shipped to worker k)
generator = router.reserve(request_id, routing_session_id) # Monarch, worker k -> router
generator.generate(prompt, ...) # Monarch, worker k -> generator
router.release_reservation(request_id)
-> Completion back to the agent
SVG: router box "InterGeneratorRouter.reserve", label "reserve / generator handle";
the blue request/Completion path now runs from GenerateFn to the Generator actors.
Must fix
- The "Summary (human-written)" section is empty. The author needs to fill it in; agents leave the placeholder.
Should consider
torchtitan/rl/examples/verifiers/rollouter.py:217-- the look-aside TODO says "when look-aside routing lands, re-check", butgenerate_fnalready calls the reserved generator directly at this head (inline comment).
Still open from earlier reviews
rollout/rollouter.py:173-175:setup_async(worker_config=...)is a temporary core parameter with one consumer. Its TODO says PR 7 removes it. A maintainer should confirm they accept it.
Details
generation_server.py:209-212TODO(monarch): this is consistent with look-aside. The generator's answer now returns to the calling worker actor, not to the router. So a worker that has stopped is the one the late answer fails on.- The controller's TODO at
controller/controller.py:676-678("nothing cancels a generate call") still holds with this PR. When Verifiers gives up on a call, the handler isn't cancelled, so the reservation stays until the generator answers. The PR body says the same. VerifiersRolloutWorker's docstring diagram (generate_fn --> a generator (the router picks it)), the Terminal-Bench README step 4, and the Verifiers README step 4 all match_make_generate_fn.
Not verified: the GPU path at this head. The body's GPU run is from an older head.
| # TODO: when look-aside routing lands (https://github.com/pytorch/torchtitan/pull/5990), | ||
| # re-check this bridge: `generate_fn` then calls the reserved generator directly, so the | ||
| # bridge is one loopback hop. Dropping it needs an HTTP endpoint on each generator, a | ||
| # reserve per model call from Verifiers' client, and another home for the policy versions | ||
| # recorded here. |
There was a problem hiding this comment.
(should consider) This TODO is conditional on something that is already true at this head. The stack now sits on look-aside routing, and Controller._make_generate_fn (controller/controller.py:679-689) already reserves a generator and calls it directly. So the "re-check" can happen now, and once PR 5990 lands on main and the stack rebases, nothing will prompt anyone to come back to "when ... lands". You could state the current state and keep only the open part:
| # TODO: when look-aside routing lands (https://github.com/pytorch/torchtitan/pull/5990), | |
| # re-check this bridge: `generate_fn` then calls the reserved generator directly, so the | |
| # bridge is one loopback hop. Dropping it needs an HTTP endpoint on each generator, a | |
| # reserve per model call from Verifiers' client, and another home for the policy versions | |
| # recorded here. | |
| # TODO: drop this loopback bridge. `generate_fn` already calls the reserved generator | |
| # directly (look-aside routing); dropping the bridge needs an HTTP endpoint on each | |
| # generator, a reserve per model call from Verifiers' client, and another home for the | |
| # policy versions recorded here. |
There was a problem hiding this comment.
Reply from claude: Applied as suggested in 029993d.
|
Reply from claude: @claude please review. This push applies your TODO wording at |
|
Claude finished @felipemello1's task in 43s —— View job Approve -- please address the item before merging (the human-written summary is still empty; the look-aside TODO at 029993d is now accurate): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. At 029993d, the look-aside TODO now describes how the code works today, and this push changes nothing else. A maintainer still needs to review, because the PR touches torchtitan/rl/rollout/rollouter.py. The body says nothing in the stack should merge while the row-0 copy sits under it.
What this PR does. Each Verifiers group now runs inside a rollout worker process, in VerifiersRolloutWorker(BaseRolloutWorker). Each worker has its own env client and its own loopback GenerationServer on port 0, and it decodes and scores its traces itself. VerifiersRollouter starts the env server, then spawns the workers with the server's address through Rollouter.setup_async(worker_config=...). On close it stops the workers first and the env server last.
Example. The TODO at examples/verifiers/rollouter.py:217-220, before and after this push:
before: "when look-aside routing lands (#5990), re-check this bridge: generate_fn then calls the
reserved generator directly ..." -> conditional on something already true at this head
after: "drop this loopback bridge. generate_fn already calls the reserved generator directly
(look-aside routing); dropping the bridge needs an HTTP endpoint on each generator, a
reserve per model call from Verifiers' client, and another home for the policy versions"
This matches the earlier suggestion word for word. It also matches Controller._make_generate_fn, which does reserve, then generator.generate, then release.
Must fix
- The "Summary (human-written)" section is empty. The author needs to fill it in; agents leave the placeholder.
Still open from earlier reviews
rollout/rollouter.py:173-175:setup_async(worker_config=...)is a temporary core parameter with one consumer. Its TODO says PR 7 removes it. A maintainer should confirm they accept it.
Not verified: the GPU path at this head. The GPU run in the body is from an older head.
|
Reply from claude: @claude please review. The bottom PR renamed the stock |
|
Claude finished @felipemello1's task in 40s —— View job Approve -- please address the item before merging (the human-written summary is still empty; the |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. At ddd4639 this PR picks up the bottom PR's rename of RolloutWorker to MessageEnvRolloutWorker, and I found no new problems. A maintainer still needs to review, because the PR touches torchtitan/rl/rollout/rollouter.py.
What this PR does. Each Verifiers group runs in a rollout worker process, in VerifiersRolloutWorker(BaseRolloutWorker). Each worker has its own env client and its own loopback GenerationServer on port 0, and it decodes and scores its own traces. VerifiersRollouter starts the env server, then spawns the workers through Rollouter.setup_async(worker_config=replace(worker, env_server_address=addr)). On close, it stops the workers first and the env server last.
Example. How the rename lands at this head:
base (6a): class MessageEnvRolloutWorker(BaseRolloutWorker) # stock worker, no alias
this PR: examples/verifiers/rollouter.py imports BaseRolloutWorker, Rollouter
(was MessageEnvRolloutWorker, used only by the deleted `worker: ... | None = None` field)
torchtitan/rl/README.md: "Subclass `MessageEnvRolloutWorker` or `Rollouter` ...;
a worker whose env isn't a `MessageEnv` subclasses `BaseRolloutWorker`"
repo-wide: no bare `RolloutWorker` identifier is left in any .py, .md or .svg
(the remaining matches are VerifiersRolloutWorker, BaseRolloutWorker, RolloutWorkerActor)
Must fix
- The "Summary (human-written)" section is empty. The author needs to fill it in; agents leave the placeholder.
Still open from earlier reviews
rollout/rollouter.py:173-175:setup_async(worker_config=...)is a temporary core parameter with one consumer. Its TODO says PR 7 removes it. A maintainer should confirm they accept it.
Not verified: the GPU path at this head. The GPU run in the body is from an older head.
|
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 34s —— View job Approve -- please address the item before merging (the human-written summary is still empty; the reordered stack and the doc rewrite at 26c5466 match the code): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. At 26c5466, after the reorder and the three passes, the code matches the last reviewed behavior, the rewritten docs match the code, and I found no new problems. A maintainer still needs to review, because the PR touches torchtitan/rl/rollout/rollouter.py. The body says nothing in the stack merges while the row-0 look-aside copy is under it.
What this PR does. Each Verifiers group runs in a rollout worker process, in VerifiersRolloutWorker(BaseRolloutWorker). Each worker has:
- its own env client
- its own loopback
GenerationServeron port 0 - the trace decode, scoring and advantages
VerifiersRollouter starts the env server, then spawns the workers through Rollouter.setup_async(worker_config=replace(worker, env_server_address=addr)). On close, it stops the workers first and the env server last. A rollout that raises still fails its whole group, as on the base branch.
Example. The recipe change, and one model call at this head:
recipe: VerifiersRollouter.Config(..., rubric=R, generation_server=G, connection_timeout_sec=T)
-> VerifiersRollouter.Config(..., worker=VerifiersRolloutWorker.Config(rubric=R, generation_server=G,
connection_timeout_sec=T))
call: agent -> env server -> HTTP 127.0.0.1:<port_k> -> worker k GenerationServer
-> generate_fn (Controller._make_generate_fn): router.reserve -> generator.generate -> release
close: Rollouter.close (wait up to _RUN_GROUP_DRAIN_TIMEOUT_S, stop_rollout_workers) -> finally env server closed
Must fix
- The "Summary (human-written)" section is empty. The author needs to fill it in; agents leave the placeholder.
Still open from earlier reviews
rollout/rollouter.py:170-172:setup_async(worker_config=...)is a temporary core parameter with one consumer. Its TODO says it goes once the Verifiers env runs in the worker, which is PR 5 in the new order. A maintainer should confirm they accept it.
Details
- The docs rewrite checks out against the code. The
VerifiersRollouterdocstring diagram, Verifiers README steps 1-4 and Terminal-Bench README steps 1, 4 and 6 all say the worker sends tasks, serves model calls throughrouter.reserveand thengenerate, and returns finished groups._ENV_SERVER_WORKERS = 16(verifiers_terminal_bench.py:84) matches "16 for TB" and "The Terminal-Bench recipe runs 16". The pool knob the README names,verifiers_env_server.serve.pool, is what both recipes set. - The SVG is deleted, and nothing in the repo still references
rl_verifiers_integration_architecture. No other file buildsVerifiersRollouter.Configwith the old top-levelrubric/generation_server/connection_timeout_secfields. The two recipes and three test files are the only callers, and all of them are updated. - Added lines are ASCII only.
test_setup_spawns_workers_with_the_env_server_address_and_close_stops_the_workers_firstguards the start -> spawn -> stop workers -> close env server order. Nothing else checks that order.
Not verified: the GPU path at this head. The body's GPU run is from an older head.
| or `DockerConfig`. With a pool, its pool workers run them. The Terminal-Bench recipe runs 16. | ||
| The server and each of its pool workers first run [`worker_setup.py`](./worker_setup.py). Every | ||
| worker imports that module, so it must not import torch. | ||
| 3. `rollouter.py` runs each group in a rollout worker process (`VerifiersRolloutWorker`), like |
There was a problem hiding this comment.
nit: missing a link on rollouter.py
It's just not consistent -- removing all the links is fine, too
There was a problem hiding this comment.
Reply from claude: Fixed in 4907466: linked it.
There was a problem hiding this comment.
Reply from claude: The new README links every file it names.
| | | | ||
| | 4. generate | 7. batch | ||
| +-------|-------- controller process (torchtitan.rl.train) ---|----------+ | ||
| | GenerationServer dataset -> VerifiersRollouter -> batcher | | ||
| | (localhost HTTP) | ^ | | ||
| +-------^---------------------------------|------|-----------------------+ | ||
| | 4. token ids 1. task | | 6. trace, reward | ||
| +-------|---------------------------------v------|-----------------------+ | ||
| | +-- controller process (torchtitan.rl.train) ---|----------+ | ||
| | | dataset -> VerifiersRollouter -> batcher | | ||
| | +---------------|-----------------^------------------------+ | ||
| | | | | ||
| | group v | finished group | ||
| +-------|------- rollout worker processes (VerifiersRolloutWorker) ------+ | ||
| | GenerationServer send tasks, convert traces, score the group | | ||
| | (localhost HTTP) | ^ | | ||
| +-------^-------------------------------|------|-------------------------+ | ||
| | | | | ||
| | 4. token ids 1. task | | 6. trace, reward | ||
| +-------|-------------------------------v------|-------------------------+ | ||
| | Verifiers env server (spawned process) | | ||
| | per rollout: interception server (chat messages <-> token ids) | | ||
| | and a Docker runtime | | ||
| +-------^---------------------------------|------------------------------+ | ||
| | | |
There was a problem hiding this comment.
It's a bit hard to read. I wonder if we could do either of
- use more width
- switch to real picture
There was a problem hiding this comment.
Reply from claude: Fixed in 4907466: redrew it as a sequence diagram, your "use more width" option. Each column is one kind of process, or the containers, and each row is one of the numbered steps below it (96 columns). PR 5 redraws it the same way for the env in the rollout worker. If you'd still rather have a rendered picture, I can make it a mermaid sequenceDiagram.
There was a problem hiding this comment.
Reply from claude: Redrawn once more, in the Verifiers README: one column per process, numbered steps, a blank row between steps. It's the only diagram now.
|
|
||
| def __init__(self, config: Config) -> None: | ||
| super().__init__(config) | ||
| self._verifiers_config = config |
There was a problem hiding this comment.
VerifiersRollouter's config is called _verifiers_config
There was a problem hiding this comment.
Reply from claude: Fixed in 4907466: deleted. With the address as a constructor arg, nothing reads it.
There was a problem hiding this comment.
Reply from claude: Still self._config in this PR.
Edited after the restack: the first version described a later PR's code.
|
|
||
| def __init__(self, config: Config) -> None: | ||
| super().__init__(config) | ||
| self._verifiers_config = config |
There was a problem hiding this comment.
and VerifiersRolloutWorker's config is again called _verifiers_config
There was a problem hiding this comment.
Reply from claude: Fixed in 4907466: renamed to self._config. BaseRolloutWorker stores no config, so it shadows nothing.
There was a problem hiding this comment.
Reply from claude: Still self._config.
| worker_config=replace( | ||
| self._verifiers_config.worker, env_server_address=env_server_address | ||
| ), |
There was a problem hiding this comment.
nah this is not right -- I think you want to make env_server_address an arg to the constructor of verifiers rollout worker, rather than a field in the config
There was a problem hiding this comment.
Reply from claude: Fixed in 4907466: VerifiersRolloutWorker(config, *, env_server_address). The worker is built in its own process, so the address goes down the spawn path (Rollouter.setup_async(worker_kwargs=...) -> spawn_rollout_workers(**kwargs) -> RolloutWorkerActor -> build(**kwargs)), as the trainer's and batcher's constructor args do. It replaces setup_async(worker_config=...) and touches 4 core files (+22/-4). PR 5 (Verifiers 0.4.1, bd22d90) deletes all of it with the env server.
There was a problem hiding this comment.
Reply from claude: It stays a constructor argument here, as you asked: VerifiersRolloutWorker(config, *, env_server_address), passed through Rollouter.setup_async(worker_kwargs=...). A TODO in rollout/rollouter.py names its removal. "Verifiers: each rollout worker runs its Verifiers envs; the env server is gone" deletes the env server, this argument and worker_kwargs from the 4 core files.
Edited after the restack: the first version described a later PR's code.
|
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. This push also answers the 5 review threads: |
|
Claude finished @felipemello1's task in 1m 42s —— View job Approve -- please address the item before merging (the human-written summary is still empty; all 5 of @tianyu-l's threads are addressed at 4907466, and he still needs to re-review): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. At 4907466, all 5 of @tianyu-l's threads are addressed in code, and the new worker_kwargs path through core is correct. I found no new problems. @tianyu-l's review still says changes requested, so he needs to re-review, and a maintainer has to sign off on the 4 core files anyway.
What this PR does. Each Verifiers group now runs in a rollout worker process, in VerifiersRolloutWorker(BaseRolloutWorker). Each worker has its own env client and its own loopback GenerationServer on port 0, and it decodes and scores its own traces. VerifiersRollouter starts the env server, then spawns the workers, giving each one the server's address as a constructor argument. On close it stops the workers first and the env server last.
Example. How the env server address reaches each worker at this head:
VerifiersRollouter.setup_async
addr = await env_server.start()
Rollouter.setup_async(..., worker_kwargs={"env_server_address": addr})
-> actor_system.spawn_rollout_workers(worker_config, num_workers=W, num_threads=T, env_server_address=addr)
-> MonarchActorSystem: RolloutWorkerActor(worker_config=..., worker_kwargs={"env_server_address": addr}, ...)
-> worker_config.build(env_server_address=addr) # Configurable.build checks for overlap with config fields
-> VerifiersRolloutWorker(config, *, env_server_address=addr)
native recipes: worker_kwargs=None -> {} -> build() -> MessageEnvRolloutWorker(config) (unchanged)
Must fix
- The "Summary (human-written)" section is empty. The author needs to fill it in; agents leave the placeholder.
Maintainer threads, at HEAD
examples/verifiers/README.md: the missingrollouter.pylink is added.terminal_bench/README.md: the diagram is redrawn as lanes, 96 columns wide (the "more width" option). @tianyu-l should confirm it reads better now.VerifiersRollouter._verifiers_config: deleted.__init__readsconfigdirectly, and the baseself._configcovers the rest.VerifiersRolloutWorker._verifiers_config: renamed toself._config.BaseRolloutWorkerstores no config, so this shadows nothing.env_server_addressas a constructor arg: done. The config field and its "leave unset" docstring are gone, andrg env_server_addressfinds no stale references.
Should consider
rollout/rollouter.py:87-96: theCustomizationdocstring doesn't mentionworker_kwargs. The comment on the parameter (L170-172) is its only documentation. That is fine for a temporary path; this is a nit.
Details
- Core diff (+22/-4):
Rollouter.setup_async(worker_kwargs=...),ActorSystem.spawn_rollout_workers(**kwargs),MonarchActorSystemandRolloutWorkerActor(worker_kwargs=...). The Monarch system is the onlyActorSystemimplementation, so no other subclass needs the new**kwargs.spawn_rollout_workers(**kwargs)matches the existingspawn_batcher(config, **kwargs)pattern. The TODO atrollouter.py:171-172names every piece to delete once the env runs in the worker. Configurable.Config.build(**kwargs)(config/configurable.py:144-169) raises when a kwarg overlaps a config field. That guards the field -> arg move.test_setup_spawns_workers_with_the_env_server_address_and_close_stops_the_workers_firstnow asserts the address arrives as a spawn kwarg. It still guards the start -> spawn -> stop workers -> close env server order. Thetest_rollouter_pool.pyedits only addworker_kwargs={}.- The Terminal-Bench lanes match the code. Row 4 draws the worker calling the generators directly (look-aside), and row 6 draws the scored group going from the worker to the controller.
Not verified: I couldn't run the unit tests here, and the GPU path wasn't re-run at this head (the body's GPU run is from an older head).
| controller rollout worker env server container generators trainer | ||
| (CPU) (CPU, xN) (Verifiers) (per rollout) (GPU) (GPU) | ||
| | | | | | | | ||
| 1 |--group---------->|--task--------->| | | | | ||
| 2 | | |--start-------->| | | | ||
| 3 | | |<-chat request--| | | | ||
| 4 | |<-token ids-----| | | | | ||
| | |--generate--------------------------------------->| | | ||
| 5 | | |--run test.sh-->| | | | ||
| 6 |<-scored group----|<-trace, reward-| | | | | ||
| 7 |--batch, packed by the batcher process-------------------------------------------->| | ||
| | | | | |<-new weights| |
There was a problem hiding this comment.
it seems that this is explaining the integration with verifiers, and would be true for most of verifiers integration. It should probably be in the verifiers readme, and here we should point there. Other than that, it looks good.
There was a problem hiding this comment.
Reply from claude: Moved. The integration is explained once, in the Verifiers README ("Integration flow"). The Terminal-Bench README keeps its agent and its grading and links there.
Edited after the restack: the first version described a later PR's code.
| 2. **Agent.** One of the env server's pool workers (`verifiers_env_server.serve.pool`) | ||
| starts a container from the task's `docker_image` and runs Terminus-2 in it | ||
| ([`harness.py`](./harness.py)). The agent types commands into a tmux shell and reads | ||
| the screen back. |
There was a problem hiding this comment.
can we make it clear that the docker part is just a place holder for people to use their sandbox provider of choice, and maybe point to the doc in verifiers readme on how to replace it? (we have some internal example with sandoq. We might have some documentation on daytona as well). I am ok with these readme changes go in a new PR, or are adressed in future prs, e.g. on the pr updating distributed rolloutworkers or the verifiers 4.1. I would rather review this only once. It could be at the end of the stack as well.
There was a problem hiding this comment.
Reply from claude: Done once, near the end of the stack: "Verifiers README: terms, concurrency and sandboxes" adds the "Sandboxes" section. It says Docker is a placeholder, and that a remote sandbox provider plugs in as a Verifiers custom runtime (new in Verifiers 0.4.1). It also covers the model path back, retries, run-wide limits and cleanup. No later PR edits that section.
Edited after the restack: the first version described a later PR's code.
| rollout worker. | ||
| 2. [`env_server.py`](./env_server.py) runs the Verifiers env server as a local process on the | ||
| controller host. The server runs the agents in the configured runtime, e.g. `SubprocessConfig` | ||
| or `DockerConfig`. With a pool, its pool workers run them. The Terminal-Bench recipe runs 16. |
There was a problem hiding this comment.
we shouldn't mention terminal bench here. This is about verifiers, not other examples. Let terminal bench worry about terminal bench. Also, this is config specific. You cannot just say that it runs 16.
There was a problem hiding this comment.
Reply from claude: Fixed: the Verifiers README names no config value that differs between the examples. It still links the two examples as places to start: in its intro and at the end of "Add an experiment", which also copies the DAPO recipe. "Verifiers README: terms, concurrency and sandboxes" adds an env table and the "Concurrency" rules later, with formulas and Verifiers' defaults.
Edited after the restack: the first version described a later PR's code.
| controller host. The server runs the agents in the configured runtime, e.g. `SubprocessConfig` | ||
| or `DockerConfig`. With a pool, its pool workers run them. The Terminal-Bench recipe runs 16. | ||
| The server and each of its pool workers first run [`worker_setup.py`](./worker_setup.py). Every | ||
| worker imports that module, so it must not import torch. |
There was a problem hiding this comment.
" so it must not import torch." you should clarify what you mean by that, i.e. importing torch takes a lot of memory. You cannot expect people to just understand why. Make the reason explicit.
There was a problem hiding this comment.
Reply from claude: The README now says why: "importing torch costs each process about 0.5 GB of memory (peak RSS after import torch)". Measured: 522 MB on torch 2.16 nightly. The rule applies to the env server and its pool workers. "Verifiers: each example is an installed package; its name is the taskset id" deletes worker_setup.py, and the rule goes with it.
Edited after the restack: the first version described a later PR's code.
| HTTP, from the env server). For each call it gets a generator from `router.reserve`, then calls | ||
| `generate` on it. Each rollout worker runs its own, on localhost. The server also records what |
There was a problem hiding this comment.
"then calls generate on it" in your diagram in terminal bench, you say that the rollout worker calls generate. Is it the worker or generation server? is there a contradiction?
There was a problem hiding this comment.
Reply from claude: There was a contradiction. Now there is one diagram: the worker's GenerationServer calls generate_fn (step 6), and nothing else does.
| 4. `rollouter.py` sends samples to Verifiers and converts the | ||
| returned trace graph into TitanRL `RolloutTurn` objects. TitanRL then applies | ||
| its rubric and advantage estimator normally. | ||
| A diagram of one group: the `VerifiersRollouter` docstring in [`rollouter.py`](./rollouter.py). |
There was a problem hiding this comment.
i dont like that we point there. I think i would rather have it here, and have the .py point to the readme. I also think that the terminal bench is better than the rollouter.py one. Lets try to make a single one that is the best of both worlds. Its fine if we need two.
There was a problem hiding this comment.
Reply from claude: Done. The diagram is in the Verifiers README, and rollouter.py points to it.
| rollout worker k (CPU process, controller host): VerifiersRolloutWorker.run_group | ||
| | env client: 8 x run(task), ZMQ --> Verifiers env server (controller host: | ||
| | 1 process, plus a worker pool if any: 16 for TB) |
There was a problem hiding this comment.
this is confusing. So we have K rollout workers. But for each, we also have 16 worker pool for verifiers env server? So its K * 16?
There was a problem hiding this comment.
Reply from claude: No: the rollout workers share one env server. 4 workers and a pool of 8 add 4 + 1 + 8 processes to the controller, not 4 x 8, as the README says under the diagram. "Verifiers: each rollout worker runs its Verifiers envs; the env server is gone" removes the env server and its pool: then each worker runs its envs itself.
Edited after the restack: the first version described a later PR's code.
| connection_timeout_sec: float = 120.0 | ||
| """Maximum time to wait for the Verifiers server to become healthy.""" | ||
|
|
||
| def __post_init__(self) -> None: |
There was a problem hiding this comment.
please, for this .py file, follow the skill coding style, and add small comments on major blocks of code. e.g.
for
if configured_taskset not in (
VerifiersTasksetConfig(),
self.training_dataloader.dataset.verifiers_taskset,
):
we could add a small 1 liner above it saying "check if taskset is registered in verifiers", or something like this (not verbatim).
There was a problem hiding this comment.
Reply from claude: Done with the code-style skill: block labels in run_group and __post_init__, and the docstrings rewritten. Blocks that aren't obvious have a one-line comment.
Edited after the restack: the first version described a later PR's code.
| renderer_multiplex: int = 256 | ||
| """Maximum concurrent rollouts sharing one Verifiers renderer instance. | ||
|
|
||
| TODO: evaluate sharing this renderer pool with TitanRL's native rollout | ||
| path instead of keeping it specific to the Verifiers client. | ||
| """ |
There was a problem hiding this comment.
can we open a new PR addressing this. Locally we also have another discussion regarding cpu threads. You can search the outcome of that research. Maybe we can have some heuristic in the controller, allow the user to override, but pick decent numbers for this based on buffer size, number of cpus available, etc?
There was a problem hiding this comment.
Reply from claude: That PR is "Rollouter: least-loaded placement; the controller sizes the pool from rollouts_per_worker". The controller computes the worker count from training rollouts in flight and rollouts_per_worker, once, before any process starts.
| await self._generation_server.start() | ||
| self._verifiers_env_client = VerifiersEnvClient(self._env_server_address) | ||
| await self._verifiers_env_client.wait_for_server_startup( | ||
| timeout=self._config.connection_timeout_sec | ||
| ) |
There was a problem hiding this comment.
lets open a PR adding some structured logger to functions here in the rollouter, so we can have a good understanding about timing, etc. We can avoid small functions that are called disproportionally many times compared to others, so it doesnt clog the logs.
There was a problem hiding this comment.
Reply from claude: Done in "Verifiers: time each rollout's sandbox start, setup, agent, model, finalize and scoring". It reports where each rollout's time went, from Verifiers' trace timing: verifiers/{boot,setup,agent,model,finalize,scoring}_time_s, mean and max per step, for every rollout, including those that failed before their first turn. Metrics, not a span per rollout: Verifiers already times each phase on the trace, so a span would repeat those numbers. A trace span times each env start.
|
Reply from claude: answers to the comments on this PR that have no inline thread.
Done; see the reply on the
Agreed, as a follow-up outside this stack. A TODO now marks it at
Done: the split is on main.
Still here, as Edited after the restack: the first version described a later PR's code. |
|
Reply from claude: Reopened as the bottom of the Verifiers stack. Its first commit is the change tianyu-l approved, rebased on main; the second addresses the review comments. "Verifiers: each rollout worker runs its Verifiers envs; the env server is gone" later moves the env into the worker and deletes the env server. Edited after the restack: this comment first said the PR closes. |
Summary (human-written)
Agent details
TLDR: Verifiers groups now run in rollout worker processes, like native groups. Each worker runs its own
GenerationServer, so the controller no longer serves every Verifiers model call or decodes every trace: it receives finished groups only. The rollouts are the same: on CPU, every training field of 16 rollouts matches the in-controller path below this PR (Results). Its base, theBaseRolloutWorkersplit, is on main.Before: the controller runs every Verifiers group.
sequenceDiagram participant C as controller process<br/>VerifiersRollouter, GenerationServer, trace decode participant E as env server<br/>runs the agent loop participant R as router participant G as generators C->>E: 1. task, once per rollout (msgpack, ZMQ) Note over E: chat to token ids E->>C: 2. each model call: token ids (JSON, HTTP) C->>R: 3. reserve a generator (Monarch) C->>G: 4. token ids (pickle, Monarch) G-->>C: reply C-->>E: completion E->>C: 5. trace + reward (msgpack, ZMQ) Note over C: trace to turns, advantagesAfter: rollout workers run them, like native groups. W =
worker_pool_size.sequenceDiagram participant C as controller process<br/>VerifiersRollouter: sends groups only participant W as rollout worker x W<br/>VerifiersRolloutWorker + its own GenerationServer participant E as env server<br/>runs the agent loop participant R as router participant G as generators C->>W: 1. group (pickle, Monarch) W->>E: 2. task, once per rollout (msgpack, ZMQ) Note over E: chat to token ids E->>W: 3. each model call: token ids (JSON, HTTP on loopback) W->>R: 4. reserve a generator (Monarch) W->>G: 5. token ids (pickle, Monarch) G-->>W: reply W-->>E: completion E->>W: 6. trace + reward (msgpack, ZMQ) Note over W: trace to turns, advantages W->>C: 7. finished group (pickle, Monarch)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".
Since the approval (second commit; the first is the approved change, rebased on main)
GenerationServer: a call diagram, one line per error status, an example request and reply, and labels for its 4 blocks.--module torchtitan_recipes.rl.verifiers_my_task).VerifiersTaskSamplefor lazily deserialized task data, a reviewer's follow-up.Problem
worker_pool_sizerollout worker processes, which runs it and returns a scored group.VerifiersRollouter.run_group_rolloutsruns the env client, the trace decode and the conversion to rollout turns in the controller process.GenerationServer(aiohttp) in the controller, which parses each request and sends it to a generator that the router picks.Solution
VerifiersRolloutWorker(BaseRolloutWorker)(the base class on main) runs one group perrun_groupcall: the env client, aGenerationServeron loopback for its agents, the trace decode, scoring and advantages. The env server and the workers both run on the controller host. Each server binds a free port.GenerationServer.Config.portis gone: a fixed port would collide across workers.worker=VerifiersRolloutWorker.Config(rubric=..., generation_server=..., connection_timeout_sec=...). The two recipes change only that. The Verifiers README draws one group, one column per process ("Integration flow"), and the docstrings point to it. The architecture SVG is deleted.VerifiersRollouterstarts the env server, then spawns the workers and passes its address to each worker's constructor:VerifiersRolloutWorker(config, *, env_server_address), throughRollouter.setup_async(worker_kwargs=...).closestops the workers first, then the env server. Why:Rollouter.closewaits for each running group, and a group waits for its runs' results from the env server (untimed in Verifiers 0.4.0). A stopped env server never sends them, so each group would wait out the 30 s drain.Rollouter.run_group_rollouts, like native groups:VerifiersRollouterno longer overrides it.rollout/group_failures). The worker raises only after every sibling finished, as main's rollouter did. The next PR turns it into anERROR_INFRArollout, so its siblings train.Results
The GPU run ran at an older head of this PR (44c5edb, 11-10), with "Cancel a rollout group on its worker"
below it and the env server stopped first. Not re-run at this head.
You may ask:
GenerationServerper worker, not one shared server? A shared server would stay in the controller, which this PR empties. Each worker keeps the policy versions and metrics of the calls it served, so they reach the controller inside the finished group.build(**kwargs)is how a runtime value reaches a constructor. The worker is built in its own process, so the value goes down the spawn path (Rollouter.setup_async(worker_kwargs=...)->spawn_rollout_workers(**kwargs)->RolloutWorkerActor->build(**kwargs)), as the trainer's and batcher's constructor args do. It is temporary: PR 6 runs the env in the rollout worker (still on Verifiers 0.4.0) and removesworker_kwargs,env_server_addressandconnection_timeout_sec.base_url.NOTE:
validate_after_training, the group overlaps that validation. Its model calls fail onceController.closecloses the generators. A rollout that is grading, or in a long tool call, needs no generator, so its group can outlast the 30 s drain.Rollouter.closethen logs "the job may exit 130": a false alarm there, since no generator owes that group an answer. On main the cancel stopped the group in the controller.run_groupreturns without waiting for that answer, and cancelling the worker'sGenerationServerhandler wouldn't stop it. If the answer reaches a worker that already stopped, Monarch fails the generator and the job exits 130 (TODO(monarch) ingeneration_server.py, Monarch issue 5301). Before this PR this path ran in the controller process, which outlives the generators. The handler isn't cancelled, so the call keeps its router reservation until the generator answers.worker_pool_sizedefaults to 4 for Verifiers too (it was a no-op before). At high rollout rates, raise it next to the env server's pool.Open for the maintainer:
worker_kwargspath, theenv_server_addressconstructor arg andconnection_timeout_secare temporary: PR 6 removes them. This PR can land first; they stay until PR 6 lands.worker_kwargspath:rollout/rollouter.py,actors/system.py,actors/monarch/system.py,actors/monarch/rollout_worker.py. TheBaseRolloutWorkersplit is on main.Test plan
pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/components/test_renderer.py tests/unit_tests/cpu/config # Verifiers 0.4.0, on main: 954 passed, 1 skippedtest_setup_spawns_workers_with_the_env_server_address_and_close_stops_the_workers_first.test_a_failing_rollout_fails_its_group_only_after_every_sibling_finished: main's test, now onVerifiersRolloutWorker.test_verifiers_worker_sends_muse_glimmer_renderer_config: the agents'base_urlis the worker's own server.VerifiersRolloutWorker(_run_single_rollout).