From e034570c246347c6a61fc08291f187fb726b7842 Mon Sep 17 00:00:00 2001 From: zhangzhaoju Date: Sat, 31 Jul 2021 10:00:32 +0800 Subject: [PATCH] Delete unused Code --- .../pipeline/pynative/pynative_execute.cc | 22 +------------------ .../pipeline/pynative/pynative_execute.h | 9 -------- mindspore/nn/cell.py | 4 ---- 3 files changed, 1 insertion(+), 34 deletions(-) diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc index aa3bfd8737..c5e7dec5f3 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc @@ -2888,22 +2888,6 @@ void PynativeExecutor::Sync() { } } -void PynativeExecutor::EnterConstruct(const py::object &cell) { - if (py_top_cell_ != nullptr) { - return; - } - py_top_cell_ = cell.ptr(); - MS_LOG(DEBUG) << "Enter construct process."; -} - -void PynativeExecutor::LeaveConstruct(const py::object &cell) { - if (py_top_cell_ != cell.ptr()) { - return; - } - py_top_cell_ = nullptr; - MS_LOG(DEBUG) << "Leave construct process."; -} - REGISTER_PYBIND_DEFINE(PynativeExecutor_, ([](const py::module *m) { (void)py::class_>(*m, "PynativeExecutor_") .def_static("get_instance", &PynativeExecutor::GetInstance, "PynativeExecutor get_instance.") @@ -2919,10 +2903,6 @@ REGISTER_PYBIND_DEFINE(PynativeExecutor_, ([](const py::module *m) { .def("__call__", &PynativeExecutor::Run, "pynative executor run grad graph.") .def("set_graph_phase", &PynativeExecutor::set_graph_phase, "pynative set graph phase") .def("set_grad_flag", &PynativeExecutor::set_grad_flag, py::arg("flag") = py::bool_(false), - "Executor set grad flag.") - .def("enter_construct", &PynativeExecutor::EnterConstruct, - "Do something before enter construct function.") - .def("leave_construct", &PynativeExecutor::LeaveConstruct, - "Do something after leave construct function."); + "Executor set grad flag."); })); } // namespace mindspore::pynative diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h index 6a74fd5e55..03655ddfa5 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h @@ -347,9 +347,6 @@ class PynativeExecutor : public std::enable_shared_from_this { ~PynativeExecutor() = default; PynativeExecutor(const PynativeExecutor &) = delete; PynativeExecutor &operator=(const PynativeExecutor &) = delete; - - void EnterConstruct(const py::object &cell); - void LeaveConstruct(const py::object &cell); GradExecutorPtr grad_executor() const; ForwardExecutorPtr forward_executor() const; @@ -380,12 +377,6 @@ class PynativeExecutor : public std::enable_shared_from_this { static std::mutex instance_lock_; static ForwardExecutorPtr forward_executor_; static GradExecutorPtr grad_executor_; - // The pointer of top python Cell object, which is always the network(inherit class Cell) ran in python test script, - // such as Resnet50(Cell),LeNet(Cell).This pointer is used to distinguish temporary primitives from global - // primitives to control memory release. Global primitives are always created in top cell's '__init__' function and - // temporary primitives are always created in other place.Temporary primitives will be released after executing top - // cell's 'construct' function but global primitives will not. - PyObject *py_top_cell_{nullptr}; }; using PynativeExecutorPtr = std::shared_ptr; diff --git a/mindspore/nn/cell.py b/mindspore/nn/cell.py index fc13cbdccf..ce3456941a 100755 --- a/mindspore/nn/cell.py +++ b/mindspore/nn/cell.py @@ -337,13 +337,9 @@ class Cell(Cell_): def run_construct(self, cast_inputs, kwargs): if self.enable_hook: - _pynative_exec.enter_construct(self) output = self._hook_construct(*cast_inputs, **kwargs) - _pynative_exec.leave_construct(self) else: - _pynative_exec.enter_construct(self) output = self.construct(*cast_inputs, **kwargs) - _pynative_exec.leave_construct(self) return output def _check_construct_args(self, *inputs, **kwargs):