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 for a few torch.nn.modules #46013

Closed
wants to merge 12 commits into from
Closed

Add type annotations for a few torch.nn.modules #46013

wants to merge 12 commits into from

Conversation

guilhermeleobas
Copy link
Collaborator

Fixes #46012

@guilhermeleobas guilhermeleobas self-assigned this Oct 8, 2020
@guilhermeleobas guilhermeleobas added the module: typing Related to mypy type annotations label Oct 8, 2020
@ngimel ngimel requested a review from zou3519 October 8, 2020 03:45
@ngimel ngimel added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 8, 2020
@@ -18,7 +18,7 @@ def __init__(self, value: float) -> None:
self.value = value

def forward(self, input: Tensor) -> Tensor:
return F.pad(input, self.padding, 'constant', self.value)
return F.pad(input, self.padding, 'constant', self.value) # type: ignore[arg-type]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the ignore necessary here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mypy infers the type of self.padding as Union[Tensor, Module] but F.pad expects padding as a Sequence[int].

torch/nn/modules/padding.py:21: error: Argument 2 to "pad" has incompatible type "Union[Tensor, Module]"; expected "Sequence[int]"  [arg-type]

Replacing # type: ignore[...] by an assertion also crashes pytorch. I think I will defer annotating this module for now since it requires more work

torch/nn/modules/rnn.py Outdated Show resolved Hide resolved
torch/nn/modules/rnn.py Outdated Show resolved Hide resolved
Copy link
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

It looks like some TorchScript tests are failing. TorchScript makes use of the type annotation information

@guilhermeleobas guilhermeleobas marked this pull request as draft October 16, 2020 00:28
@dr-ci
Copy link

dr-ci bot commented Oct 16, 2020

💊 CI failures summary and remediations

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



🕵️ 4 new failures recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See CircleCI build binary_windows_libtorch_3_7_cpu_debug_build (1/4)

Step: "Build" (full log | diagnosis details | 🔁 rerun)

FAILED: caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/core/TensorMethods.cpp.obj
caused by: Failed to read response header
caused by: failed to fill whole buffer
[2574/3801] Building CXX object caffe2\CMakeFiles\torch_cpu.dir\__\aten\src\TH\THGeneral.cpp.obj 
FAILED: caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/TH/THGeneral.cpp.obj  
VX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION /MDd /Z7 /Ob0 /Od /RTC1 /w /bigobj -DCAFFE2_USE_GLOO -DUSE_GCC_GET_CPUID -DUSE_AVX -DUSE_AVX2 -DTH_HAVE_THREAD /Z7 /EHsc /DNOMINMAX /wd4267 /wd4251 /wd4522 /wd4838 /wd4305 /wd4244 /wd4190 /wd4101 /wd4996 /wd4275 /bigobj -openmp:experimental -DCAFFE2_BUILD_MAIN_LIB -DONNX_BUILD_MAIN_LIB -std:c++14 /showIncludes /Focaffe2\CMakeFiles\torch_cpu.dir\__\aten\src\TH\THGeneral.cpp.obj /Fdcaffe2\CMakeFiles\torch_cpu.dir\ /FS -c ..\..\aten\src\TH\THGeneral.cpp 
error: failed to execute compile
caused by: error reading compile response from server
caused by: Failed to read response header
caused by: failed to fill whole buffer
[2575/3801] Building CXX object caffe2\CMakeFiles\torch_cpu.dir\__\aten\src\ATen\core\TensorMethods.cpp.obj 
FAILED: caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/core/TensorMethods.cpp.obj  
N -DHAVE_AVX2_CPU_DEFINITION /MDd /Z7 /Ob0 /Od /RTC1 /w /bigobj -DCAFFE2_USE_GLOO -DUSE_GCC_GET_CPUID -DUSE_AVX -DUSE_AVX2 -DTH_HAVE_THREAD /Z7 /EHsc /DNOMINMAX /wd4267 /wd4251 /wd4522 /wd4838 /wd4305 /wd4244 /wd4190 /wd4101 /wd4996 /wd4275 /bigobj -openmp:experimental -DCAFFE2_BUILD_MAIN_LIB -DONNX_BUILD_MAIN_LIB -std:c++14 /showIncludes /Focaffe2\CMakeFiles\torch_cpu.dir\__\aten\src\ATen\core\TensorMethods.cpp.obj /Fdcaffe2\CMakeFiles\torch_cpu.dir\ /FS -c aten\src\ATen\core\TensorMethods.cpp 
error: failed to execute compile
caused by: error reading compile response from server
caused by: Failed to read response header
caused by: failed to fill whole buffer
ninja: build stopped: subcommand failed. 
CMAKE_PREFIX_PATH=C:\w\b\windows\conda\envs\py37\Lib\site-packages -DCUDA_NVCC_EXECUTABLE=C:\w\b\windows\tmp_bin\randomtemp.exe -DINSTALL_TEST=0 -DJAVA_HOME=C:/Users/circleci/project/.circleci/windows-jni/ -DNUMPY_INCLUDE_DIR=C:\w\b\windows\conda\envs\py37\lib\site-packages\numpy\core\include -DPYTHON_EXECUTABLE=C:\w\b\windows\conda\envs\py37\python.exe -DPYTHON_INCLUDE_DIR=C:\w\b\windows\conda\envs\py37\include -DUSE_CUDA=0 -DUSE_FBGEMM=1 -DUSE_NUMPY=True -DUSE_SCCACHE=1 C:\w\b\windows\pytorch 
cmake --build . --target install --config Debug -- -j 16 
Traceback (most recent call last): 
  File "../tools/build_libtorch.py", line 20, in <module> 

See CircleCI build pytorch_xla_linux_bionic_py3_6_clang9_build (2/4)

Step: "(Optional) Merge target branch" (full log | diagnosis details | 🔁 rerun)

Automatic merge failed; fix conflicts and then commit the result.
CONFLICT (add/add): Merge conflict in .circleci/config.yml 
Auto-merging .circleci/config.yml 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/simple/docker_definitions.py 
Auto-merging .circleci/cimodel/data/simple/docker_definitions.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/pytorch_build_data.py 
Auto-merging .circleci/cimodel/data/pytorch_build_data.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/dimensions.py 
Auto-merging .circleci/cimodel/data/dimensions.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/binary_build_data.py 
Auto-merging .circleci/cimodel/data/binary_build_data.py 
Automatic merge failed; fix conflicts and then commit the result. 

See CircleCI build pytorch_linux_xenial_py3_6_gcc5_4_build (3/4)

Step: "(Optional) Merge target branch" (full log | diagnosis details | 🔁 rerun)

Automatic merge failed; fix conflicts and then commit the result.
CONFLICT (add/add): Merge conflict in .circleci/config.yml 
Auto-merging .circleci/config.yml 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/simple/docker_definitions.py 
Auto-merging .circleci/cimodel/data/simple/docker_definitions.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/pytorch_build_data.py 
Auto-merging .circleci/cimodel/data/pytorch_build_data.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/dimensions.py 
Auto-merging .circleci/cimodel/data/dimensions.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/binary_build_data.py 
Auto-merging .circleci/cimodel/data/binary_build_data.py 
Automatic merge failed; fix conflicts and then commit the result. 

See CircleCI build pytorch_linux_xenial_cuda9_2_cudnn7_py3_gcc5_4_build (4/4)

Step: "(Optional) Merge target branch" (full log | diagnosis details | 🔁 rerun)

Automatic merge failed; fix conflicts and then commit the result.
CONFLICT (add/add): Merge conflict in .circleci/config.yml 
Auto-merging .circleci/config.yml 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/simple/docker_definitions.py 
Auto-merging .circleci/cimodel/data/simple/docker_definitions.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/pytorch_build_data.py 
Auto-merging .circleci/cimodel/data/pytorch_build_data.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/dimensions.py 
Auto-merging .circleci/cimodel/data/dimensions.py 
CONFLICT (add/add): Merge conflict in .circleci/cimodel/data/binary_build_data.py 
Auto-merging .circleci/cimodel/data/binary_build_data.py 
Automatic merge failed; fix conflicts and then commit the result. 

🚧 1 fixed upstream failure:

These were probably caused by upstream breakages that were already fixed.

Please rebase on the viable/strict branch (expand for instructions)

Since your merge base is older than viable/strict, run these commands:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase FETCH_HEAD

Check out the recency history of this "viable master" tracking branch.


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 on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 63 times.

@guilhermeleobas
Copy link
Collaborator Author

Hi @zou3519, thanks for the review. I've marked the PR as draft and will work/experiment a bit more

@codecov
Copy link

codecov bot commented Oct 27, 2020

Codecov Report

Merging #46013 (3ab5183) into master (8339f88) will increase coverage by 33.65%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master   #46013       +/-   ##
===========================================
+ Coverage   35.26%   68.92%   +33.65%     
===========================================
  Files         443      434        -9     
  Lines       56588    56063      -525     
===========================================
+ Hits        19958    38640    +18682     
+ Misses      36630    17423    -19207     

@guilhermeleobas guilhermeleobas marked this pull request as ready for review October 27, 2020 00:59
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.

Thanks @guilhermeleobas, this LGTM modulo adding a comment for the tricky subclassing issue.

torch/nn/modules/rnn.py Show resolved Hide resolved
@guilhermeleobas
Copy link
Collaborator Author

Thanks for the review, @rgommers

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.

LGTM now, and CI failures are all unrelated (connectivity/merge issues).

@rgommers rgommers requested review from ezyang and malfet and removed request for apaszke November 16, 2020 21:58
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.

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

@facebook-github-bot
Copy link
Contributor

@ezyang merged this pull request in ca8b943.

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 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.* typechecks during CI
6 participants