!23511 Fix core dump bug

Merge pull request !23511 from zjun/fix_coredump_bug
This commit is contained in:
i-robot 2021-09-16 01:50:59 +00:00 committed by Gitee
commit c8b9d45abc
3 changed files with 11 additions and 1 deletions

View File

@ -2103,6 +2103,8 @@ void GradExecutor::InitResourceAndDfBuilder(const std::string &cell_id, const py
auto cur_top_is_dynamic = top_cell()->is_dynamic();
MakeNewTopGraph(cell_id, args, false);
top_cell()->set_is_dynamic(cur_top_is_dynamic);
} else {
MS_LOG(EXCEPTION) << "cell stack size " << cell_stack_.size() << ", grad_order_ " << grad_order_;
}
}
@ -3173,6 +3175,7 @@ REGISTER_PYBIND_DEFINE(PynativeExecutor_, ([](const py::module *m) {
.def("grad_ms_function", &PynativeExecutor::GradMsFunction, "pynative grad for ms_function.")
.def("grad_net", &PynativeExecutor::GradNet, "pynative grad graph.")
.def("clear_cell", &PynativeExecutor::ClearCell, "pynative clear status.")
.def("clear_res", &PynativeExecutor::ClearRes, "pynative clear exception res.")
.def("clear_grad", &PynativeExecutor::ClearGrad, "pynative clear grad status.")
.def("sync", &PynativeExecutor::Sync, "pynative sync stream.")
.def("set_lazy_build", &PynativeExecutor::SetLazyBuild, "pynative build kernel async")

View File

@ -387,6 +387,9 @@ class _PynativeExecutor:
def del_cell(self, cell_id=""):
self._executor.clear_cell(cell_id)
def clear_res(self):
return self._executor.clear_res()
def clear_grad(self, obj, *args, **kwargs):
self._executor.clear_grad(obj, *args, *(kwargs.values()))

View File

@ -426,7 +426,11 @@ class Cell(Cell_):
cast_inputs = inputs
with self.CellGuard():
output = self.run_construct(cast_inputs, kwargs)
try:
output = self.run_construct(cast_inputs, kwargs)
except TypeError as err:
_pynative_executor.clear_res()
raise err
if _pynative_executor.is_top_cell():
_pynative_executor.execute_all_task()