From e0bae0737de237b9b805e8acf1e2f95c0e8afc55 Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Thu, 5 Nov 2020 16:23:18 -0800 Subject: [PATCH] Update on "Add Python declaration of torch._C and torch._C._autograd modules." Differential Revision: [D24761503](https://our.internmc.facebook.com/intern/diff/D24761503) [ghstack-poisoned] --- torch/csrc/distributed/autograd/init.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/torch/csrc/distributed/autograd/init.cpp b/torch/csrc/distributed/autograd/init.cpp index 02c5f277a921..ad6dfa7d8f46 100644 --- a/torch/csrc/distributed/autograd/init.cpp +++ b/torch/csrc/distributed/autograd/init.cpp @@ -23,8 +23,10 @@ PyObject* dist_autograd_init(PyObject* _unused, PyObject* noargs) { } auto torch_C_module = THPObjectPtr(PyImport_ImportModule("torch._C")); - if (!torch_C_module) - return nullptr; + if (!torch_C_module) { + throw python_error(); + } + auto torch_C_m = py::handle(torch_C_module).cast(); auto m = torch_C_m.def_submodule("_distributed_autograd", "distributed autograd bindings");