!1999 Fix python test case of UT probability failure.

Merge pull request !1999 from rick_sanchez/huangyong
pull/1999/MERGE
mindspore-ci-bot 5 years ago committed by Gitee
commit 871d6524c3

@ -882,7 +882,7 @@ void ClearResAtexit() {
pipeline::GetMethodMap().clear(); pipeline::GetMethodMap().clear();
pipeline::ExecutorPy::ClearRes(); pipeline::ExecutorPy::ClearRes();
pipeline::ReclaimOptimizer(); pipeline::ReclaimOptimizer();
pynative::PynativeExecutor::GetInstance()->Clean(); pynative::PynativeExecutor::GetInstance()->ClearRes();
#ifdef ENABLE_GE #ifdef ENABLE_GE
transform::DfGraphManager::GetInstance().ClearGraph(); transform::DfGraphManager::GetInstance().ClearGraph();
transform::DfGraphConvertor::get_adpt_map().clear(); transform::DfGraphConvertor::get_adpt_map().clear();

@ -595,7 +595,7 @@ py::tuple RunOp(const py::args &args) {
void ClearPyNativeSession() { session = nullptr; } void ClearPyNativeSession() { session = nullptr; }
PynativeExecutor::~PynativeExecutor() { Clean(); } PynativeExecutor::~PynativeExecutor() { ClearRes(); }
PynativeExecutor::PynativeExecutor() { grad_flag_ = false; } PynativeExecutor::PynativeExecutor() { grad_flag_ = false; }
@ -849,17 +849,32 @@ void PynativeExecutor::GradNet(const GradOperationPtr &grad, const py::object &c
pipeline::ReclaimOptimizer(); pipeline::ReclaimOptimizer();
} }
void PynativeExecutor::Clear() { void PynativeExecutor::Clear(const std::string &flag) {
MS_LOG(INFO) << "Clear all res"; if (flag == "resource") {
top_g_ = curr_g_ = nullptr; MS_LOG(INFO) << "Clear res";
std::stack<FuncGraphPtr>().swap(graph_p_); Clean();
return;
}
MS_LOG(INFO) << "Clear";
top_g_ = nullptr;
curr_g_ = nullptr;
graph_info_map_.clear(); graph_info_map_.clear();
std::stack<FuncGraphPtr>().swap(graph_p_);
} }
void PynativeExecutor::Clean() { void PynativeExecutor::Clean() {
MS_LOG(INFO) << "Clean all res";
Clear();
grad_flag_ = false;
graph_map_.clear(); graph_map_.clear();
cell_graph_map_.clear(); cell_graph_map_.clear();
Clear(); df_builder_ = nullptr;
ad::CleanRes();
pipeline::ReclaimOptimizer();
}
void PynativeExecutor::ClearRes() {
Clean();
resource_.reset(); resource_.reset();
} }

@ -68,8 +68,9 @@ class PynativeExecutor : public std::enable_shared_from_this<PynativeExecutor> {
void NewGraph(const py::object &cell, const py::args &args); 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 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 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 Clean();
void ClearRes();
bool grad_flag() { return grad_flag_; } bool grad_flag() { return grad_flag_; }
void set_grad_flag(bool flag) { grad_flag_ = flag; } void set_grad_flag(bool flag) { grad_flag_ = flag; }
AnfNodePtr GetInput(const py::object &obj, const py::object &op_mask); AnfNodePtr GetInput(const py::object &obj, const py::object &op_mask);

@ -293,8 +293,8 @@ class _PynativeExecutor:
def grad(self, grad, obj, weights, *args): def grad(self, grad, obj, weights, *args):
self._executor.grad_net(grad, obj, weights, *args) self._executor.grad_net(grad, obj, weights, *args)
def clear(self): def clear(self, flag=""):
self._executor.clear() self._executor.clear(flag)
def set_grad_flag(self, flag): def set_grad_flag(self, flag):
self._executor.set_grad_flag(flag) self._executor.set_grad_flag(flag)

@ -186,6 +186,7 @@ class Cell:
raise AttributeError("'{}' object has no attribute '{}'.".format(type(self).__name__, name)) raise AttributeError("'{}' object has no attribute '{}'.".format(type(self).__name__, name))
def __del__(self): def __del__(self):
_pynative_exec.clear("resource")
if hasattr(self, "_create_time"): if hasattr(self, "_create_time"):
_executor.del_net_res(str(self._create_time)) _executor.del_net_res(str(self._create_time))

Loading…
Cancel
Save