[FEAT] Support PyTorch DCP for FSDP#497
Conversation
… into sxj/add-fsdp-dcp
Summary of ChangesHello @fishcrap, 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 significantly enhances the checkpointing capabilities for FSDP models by integrating native support for PyTorch Distributed Checkpoint (DCP) format. This change enables more efficient and robust saving and loading of large-scale distributed models and their associated optimizer states, streamlining the training recovery process and ensuring compatibility with modern PyTorch distributed features. Highlights
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 introduces support for PyTorch Distributed Checkpoint (DCP) for FSDP models, which is a valuable feature for efficient checkpointing in large-scale distributed training. The implementation is well-designed, notably with the DCPState wrapper that cleanly integrates with PyTorch's Stateful protocol. The changes in FSDPEngine and RecoverHandler are logical and correctly enable DCP as the new default. The inclusion of comprehensive distributed tests is excellent for ensuring the correctness of this new functionality. I've identified a minor issue in the test implementation regarding hardcoded checkpoint paths that could lead to test flakiness, and I've provided a suggestion to improve its robustness. Overall, this is a solid contribution.
6fbcccd to
cbd31fd
Compare
* add dcp distributed test * use dcp for recover
* add dcp distributed test * use dcp for recover
Description
This PR adds support for PyTorch Distributed Checkpoint (DCP) format for FSDP models, enabling more efficient checkpointing and recovery for large-scale distributed training.
Key changes include:
_save_to_dcp()and_load_from_dcp()methods that use PyTorch's distributed checkpoint API to save/load FSDP2 models along with optimizer statesDCPStateclass inareal/utils/fsdp/checkpoint.pythat implements the PyTorchStatefulprotocol for seamless integration with DCP's save/load APIsareal/utils/recover.pyto use DCP format by default for checkpoint saving and loading during recoverytest_fsdp_dcp.pyandrun_fsdp_dcp_distributed.py) that verify DCP functionality with multiple GPUs and various scenarios including optimizer state persistencetest_train_engine.pyto include DCP save/load testing for all supported enginesBenefits:
Related Issue
N/A
Type of Change
Checklist
jb build docs/gemini review)Breaking Change Details (if applicable):
N/A
Additional Context
N/A
Need help? Check the Contributing Guide or ask in
GitHub Discussions!