Repository navigation
[rl] Every generate call goes over HTTP to its generator (10/14) - #5506
felipemello1 wants to merge 8 commits into
Conversation
aa0cdbc to
d596a8e
Compare
66f7d01 to
15817d3
Compare
d596a8e to
c8a316a
Compare
15817d3 to
9df6ee4
Compare
c8a316a to
5761d00
Compare
9df6ee4 to
d0ac2ea
Compare
|
pelase move the flow diagram to the tldr portion, so the problem that controller is the middle-man, is clear. Also, i find this pr description a bit to verbose and hard to digest. Please reduce noise and keep the signal. Do not delete or omit important information. Just be less verbose and add more structure. The main thing that this pr is solving is that, when we have large number of nodes, passing everything through the controller is not sustainable. The second thing we are solving is that we want to be more flexible to be plug and play, and everything expects an http server. |
| ) | ||
|
|
||
|
|
||
| class _InterGeneratorRouterActorEndpoints: |
There was a problem hiding this comment.
please add a docstring to this class. Its a bit unclear why it exists if all it does is to call .super
| # so all of the rollout's traces (sub-agents too) share that generator. | ||
| endpoint = await generator_client.acquire_rollout(group_id=group_id) | ||
| verifiers_episode = None | ||
| try: |
There was a problem hiding this comment.
why would we put try here if we didnt need it before?
| # The same JSON for every rollout on a generator, so Verifiers keeps one HTTP | ||
| # client per generator. | ||
| client=self._verifiers_train_client_config.model_copy( | ||
| update={"base_url": f"{endpoint.url}/v1"} | ||
| ), |
There was a problem hiding this comment.
my understanding is that this is taking the endpoing, which i am not sure what i look like, and adding hte /v1. Why? and how is that related to "same json for every rollout and keeping one http client per generator? can we make all of this more obvious without making it more verbose? maybe a 1line example of what it looks like, add a type hint to endpoint:typehint = ..., etc.
| session_ids=( | ||
| [trace.id for trace in verifiers_episode.traces] | ||
| if verifiers_episode is not None | ||
| else [] | ||
| ), | ||
| ) |
There was a problem hiding this comment.
before we had to pass only a trace id, now we have to pass a list? its very confusing here what is a session vs trace vs rollout
| _METRIC_TYPES = { | ||
| value_type.__name__: value_type for value_type in (m.Mean, m.Max, m.Min, m.Sum) | ||
| } |
There was a problem hiding this comment.
this would get stale. Why are we defining this here? what if someone adds a new metric type?
| self.generate_fn = generate_fn | ||
| def url(self) -> str: | ||
| """Base URL other hosts can reach, e.g. `"http://host-3.example.com:41233"`.""" | ||
| return f"http://{socket.getfqdn()}:{self.port}" |
There was a problem hiding this comment.
hostname is not always reachable from a different host. IP address is better, although still might not be reachable in some scenarios.
main does not have this problem because Router and Rollouters are on the same host, so they can use loopback.
There was a problem hiding this comment.
reply from claude: agreed that a hostname isn't always resolvable from another host. But I tried the IP, and it breaks Verifiers on hosts behind an HTTP proxy:
- Verifiers' httpx client honors
HTTP_PROXY. - The env server exempts only
127.0.0.1,localhost. - On our hosts
NO_PROXYmatches the domain, not the IP: the proxy answered 400, and the hostname got 200.
So this PR keeps getfqdn(). Moving to an IP is a follow-up, and it also has to add the generator hosts to the env server's no_proxy.
d0ac2ea to
2703106
Compare
efa6953 to
dbc8b18
Compare
2703106 to
f35c21c
Compare
|
reply from claude:
|
dbc8b18 to
51ddd7c
Compare
f35c21c to
a683e38
Compare
…LURM (#5572) ## Summary (human-written) This PR adds a slurm launcher, so we can launch a job using multiple hosts. See `rl_grpo_qwen3_0_6b_flex_slurm` for the example of how it is used. ## Why TitanRL can run on several hosts only through a launcher that builds `MonarchActorSystem(host_meshes=...)` itself; the in-repo path (`python -m torchtitan.rl.train`) runs every role on the controller's host. There is no way to submit a recipe to a cluster scheduler from this repo. **Example.** Qwen3-0.6B GRPO on two 4-GPU SLURM nodes: ```bash python -m torchtitan.rl.actors.monarch.launcher.submit \ --module torchtitan_recipes.rl.alphabet_sort --config rl_grpo_qwen3_0_6b_flex_slurm ``` ``` node 0 (mesh trainer): trainer, TP=2 x FSDP=2 4 GPUs node 1 (mesh node_0): generator_0..3, 1 GPU each 4 GPUs ``` ## What changed - **Launch recipes** (`launcher/base.py`): `MonarchControllerWithLauncher` is a `Controller` subclass whose `Config` adds `launcher` at the root, so a launch recipe is "this RL recipe on this cluster", built with `MonarchControllerWithLauncher.Config.from_controller_config(config, launcher=...)`. `Controller.Config` and `MonarchActorSystem.Config` have no launcher settings. - **Building the actor system** (`controller.py`): `setup_async` builds it through a new `Controller._build_actor_system()`, which builds `config.actor_system`. `MonarchControllerWithLauncher` overrides it to acquire the planned hosts and build `MonarchActorSystem(host_meshes=...)` from `self.config`. - **Submit**: `launcher/submit.py` plans the layout on the submit host and submits. The scheduler runs the unchanged `python -m torchtitan.rl.train` with the same arguments; `config.build()` builds `MonarchControllerWithLauncher`. - **Layout planner** (`MonarchLauncher._layout`): places the trainer, then each generator, filling one node before the next. A role using a node or more gets whole nodes; smaller roles share nodes; idle GPUs are logged as one warning. Table of examples in `torchtitan/rl/actors/monarch/README.md` ("Layout"). - **`SlurmLauncher`** (`launcher/slurm.py`): one Monarch `SlurmJob` in batch mode, controller on SLURM's head node. Site settings go in `slurm_args`; flags the launcher owns are rejected. JIT caches (Triton, vLLM, FlashInfer) default to node-local `/tmp/torchtitan-<uid>`. - **Example launch recipe** `rl_grpo_qwen3_0_6b_flex_slurm` in `alphabet_sort.py`. - **Removed** `MonarchActorSystem`'s `generator_env` argument (and `extra_env` behind it): unused since #4834 removed its only caller. - Small, mechanical: `Controller.Config.resolve_overrides()` (moved out of `Controller.__init__` so `submit` plans from the overridden config); `generator_role_names` in `provisioning.py`, shared by the planner and `MonarchActorSystem`. ## Alternatives considered - Launcher on `MonarchActorSystem.Config` (an earlier version of this PR): makes every recipe pick its scheduler and adds a second way to pass hosts. - A separate job entry point passing a pre-built actor system through a `train.main` hook and `setup_async(actor_system=...)` (an earlier version of this PR): more code, and the hook got the config before overrides were applied, so root-level overrides never reached the job. - Launcher config wrapping `Controller.Config` in a `job` field: `--override` needs `override` at the root, so CLI overrides and `--print-config` would change. - Launcher config loaded separately from the RL recipe (`--launcher module:fn`): launches are defined per recipe and cluster in practice, as in fairtitan. ## User-facing changes | Before | After | | --- | --- | | Multi-host only via an out-of-repo launcher passing `host_meshes` | Also `launcher.submit` with a `MonarchControllerWithLauncher.Config` recipe | | `python -m torchtitan.rl.train` | Unchanged | | `controller.setup_async(actor_system=...)` | **Removed.** Subclass `Controller` and override `_build_actor_system` | | `MonarchActorSystem(..., generator_env=...)` | **Removed** (no in-repo caller since #4834) | ## Numerics No computation change. Without a launcher, `Controller._build_actor_system` builds `config.actor_system`, as `setup_async` did before. ## Testing - CPU: `pytest tests/rl/unit_tests/cpu/`: 530 passed, 9 skipped, 1 failed. The failure, `test_model_defaults[dapo_math]`, also fails without this PR: the local venv's `torch_checkpointing` lacks `CallbackArgs`. `test_dapo_math.py` is not collected locally (optional `math_verify` missing). `test_launcher.py` covers the layout planner (examples, idle warning, fits the hosts, rejected sizes, shared mesh objects), `submit`, `MonarchControllerWithLauncher` (builds the subclass, requires a Monarch actor system, acquires hosts from the layout), and `SlurmLauncher`'s `sbatch` arguments, env and validation. - Real SLURM runs on FAIR CoreWeave GB300 (4 GPUs per node), account `sysml`, `--segment=1`, `bind_to="::"`, `HF_HUB_OFFLINE`, `HF_DATASETS_OFFLINE` and `MONARCH_RDMA_IBVERBS_TARGET` in `launcher.env`, W&B disabled; launch recipes local, not committed: | Job | Layout | Result | | --- | --- | --- | | 2338739 | `rl_grpo_qwen3_0_6b_flex_slurm` at the head commit (`MonarchControllerWithLauncher`): node 0: trainer (TP=2 x FSDP=2); node 1: generator_0..3 (1 GPU each) | completed, exit 0, 6m32s; job runs plain `torchtitan.rl.train`; trainer mesh dp_shard=2 x tp=2; 10 steps (loss -0.0032 -> -0.0024, grad norm 2.17 -> 0.62); weight sync to the generator node every step; validation reward 0.181 -> 0.216 | | 2205059 | node 0: trainer (TP=2), generator_0, generator_1; node 1: generator_2, generator_3 (2 GPUs idle on node 1) | completed, exit 0, 6m35s; 10 steps (loss -0.0041 -> 0.00012); weight sync to both nodes every step; validation reward 0.181 -> 0.226 | | 2312888 | `rl_grpo_qwen3_0_6b_flex_slurm`, before the `Controller` subclass: node 0: trainer (TP=2 x FSDP=2); node 1: generator_0..3 (1 GPU each) | completed, exit 0, 6m36s; submitted through `launcher.job`; trainer mesh dp_shard=2 x tp=2; 10 steps (loss -0.0064 -> -0.0022, grad norm 5.09 -> 0.53); weight sync to the generator node every step; validation reward 0.181 -> 0.197 | | 2205441 | earlier recipe version: node 0: trainer (FSDP=4); node 1: generator_0..3 (1 GPU each); submitted through `launcher.job` | completed, exit 0, 6m42s; 10 steps (loss -0.013 -> -0.0024); weight sync to the generator node every step; validation reward 0.181 -> 0.181 | - Single-node regression, `python -m torchtitan.rl.train --module torchtitan_recipes.rl.alphabet_sort --config rl_grpo_qwen3_0_6b_flex` on one 4-GPU node, this PR vs. its base `01586df70` (the recipe is not seeded or deterministic, so losses are compared by range, not bitwise): | Job | Code | Result | | --- | --- | --- | | 2338740 | head commit | completed, exit 0, 7m29s; 10 steps (loss -0.0036 -> -0.00076, grad norm 2.77 -> 0.56); validation reward 0.179 -> 0.192 | | 2338741 | base `01586df70` | completed, exit 0, 7m29s; 10 steps (loss -0.0051 -> -0.0014, grad norm 3.78 -> 0.55); validation reward 0.179 -> 0.193 | ## Known issues / follow-ups - Not yet tested with #5506 (HTTP generation), where rollout workers call generators on other nodes; a 3-node smoke test once both are in. - `SlurmLauncher` reads the SLURM job id through a private Monarch attribute (TODO in `slurm.py`). - fairtitan's SLURM launcher calls `setup_async(actor_system=...)`; it moves to this launcher in a companion change.
…/session example, lease and base_url comments, metric codec for every type
51ddd7c to
49739f6
Compare
a683e38 to
6fe0b09
Compare
…mello1/http/3-generate-over-http # Conflicts: # tests/rl/unit_tests/cpu/test_verifiers.py # torchtitan/rl/examples/verifiers/rollouter.py
…mello1/http/3-generate-over-http # Conflicts: # tests/rl/unit_tests/cpu/test_verifiers.py # torchtitan/rl/examples/verifiers/rollouter.py
…mello1/http/3-generate-over-http
…mello1/http/3-generate-over-http # Conflicts: # torchtitan/rl/examples/verifiers/rollouter.py # torchtitan/rl/generator/generation_server.py
…mello1/http/3-generate-over-http
…mello1/http/3-generate-over-http # Conflicts: # torchtitan/rl/generator/generation_server.py
TLDR: Every
generatecall now goes over HTTP straight to its generator, so the controller and the router are no longer middle-men for prompts and completions. That matters for two reasons:At ~62 Verifiers calls/s on 8 x H100, the controller's CPU drops from 22.6 to 13.9 s per training step, and its GC from 1.41 to 0.78 s.
Stack (14 PRs, merge bottom-up; this PR is in bold)
PRs 2-7 don't need the HTTP design and can be reviewed now. PRs 8-14 wait on the design discussion on PRs 9 and 10.
Problem
generateon the router actor, which pickles the prompt and the completion through itself on every call.GenerationServerinside the controller, then to the router, then to the generator.Solution
GenerationServer, bound toGenerator.generate.InterGeneratorRouter.acquire(session, group_id)returns a generator's index and URL and takes one unit of load (a lease);release(index, group_id)gives it back.GeneratorClientserves both paths. Native takes a lease per call (routing unchanged); Verifiers takes one per rollout, returned byrouter.release_rolloutwith its policy versions and metrics."response_format": "torchtitan"returns raw int32 token ids and float64 logprobs.Results
Numerics: bitwise identical training samples (token, logprob and prompt bytes, policy versions, messages, rewards, advantages, generator metrics). Only the router is faked there; its
release_rollout-> generatorrelease_sessionshop is covered by unit tests.Step times are within run-to-run noise: one node doesn't bind on the controller, and the high-rate Verifiers runs are bound by the single env server.
You may ask:
acquirereturns no actor handle (unpickling one per call cost 1.4% of the controller's GIL).NOTE:
release); the router's ceiling isn't measured.socket.getfqdn(). At setup the router checks every URL from its own host. Tested on one host.SlurmLauncher([rl] Scheduler launchers on the Monarch actor system, starting with SLURM #5572), the router and the rollout workers run on the controller's node (spawn_cpu_procs), so the router's URL check runs from the callers' host. Not yet run underSlurmLauncher; the 3-node smoke from [rl] Scheduler launchers on the Monarch actor system, starting with SLURM #5572 is the first run with both.Test plan
New tests in
test_generation_server.py(both formats, a client that hangs up, the lease, the metrics codec),test_inter_generator_router.py(lease,release_rollout, URL check) andtest_engine_loop.py(the server closes after the engine loop).