Repository navigation
[RL] Remove FULL_AND_PIECEWISE CUDA graph mode - #4834
Conversation
| previous = getattr(self, "_force_gdn_attention_metadata", False) | ||
| self._force_gdn_attention_metadata = ( | ||
| getattr(self, "_has_torchtitan_gdn", False) | ||
| and cudagraph_runtime_mode == CUDAGraphMode.PIECEWISE |
There was a problem hiding this comment.
In titan, it'd never be in this status because of https://github.com/pytorch/torchtitan/blob/main/torchtitan/rl/generator.py#L177?
Also, any blockers for always enabling FULL cudagraph capture, and even remove "full_and_piecewise" option?
There was a problem hiding this comment.
No it will happen, CUDAGraphMode is not our config, it's vllm's runtime config. For example if our config is FULL_AND_PIECEWISE, for a prefill/mixed batch, the runtime mode is
Also, any blockers for always enabling FULL cudagraph capture, and even remove "full_and_piecewise" option?
For Qwen3.5 model, yes we should only allow FULL cudagraph mode in our config. But for all the models, killing "full_and_piecewise" option might not be feasible eg I remember when testing MoE models, some backend needs cudagraph break
ccdc8c5 to
e050755
Compare
e050755 to
478392f
Compare
478392f to
5f0e15e
Compare
5f0e15e to
7dcfdab
Compare
| super().__init__(kv_cache_spec, layer_names, vllm_config, device) | ||
| self.kv_cache_spec = kv_cache_spec | ||
| compilation = vllm_config.compilation_config | ||
| if compilation.cudagraph_mode not in ( |
There was a problem hiding this comment.
do we need this because we are keeping FULL_DECODE_ONLY? should we remove it as well?
There was a problem hiding this comment.
No I failed to consider the FULL_DECODE_ONLY case. We are not removing FULL_DECODE_ONLY case yet, we could. vllm said it's useful for P/D setup decode instances: https://docs.vllm.ai/en/stable/design/cuda_graphs/#cudagraphmodes
The CUDAGraphMode here only have 3 types: https://docs.vllm.ai/en/stable/api/vllm/config/compilation/#vllm.config.compilation.CUDAGraphMode , and FULL_DECODE_ONLY will be dispatched to None/ FULL/PIECEWISE according to the input batch.
Here the check is abandoning GDN using CUDAGraphMode.PIECEWISE. As we removed FULL_AND_PIECEWISE, PIECEWISE, we should remove this check.
| compilation = vllm_config.compilation_config | ||
| if compilation.cudagraph_mode not in ( | ||
| CUDAGraphMode.NONE, | ||
| CUDAGraphMode.FULL, |
There was a problem hiding this comment.
Default to be FULL, remove flag FULL_AND_PIECEWISE
| super().__init__(kv_cache_spec, layer_names, vllm_config, device) | ||
| self.kv_cache_spec = kv_cache_spec | ||
| compilation = vllm_config.compilation_config | ||
| if compilation.cudagraph_mode not in ( |
There was a problem hiding this comment.
No I failed to consider the FULL_DECODE_ONLY case. We are not removing FULL_DECODE_ONLY case yet, we could. vllm said it's useful for P/D setup decode instances: https://docs.vllm.ai/en/stable/design/cuda_graphs/#cudagraphmodes
The CUDAGraphMode here only have 3 types: https://docs.vllm.ai/en/stable/api/vllm/config/compilation/#vllm.config.compilation.CUDAGraphMode , and FULL_DECODE_ONLY will be dispatched to None/ FULL/PIECEWISE according to the input batch.
Here the check is abandoning GDN using CUDAGraphMode.PIECEWISE. As we removed FULL_AND_PIECEWISE, PIECEWISE, we should remove this check.
7dcfdab to
69a1acf
Compare
Review feedback (tianyu-l). generator_env was added in pytorch#3829 so train.py could pass the breakable CUDA graph env var to the generator procs; pytorch#4834 removed that caller, and nothing in torchtitan or fairtitan sets it since. Remove it from MonarchActorSystem and spawn_proc_mesh, along with extra_env on PerHostProvisioner.allocate and _spawn_proc_mesh, whose only source it was.
Review feedback (tianyu-l). generator_env was added in pytorch#3829 so train.py could pass the breakable CUDA graph env var to the generator procs; pytorch#4834 removed that caller, and nothing in torchtitan or fairtitan sets it since. Remove it from MonarchActorSystem and spawn_proc_mesh, along with extra_env on PerHostProvisioner.allocate and _spawn_proc_mesh, whose only source it was.
…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.
Summary
FULL_AND_PIECEWISEfrom TorchTitan RL generator configuration and delete its mode-specific launch wiring; keepNONE,FULL_DECODE_ONLY, andFULLFULLin the checked-in graph-compatible Qwen3.5/GDN and DeepEP recipesFULL_DECODE_ONLYfor GDN: decode runs FULL, while prefill and mixed batches run eagerWhy
TorchTitan GDN prepares stable metadata for native FULL capture of prefill, mixed batches, and decode in its supported generator configuration.
FULL_DECODE_ONLYis also valid: vLLM defines it as(FULL, NONE)with no PIECEWISE runtime path. A global mode guard in the GDN metadata builder incorrectly rejected it; this change removes that guard. The TorchTitan generator no longer offers FULL_AND_PIECEWISE, while the upstream vLLM enum remains unchanged.Testing
python -m pytest -q tests/unit_tests/rl/test_gdn_graph_metadata.py(5 passed), including FULL_DECODE_ONLY decode-to-FULL and prefill-to-NONE dispatch69a1acf03