forked from huawei/mindspore2022
Fix python test case of UT probability failure.
This commit is contained in:
parent
717169f99e
commit
ea5fa78385
|
|
@ -882,7 +882,7 @@ void ClearResAtexit() {
|
|||
pipeline::GetMethodMap().clear();
|
||||
pipeline::ExecutorPy::ClearRes();
|
||||
pipeline::ReclaimOptimizer();
|
||||
pynative::PynativeExecutor::GetInstance()->Clean();
|
||||
pynative::PynativeExecutor::GetInstance()->ClearRes();
|
||||
#ifdef ENABLE_GE
|
||||
transform::DfGraphManager::GetInstance().ClearGraph();
|
||||
transform::DfGraphConvertor::get_adpt_map().clear();
|
||||
|
|
|
|||
|
|
@ -595,7 +595,7 @@ py::tuple RunOp(const py::args &args) {
|
|||
|
||||
void ClearPyNativeSession() { session = nullptr; }
|
||||
|
||||
PynativeExecutor::~PynativeExecutor() { Clean(); }
|
||||
PynativeExecutor::~PynativeExecutor() { ClearRes(); }
|
||||
|
||||
PynativeExecutor::PynativeExecutor() { grad_flag_ = false; }
|
||||
|
||||
|
|
@ -849,17 +849,32 @@ void PynativeExecutor::GradNet(const GradOperationPtr &grad, const py::object &c
|
|||
pipeline::ReclaimOptimizer();
|
||||
}
|
||||
|
||||
void PynativeExecutor::Clear() {
|
||||
MS_LOG(INFO) << "Clear all res";
|
||||
top_g_ = curr_g_ = nullptr;
|
||||
std::stack<FuncGraphPtr>().swap(graph_p_);
|
||||
void PynativeExecutor::Clear(const std::string &flag) {
|
||||
if (flag == "resource") {
|
||||
MS_LOG(INFO) << "Clear res";
|
||||
Clean();
|
||||
return;
|
||||
}
|
||||
MS_LOG(INFO) << "Clear";
|
||||
top_g_ = nullptr;
|
||||
curr_g_ = nullptr;
|
||||
graph_info_map_.clear();
|
||||
std::stack<FuncGraphPtr>().swap(graph_p_);
|
||||
}
|
||||
|
||||
void PynativeExecutor::Clean() {
|
||||
MS_LOG(INFO) << "Clean all res";
|
||||
Clear();
|
||||
grad_flag_ = false;
|
||||
graph_map_.clear();
|
||||
cell_graph_map_.clear();
|
||||
Clear();
|
||||
df_builder_ = nullptr;
|
||||
ad::CleanRes();
|
||||
pipeline::ReclaimOptimizer();
|
||||
}
|
||||
|
||||
void PynativeExecutor::ClearRes() {
|
||||
Clean();
|
||||
resource_.reset();
|
||||
}
|
||||
|
||||
|
|
@ -908,8 +923,8 @@ REGISTER_PYBIND_DEFINE(PynativeExecutor_, ([](const py::module *m) {
|
|||
.def_static("get_instance", &PynativeExecutor::GetInstance, "PynativeExecutor get_instance.")
|
||||
.def("new_graph", &PynativeExecutor::NewGraph, "pynative new a graph.")
|
||||
.def("end_graph", &PynativeExecutor::EndGraph, "pynative end a graph.")
|
||||
.def("grad_net", &PynativeExecutor::GradNet, "pynative grad graph.")
|
||||
.def("clear", &PynativeExecutor::Clear, "pynative clear status.")
|
||||
.def("grad_net", &PynativeExecutor::GradNet, "pynative grad graph.")
|
||||
.def("clear", &PynativeExecutor::Clear, "pynative clear status.")
|
||||
.def("__call__", &PynativeExecutor::Run, py::arg("args"), py::arg("phase") = py::str(""),
|
||||
"Executor run function.")
|
||||
.def("set_grad_flag", &PynativeExecutor::set_grad_flag, py::arg("flag") = py::bool_(false),
|
||||
|
|
|
|||
|
|
@ -68,8 +68,9 @@ class PynativeExecutor : public std::enable_shared_from_this<PynativeExecutor> {
|
|||
void NewGraph(const py::object &cell, const py::args &args);
|
||||
void EndGraph(const py::object &cell, const py::object &out, const py::args &args);
|
||||
void GradNet(const GradOperationPtr &grad, const py::object &cell, const py::object &weights, const py::args &args);
|
||||
void Clear();
|
||||
void Clear(const std::string &flag = "");
|
||||
void Clean();
|
||||
void ClearRes();
|
||||
bool grad_flag() { return grad_flag_; }
|
||||
void set_grad_flag(bool flag) { grad_flag_ = flag; }
|
||||
AnfNodePtr GetInput(const py::object &obj, const py::object &op_mask);
|
||||
|
|
|
|||
|
|
@ -293,8 +293,8 @@ class _PynativeExecutor:
|
|||
def grad(self, grad, obj, weights, *args):
|
||||
self._executor.grad_net(grad, obj, weights, *args)
|
||||
|
||||
def clear(self):
|
||||
self._executor.clear()
|
||||
def clear(self, flag=""):
|
||||
self._executor.clear(flag)
|
||||
|
||||
def set_grad_flag(self, flag):
|
||||
self._executor.set_grad_flag(flag)
|
||||
|
|
|
|||
|
|
@ -186,6 +186,7 @@ class Cell:
|
|||
raise AttributeError("'{}' object has no attribute '{}'.".format(type(self).__name__, name))
|
||||
|
||||
def __del__(self):
|
||||
_pynative_exec.clear("resource")
|
||||
if hasattr(self, "_create_time"):
|
||||
_executor.del_net_res(str(self._create_time))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue