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 type annotations to torch.nn.modules.module #49045

Closed
wants to merge 7 commits into from
Closed

add type annotations to torch.nn.modules.module #49045

wants to merge 7 commits into from

Conversation

guilhermeleobas
Copy link
Collaborator

Fixes #49044

@guilhermeleobas guilhermeleobas added the module: typing Related to mypy type annotations label Dec 8, 2020
@guilhermeleobas guilhermeleobas self-assigned this Dec 8, 2020
@facebook-github-bot facebook-github-bot added cla signed oncall: distributed Add this issue/PR to distributed oncall triage queue fx labels Dec 8, 2020
@dr-ci
Copy link

dr-ci bot commented Dec 8, 2020

💊 CI failures summary and remediations

As of commit b9382f2 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

This comment has been revised 33 times.

@codecov
Copy link

codecov bot commented Dec 9, 2020

Codecov Report

Merging #49045 (b9382f2) into master (4774c68) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #49045      +/-   ##
==========================================
- Coverage   80.72%   80.72%   -0.01%     
==========================================
  Files        1904     1904              
  Lines      206764   206764              
==========================================
- Hits       166908   166907       -1     
- Misses      39856    39857       +1     

@guilhermeleobas guilhermeleobas marked this pull request as ready for review December 9, 2020 15:38
@H-Huang H-Huang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Dec 10, 2020
@rgommers
Copy link
Collaborator

@guilhermeleobas could you also add comments here about the ignores you added? That helps both with review (reproducing the failures and using reveal_type is my alternative), and when the next person has to touch that bit of code.

@rgommers
Copy link
Collaborator

Also, in your next commit message, can you add that it closes gh-48640?

@guilhermeleobas
Copy link
Collaborator Author

Hi @rgommers, thanks for the review. I've addressed your comments

Copy link
Collaborator

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks @guilhermeleobas.

CI notifications seem stuck, but CI is done - see https://app.circleci.com/pipelines/github/pytorch/pytorch?branch=pull%2F49045. Failures are unrelated.

Comment on lines 91 to 93
# Type ignore here is required because "n" and "p" have different types
# a few lines above
for n, p in self.root.named_buffers(): # type: ignore[assignment]
Copy link
Contributor

Choose a reason for hiding this comment

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

why cant we just use different variable names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that works too

load = None # break load->load reference cycle
# instruction "load = None" => break load->load reference cycle
# type ignore[...] is required because mypy isn't happy with the redef of "load"
load = None # type: ignore[assignment]
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not python expert. but cant we use del load to remove the function reference itself? (after all the load has been done, yes?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes!

@guilhermeleobas
Copy link
Collaborator Author

Do not merge this PR until one checks if the annotations introduce any regression. See:
#49564 (comment)

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@walterddr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

picky back on this PR - i dont think there's any additional item that needs to be test with JIT-ability for this change. am I missing any? @malfet

@@ -279,7 +279,7 @@ def parameters(self, recurse: bool = True) -> Iterator[Parameter]:

def named_parameters( # type: ignore[return]
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we remove this type ignore as well since we fixed the return Parameter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

torch/distributed/nn/api/remote_module.py:280: error: Missing return statement  [return]

Copy link
Contributor

Choose a reason for hiding this comment

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

lol. Got it.

@guilhermeleobas guilhermeleobas marked this pull request as ready for review January 8, 2021 16:50
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@walterddr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

looks good. I dont see any additional JIT test required.

@walterddr
Copy link
Contributor

actually please rebase master --> seems like merge conflict is preventing fb internal CI to run

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@walterddr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@walterddr merged this pull request in 5f8e1a1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed Merged module: typing Related to mypy type annotations oncall: distributed Add this issue/PR to distributed oncall triage queue open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable torch.nn.modules.module typechecks during CI
6 participants