-
Notifications
You must be signed in to change notification settings - Fork 48
Add Synchronizer
#131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Synchronizer
#131
Conversation
Add `group` to `config`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @chenyushuo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a dedicated Synchronizer component to centralize and manage model weight synchronization in a distributed training setup. It significantly enhances the system's flexibility by supporting various synchronization methods (NCCL, checkpoint, state_dict) and styles (fixed, dynamic), abstracting the complexity of inter-component weight updates. The changes involve substantial refactoring of the explorer and trainer's weight management logic to interact with this new central service, alongside minor configuration and dependency updates.
Highlights
- New
SynchronizerComponent: Introduced a newSynchronizerclass (trinity/common/synchronizer.py) as a Ray actor to centralize and manage model weight synchronization between the trainer and explorer. This component handles the coordination and transfer of model state dictionaries. - Enhanced Synchronization Methods and Styles: Expanded synchronization capabilities by adding a new
SyncMethod.STATE_DICTand introducingSyncStylewith options forFIXED,DYNAMIC_BY_TRAINER, andDYNAMIC_BY_EXPLORER. These new options provide greater flexibility in how and when model weights are synchronized across distributed components. - Refactored Model Weight Update Pipeline: The logic for updating model weights in both the
ExplorerandTrainerhas been significantly refactored to leverage the newSynchronizeractor. This includes changes intrinity/explorer/explorer.py,trinity/trainer/trainer.py, and relatedvllmmodel files, abstracting the underlying synchronization mechanism. - Improved Checkpoint and State Dict Management: A new
FSDPCheckpointManager(trinity/trainer/verl/fsdp_checkpoint_manager.py) was added to facilitate the saving and uploading of model state dictionaries to theSynchronizer, particularly for checkpoint-based and direct state dict synchronization methods. - Configuration and Monitoring Enhancements: Added a
groupfield to the mainConfigandTrainerconfigurations, which is now utilized by theMonitor(e.g., Wandb) for better organization and tracking of experiments.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a Synchronizer actor to manage synchronization between the explorer and trainer. The review identifies several critical issues, including potential deadlocks, incorrect use of Ray's async APIs, and a bug where an incorrect model version is used for synchronization. There are also high-severity issues like blocking I/O in an async actor. Addressing these is crucial for the correctness and performance of the new synchronization mechanism. I've also included some medium-severity suggestions for improving maintainability.
….init` to `f"{group}_{role}"`.
2. Rename `SyncMethod.STATE_DICT` to `SyncMethod.MEMORY`.
3. Add `wait_for_saving` when trainer shutdown.
4. Refactor `explorer_status` to `explorer_status_counter` in `Synchronizer` for multi explorer.
5. add "rollout/model_version" to monitor.
6. apply some suggestions made by gemini.
2. Fix shutdown in `both` 3. Refactored the internal status transition logic of `Trainer` and `Explorer` in`Synchronizer`. 4. Avoid duplicate model saving. 5. Bug fix where model was exited before it was saved.
|
/unittest-all |
Summary
Tests
Github Test Reporter by CTRF 💚 |
2. Rename `use_state_dict_weights_update` to `use_nccl_sync` 3. Add more explanation to `fsdp_checkpoint_manager`.
2. Rename `wait_for_saving` to `wait_on_save_thread`.
|
/unittest-all |
Summary
Tests
Github Test Reporter by CTRF 💚 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a centralized Synchronizer class to coordinate model weight synchronization between trainer and explorer components, supporting three synchronization methods (NCCL, checkpoint, memory) and three synchronization styles (fixed, dynamic_by_trainer, dynamic_by_explorer). The implementation also improves checkpoint saving performance by using background threads.
Key changes:
- Introduces the
Synchronizerclass for centralized synchronization management - Adds
groupparameter to monitoring configuration for better experiment organization - Implements threaded checkpoint saving to avoid blocking the training loop
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| trinity/common/synchronizer.py | New centralized synchronizer class implementation |
| trinity/trainer/verl/fsdp_checkpoint_manager.py | Enhanced checkpoint manager with threaded saving and synchronizer integration |
| trinity/trainer/verl_trainer.py | Updated trainer to use synchronizer and new checkpoint methods |
| trinity/trainer/trainer.py | Modified trainer interface to support new synchronization methods |
| trinity/explorer/explorer.py | Updated explorer to use centralized synchronizer |
| trinity/common/config.py | Added group field and synchronizer configuration updates |
| trinity/utils/monitor.py | Added group parameter to monitoring classes |
| trinity/common/constants.py | Added new sync methods and styles enums |
Comments suppressed due to low confidence (1)
trinity/trainer/verl/fsdp_checkpoint_manager.py:109
- The TODO comment indicates that the
load_state_dictoperation should be moved to a background thread to avoid blocking the main execution. This could impact performance during checkpoint loading.
Modified from verl.utils.checkpoint.fsdp_checkpoint_manager.py:save_checkpoint
|
/unittest-all |
|
/unittest-all |
|
/unittest-module-synchronizer |
|
/unittest-module-common |
|
/unittest-module-common |
|
/unittest-all |
Summary
Tests
Github Test Reporter by CTRF 💚 |
|
/unittest-all |
Summary
Tests
Github Test Reporter by CTRF 💚 |
|
Regarding for FSDP.summon_full_params seems not available in FSDP2: |
Description
Synchronizerclass, which supports threeSyncMethod(nccl,checkpointandmemory) and threeSyncStyle(fixed,dynamic_by_traineranddynamic_by_explorer).grouptoconfig.py.Checklist
Please check the following items before code is ready to be reviewed.