Skip to content

Conversation

@nninept
Copy link
Contributor

@nninept nninept commented Jul 20, 2022

What does this PR do?

Fixes mypy typing errors in pytorch_lightning/utilities/meta.py in #13445.

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 20, 2022
@nninept
Copy link
Contributor Author

nninept commented Jul 20, 2022

While fixing the document, I realized that there is a slight problem with the code file itself.
init_meta function is not fully completed, and there are some kinds of missmatch in return type and parameters.
But this PR is for mypy typing errors, so I simply wrote the comment to ignore about the problems instead of modifying the codes.

@otaj otaj mentioned this pull request Jul 20, 2022
52 tasks
@nninept nninept changed the title Fix mypy errors attributed to pytorch_lightning/utilities/meta.py Fix mypy errors attributed to pytorch_lightning/utilities/meta.py Jul 21, 2022
@otaj
Copy link
Contributor

otaj commented Jul 21, 2022

While fixing the document, I realized that there is a slight problem with the code file itself. init_meta function is not fully completed, and there are some kinds of missmatch in return type and parameters. But this PR is for mypy typing errors, so I simply wrote the comment to ignore about the problems instead of modifying the codes.

Hi @nninept, can you please open a new issue describing it? I have to say, I'm not very familiar with the internals of this file, so with a new issue, there's a better chance, someone more familiar with it will take a look :)

@nninept
Copy link
Contributor Author

nninept commented Jul 22, 2022

While fixing the document, I realized that there is a slight problem with the code file itself. init_meta function is not fully completed, and there are some kinds of missmatch in return type and parameters. But this PR is for mypy typing errors, so I simply wrote the comment to ignore about the problems instead of modifying the codes.

Hi @nninept, can you please open a new issue describing it? I have to say, I'm not very familiar with the internals of this file, so with a new issue, there's a better chance, someone more familiar with it will take a look :)

Sure! I'll open new related issue soon.

@codecov
Copy link

codecov bot commented Jul 23, 2022

Codecov Report

Merging #13763 (13b633e) into master (fff62f0) will decrease coverage by 10%.
The diff coverage is 31%.

❗ Current head 13b633e differs from pull request most recent head c451038. Consider uploading reports for the commit c451038 to get more accurate results

@@            Coverage Diff            @@
##           master   #13763     +/-   ##
=========================================
- Coverage      86%      76%    -10%     
=========================================
  Files         332      332             
  Lines       26127    26050     -77     
=========================================
- Hits        22481    19808   -2673     
- Misses       3646     6242   +2596     

@otaj otaj added this to the pl:1.8 milestone Jul 26, 2022
Comment on lines +294 to +295
if isinstance(obj, Exception):
raise obj
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you taking these changes from upstream?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote this line because init_meta function returns MisconfigurationException when _TORCH_GREATER_EQUAL_1_10 is false.
If the error is returned, obj.materialize would be none. So I thought that it would be better to raise error explicitly

@mergify mergify bot added the ready PRs ready to be merged label Jul 26, 2022
module_fn: Callable[..., Module], *args: Any, **kwargs: Any
) -> Union[Module, MisconfigurationException]:
if not _TORCH_GREATER_EQUAL_1_10:
return MisconfigurationException("`init_meta` is supported from PyTorch 1.10.0")
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering, why it returns an Exception instead of raising it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a bug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified definition line of init_meta function because mypy shows error when conditional function do not have same identical signature.
And original code returns MisconfigurationException, so I followed to return error without additional modify

@otaj otaj enabled auto-merge (squash) July 27, 2022 16:48
auto-merge was automatically disabled August 5, 2022 12:20

Pull request was closed

@awaelchli
Copy link
Contributor

awaelchli commented Aug 5, 2022

@nninept
For your information, we closed this PR because we found a way to not rely on this implementation (#13868). We decided to deprecate the code, so the mypy issues don't need any fixing anymore.

Thanks for working on this!

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.

6 participants