Skip to content

Conversation

smacke
Copy link
Contributor

@smacke smacke commented Feb 17, 2021

Summary:
Add type stubs for caffe2 protos and scripts for generating them.

It's worth calling special attention to the following. In order to make DeviceTypes like CPU, CUDA, etc. directly accessible from the caffe2_pb2 module, they are currently freedom-patched into it in caffe2/python/__init__.py. This is not ideal: it would be better if these were autogenerated when the protobuf definitions were created by using allow_alias = true in the DeviceTypeProto definition in caffe2.proto.

However, it is impossible to do this currently without significant effort. The issue is that the generated proto constants would conflict with various constants defined in the C++ caffe2 codebase in caffe2_pb.h. We cannot simply remove these constants and replace them with the caffe2 DeviceTypeProto constants, because a huge portion of code expects at::DeviceType constants defined in core/DeviceType.h (apparently duplicated to avoid having to figure out how to autogenerate the protobuf definitions using cmake for ATen).

Instead, we make a best-effort to add additional definitions in caffe2_pb2.py by looking for any freedom-patched constants in caffe2/python/__init__.py and making sure they have corresponding stubs in the pyi (see gen_proto_typestubs_helper.py).

Test Plan: Make sure CI is green; we're just adding stubs.

Reviewed By: d4l3k

Differential Revision: D26331875

Summary:
Add type stubs for caffe2 protos and scripts for generating them.

It's worth calling special attention to the following. In order to make `DeviceType`s like `CPU`, `CUDA`, etc. directly accessible from the `caffe2_pb2` module, they are currently freedom-patched into it in `caffe2/python/__init__.py`. This is not ideal: it would be better if these were autogenerated when the protobuf definitions were created by using `allow_alias = true` in the `DeviceTypeProto` definition in `caffe2.proto`.

However, it is impossible to do this currently without significant effort. The issue is that the generated proto constants would conflict with various constants defined in the C++ caffe2 codebase in `caffe2_pb.h`. We cannot simply remove these constants and replace them with the caffe2 DeviceTypeProto constants, because a huge portion of code expects `at::DeviceType` constants defined in `core/DeviceType.h` (apparently duplicated to avoid having to figure out how to autogenerate the protobuf definitions using cmake for ATen).

Instead, we make a best-effort to add additional definitions in `caffe2_pb2.py` by looking for any freedom-patched constants in `caffe2/python/__init__.py` and making sure they have corresponding stubs in the pyi (see `gen_proto_typestubs_helper.py`).

Test Plan: Make sure CI is green; we're just adding stubs.

Reviewed By: d4l3k

Differential Revision: D26331875

fbshipit-source-id: 4b439e91e93bcb9b10623a1120bef2e918910414
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Feb 17, 2021

💊 CI failures summary and remediations

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



🕵️ 5 new failures recognized by patterns

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

See CircleCI build pytorch_linux_bionic_py3_8_gcc9_coverage_test1 (1/5)

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

Feb 17 03:19:33 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]" [arg-type]
Feb 17 03:18:03   test_run_mypy (__main__.TestTypeHints)
Feb 17 03:19:33 Runs mypy over all files specified in our mypy configs ... FAIL (89.320s)
Feb 17 03:19:33 
Feb 17 03:19:33 ======================================================================
Feb 17 03:19:33 FAIL [89.320s]: test_run_mypy (__main__.TestTypeHints) [mypy.ini]
Feb 17 03:19:33 Runs mypy over all files specified in our mypy configs
Feb 17 03:19:33 ----------------------------------------------------------------------
Feb 17 03:19:33 Traceback (most recent call last):
Feb 17 03:19:33   File "test_type_hints.py", line 171, in test_run_mypy
Feb 17 03:19:33     self.fail(f"mypy failed: {stdout} {stderr}")
Feb 17 03:19:33 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]"  [arg-type]
Feb 17 03:19:33 Found 1 error in 1 file (checked 1234 source files)
Feb 17 03:19:33  
Feb 17 03:19:33 
Feb 17 03:19:33 ----------------------------------------------------------------------
Feb 17 03:19:33 Ran 2 tests in 98.972s
Feb 17 03:19:33 
Feb 17 03:19:33 FAILED (failures=1)
Feb 17 03:19:33 
Feb 17 03:19:33 Generating XML reports...
Feb 17 03:19:33 Generated XML report: test-reports/python-unittest/TEST-TestTypeHints-20210217031754.xml

See CircleCI build pytorch_linux_xenial_py3_clang5_asan_test1 (2/5)

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

Feb 17 03:14:16 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]" [arg-type]
Feb 17 03:12:41 Test results will be stored in test-reports/python-unittest
Feb 17 03:12:51   test_doc_examples (__main__.TestTypeHints) ... ok (10.534s)
Feb 17 03:14:16   test_run_mypy (__main__.TestTypeHints) ... FAIL (84.378s)
Feb 17 03:14:16 
Feb 17 03:14:16 ======================================================================
Feb 17 03:14:16 FAIL [84.378s]: test_run_mypy (__main__.TestTypeHints) [mypy.ini]
Feb 17 03:14:16 ----------------------------------------------------------------------
Feb 17 03:14:16 Traceback (most recent call last):
Feb 17 03:14:16   File "test_type_hints.py", line 171, in test_run_mypy
Feb 17 03:14:16     self.fail(f"mypy failed: {stdout} {stderr}")
Feb 17 03:14:16 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]"  [arg-type]
Feb 17 03:14:16 Found 1 error in 1 file (checked 1234 source files)
Feb 17 03:14:16  
Feb 17 03:14:16 
Feb 17 03:14:16 ----------------------------------------------------------------------
Feb 17 03:14:16 Ran 2 tests in 94.913s
Feb 17 03:14:16 
Feb 17 03:14:16 FAILED (failures=1)
Feb 17 03:14:16 
Feb 17 03:14:16 Generating XML reports...
Feb 17 03:14:16 Generated XML report: test-reports/python-unittest/TEST-TestTypeHints-20210217031241.xml

See CircleCI build pytorch_linux_xenial_cuda10_2_cudnn7_py3_gcc7_test1 (3/5)

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

Feb 17 03:55:29 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]" [arg-type]
Feb 17 03:54:02 ----------------------------------------------------------------------
Feb 17 03:54:11   test_doc_examples (__main__.TestTypeHints) ... ok (8.562s)
Feb 17 03:55:29   test_run_mypy (__main__.TestTypeHints) ... FAIL (77.903s)
Feb 17 03:55:29 
Feb 17 03:55:29 ======================================================================
Feb 17 03:55:29 FAIL [77.903s]: test_run_mypy (__main__.TestTypeHints) [mypy.ini]
Feb 17 03:55:29 ----------------------------------------------------------------------
Feb 17 03:55:29 Traceback (most recent call last):
Feb 17 03:55:29   File "test_type_hints.py", line 171, in test_run_mypy
Feb 17 03:55:29     self.fail(f"mypy failed: {stdout} {stderr}")
Feb 17 03:55:29 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]"  [arg-type]
Feb 17 03:55:29 Found 1 error in 1 file (checked 1234 source files)
Feb 17 03:55:29  
Feb 17 03:55:29 
Feb 17 03:55:29 ----------------------------------------------------------------------
Feb 17 03:55:29 Ran 2 tests in 86.465s
Feb 17 03:55:29 
Feb 17 03:55:29 FAILED (failures=1)
Feb 17 03:55:29 
Feb 17 03:55:29 Generating XML reports...
Feb 17 03:55:29 Generated XML report: test-reports/python-unittest/TEST-TestTypeHints-20210217035402.xml

See CircleCI build pytorch_linux_bionic_py3_6_clang9_test (4/5)

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

Feb 17 03:10:51 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]" [arg-type]
Feb 17 03:09:28 Test results will be stored in test-reports/python-unittest
Feb 17 03:09:37   test_doc_examples (__main__.TestTypeHints) ... ok (8.704s)
Feb 17 03:10:51   test_run_mypy (__main__.TestTypeHints) ... FAIL (74.472s)
Feb 17 03:10:51 
Feb 17 03:10:51 ======================================================================
Feb 17 03:10:51 FAIL [74.472s]: test_run_mypy (__main__.TestTypeHints) [mypy.ini]
Feb 17 03:10:51 ----------------------------------------------------------------------
Feb 17 03:10:51 Traceback (most recent call last):
Feb 17 03:10:51   File "test_type_hints.py", line 171, in test_run_mypy
Feb 17 03:10:51     self.fail(f"mypy failed: {stdout} {stderr}")
Feb 17 03:10:51 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]"  [arg-type]
Feb 17 03:10:51 Found 1 error in 1 file (checked 1234 source files)
Feb 17 03:10:51  
Feb 17 03:10:51 
Feb 17 03:10:51 ----------------------------------------------------------------------
Feb 17 03:10:51 Ran 2 tests in 83.176s
Feb 17 03:10:51 
Feb 17 03:10:51 FAILED (failures=1)
Feb 17 03:10:51 
Feb 17 03:10:51 Generating XML reports...
Feb 17 03:10:51 Generated XML report: test-reports/python-unittest/TEST-TestTypeHints-20210217030928.xml

See CircleCI build pytorch_linux_xenial_py3_6_gcc5_4_test (5/5)

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

Feb 17 03:15:11 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]" [arg-type]
Feb 17 03:13:50 Test results will be stored in test-reports/python-unittest
Feb 17 03:13:58   test_doc_examples (__main__.TestTypeHints) ... ok (8.433s)
Feb 17 03:15:11   test_run_mypy (__main__.TestTypeHints) ... FAIL (73.424s)
Feb 17 03:15:11 
Feb 17 03:15:11 ======================================================================
Feb 17 03:15:11 FAIL [73.424s]: test_run_mypy (__main__.TestTypeHints) [mypy.ini]
Feb 17 03:15:11 ----------------------------------------------------------------------
Feb 17 03:15:11 Traceback (most recent call last):
Feb 17 03:15:11   File "test_type_hints.py", line 171, in test_run_mypy
Feb 17 03:15:11     self.fail(f"mypy failed: {stdout} {stderr}")
Feb 17 03:15:11 AssertionError: mypy failed: caffe2/contrib/aten/aten_test.py:28: error: Argument 2 to "given" has incompatible type "**Dict[str, object]"; expected "Union[SearchStrategy[Any], InferType]"  [arg-type]
Feb 17 03:15:11 Found 1 error in 1 file (checked 1234 source files)
Feb 17 03:15:11  
Feb 17 03:15:11 
Feb 17 03:15:11 ----------------------------------------------------------------------
Feb 17 03:15:11 Ran 2 tests in 81.857s
Feb 17 03:15:11 
Feb 17 03:15:11 FAILED (failures=1)
Feb 17 03:15:11 
Feb 17 03:15:11 Generating XML reports...
Feb 17 03:15:11 Generated XML report: test-reports/python-unittest/TEST-TestTypeHints-20210217031350.xml

❄️ 1 failure tentatively classified as flaky

but reruns have not yet been triggered to confirm:

See CircleCI build pytorch_linux_bionic_py3_8_gcc9_coverage_test2 (1/1)

Step: "Run tests" (full log | diagnosis details | 🔁 rerun) ❄️

Feb 17 05:21:46 RuntimeError: Process 3 terminated or timed out after 100.07947945594788 seconds
Feb 17 05:21:46 ======================================================================
Feb 17 05:21:46 ERROR [100.130s]: test_backward_without_rpc (__main__.TensorPipeDistAutogradTestWithSpawn)
Feb 17 05:21:46 ----------------------------------------------------------------------
Feb 17 05:21:46 Traceback (most recent call last):
Feb 17 05:21:46   File "/opt/conda/lib/python3.8/site-packages/torch/testing/_internal/common_distributed.py", line 286, in wrapper
Feb 17 05:21:46     self._join_processes(fn)
Feb 17 05:21:46   File "/opt/conda/lib/python3.8/site-packages/torch/testing/_internal/common_distributed.py", line 403, in _join_processes
Feb 17 05:21:46     self._check_return_codes(elapsed_time)
Feb 17 05:21:46   File "/opt/conda/lib/python3.8/site-packages/torch/testing/_internal/common_distributed.py", line 444, in _check_return_codes
Feb 17 05:21:46     raise RuntimeError('Process {} terminated or timed out after {} seconds'.format(i, elapsed_time))
Feb 17 05:21:46 RuntimeError: Process 3 terminated or timed out after 100.07947945594788 seconds
Feb 17 05:21:46 
Feb 17 05:21:46 ----------------------------------------------------------------------
Feb 17 05:21:46 Ran 411 tests in 1454.762s
Feb 17 05:21:46 
Feb 17 05:21:46 FAILED (errors=1, skipped=66)
Feb 17 05:21:46 
Feb 17 05:21:46 Generating XML reports...
Feb 17 05:21:46 Generated XML report: test-reports/dist-gloo/TEST-TensorPipeDdpComparisonTestWithSpawn-20210217045731.xml
Feb 17 05:21:46 Generated XML report: test-reports/dist-gloo/TEST-TensorPipeDdpUnderDistAutogradTestWithSpawn-20210217045731.xml
Feb 17 05:21:46 Generated XML report: test-reports/dist-gloo/TEST-TensorPipeDistAutogradTestWithSpawn-20210217045731.xml

ci.pytorch.org: 1 failed


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.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D26331875

@smacke smacke changed the title [BE][typing] add caffe2/torch proto stubs (1 of 2) [typing] add caffe2/torch proto stubs Feb 17, 2021
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in a8885ee.

smacke added a commit to smacke/pytorch that referenced this pull request Feb 17, 2021
Summary: After adding .pyi stubs for torch / caffe2 protos, there were some mypy false positives (pytorch#52341). We tell mypy to ignore the offending file here.

Test Plan: Let CI run.

Reviewed By: dzhulgakov

Differential Revision: D26490302

fbshipit-source-id: e1eb47d257ddcb613253eea9a305ca08b8935c9e
facebook-github-bot pushed a commit that referenced this pull request Feb 17, 2021
Summary:
Pull Request resolved: #52370

After adding .pyi stubs for torch / caffe2 protos, there were some mypy false positives (#52341). We tell mypy to ignore the offending file here.

Test Plan: Let CI run.

Reviewed By: malfet, dzhulgakov

Differential Revision: D26490302

fbshipit-source-id: 87cdfd7419efdc7abece9ca975a464201732b7a0
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
Summary:
Pull Request resolved: pytorch#52341

Add type stubs for caffe2 protos and scripts for generating them.

It's worth calling special attention to the following. In order to make `DeviceType`s like `CPU`, `CUDA`, etc. directly accessible from the `caffe2_pb2` module, they are currently freedom-patched into it in `caffe2/python/__init__.py`. This is not ideal: it would be better if these were autogenerated when the protobuf definitions were created by using `allow_alias = true` in the `DeviceTypeProto` definition in `caffe2.proto`.

However, it is impossible to do this currently without significant effort. The issue is that the generated proto constants would conflict with various constants defined in the C++ caffe2 codebase in `caffe2_pb.h`. We cannot simply remove these constants and replace them with the caffe2 DeviceTypeProto constants, because a huge portion of code expects `at::DeviceType` constants defined in `core/DeviceType.h` (apparently duplicated to avoid having to figure out how to autogenerate the protobuf definitions using cmake for ATen).

Instead, we make a best-effort to add additional definitions in `caffe2_pb2.py` by looking for any freedom-patched constants in `caffe2/python/__init__.py` and making sure they have corresponding stubs in the pyi (see `gen_proto_typestubs_helper.py`).

Test Plan: Make sure CI is green; we're just adding stubs.

Reviewed By: d4l3k

Differential Revision: D26331875

fbshipit-source-id: 2eea147e5bf393542f558ff8cf6385c47624b770
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
Summary:
Pull Request resolved: pytorch#52370

After adding .pyi stubs for torch / caffe2 protos, there were some mypy false positives (pytorch#52341). We tell mypy to ignore the offending file here.

Test Plan: Let CI run.

Reviewed By: malfet, dzhulgakov

Differential Revision: D26490302

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants