Repository navigation
[rl] Overlap trainer->generator weight sync with the next training step - #3810
Conversation
Run push (trainer->store) and pull + buffer-slot release (store->generators) as background tasks via a new WeightSyncManager, joined at two points that keep the single TorchStore key correct: the push before optim mutates weights, and the pull before the next push overwrites the key. Hides the handoff under the next step's fwd/bwd; off-policy staleness is unchanged (release rides on the pull, so new rollouts are born on the fresh weights).
These two awaited regions ran outside any trace span, so they showed up as an unexplained gap between train_step spans in the gantt. Wrap them so the per-step overhead is attributable.
Upstream renamed generator_router.py -> routing/inter_generator_router.py (GeneratorRouter -> InterGeneratorRouter). Re-add the staggering TODO at the new pull fanout and update WeightSyncManager's import/type-hint.
tianyu-l
left a comment
There was a problem hiding this comment.
nice, please address comments before merge
| self._generator_pull_and_release_buffer_slots(version, push_task) | ||
| ) | ||
|
|
||
| async def wait_prev_trainer_weight_push(self) -> list[m.Metric]: |
There was a problem hiding this comment.
unambiguous, so prefer shorter names, especially you also have things like start_async_push_pull
| async def wait_prev_trainer_weight_push(self) -> list[m.Metric]: | |
| async def wait_prev_push(self) -> list[m.Metric]: |
| ) | ||
| ] | ||
|
|
||
| async def wait_prev_generator_weight_pull(self) -> list[m.Metric]: |
There was a problem hiding this comment.
| async def wait_prev_generator_weight_pull(self) -> list[m.Metric]: | |
| async def wait_prev_pull(self) -> list[m.Metric]: |
| ) | ||
|
|
||
| async def wait_prev_trainer_weight_push(self) -> list[m.Metric]: | ||
| if self._trainer_push_task is not None: |
There was a problem hiding this comment.
when would it be None? Should we raise if so?
There was a problem hiding this comment.
only on step 0. I added a NoOp in init and removed the check from the "wait_prev_trainer_weight_push/pull"
| ] | ||
|
|
||
| async def wait_prev_generator_weight_pull(self) -> list[m.Metric]: | ||
| if self._generator_pull_task is not None: |
| trainer=self.trainer, | ||
| generator_router=self.generator_router, | ||
| group_buffer=self._group_buffer, | ||
| groups_per_train_step=async_loop.num_groups_per_train_step, |
There was a problem hiding this comment.
let's make name consistent in controller and weight sync manager
| from torchtitan.observability import structured_logger as sl | ||
|
|
||
|
|
||
| class WeightSyncManager: |
There was a problem hiding this comment.
I know that the scope is somewhat different, but it could cause confusion because of similar names
https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/rl/actors/generator.py#L709
There was a problem hiding this comment.
i tried to find a better name, but didnt like any. I will merge like this for now. Lets revisit it.
- wait_prev_trainer_weight_push/pull -> wait_prev_push/pull - WeightSyncManager param groups_per_train_step -> num_groups_per_train_step - step-0: seed no-op tasks so wait_prev_* never sees None (drop the guards) - TODO(perf): per-generator buffer-slot release
…ep (pytorch#3810) Overlaps push/pull weight sync with trainers next step. For details, check docstring of WeightSyncManager. Understanding the image: We preserve the push->pull order, but we overlap it with trainer. 1st track: generator 2nd track: trainer 3rd track: controller <img width="1660" height="372" alt="image" src="https://github.com/user-attachments/assets/fea3a1ae-3afa-405c-947a-61856f80cab9" /> PS: There are some gaps in the controller. I think its the metrics processor. Time-wise is very small -- this is the 0.6b model and it shouldnt matter for a larger model. But i will add the log and update this graph below. --------- Co-authored-by: Felipe Mello <[email protected]>
Merged upstream/main 0e88661..390ea37 (3 commits) -- all under experiments/rl/ (weight-sync overlap pytorch#3810, Search R1 chunked loss pytorch#3813, generator init race fix pytorch#3809). ezpz does not import from rl/; model/ parallelize/config/trainer surface byte-identical pre/post merge, so no replays and no distributed smoke needed (import surface unchanged).
…ep (pytorch#3810) Overlaps push/pull weight sync with trainers next step. For details, check docstring of WeightSyncManager. Understanding the image: We preserve the push->pull order, but we overlap it with trainer. 1st track: generator 2nd track: trainer 3rd track: controller <img width="1660" height="372" alt="image" src="https://github.com/user-attachments/assets/fea3a1ae-3afa-405c-947a-61856f80cab9" /> PS: There are some gaps in the controller. I think its the metrics processor. Time-wise is very small -- this is the 0.6b model and it shouldnt matter for a larger model. But i will add the log and update this graph below. --------- Co-authored-by: Felipe Mello <[email protected]>
Overlaps push/pull weight sync with trainers next step. For details, check docstring of WeightSyncManager.
Understanding the image: We preserve the push->pull order, but we overlap it with trainer.

1st track: generator
2nd track: trainer
3rd track: controller
PS: There are some gaps in the controller. I think its the metrics processor. Time-wise is very small -- this is the 0.6b model and it shouldnt matter for a larger model. But i will add the log and update this graph below.