Repository navigation
[rl] Select the actor framework by config: ActorSystem, implemented for Monarch - #5391
Conversation
| self, config: Generator.Config, **kwargs: Any | ||
| ) -> list[ServiceHandle]: | ||
| """Spawn the provisioned generators; ``kwargs`` go to ``Generator``'s | ||
| constructor.""" |
There was a problem hiding this comment.
This interface can be remove. Controller only needs spawn_generator_router to get the generation stack.
There was a problem hiding this comment.
Agreed, done. spawn_generator_router(router_config, generator_config=..., **generator_kwargs) now spawns the generators and the router over them and returns only the router. The one other use of the generator handles, TorchStore client setup, moved into initialize_torchstore().
| self, config: RolloutWorker.Config, *, num_workers: int, num_threads: int | ||
| ) -> Any: | ||
| """Spawn a pool of ``num_workers`` rollout worker processes on the | ||
| controller host, each running ``num_threads`` rollout threads.""" |
There was a problem hiding this comment.
The rollout_workers related methods feel weird since they are used to created a private field in Rollouter.
There was a problem hiding this comment.
I kept these, because the pool is an implementation detail of the default Rollouter: VerifiersRollouter runs rollouts in its Verifiers EnvServer and spawns no pool. If the controller spawned the pool and passed it in, it would spawn processes the Verifiers rollouter never uses, or need a "does this rollouter want a pool" flag. So the rollouter still spawns its pool through the actor system it is given.
While checking this I found that VerifiersRollouter.setup_async did not take actor_system, so the verifiers recipes would have failed. Fixed, with a test that its signature matches Rollouter.setup_async. Happy to switch to a controller-owned pool if you prefer it.
|
The dependency inversion itself makes sense if the goal is to support multiple backends. But it does come with a price since it requires more work when the interface gets complicated. e.g. #5285 would need more careful design to conform with the |
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class MonarchActorSystem(ActorSystem): |
There was a problem hiding this comment.
The abstraction and APIs make sense to me, but I'm kind of confused about the name System. My proposal is maybe ActorRuntime , or what's your consideration of this class
There was a problem hiding this comment.
it's from an established term on a related thing https://pekko.apache.org/docs/pekko/1.3/general/actor-systems.html
There was a problem hiding this comment.
Added this reasoning to the ActorSystem docstring: the name follows Akka/Pekko's actor system, the container that creates, places and stops actors. This class owns placement and lifecycle (provision, spawn_*, stop, shutdown), not only how actors execute, which "runtime" would suggest.
|
message from claude: @tianyu-l one concern before this merges: launchers that bring their own hosts.
Could |
15b4d87 to
6beddf2
Compare
@pzhan9 agreed, it has a cost: each new service adds an
With your |
|
@felipemello1 thanks for catching this, fixed in this PR. actor_system = config.actor_system.build(host_meshes=host_meshes, generator_env=generator_env)
await controller.setup_async(actor_system=actor_system)
|
6beddf2 to
11576f8
Compare
…or Monarch The controller, rollouter and train.py used Monarch directly to provision proc meshes, set up torch elastic, spawn every service and stop the meshes. Put that behind an interface selected by config, the way Generator.Config.engine selects the inference engine: - actors/system.py: ActorSystem, which provisions processes, spawns each service (trainer, generators, generator router, rollout workers), initializes TorchStore on the trainer's processes, stops them, and shuts its client down. It documents the call convention its handles follow (.call() with .get(rank), .call_one(), .choose(), .stream()). ServiceHandle carries a service's all-ranks and rank-0 handles, so the controller and router no longer slice meshes. - Controller.Config.actor_system selects it (default MonarchActorSystem.Config(), imported lazily). The controller provisions and spawns through it in setup_async and stops it in close; the rollouter spawns and stops its worker pool through it; train.py only builds, runs and closes the controller and shuts the actor system's client down. - actors/monarch/system.py: MonarchActorSystem. actors/monarch/provisioning.py takes train.py's proc mesh provisioning (PerHostProvisioner, HostMeshes, spawn_proc_mesh, spawn bootstraps) plus spawn_cpu_procs and shutdown. - actors/monarch/router.py: InterGeneratorRouterActor, the endpoints and the singleton check. InterGeneratorRouter is now a plain class with public async methods, like Trainer and Generator. Processes and actors are created in the same order as before: GPU meshes, router process, torch elastic, trainer, generators, router, rollout workers, TorchStore. Teardown order is unchanged too.
…DMAMicrobatch interface The batcher and the trainer used MonarchRDMAMicrobatch directly, so both imported monarch.rdma. They now use an RDMAMicrobatch protocol (read, drop, and the batch/DP rank/microbatch indices) and an injected RegisterRDMAMicrobatch; BatcherActor passes MonarchRDMAMicrobatch.register. RDMAMicrobatchPrefetcher stays in the trainer, as it only calls read(). A batcher with rdma_min_tensor_bytes set and no registration raises.
11576f8 to
b5304bf
Compare
Summary: Follow up #5391. Update launcher provisioning imports and controller setup to use the ActorSystem API. Pass allocated host meshes to the configured actor system and apply RL environment defaults before importing torch-dependent modules. Remove redundant tests that compare method names, signatures, or a default configuration type. Existing behavioral tests cover router dispatch, Verifiers setup with the controller's arguments, Monarch provisioning, and trainer rank grouping. Reviewed By: fegin Differential Revision: D125905793 Pull Request resolved: #5535
Stacked on #5317.
Why
The controller, the rollouter, the trainer, the batcher and
train.pyused Monarch directly:train.pyprovisioned the GPU proc meshes; the controller spawned the router and batcher processes, set up torch elastic, spawned every actor, sliced the trainer by DP rank and stopped the meshes; the rollouter spawned and stopped its worker pool; the batcher and the trainer exchangedMonarchRDMAMicrobatches. Running the RL loop on another actor framework (e.g. Ray) would mean editing all of them.This PR puts actor placement behind an interface selected by config, the way
Generator.Config.engineselects the inference engine (#5317).What changed
actors/system.py:ActorSystem, framework-agnostic. It provisions processes, spawns each service, initializes TorchStore (storage on the trainer's processes, plus every trainer and generator actor's client), stops the processes, and shuts its client down. The name follows Akka/Pekko's actor system (see its docstring). Its docstring also defines the call convention its handles follow:.call()with.get(rank)on the result,.call_one(),.choose(),.stream(),.broadcast()(Monarch's endpoint calls; another framework wraps its handles to provide them).spawn_trainer(config, dp_degree=...)returns aTrainerHandle: all-ranks, rank-0 and per-DP-rank handles. The actor system slices the trainer by DP rank and checks the(dp, cp, tp)layout withget_dp_rank, so the controller no longer slices meshes.spawn_generator_router(router_config, generator_config=...)spawns the generators and the router over them, and returns only the router: the controller reaches the generators through the router.spawn_batcher,spawn_rollout_workers/stop_rollout_workers.Controller.Config.actor_systemselects the implementation; the defaultMonarchActorSystem.Config()is imported lazily.Controller.setup_async(actor_system=...)also accepts one the launcher built, e.g. aMonarchActorSystemon hosts it allocated (host_meshes,generator_envconstructor arguments), so launchers that bring their own hosts keep working.train.pyonly builds, runs and closes the controller, then calls the actor system'sshutdown().actors/monarch/system.py:MonarchActorSystem.actors/monarch/provisioning.pytakestrain.py's proc mesh provisioning (PerHostProvisioner,HostMeshes,spawn_proc_mesh, the spawn bootstraps) plusspawn_cpu_procsand the clientshutdown.actors/monarch/router.py:InterGeneratorRouterActor, the endpoints and the singleton check.InterGeneratorRouteris now a plain class with public async methods, likeTrainerandGenerator.MonarchRDMAMicrobatchmoves toactors/monarch/rdma_microbatch.py. The batcher and the trainer use anRDMAMicrobatchprotocol (read,drop, the batch/DP rank/microbatch indices) intrainer/rdma_microbatch.py, next toRDMAMicrobatchPrefetcher;BatcherActorinjectsMonarchRDMAMicrobatch.registerintoBatcher.VerifiersRollouter.setup_asynctakesactor_system(unused: rollouts run in the Verifiers EnvServer), plus a test that its signature matchesRollouter.setup_async.After this PR no module outside
actors/monarch/imports Monarch, except the controller's lazy default config.actors/monarch/README.mddescribes the package and the call convention that remains outside it.Behavior
ts.initialize(mesh=trainer_mesh)and the per-actor TorchStore client setup move intoActorSystem.initialize_torchstore()(with a TODO to move it to a model state dict transport).rdma_min_tensor_bytesset but no registration raisesValueError.Testing
verifiers) pass withverifiers==0.3.1: 37 passed, 1 skipped. New tests cover provisioning order and launcher host meshes, trainer DP-rank grouping and the layout check, teardown order with the batcher, and the Batcher's missing-registration error.pre-commit runon the changed files: clean.dc9ea005e), GB300, Qwen3 debug model with random init and a deterministic varying reward, 6 steps:rdma_min_tensor_bytes=1024(3 GPUs, per-DP-rank columns over RDMA): bitwise identical;target_offpolicy_steps=3): finishes all steps on both. Both then hit the same teardown error on main and here (the rollout worker mesh stops while a router reply is in flight).