Skip to content
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

Flexible and easy to use HSDP setting #19504

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

Liyang90
Copy link
Contributor

@Liyang90 Liyang90 commented Feb 20, 2024

What does this PR do?

Fixes #19502

It allows users to provide device_mesh as a tuple to the FSDPStrategy.

The test case for hybrid fsdp strategy would be broken, because _init_sharding_strategy is moved out of the __init__ function.

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--19504.org.readthedocs.build/en/19504/

@github-actions github-actions bot added fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package labels Feb 20, 2024
@Liyang90 Liyang90 marked this pull request as ready for review March 5, 2024 00:11
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 42.85714% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 58%. Comparing base (76b691d) to head (9d7dfbe).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #19504     +/-   ##
=========================================
- Coverage      82%      58%    -24%     
=========================================
  Files         424      419      -5     
  Lines       34919    34852     -67     
=========================================
- Hits        28628    20127   -8501     
- Misses       6291    14725   +8434     

@Liyang90 Liyang90 changed the title [DRAFT] Flexible and easy to use HSDP setting Flexible and easy to use HSDP setting Mar 7, 2024
@awaelchli awaelchli added community This PR is from the community feature Is an improvement or enhancement strategy: fsdp Fully Sharded Data Parallel labels Mar 8, 2024
@awaelchli awaelchli self-assigned this Mar 8, 2024
@awaelchli awaelchli added this to the 2.3 milestone Mar 8, 2024
Copy link
Member

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

Great job. Looking forward to this feature.

if isinstance(self._fsdp_kwargs.get("device_mesh"), tuple):
from torch.distributed.device_mesh import init_device_mesh

self._fsdp_kwargs["device_mesh"] = init_device_mesh("cuda", self._fsdp_kwargs["device_mesh"])
Copy link
Member

Choose a reason for hiding this comment

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

Since the tuple specification is a feature of Lightning, we should list the device_mesh parameter explicitly in the init args (see the docstring I added). The kwargs are for things that we pass down to FSDP directly.

So I suggest to set self.device_mesh and update this attribute here to the actual DeviceMesh 😃

Copy link
Contributor Author

@Liyang90 Liyang90 Mar 13, 2024

Choose a reason for hiding this comment

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

If device_mesh is separated from kwargs, we will fail the check in _init_sharding_strategy in the self.__init__.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed now. @awaelchli could you take a look again?

@Liyang90 Liyang90 requested a review from Borda as a code owner April 18, 2024 18:32
@npuichigo
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community This PR is from the community fabric lightning.fabric.Fabric feature Is an improvement or enhancement has conflicts pl Generic label for PyTorch Lightning package strategy: fsdp Fully Sharded Data Parallel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow flexible and easy to configure HSDP
4 participants