__init__.py 1016 B

123456789101112131415161718192021222324
  1. import warnings
  2. # NOTE: we have to import python protobuf here **before** we load cpp extension.
  3. # Otherwise it breaks under certain build conditions if cpp implementation of
  4. # protobuf is used. Presumably there's some registry in protobuf library and
  5. # python side has to initialize the dictionary first, before static
  6. # initialization in python extension does so. Otherwise, duplicated protobuf
  7. # descriptors will be created and it can lead to obscure errors like
  8. # "Parameter to MergeFrom() must be instance of same class:
  9. # expected caffe2.NetDef got caffe2.NetDef."
  10. #
  11. # This has to be done for all python targets, so listing them here
  12. try:
  13. from caffe2.proto import caffe2_pb2, metanet_pb2, torch_pb2
  14. except ImportError:
  15. warnings.warn('Caffe2 support is not enabled in this PyTorch build. '
  16. 'Please enable Caffe2 by building PyTorch from source with `BUILD_CAFFE2=1` flag.')
  17. raise
  18. try:
  19. from caffe2.caffe2.fb.session.proto import session_pb2
  20. except ImportError:
  21. pass