-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Added annotation typing to models._utils #2854
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @frgfm, thanks a lot for the PR! Could you please split this PR into multiple as it is very hard to review with that many changes. I think it would be best to do a separate PR for every model / file.
I've reviewed the first three files and found a couple of things.
c06a7dc
to
159bc78
Compare
@pmeier sure, I updated this PR to focus on |
That is alright. I'll go through them one by one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy
CI is failing with
torchvision/models/_utils.py:60: error:
Signature of "forward" incompatible with supertype "ModuleDict" [override]
def forward(self, x: torch.Tensor) ->...
@frgfm Removing the annotation is not the way to go here. Either fix it or if it is unfixable (which might be the case here) use the correct annotations and add a |
The test failures are related. I'll look into it and get back to you. |
@frgfm It seems torchscript is the offender here. I suspect it can't handle the If it is I'm not sure to move forward. We can't make torchscript and |
@pmeier Yes, I figured out the same thing yesterday unfortunately.
Let me know which way you prefer to proceed with! |
In general torchscript > mypy holds. Thus, while the type hints are nice to have, passing tests for torchscript is a requirement. Could you simply remove the |
Yes. The situation with torchscript is delicate, and if we need to chose between mypy and torchscript, torchscript wins. In general, all torchvision models already have type annotation in the forward because they all support torchscript. The difference with mypy is that torchscript assumes that
So if you want to play safe, I would say to only add type annotations to the constructor of the models, or the model builder functions. This way it won't affect torchscript, but mypy won't probably be happy either. Which means that it might be hard to enable full mypy testing to the models. |
Right now, we allow untyped definitions. Thus, if we simply remove the annotations from
@frgfm In that case you could simply revert the last two commits and this PR should be ready. |
f19fda4
to
2ae0057
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks a lot @frgfm. Note that the further process will be delayed, since we are currently preparing the next release of torchvision
.
Should I update
to
though? |
Yes that would be nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
* style: Added typing in models._utils * fix: Removed non-necessary import * fix: Removed type annotation of forward method * refactor: Removed un-necessary import
* style: Added typing in models._utils * fix: Removed non-necessary import * fix: Removed type annotation of forward method * refactor: Removed un-necessary import
Hello folks 👋
As per #2025, annotation typing are welcome in torchvision. So I started with
torchvision.models._utils
in this PR. A few points of attention:Callable[..., nn.Module]
for module constructors (passingBatchNorm2d
for instance), I'm unsure whether that is good choice? any recommendation?Any feedback is welcome!