Skip to content

[RL] Remove FULL_AND_PIECEWISE CUDA graph mode - #4834

Merged
wwwjn merged 1 commit into
mainfrom
jianiw/gdn-piecewise-metadata
Sep 24, 2026
Merged

wwwjn merged 1 commit into
mainfrom
jianiw/gdn-piecewise-metadata

Conversation

@wwwjn

@wwwjn wwwjn commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • remove FULL_AND_PIECEWISE from TorchTitan RL generator configuration and delete its mode-specific launch wiring; keep NONE, FULL_DECODE_ONLY, and FULL
  • use FULL in the checked-in graph-compatible Qwen3.5/GDN and DeepEP recipes
  • remove the GDN eager-break decorator, but leave the shared attention implementation and generic generator launch environment support unchanged
  • allow FULL_DECODE_ONLY for GDN: decode runs FULL, while prefill and mixed batches run eager

Why

TorchTitan GDN prepares stable metadata for native FULL capture of prefill, mixed batches, and decode in its supported generator configuration. FULL_DECODE_ONLY is 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 dispatch
  • changed-file pre-commit hooks passed except Pyrefly, whose executable is unavailable locally
  • CI restarted for commit 69a1acf03

@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Sep 22, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 22, 2026
Comment thread torchtitan/rl/model/vllm_worker.py Outdated
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

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.

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?

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.

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

@wwwjn
wwwjn force-pushed the jianiw/gdn-piecewise-metadata branch from ccdc8c5 to e050755 Compare September 23, 2026 17:15
@wwwjn wwwjn changed the title [RL] Capture GDN in PIECEWISE CUDA graphs [RL] Require FULL CUDA graphs for GDN Sep 23, 2026
@wwwjn
wwwjn force-pushed the jianiw/gdn-piecewise-metadata branch from e050755 to 478392f Compare September 23, 2026 17:17
@wwwjn wwwjn changed the title [RL] Require FULL CUDA graphs for GDN [WIP][RL] Require FULL CUDA graphs for GDN Sep 23, 2026
@wwwjn wwwjn changed the title [WIP][RL] Require FULL CUDA graphs for GDN [RL] Require FULL CUDA graphs for GDN Sep 23, 2026
@wwwjn
wwwjn force-pushed the jianiw/gdn-piecewise-metadata branch from 478392f to 5f0e15e Compare September 23, 2026 20:59
@wwwjn wwwjn changed the title [RL] Require FULL CUDA graphs for GDN [RL] Remove FULL_AND_PIECEWISE CUDA graph mode Sep 23, 2026
@wwwjn
wwwjn force-pushed the jianiw/gdn-piecewise-metadata branch from 5f0e15e to 7dcfdab Compare September 23, 2026 21:42
Comment thread torchtitan/rl/model/gdn_backend.py Outdated
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 (

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.

do we need this because we are keeping FULL_DECODE_ONLY? should we remove it as well?

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.

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.

Comment thread torchtitan/rl/model/gdn_backend.py Outdated
compilation = vllm_config.compilation_config
if compilation.cudagraph_mode not in (
CUDAGraphMode.NONE,
CUDAGraphMode.FULL,

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.

Default to be FULL, remove flag FULL_AND_PIECEWISE

Comment thread torchtitan/rl/model/gdn_backend.py Outdated
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 (

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.

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.

@wwwjn
wwwjn force-pushed the jianiw/gdn-piecewise-metadata branch from 7dcfdab to 69a1acf Compare September 24, 2026 00:29
@wwwjn
wwwjn merged commit 54693c6 into main Sep 24, 2026
19 checks passed
pzhan9 added a commit to pzhan9/torchtitan that referenced this pull request Nov 3, 2026
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.
pzhan9 added a commit to pzhan9/torchtitan that referenced this pull request Nov 3, 2026
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.
pzhan9 added a commit that referenced this pull request Nov 3, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests 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.

2 participants