diff --git a/torch_npu/csrc/InitNpuBindings.cpp b/torch_npu/csrc/InitNpuBindings.cpp index d42d78b52c..c433163da8 100644 --- a/torch_npu/csrc/InitNpuBindings.cpp +++ b/torch_npu/csrc/InitNpuBindings.cpp @@ -73,18 +73,9 @@ PyObject * THPModule_npu_shutdown(PyObject * /* unused */) Py_RETURN_NONE; } -// Callback for python part. Used for additional initialization of python classes -static PyObject * THPModule_initExtension(PyObject *_unused, PyObject *shm_manager_path) { - HANDLE_TH_ERRORS - torch_npu::utils::_initialize_python_bindings(); - Py_RETURN_NONE; - END_HANDLE_TH_ERRORS -} - // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays) static PyMethodDef TorchNpuMethods[] = { {"_npu_shutdown", (PyCFunction)THPModule_npu_shutdown, METH_NOARGS, nullptr}, - {"_initExtension", THPModule_initExtension, METH_NOARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; @@ -111,6 +102,7 @@ PyObject* initModule(){ AddPyMethodDefs(methods, torch_npu::profiler::profiler_functions()); AddPyMethodDefs(methods, torch_npu::distributed::python_functions()); AddPyMethodDefs(methods, torch_npu::utils::tensor_functions()); + AddPyMethodDefs(methods, torch_npu::utils::npu_extension_functions()); static struct PyModuleDef torchnpu_module = { PyModuleDef_HEAD_INIT, "torch_npu._C", diff --git a/torch_npu/csrc/utils/TensorType.cpp b/torch_npu/csrc/utils/TensorType.cpp index ba94d4d5bf..bbc5b4f8fc 100644 --- a/torch_npu/csrc/utils/TensorType.cpp +++ b/torch_npu/csrc/utils/TensorType.cpp @@ -305,5 +305,23 @@ static void py_bind_tensor_types(const std::vector& tensor_types) } } +// Callback for python part. Used for additional initialization of python classes +static PyObject * THPModule_initExtension(PyObject *_unused, PyObject *noargs) { + HANDLE_TH_ERRORS + _initialize_python_bindings(); + Py_RETURN_NONE; + END_HANDLE_TH_ERRORS +} + +// autograd methods on torch._C +static PyMethodDef TorchNpuExtensionMethods[] = { + {"_initExtension", (PyCFunction)THPModule_initExtension, METH_NOARGS, nullptr}, + {nullptr, nullptr, 0, nullptr} +}; + +PyMethodDef* npu_extension_functions() { + return TorchNpuExtensionMethods; +} + } } diff --git a/torch_npu/csrc/utils/TensorType.h b/torch_npu/csrc/utils/TensorType.h index a241085128..282b7eadff 100644 --- a/torch_npu/csrc/utils/TensorType.h +++ b/torch_npu/csrc/utils/TensorType.h @@ -28,5 +28,7 @@ namespace utils { // torch.npu.DoubleTensor, etc. and binds them in their containing modules. void _initialize_python_bindings(); +PyMethodDef* npu_extension_functions(); + } }