Skip to content

(1/5) Add callback to sync weights before training begins#5319

Open
AmineDiro wants to merge 2 commits intomainfrom
feature/async-grpo-weight-sync-callback
Open

(1/5) Add callback to sync weights before training begins#5319
AmineDiro wants to merge 2 commits intomainfrom
feature/async-grpo-weight-sync-callback

Conversation

@AmineDiro
Copy link
Copy Markdown
Member

@AmineDiro AmineDiro commented Mar 20, 2026

What does this PR do?

  • Introduces the _InitialWeightSyncCallback class to handle the first weight sync.
  • Replaces the manual self._sync_weight() call inside AsyncGRPOTrainer._inner_training_loop with this dedicated callback.
  • Registers the callback in the trainer's init.
  • This ensures vLLM is guaranteed to use the current policy weights (after FSDP wrapping and moving parameters to the GPU) before producing the first batch of samples.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.


Note

Medium Risk
Changes the training startup sequence by moving the first vLLM weight sync and rollout worker start into an on_train_begin callback, which could affect distributed initialization/order and rollout generation timing.

Overview
Ensures the vLLM rollout worker sees the correct policy weights before the first training step by adding _InitialWeightSyncCallback, which runs a one-time _sync_weight() on on_train_begin, starts the rollout worker on the main process, and then unregisters itself.

Removes the previous manual initial sync/start logic from AsyncGRPOTrainer._inner_training_loop, keeping periodic weight syncing via StepIntervalCallback unchanged.

Written by Cursor Bugbot for commit 4bf9211. This will update automatically on new commits. Configure here.

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread trl/experimental/async_grpo/async_grpo_trainer.py
@AmineDiro AmineDiro changed the title Add callback to sync weights before training begins (1/5) Add callback to sync weights before training begins Mar 20, 2026
Copy link
Copy Markdown
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertvillanova curious to know if you think this is a good pattern

The rollout worker should start after initial weight synchronization,
not at the beginning of the training loop. This ensures weights are
properly synced before any rollout generation begins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants