refactor(core/loader): abstract torch.distributed APIs in CheckpointLoader#47
refactor(core/loader): abstract torch.distributed APIs in CheckpointLoader#47ronaldw07 wants to merge 3 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @ronaldw07, 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 refactors the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors DefaultMLFlashpointCheckpointLoader to abstract away direct calls to torch.distributed by using dependency injection for distributed communication functions. This is a solid improvement that will make the code more modular and easier to test. The implementation is clean and follows the stated goal. I have one suggestion to make the new __init__ parameters keyword-only to improve API robustness.
8582a43 to
36266d6
Compare
Add injectable callable parameters to DefaultMLFlashpointCheckpointLoader for get_rank, get_node_local_rank, broadcast_object_list, all_gather_object, and get_world_size, mirroring the pattern already used in DefaultMLFlashpointCheckpointSaver. All parameters default to the corresponding torch.distributed functions, preserving backwards compatibility. This makes the loader easier to test via dependency injection and allows swapping implementations without subclassing or monkey-patching torch.distributed. Closes google#30
3bfb113 to
796be51
Compare
| mock_all_gather.assert_called_once() | ||
| mock_broadcast.assert_not_called() | ||
| args, _ = mock_all_gather.call_args | ||
| self.mock_all_gather.assert_called() |
There was a problem hiding this comment.
should this still be assert_called_once?
g-husam
left a comment
There was a problem hiding this comment.
Thanks for this! Looks good, just need to double check and ensure assertions are not modified, and address lint/build issues
Summary
Closes #30
global_rank_getter,local_rank_getter,broadcast_object_list_func,all_gather_object_func,get_world_size_func) toDefaultMLFlashpointCheckpointLoader.__init__torch.distributedcalls in method bodies with these injected callablestorch.distributedfunctions, preserving full backwards compatibilityDefaultMLFlashpointCheckpointSaverTest plan
torch.distributedNeMoMLFlashpointCheckpointLoaderand other subclasses continue to work unchanged since they callsuper().__init__with only the original positional arguments