Skip to content

Port NumPy typing testing style to PyTorch#52408

Closed
guilhermeleobas wants to merge 11 commits intopytorch:masterfrom
guilhermeleobas:mypy_tests
Closed

Port NumPy typing testing style to PyTorch#52408
guilhermeleobas wants to merge 11 commits intopytorch:masterfrom
guilhermeleobas:mypy_tests

Conversation

@guilhermeleobas
Copy link
Copy Markdown
Collaborator

@guilhermeleobas guilhermeleobas commented Feb 18, 2021

ref: #16574

@guilhermeleobas guilhermeleobas added the module: typing Related to mypy type annotations label Feb 18, 2021
@guilhermeleobas guilhermeleobas self-assigned this Feb 18, 2021
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Feb 18, 2021

💊 CI failures summary and remediations

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


  • 1/1 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

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

See CircleCI build pytorch_windows_vs2019_py36_cuda10.1_build (1/1)

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

ls: cannot access '/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe': No such file or directory

Folders: 11
Files: 130
Size:       907512
Compressed: 111420
+ mkdir -p 'C:/Program Files/NVIDIA Corporation/NvToolsExt'
+ cp -r NvToolsExt/bin NvToolsExt/docs NvToolsExt/include NvToolsExt/lib NvToolsExt/samples 'C:/Program Files/NVIDIA Corporation/NvToolsExt/'
+ export 'NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\'
+ NVTOOLSEXT_PATH='C:\Program Files\NVIDIA Corporation\NvToolsExt\'
+ ls '/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe'
ls: cannot access '/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe': No such file or directory
+ echo 'CUDA installation failed'
CUDA installation failed
+ mkdir -p /c/w/build-results
+ 7z a 'c:\w\build-results\cuda_install_logs.7z' cuda_install_logs

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
1 folder, 2 files, 3721951 bytes (3635 KiB)


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.

Copy link
Copy Markdown
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, looks great from a first look. I will do a more detailed review later.

Would it make sense to also add a pass/ and a fail/ directory (like NumPy has too) with a couple of tests in each? Or do you prefer to leave that for later.

@rgommers
Copy link
Copy Markdown
Collaborator

Cc @malfet and @walterddr for visibility. This PR introduces a new, more compact and extensive, test style for type annotation tests. As suggested in #16574 (comment). The machinery is largely taken from NumPy, this approach is working well there.

@malfet
Copy link
Copy Markdown
Contributor

malfet commented Feb 23, 2021

@guilhermeleobas can you please rebase your change against https://github.com/pytorch/pytorch/tree/viable/strict ? (to see clean picture on the PR)

@guilhermeleobas
Copy link
Copy Markdown
Collaborator Author

Would it make sense to also add a pass/ and a fail/ directory (like NumPy has too) with a couple of tests in each? Or do you prefer to leave that for later.

@rgommers, I can add both in a later PR.

@guilhermeleobas can you please rebase your change against https://github.com/pytorch/pytorch/tree/viable/strict ? (to see clean picture on the PR)

@malfet, done!

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 24, 2021

Codecov Report

Merging #52408 (7cb370e) into master (7a178a8) will decrease coverage by 0.33%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #52408      +/-   ##
==========================================
- Coverage   80.76%   80.42%   -0.34%     
==========================================
  Files        1975     1975              
  Lines      216841   216841              
==========================================
- Hits       175134   174404     -730     
- Misses      41707    42437     +730     

Copy link
Copy Markdown
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.

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

Copy link
Copy Markdown
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. do we want to add the test into test/run_test.py list and run it on CI?

@rgommers
Copy link
Copy Markdown
Collaborator

looks good. do we want to add the test into test/run_test.py list and run it on CI?

Yes, I think so.

Would it make sense to also add a pass/ and a fail/ directory (like NumPy has too) with a couple of tests in each? Or do you prefer to leave that for later.

@rgommers, I can add both in a later PR.

Sounds good. Another thing that would be good as a follow-up is to get rid of everything in test/type_hint_tests/ by converting those to the test style in this PR.

@malfet
Copy link
Copy Markdown
Contributor

malfet commented Feb 26, 2021

Can you please add this new .py file to run_test.py (PyTorch test framework is not pytest compatible yet, so your PR is essentially a no-op at the moment)

@guilhermeleobas
Copy link
Copy Markdown
Collaborator Author

Done @malfet

Comment thread test/test_typing.py
import shutil
from typing import IO, Dict, List

import pytest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove pytest dependency (as I've mentioned in my previous comment, pytorch test infra is not compatible with it yet)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oops, my bad. Do you know if pytest support is landing in a near future?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove pytest dependency (as I've mentioned in my previous comment, pytorch test infra is not compatible with it yet)

After looking into it, this isn't quite right - there are unconditional import pytest statements in the codebase (see
#11578 (comment)). There's no point spending significant effort rewriting this bit of by now well-tested code. I think the correct solution is to keep this file as is, and:

  • add the file name to USE_PYTEST_LIST in test/run_test.py
  • make the test runnable standalone by, at the end of the file, adding:
if __name__ == '__main__':
    pytest.main([__file__])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the suggestion Ralf. I've put the file on USE_PYTEST_LIST

Comment thread test/test_typing.py Outdated
Comment thread test/test_typing.py
Comment on lines +47 to +48
if os.path.isdir(CACHE_DIR):
shutil.rmtree(CACHE_DIR)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a comment why cache needs to be invalidated before running the tests?
MyPy should be capable of updating the cache if files have changed between the runs, shouldn't it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was also inherited from NumPy source code. But from my personal experience, 99% of the time mypy is capable of invalidating the cache. Only in a few specific scenarios this wasn't true.

Comment thread test/test_typing.py Outdated
Copy link
Copy Markdown
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.

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

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@malfet merged this pull request in cb68039.

@guilhermeleobas guilhermeleobas deleted the mypy_tests branch March 15, 2021 17:47
facebook-github-bot pushed a commit that referenced this pull request Mar 19, 2021
#53167)

Summary:
This is a follow-up PR of #52408 and move/convert all files under `test/type_hint_tests/*.py` to use the new test style.

Pull Request resolved: #53167

Reviewed By: ejguan

Differential Revision: D27081041

Pulled By: walterddr

fbshipit-source-id: 56508083800a5e12a7af88d095ca26229f0df358
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
Summary:
ref: pytorch#16574

Pull Request resolved: pytorch#52408

Reviewed By: anjali411

Differential Revision: D26654687

Pulled By: malfet

fbshipit-source-id: 6feb603d8fb03c2ba2a01468bfde1a9901e889fd
facebook-github-bot pushed a commit that referenced this pull request Apr 15, 2021
Summary:
This is a follow-up PR of #52408 and includes the `pass/` and `fail/` directories.

Pull Request resolved: #54234

Reviewed By: walterddr

Differential Revision: D27681410

Pulled By: malfet

fbshipit-source-id: e6817df77c758f4c1295ea62613106c71cfd3fc3
krshrimali pushed a commit to krshrimali/pytorch that referenced this pull request May 19, 2021
Summary:
This is a follow-up PR of pytorch#52408 and includes the `pass/` and `fail/` directories.

Pull Request resolved: pytorch#54234

Reviewed By: walterddr

Differential Revision: D27681410

Pulled By: malfet

fbshipit-source-id: e6817df77c758f4c1295ea62613106c71cfd3fc3
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
ref: pytorch#16574

Pull Request resolved: pytorch#52408

Reviewed By: anjali411

Differential Revision: D26654687

Pulled By: malfet

fbshipit-source-id: 6feb603d8fb03c2ba2a01468bfde1a9901e889fd
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
pytorch#53167)

Summary:
This is a follow-up PR of pytorch#52408 and move/convert all files under `test/type_hint_tests/*.py` to use the new test style.

Pull Request resolved: pytorch#53167

Reviewed By: ejguan

Differential Revision: D27081041

Pulled By: walterddr

fbshipit-source-id: 56508083800a5e12a7af88d095ca26229f0df358
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
This is a follow-up PR of pytorch#52408 and includes the `pass/` and `fail/` directories.

Pull Request resolved: pytorch#54234

Reviewed By: walterddr

Differential Revision: D27681410

Pulled By: malfet

fbshipit-source-id: e6817df77c758f4c1295ea62613106c71cfd3fc3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants