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

make shufflenet and resnet scriptable #1270

Merged
merged 6 commits into from
Sep 2, 2019
Merged

Conversation

eellison
Copy link
Contributor

@eellison eellison commented Aug 28, 2019

ShuffleNet:

  • added type annotations
  • previously branch1 was only conditionally defined

Resnet:

  • need to add downsample to constants so that script can compile when it is None

@@ -34,6 +34,7 @@ def conv1x1(in_planes, out_planes, stride=1):

class BasicBlock(nn.Module):
expansion = 1
__constants__ = ['downsample']
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain a bit why this is a constant? downsample has learnable parameters.

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 can make it an empty sequential instead.

Copy link
Contributor Author

@eellison eellison Aug 28, 2019

Choose a reason for hiding this comment

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

__constants__ only makes it a constant if it's None, otherwise it treats it as a regular submodule. It's a little bit of a confusing api, because we don't currently support Modules as first-class values and typing Optional[Module]. @driazati

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I think I got it. I think I prefer the __constants__ in this case, even though Optional[Module] would be nicer.

@eellison eellison changed the title make shufflenet scriptable make shufflenet and resnet scriptable Aug 28, 2019
@eellison eellison requested a review from driazati August 28, 2019 17:24
@fmassa
Copy link
Member

fmassa commented Aug 29, 2019

CI is failing, probably because we might need to use PyTorch nightly now?

Can you try changing

- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION pytorch scipy -c pytorch
and see if tests work now?

@fmassa
Copy link
Member

fmassa commented Aug 29, 2019

I've merged another PR that changed the CI to use pytorch nightly, so let me re-run the CI

@fmassa fmassa closed this Aug 29, 2019
@fmassa fmassa reopened this Aug 29, 2019
@eellison
Copy link
Contributor Author

@fmassa thanks!

@fmassa
Copy link
Member

fmassa commented Aug 30, 2019

@eellison there is a linter error due to the type annotation not finding Tensor. Can you look into fixing it, either by doing torch.Tensor or by making the linter less strict (or something else)?

@eellison
Copy link
Contributor Author

@eellison there is a linter error due to the type annotation not finding Tensor. Can you look into fixing it, either by doing torch.Tensor or by making the linter less strict (or something else)?

yep will do

@codecov-io
Copy link

codecov-io commented Aug 30, 2019

Codecov Report

Merging #1270 into master will decrease coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1270      +/-   ##
==========================================
- Coverage   65.56%   65.48%   -0.08%     
==========================================
  Files          74       74              
  Lines        5784     5786       +2     
  Branches      884      884              
==========================================
- Hits         3792     3789       -3     
- Misses       1726     1730       +4     
- Partials      266      267       +1
Impacted Files Coverage Δ
torchvision/models/resnet.py 88.41% <100%> (+0.07%) ⬆️
torchvision/models/shufflenetv2.py 85.71% <100%> (+0.17%) ⬆️
torchvision/transforms/functional.py 70.23% <0%> (-1.16%) ⬇️
torchvision/transforms/transforms.py 80.35% <0%> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93bceaf...e14d72d. Read the comment docs.

@@ -51,6 +52,8 @@ def __init__(self, inp, oup, stride):
nn.BatchNorm2d(branch_features),
nn.ReLU(inplace=True),
)
else:
self.branch1 = nn.Sequential()
Copy link
Member

Choose a reason for hiding this comment

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

I'm merging this in, but it would be great if torchscript could support Optional[nn.Module].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants