Skip to content

Conversation

@donlapark
Copy link
Contributor

@donlapark donlapark commented Jul 25, 2022

What does this PR do?

Fixes mypy errors in pytorch_lightning/strategies/deepspeed.py as addressed in #13445.

The code suggests that lightning_model.training is always assumed to have type pl.Trainer and not None. However, mypy does not know this and throw out an error whenever lightning_model.training is called.

In addition, mypy seems to not recognize hasattr as mentioned in this issue, causing it to throw an error on the following line (671-672) without #type: ignore:

if hasattr(train_dataloader, "batch_sampler"):
    batch_size = train_dataloader.batch_sampler.batch_size  # type: ignore[union-attr]

Does your PR introduce any breaking changes? If yes, please list them.

Before submitting

  • Was this discussed/approved 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:

  • 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

Did you have fun?

Make sure you had fun coding 🙃

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Jul 25, 2022
@donlapark donlapark changed the title Fixes typing deepspeed Fixes various typing errors in pytorch_lightning/strategies/deepspeed.py Jul 25, 2022
@otaj otaj mentioned this pull request Jul 25, 2022
52 tasks
@codecov
Copy link

codecov bot commented Jul 25, 2022

Codecov Report

Merging #13832 (6c1cbd7) into master (a90ef3b) will increase coverage by 27%.
The diff coverage is 71%.

@@            Coverage Diff            @@
##           master   #13832     +/-   ##
=========================================
+ Coverage      49%      76%    +27%     
=========================================
  Files         332      332             
  Lines       26000    26186    +186     
=========================================
+ Hits        12728    19848   +7120     
+ Misses      13272     6338   -6934     

@otaj
Copy link
Contributor

otaj commented Jul 26, 2022

Hi @donlapark, it seems, that if you remove "pytorch_lightning.strategies.deepspeed" from pyproject.toml file, not many errors go away. I pushed the change with removal of the file from mypy ignoring so you can easily see them.

Copy link
Contributor

@rohitgr7 rohitgr7 left a comment

Choose a reason for hiding this comment

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

Great work!

BTW, you can also add all suggestions in a batch and commit them at once inside the PR's Files changed section.

ref: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/incorporating-feedback-in-your-pull-request

@mergify mergify bot added the ready PRs ready to be merged label Jul 26, 2022
@donlapark
Copy link
Contributor Author

Wow, I should have known that. Thanks for the tip!

@otaj otaj enabled auto-merge (squash) July 27, 2022 07:37
@otaj otaj added this to the pl:1.6.x milestone Jul 27, 2022
Copy link
Contributor

@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!

@otaj otaj merged commit 25de488 into Lightning-AI:master Jul 27, 2022
@donlapark donlapark deleted the fixes_typing_deepspeed branch September 7, 2022 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pl Generic label for PyTorch Lightning package ready PRs ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants