pytorch
a8885ee7 - [BE][typing] add caffe2/torch proto stubs (1 of 2) (#52341)

Commit
3 years ago
[BE][typing] add caffe2/torch proto stubs (1 of 2) (#52341) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/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
Author
Parents
Loading