Skip to content

[rl] Overlap trainer->generator weight sync with the next training step - #3810

Merged
felipemello1 merged 7 commits into
pytorch:mainfrom
felipemello1:63-overlap-weight-sync
Jun 28, 2026
Merged

felipemello1 merged 7 commits into
pytorch:mainfrom
felipemello1:63-overlap-weight-sync

Conversation

@felipemello1

@felipemello1 felipemello1 commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

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
image

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.

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).
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 28, 2026
Felipe Mello added 5 commits June 27, 2026 22:24
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 tianyu-l 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.

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]:

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.

unambiguous, so prefer shorter names, especially you also have things like start_async_push_pull

Suggested change
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]:

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.

Suggested change
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:

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.

when would it be None? Should we raise if so?

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.

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:

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.

similar

Comment thread torchtitan/experiments/rl/controller.py Outdated
trainer=self.trainer,
generator_router=self.generator_router,
group_buffer=self._group_buffer,
groups_per_train_step=async_loop.num_groups_per_train_step,

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.

let's make name consistent in controller and weight sync manager

from torchtitan.observability import structured_logger as sl


class WeightSyncManager:

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.

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.

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
@felipemello1
felipemello1 merged commit 390ea37 into pytorch:main Jun 28, 2026
7 of 12 checks passed
saforem2 pushed a commit to saforem2/torchtitan that referenced this pull request Jun 28, 2026
…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]>
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Jun 28, 2026
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).
jemitche1 pushed a commit to jemitche1/torchtitan that referenced this pull request Jul 15, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu 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