Repository navigation
Add precomputed routing for weight sync - #5061
Merged
Merged
Conversation
tushar00jain
force-pushed
the
fs-head/draft/3
branch
2 times, most recently
from
October 5, 2026 17:46
42357b7 to
665426f
Compare
tushar00jain
marked this pull request as ready for review
October 5, 2026 17:51
tushar00jain
requested review from
fegin,
felipemello1,
pzhan9,
tianyu-l,
wconstab and
wwwjn
as code owners
October 5, 2026 17:51
tianyu-l
reviewed
Oct 5, 2026
tushar00jain
force-pushed
the
fs-head/draft/3
branch
2 times, most recently
from
October 6, 2026 01:50
891cef0 to
da9e951
Compare
tushar00jain
force-pushed
the
fs-head/draft/3
branch
from
October 6, 2026 02:00
da9e951 to
fda8b37
Compare
tianyu-l
reviewed
Oct 6, 2026
tushar00jain
force-pushed
the
fs-head/draft/3
branch
from
October 6, 2026 02:29
fda8b37 to
89ba799
Compare
wwwjn
added a commit
that referenced
this pull request
Oct 6, 2026
Stacked on #5061 (TorchStore routing weight sync). - Lift the RL trainer PP restriction; context parallelism raises a ValueError until a follow-up adds support. - Group RL microbatches into PP schedule steps (num_pp_microbatches is plumbed into the batcher) and broadcast loss metrics from the last stage. - TrainingEngine packs per-microbatch loss kwargs (e.g. advantages, generator logprobs) into PP targets and keeps per-microbatch loss metrics, dropping the calls made by first-step metadata inference. - Every PP stage publishes its partial state dict into the single "model_state_dict" TorchStore key, so generators do not depend on the trainer PP layout. This requires weight_sync.mode="routing" (#5061): the routing client merges every stage's MAPPING and checks full coverage, while controller mode reads MAPPING from a single volume and would silently drop the other stages. The controller rejects trainer PP without routing. - Generators no longer request the vLLM attention scale buffers, which the trainer never publishes; routing mode errors on unpublished keys. - Add CPU unit tests and an 8-GPU PP=2 x FSDP=2 integration test.
fs-branch: draft/3
tushar00jain
force-pushed
the
fs-head/draft/3
branch
from
October 6, 2026 16:20
89ba799 to
344d3de
Compare
wwwjn
added a commit
that referenced
this pull request
Oct 6, 2026
- Lift the RL trainer PP restriction; context parallelism raises a ValueError until a follow-up adds support. - Group RL microbatches into PP schedule steps (num_pp_microbatches is plumbed into the batcher) and broadcast loss metrics from the last stage. - TrainingEngine packs per-microbatch loss kwargs (e.g. advantages, generator logprobs) into PP targets and keeps per-microbatch loss metrics, dropping the calls made by first-step metadata inference. - Every PP stage publishes its partial state dict into the single "model_state_dict" TorchStore key, so generators do not depend on the trainer PP layout. The TorchStore routing client (#5061) merges every stage's publication and checks that the requested keys are covered. - Generators no longer request the vLLM attention scale buffers, which the trainer never publishes; routing errors on unpublished keys. - Add CPU unit tests and an 8-GPU PP=2 x FSDP=2 integration test.
wwwjn
added a commit
that referenced
this pull request
Oct 8, 2026
- Lift the RL trainer PP restriction; context parallelism raises a ValueError until a follow-up adds support. - Group RL microbatches into PP schedule steps (num_pp_microbatches is plumbed into the batcher) and gather loss metrics from the rank that holds the last stage. - Keep the shared TrainingEngine unchanged. Under PP the RL trainer builds PipelineTrainingEngine (torchtitan/rl/pipeline_parallel.py), which packs the per-token loss arguments (advantages, generator logprobs, loss mask, temperature) into the PP targets. PackedTargetLoss unpacks them inside ChunkedLossWrapper and records metrics, which are regrouped into one dict per microbatch; the leading calls made by first-step metadata inference are skipped. - Every PP stage publishes its partial state dict into the single "model_state_dict" TorchStore key, so generators do not depend on the trainer PP layout. The TorchStore routing client (#5061) merges every stage's publication and checks that the requested keys are covered. - Generators no longer request the vLLM attention scale buffers, which the trainer never publishes; routing errors on unpublished keys. - Add CPU unit tests and an 8-GPU PP=2 x FSDP=2 integration test.
wwwjn
added a commit
that referenced
this pull request
Oct 19, 2026
**Depends on pytorch/pytorch#200238**, which adds `step(loss_kwarg_mbs=...)` to pipeline schedules. Every PP run in TorchTitan now passes it, so CI will fail until that change reaches the torch nightly. ## Why The RL trainer rejected pipeline parallelism for two reasons: 1. TorchStore could not publish a complete model from stage-local state dicts. The routing client from #5061 fixes this: every stage publishes into the same key. 2. The RL loss takes per-token arguments (advantages, generator logprobs, loss mask, temperature) that differ per microbatch, and pipeline schedules passed the same `loss_kwargs` to every microbatch. pytorch/pytorch#200238 adds `loss_kwarg_mbs` for this, so TorchTitan no longer needs an RL-side workaround. ## What changes - **Engine (shared):** under PP, the engine copies `global_loss_token_counts` into each microbatch's loss arguments and passes them to the schedule as `loss_kwarg_mbs`, instead of raising "not supported with pipeline parallelism yet". It also collects one loss metrics dict per microbatch: the schedule's scalar loss wrapper fills a per-microbatch `loss_metrics` dict, replacing it on each call because the schedule also calls the loss on microbatch 0 while inferring stage metadata. `ForwardBackwardResult.loss_metrics` is now nested like `microbatch_groups` (one list per group, one dict per microbatch). The pretraining trainers do not read these metrics. - **GraphTrainer:** its traced loss takes one shared set of loss arguments. It overrides `_pp_forward_backward_microbatch_group` to keep passing the shared `loss_kwargs` to its runtime, and its existing rejection of per-microbatch loss arguments now also covers its PP path. - **RL trainer:** - Lifts the PP restriction. Context parallelism still raises, because per-token loss arguments are not sharded along the sequence yet. - The batcher returns `TrainerStepBatch.microbatch_groups` (`[num_groups][num_pp_microbatches][dp_degree]`), so each group runs as one pipeline step. The controller sends each DP rank its grouped column; the Monarch actor system now slices the trainer ranks as `(pp, dp, cp, tp)` so a DP rank's slice spans every pipeline stage. - Ranks without the last stage return no metrics, and the controller takes the result from a rank that has it. V-style schedules (ZBV, DualPipeV) put the last stage on the first PP rank, so this does not assume a fixed rank. - RDMA microbatch transfer (`async_loop.batcher.rdma_min_tensor_bytes`, off by default) keeps the group structure, but is rejected together with PP for now: its prefetcher reads one microbatch per group. - Every stage publishes its partial state dict into the single `model_state_dict` key, so generators do not depend on the trainer PP layout. - **CI:** new 8-GPU integration test `rl_grpo_pp2_interleaved1f1b_fsdp2_gen_tp2`: Qwen3-0.6B, trainer PP=2 with Interleaved1F1B (two stages per rank) x FSDP=2, two TP=2 generators, untied embeddings. ## Test plan - `tests/unit_tests/cpu/test_trainer.py`, `tests/unit_tests/cpu/test_pipeline_parallel.py`, and GraphTrainer's `test_trace_module.py` and `test_graph_pp_runner.py` pass on the 2026-10-07 CPU nightly with pytorch/pytorch#200238 applied. One GraphPP test fails because the optional `dist_moe` package is not installed, which is unrelated. - RL CPU unit tests pass locally with vLLM stubbed out (no real vLLM on that host); the per-file failure set matches `main`. The tests that spawn Monarch processes (`test_batcher_actor.py`, the multi-rank RDMA test) time out on that host on `main` too, so CI covers them. - Not yet run on this version: the 8-GPU integration test. It needs vLLM plus the PyTorch change; CI covers it once #200238 is in the nightly. - An earlier version of this PR, which used an RL-side workaround instead of the PyTorch change, ran an 8-step deterministic batch-invariant run where PP=2 x FSDP=2 matched no-PP FSDP=2 bit for bit on loss, entropy, and reward, with `logprob_diff/max = 0`. grad_norm differed by 1 ULP at one step. This needs re-running on this version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack (top to bottom):
Integrate Titan to optionally use the new locally cached routing plan. Currently, we look up and creating the routing plan every time weights need to be pulled on the generator. This change speeds up weight transfer by dispatching the requests faster. This also unblocks features in Titan e.g. pipeline parallel that need merged state_dict's from multiple trainers and dtype conversion inside torchstore.
API Changes
ts.initialize()that initializes torchstore in the new mode - a lightweight API that spawns ts actorsts.client(role=...)- this tells ts who stores the data and who needs to get the dataHow it works
There is some metadata exchange that happens lazily on the first
get_state_dictandput_state_dictFirst
put_state_dictThe trainer ts clients send state dict metadata to a coordinator
First
get_state_dictThe generator ts clients