Skip to content

Fix mypy errors in pytorch_lightning/strategies/sharded.py #14184

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

Merged
merged 6 commits into from
Aug 27, 2022

Conversation

lijm1358
Copy link
Contributor

@lijm1358 lijm1358 commented Aug 12, 2022

What does this PR do?

Fixes mypy typing errors in pytorch_lightning/strategies/sharded.py in #13445

src/pytorch_lightning/strategies/sharded.py:55: error: Cannot determine type of "_rank_0_will_call_children_scripts"  [has-type]
src/pytorch_lightning/strategies/sharded.py:59: error: Item "None" of "Optional[Accelerator]" has no attribute "setup"  [union-attr]
src/pytorch_lightning/strategies/sharded.py:68: error: Argument 1 to "apply" of "LayerSync" has incompatible type "Optional[Module]"; expected Module  [arg-type]
src/pytorch_lightning/strategies/sharded.py:77: error: Item "None" of "Optional[Module]" has no attribute "trainer"  [union-attr]
src/pytorch_lightning/strategies/sharded.py:77: error: Argument 1 to "setup_optimizers" of "Strategy" has incompatible type "Union[Tensor, Module, Any]"; expected "Trainer"  [arg-type]
src/pytorch_lightning/strategies/sharded.py:79: error: Argument 1 to "_LightningModuleWrapperBase" has incompatible type "Optional[Module]"; expected "Union[LightningModule, _LightningPrecisionModuleWrapperBase, None]"  [arg-type]
src/pytorch_lightning/strategies/sharded.py:101: error: Item "Tensor" of "Union[Tensor, Module]" has no attribute "state"  [union-attr]
src/pytorch_lightning/strategies/sharded.py:101: error: Item "Tensor" of "Union[Any, Tensor, Module]" has no attribute "fn"  [union-attr]
src/pytorch_lightning/strategies/sharded.py:104: error: Argument 1 to "_reinit_optimizers_with_oss" of "DDPShardedStrategy" has incompatible type "List[Optimizer]"; expected "List[Union[Optimizer, LightningOptimizer]]"  [arg-type]
src/pytorch_lightning/strategies/sharded.py:104: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
src/pytorch_lightning/strategies/sharded.py:104: note: Consider using "Sequence" instead, which is covariant
src/pytorch_lightning/strategies/sharded.py:123: error: Return type "Optional[Dict[Any, Any]]" of "optimizer_state" incompatible with return type "Dict[str, Tensor]" in supertype "Strategy"  [override]
src/pytorch_lightning/strategies/sharded.py:130: error: Function is missing a type annotation  [no-untyped-def]
src/pytorch_lightning/strategies/sharded.py:153: error: Function is missing a return type annotation  [no-untyped-def]
src/pytorch_lightning/strategies/sharded.py:153: note: Use "-> None" if function does not return a value
Found 12 errors in 1 file (checked 223 source files)

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 Aug 12, 2022
@akihironitta akihironitta added code quality community This PR is from the community labels Aug 12, 2022
@lijm1358 lijm1358 marked this pull request as ready for review August 12, 2022 13:39
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.

Thx!!

@awaelchli awaelchli added this to the pl:1.8 milestone Aug 12, 2022
@mergify mergify bot added the ready PRs ready to be merged label Aug 14, 2022
@otaj otaj mentioned this pull request Aug 15, 2022
52 tasks
@mergify mergify bot added has conflicts and removed ready PRs ready to be merged labels Aug 26, 2022
@mergify mergify bot added ready PRs ready to be merged and removed has conflicts ready PRs ready to be merged labels Aug 26, 2022
@otaj otaj enabled auto-merge (squash) August 26, 2022 12:44
@otaj otaj merged commit 03f2f32 into Lightning-AI:master Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality community This PR is from the community 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.

5 participants