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

Add Deepspeed Zero 3 MiCS support (Issues #20378) #20461

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

Conversation

hehepig4
Copy link

@hehepig4 hehepig4 commented Dec 3, 2024

What does this PR do?

After deepspeed 0.9.2, they provided Mics support, which can specify how to split parameters across devices in Zero stage 3 reference.

To activate MiCS, users should add 'mics_shard_size' in deepspeed config, and use 'deepspeed.zero.MiCS_Init' instead of 'deepspeed.zero.Init' when initializing models. Issues occur when:

  1. Specify mics_shard_size>0 while using deepspeed.zero.Init causes exceptions.

The core changes are done by altering zero.Init in DeepSpeedStrategy.model_sharded_context (line 519 in lightning.pytorch.strategies.deepspeed.py) when detecting 'mics_shard_size' in deepspeed zero_optmization config.

Fixes & adds support for #20378

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--20461.org.readthedocs.build/en/20461/

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Dec 3, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 88%. Comparing base (60289d7) to head (87eefdc).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #20461   +/-   ##
=======================================
- Coverage      88%      88%   -0%     
=======================================
  Files         267      267           
  Lines       23382    23389    +7     
=======================================
  Hits        20479    20479           
- Misses       2903     2910    +7     

@lantiga
Copy link
Collaborator

lantiga commented Dec 5, 2024

This is great, thanks for the contribution @hehepig4

@lantiga
Copy link
Collaborator

lantiga commented Dec 5, 2024

let's see how CI goes and we can proceed

@lantiga
Copy link
Collaborator

lantiga commented Dec 5, 2024

In the meantime @hehepig4, would you be willing to add a mention to this in the relevant docs section?

https://github.com/Lightning-AI/pytorch-lightning/blob/master/docs/source-pytorch/advanced/model_parallel/deepspeed.rst

Also ideally we could make the same exact change in Fabric as well:
https://github.com/Lightning-AI/pytorch-lightning/blob/master/src/lightning/fabric/strategies/deepspeed.py#L376

@hehepig4
Copy link
Author

hehepig4 commented Dec 6, 2024

Thanks! I will first work on docs, then fabric.

@github-actions github-actions bot added docs Documentation related fabric lightning.fabric.Fabric labels Dec 6, 2024
Copy link
Collaborator

@lantiga lantiga left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the updates. I see CI is going out of memory, I need to further investigate.

docs/source-pytorch/advanced/model_parallel/deepspeed.rst Outdated Show resolved Hide resolved
src/lightning/pytorch/strategies/deepspeed.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation related fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package strategy: deepspeed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants