Skip to content

[rl] PBSLauncher: run RL recipes on PBS clusters - #5403

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
songhappy:rl-multihost
Nov 21, 2026
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
songhappy:rl-multihost

Conversation

@songhappy

@songhappy songhappy commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Part of the RFC #5401 (GRPO on Intel XPU). RL recipes on main can only be launched on SLURM clusters, so PBS systems like Aurora had no supported launcher.

PBSLauncher adds one next to SlurmLauncher, on the launcher interface from #5572, using Monarch's PBSJob. It only handles what PBS does differently: it submits with qsub -V, since PBS doesn't pass the submit environment, and it copies the job state Monarch writes to a per-job path, since PBS has no --chdir (removable once meta-pytorch/monarch#5414 lands). The README's PBS section shows a launch recipe and the site settings PBS clusters need: python_exe as a script that loads the environment, and a short TMPDIR (meta-pytorch/monarch#5415).

Tested:

  • test_launcher.py: the job is built correctly, hosts are acquired, invalid pbs_args are rejected.
  • On ALCF Aurora (PBS Pro, Cray PALS) with current Monarch main: a 1-node job submits, the controller attaches, and with [rl] Run GRPO on Intel XPU through the stock RL path #5402 Qwen3-0.6B GRPO trains 5/5 steps through PBSLauncher.
  • Earlier 2-node jobs placed the trainer and generators on the planned nodes and tiles.

Needs a Monarch with meta-pytorch/monarch#5273 (PBSJob without rank_env).

@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 15, 2026
@songhappy songhappy changed the title [rl] Place roles on the hosts of a Monarch job in torchtitan.rl.train [rl] PBSLauncher: run RL recipes on PBS clusters Nov 18, 2026
@songhappy
songhappy marked this pull request as ready for review November 18, 2026 00:11
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 18, 2026
@github-actions
github-actions Bot requested a review from pzhan9 November 18, 2026 00:11
@tianyu-l

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 2m 59s —— View job


Approve -- please address the items before merging: review (4 inline comments)

@claude claude Bot left a comment

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.

Verdict: Approve -- please address the items below before merging. The design follows SlurmLauncher and handles the two real ways PBS differs from SLURM. What's left are small local fixes: argument validation and TODOs for the Monarch gaps it works around.

What this PR does. It adds PBSLauncher (launcher/pbs.py), a sibling of SlurmLauncher. It submits a single Monarch PBSJob in batch mode with qsub -V, because PBS doesn't pass the submit environment to the job. The controller runs on the job's first node, and mpiexec starts one Monarch worker per node. PBS can't set the working directory (SLURM uses --chdir), so apply() runs from the submit directory. Monarch writes its job state there, and the launcher copies it to <dump_folder>/launcher/<job>/job_state.pkl for the controller to load. The README gets a PBS section, and three CPU unit tests are added.

Example.

PBSLauncher.Config(gpus_per_node=12, pbs_args=["-q debug", "-A proj"],
                   mpiexec_args=["--cpu-bind=none"], rank_env="PALS_RANKID")
# submit: qsub with #PBS -V, -q debug, -A proj; cwd = submit dir
#   -> ./.monarch/job_state.pkl copied to <dump>/launcher/<job>/job_state.pkl
#   -> TORCHTITAN_RL_PBS_JOB_STATE=<that path> exported via -V
# job: controller job_load(<that path>) -> attaches to the trainer/generator meshes

Must fix

  1. launcher/pbs.py:80-82: validation only checks the first option of each entry, so pbs_args=["-q debug -N name"] gets through. Check every token, as SlurmLauncher does (inline suggestion).
  2. launcher/pbs.py:124-129: copying ./.monarch/job_state.pkl works around Monarch (no option for the state path or working directory). Add a TODO with a Monarch issue link. The copy also runs after the job is queued, and two submits from the same directory at once can swap states.
  3. README.md:119-121: the TMPDIR workaround is for a Monarch socket-path bug. Link an upstream issue.
  4. PR description: it doesn't use the template. Please add the ## Summary (human-written) section; the current prose can stay under "Why" / "What changed" / "Testing".

Should consider

  • launcher/pbs.py:134-138: acquire_hosts, the JIT-cache defaults and the state_dir setup are copied from slurm.py. Now that there are two launchers, share them in base.py with one job-state env var. That saves about 20 lines and lets test_pbs_acquire_hosts be deleted.
  • launcher/pbs.py:55: the mpiexec field isn't set by the README example or the Aurora setup described. Unless a cluster needs a different launcher binary, drop it and keep PBSJob's default.
Details
  • Necessity: PBS clusters such as ALCF Aurora can't run the RL recipes on main, because SlurmLauncher is the only scheduler launcher. The PR builds on the launcher interface from #5572 rather than adding a parallel mechanism, and the scheduler-specific code is confined to launcher/pbs.py. Monarch is already a dependency of this package, so nothing new is added.
  • Why the copy can't be avoided in torchtitan: running apply() from state_dir (the SLURM approach) would start the batch script and the mpiexec workers in state_dir. The recipe's relative paths (model, dataset) would then break on the workers, not only in the controller, so a cd in client_script isn't enough. The proper fix is upstream.
  • Tests: test_pbs_submit_builds_the_job mostly re-checks the kwargs passed to the mock. The checks worth keeping are the per-job state copy and the -V prefix. It mirrors the existing SLURM test, so this isn't blocking.

Not verified: how Monarch's PBSJob writes pbs_args (one #PBS line per entry, per the docstring), which qsub options it sets itself (-N/-j/-o/select), and whether its batch script runs cd $PBS_O_WORKDIR. I couldn't inspect Monarch's source here. The multi-node Aurora runs are taken from the description.

A maintainer still needs to review.

Comment thread torchtitan/rl/actors/monarch/README.md Resolved
@tianyu-l

Copy link
Copy Markdown
Contributor

@songhappy please address claude review

Submits one Monarch PBSJob with qsub -V; copies the job state until monarch#5414.
@songhappy

Copy link
Copy Markdown
Contributor Author

Addressed the review; also dropped rank_env, which current Monarch's PBSJob no longer accepts. PTAL @tianyu-l

@tianyu-l

Copy link
Copy Markdown
Contributor

@claude review again

@claude

claude Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 1m 11s —— View job


Approve: all four earlier must-fix items are resolved; one open question about the minimum Monarch version -- review

@claude claude Bot left a comment

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.

Verdict: Approve -- all four must-fix items from the last review are fixed at 4b2bab3, and the new changes (dropping mpiexec and rank_env) remove config surface without adding anything new.

Earlier must-fix items

  1. pbs_args validation -- resolved. Every token is checked now (pbs.py:75-78), and "-q debug -N name" is in test_pbs_config_validation.
  2. Job-state copy workaround -- resolved. There is a TODO(meta-pytorch/monarch#5414) at pbs.py:120-121, and that Monarch PR (optional PBSJob workdir) is open.
  3. TMPDIR workaround -- resolved. The README links meta-pytorch/monarch#5415 and says to drop the workaround once it is fixed.
  4. PR description -- resolved. It now has ## Summary (human-written).

Earlier should-consider items

  • Dropping the mpiexec field -- done.
  • Sharing acquire_hosts, the JIT-cache defaults and the state env var with slurm.py -- the author declined and wants to wait for a third launcher. It's a judgment call (about 15 duplicated lines) and doesn't block. I'm leaving it for the maintainer to decide. Note that CLAUDE.md principle 4 asks to unify near-identical code once a second consumer exists, and PBS is that second consumer.

New since the last review

  • rank_env is gone, so the config no longer has a knob Monarch's PBSJob doesn't accept. This depends on meta-pytorch/monarch#5273. On GitHub that PR shows as closed, not merged, but its title has the (#5273) suffix that commits landed internally get.

Questions

  • Is meta-pytorch/monarch#5273 in a released torchmonarch? .ci/docker/requirements-rl.txt pins torchmonarch>=0.7.0. If 0.7.0 doesn't include it, the README's PBS section should give the minimum Monarch version (or a nightly), so Aurora users don't get a confusing PBSJob error.

Not verified: whether #5273 is in a Monarch release, and the Aurora runs, which are taken from the description.

A maintainer still needs to review.

@tianyu-l
tianyu-l merged commit afe7035 into pytorch:main Nov 21, 2026
25 checks passed
felipemello1 added a commit that referenced this pull request Nov 24, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
     this approach, and what you checked yourself. -->

## Agent details

**TLDR:** Trainer microbatches now go over Monarch RDMA by default:
`async_loop.batcher.rdma_min_tensor_bytes` goes from `None` (by value)
to `1024`. On one host, a 1 GiB microbatch takes 0.55 s by RDMA over
ibverbs vs 1.9 s by value, and every read was byte-exact.
`rdma_min_tensor_bytes=None` keeps the by-value message.

**Problem**
1. The RDMA path for trainer microbatches is opt-in: by default each
trainer rank gets its column of the batch inside the `forward_backward`
RPC message.
2. By value, the controller pickles every microbatch, Monarch copies it,
and the rank unpickles it.
3. That grows with the microbatch: 16 MiB takes 21 ms per call by value
vs 8.4 ms by RDMA, and 1 GiB 1.9 s vs 0.55 s (ibverbs, one host).

**Solution**
1. `Batcher.Config.rdma_min_tensor_bytes` defaults to 1024: tensors of
at least 1 KiB stay in the batcher as RDMA buffers; smaller ones (token
counts) stay in the message.
2. If Monarch has no RDMA backend (`monarch.rdma.get_rdma_backend() ==
"none"`), `MonarchActorSystem.spawn_batcher` raises and says to set
`rdma_min_tensor_bytes=None`. Otherwise Monarch uses ibverbs where the
host has it, else TCP (Monarch's TCP fallback is on by default).
3. RDMA with trainer pipeline parallelism still raises. The error now
says to set `rdma_min_tensor_bytes=None`, and the PP=2 `alphabet_sort`
test recipe sets it.
4. Every RL recipe sets `preprocess_microbatch_groups_lazily=True` (they
already turn accelerator graphs off), so each trainer rank reads its
next microbatches while it trains on the current one.
5. `None` sends microbatches by value, as before.

**Results**

Stress, one host (H100 devserver, CPU tensors, Monarch 0.7): the owner
registers a fresh microbatch with random bytes each step, a reader
process reads it, the owner drops the previous one. 5 steps per size,
medians of steps 2-5. Every read was byte-exact. Read = reader side,
fresh destination included. Call = one actor call, RDMA vs the same
microbatch by value:
```text
per microbatch   read, ibverbs   read, TCP   call: ibverbs / TCP / by value
1023 B           0.12 ms         0.19 ms     2.5 / 3.1 / 2.7 ms     (below 1 KiB: by value)
1 KiB            7.8 ms          0.5 ms      11 / 2.9 / 3.2 ms
1 MiB            6.4 ms          1.9 ms      12 / 7.8 / 5.5 ms
16 MiB           3.6 ms          15 ms       8.4 / 19 / 21 ms
256 MiB          83 ms           449 ms      0.17 / 0.49 / 0.56 s
1 GiB            334 ms          1.6 s       0.55 / 1.8 / 1.9 s
```
- 4 readers, 256 MiB each, at once: 81 ms over ibverbs (13 GB/s
together), 630 ms over TCP.
- Registering (in the batcher, at pack time) pins memory over ibverbs:
26 ms at 256 MiB, 264 ms at 1 GiB; under 1 ms over TCP.
- Up to 1 MiB, an ibverbs read costs 6-8 ms, a few ms more than by
value.

GPU, Qwen3-0.6B, H100, batch invariant, lockstep, trainer DP 1 + one TP
1 generator (2 GPUs), 4,096-token microbatches, 5 steps:
```text
                                    loss/mean, step 5   bit_wise/logprob_diff/max   read_microbatches/max, steps 1-5
None (by value)                     0.00061             0                           -
1024 (default), ibverbs             0.00061             0                           126, 36, 12, 19, 21 ms
1024, TCP                           0.00061             0                           57, 15, 10, 14, 17 ms
```
- `loss/mean` is bitwise equal across the three runs at all 5 steps.
Step 1 includes RDMA setup.
- TCP = `MONARCH_RDMA_DISABLE_IBVERBS=1
MONARCH_RDMA_ALLOW_TCP_FALLBACK=1`. The `None` run is from an earlier
build of this change; `None` runs none of the changed code.
- Measured on an earlier version of this PR, before main moved the RDMA
code behind the actor system. Not re-run since.

End to end at recipe size: H100, Qwen3-0.6B, batch invariant, lockstep,
10 steps, one TP 1 generator, 4,096-token microbatches (0.16 MB).
Measured on the opt-in version of this path:
```text
forward_backward                 trainer DP 1   trainer DP 2
by value                         1.393 s        0.909 s
RDMA, reads before compute       1.414 s        0.910 s
RDMA, reads overlapped (lazy)    1.399 s        0.932 s
```
- The rows differ by run-to-run noise.
- At 5.2 GB per step (CPU Monarch, one host, TCP, 4 ranks, reads
included): 9.1-11.1 s by value vs 3.3-4.1 s by RDMA.

You may ask:
- **Why not probe ibverbs at startup?** A failed registration leaves
Monarch's RDMA manager dead in its process, so a probe needs a child
process. Like TorchStore, we only check that Monarch has an RDMA
backend.
- **What about a host that lists ibverbs devices it can't use?** It
fails at the first batch: set `rdma_min_tensor_bytes=None`, or
`MONARCH_RDMA_DISABLE_IBVERBS=1` for TCP in every process (weight sync
included). The docstring says so.
- **Why 1 KiB?** Registering a buffer costs far more than sending a few
bytes, and `RDMABuffer` rejects empty tensors.
- **Isn't RDMA slower for small microbatches?** Per call, by a few ms
(stress table, 1 KiB-1 MiB). End to end at recipe size it is within
noise (table above).

NOTE:
- Builds on main's #6199 (torchmonarch 0.8.0, which removed the
CUDA-context workaround).
- The RL GPU CI now takes the RDMA path (ibverbs or TCP, whichever its
containers have).
- A config that passes its own `TrainingConfig` without
`preprocess_microbatch_groups_lazily=True` reads each microbatch before
compute, ~6-8 ms each over ibverbs at small sizes.
- Lazy on vs off at an earlier head of this PR (6aed435), Qwen3-0.6B
alphabet_sort, trainer TP 1 + one TP 1 generator, 4,096-token
microbatches, 8 steps, RDMA over TCP: `forward_backward` median over
steps 3-8 is 1.84 s with lazy and 1.64 s without. Per microbatch it is
353 vs 396 ms. The two runs sampled different rollouts (3-6 microbatches
per step), so these differences are noise. Lazy can only overlap the
RDMA reads and the input preprocessing, which take 30-60 ms per step
here (~2-4% of `forward_backward`). A lockstep, batch-invariant rerun
was not done: another job took the GPUs.
- Not tested on more than one host, on Intel XPU (#5402, GRPO on XPU) or
on PBS clusters (#5403, the PBS launcher). If the first batch fails
there, set `rdma_min_tensor_bytes=None`.

**Test plan**
- `pytest tests/rl/unit_tests/cpu
tests/unit_tests/cpu/components/test_renderer.py
tests/unit_tests/cpu/config` (repo root, Monarch 0.8.0): 965 passed, 7
skipped. With Verifiers 0.4.0 installed: 1049 passed, 1 skipped. Same
counts as main (a7887db). The skips are skipped on main too.
- `test_rdma_microbatch.py`: by value with `None`; 4 rank processes read
their columns byte-exact over real Monarch TCP across 3 released
batches.
- At an earlier head of this PR (6aed435): every zero-argument RL
recipe that builds here (54 of 56; the other 2 need a torchao nightly or
sglang), rebuilt and validated with `__post_init__` as `ConfigLoader`
does: none fails on RDMA, and all end with lazy preprocessing on and
accelerator graphs off.
- `test_batcher_actor.py`: the batcher process on the default config
sends `input` by RDMA and token counts by value.
- In-process batchers in the tests set `rdma_min_tensor_bytes=None`:
only an actor system provides RDMA registration.
- The stress script and GPU runs above (earlier heads of this PR).

Co-authored-by: Felipe Mello <[email protected]>
songhappy added a commit to songhappy/torchtitan that referenced this pull request Nov 30, 2026
…orch#5404 closed

pytorch#5402 rebased and made device-generic; pytorch#5403 is now PBSLauncher on upstream's scheduler launchers; the allocator and vLLM-eager settings move to the launcher and recipe.
songhappy added a commit to songhappy/torchtitan that referenced this pull request Nov 30, 2026
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