From 08cc10324e237c5c6d80cbb84fff215c7dade3d8 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Mon, 11 Jan 2021 10:46:17 +0800 Subject: [PATCH] fix(imperative): fix persistent_cache GitOrigin-RevId: 8f7bb5899f91c9350cb7dd9a3a4dffac29784d5d --- imperative/python/megengine/__init__.py | 1 - imperative/python/src/helper.h | 2 +- imperative/python/src/tensor.cpp | 11 ++++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/imperative/python/megengine/__init__.py b/imperative/python/megengine/__init__.py index aac03103..f5749183 100644 --- a/imperative/python/megengine/__init__.py +++ b/imperative/python/megengine/__init__.py @@ -93,7 +93,6 @@ _persistent_cache_impl_ins.reg() atexit.register(_full_sync) del _set_fork_exec_path_for_timed_func -del _persistent_cache_impl_ins # subpackages import megengine.autodiff diff --git a/imperative/python/src/helper.h b/imperative/python/src/helper.h index b9f61e3d..8df0b5e3 100644 --- a/imperative/python/src/helper.h +++ b/imperative/python/src/helper.h @@ -366,7 +366,7 @@ namespace detail { return true; } static handle cast(mgb::PersistentCache::Blob blob, return_value_policy /* policy */, handle /* parent */) { - return bytes((const char*)blob.ptr, blob.size); + return bytes((const char*)blob.ptr, blob.size).release(); } }; diff --git a/imperative/python/src/tensor.cpp b/imperative/python/src/tensor.cpp index eec79e74..947cb271 100644 --- a/imperative/python/src/tensor.cpp +++ b/imperative/python/src/tensor.cpp @@ -421,8 +421,10 @@ PyObject* TensorWrapper::numpy() { } return np_val.release().ptr(); } - - auto&& hv = interpreter_for_py->get_value(m_tensor->m_handle.get()); + auto&& hv = [&]() { + py::gil_scoped_release _; + return interpreter_for_py->get_value(m_tensor->m_handle.get()); + }(); auto arr = py::reinterpret_steal(npy::ndarray_from_tensor(hv, npy::ShareType::TRY_SHARE)); if (!arr) { PyErr_SetString(PyExc_ValueError, "tensor invalid"); @@ -492,7 +494,10 @@ PyObject* TensorWrapper::_dev_tensor(){ if (m_tensor->m_trace_info.recording && !skip_tracing) { PyObject_SetAttrString(m_tensor->m_trace_info.trace_mixin_info, "data_read", py::cast(true).release().ptr()); } - auto dev_tensor = interpreter_for_py->get_dev_tensor(m_tensor->m_handle.get()); + auto dev_tensor = [&](){ + py::gil_scoped_release _; + return interpreter_for_py->get_dev_tensor(m_tensor->m_handle.get()); + }(); return py::cast(dev_tensor).release().ptr(); } -- GitLab