diff --git a/mindspore/ccsrc/pipeline/jit/pass.cc b/mindspore/ccsrc/pipeline/jit/pass.cc index db55ebcd665..a79590fc4cb 100644 --- a/mindspore/ccsrc/pipeline/jit/pass.cc +++ b/mindspore/ccsrc/pipeline/jit/pass.cc @@ -151,6 +151,7 @@ FuncGraphPtr PrimBpOptPassStep1(const opt::irpass::OptimizeIRPassLib &irpass, co FuncGraphPtr PrimBpOptPassStep2(const opt::irpass::OptimizeIRPassLib &irpass, const ResourcePtr &res) { opt::OptPassConfig switch_simplify_ = opt::OptPassConfig({ irpass.switch_simplify_, + irpass.reduce_eliminate_, }); opt::OptPassConfig inline_ = opt::OptPassConfig({ diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc index c903d99433c..4a872fff18d 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc @@ -611,6 +611,11 @@ void UpdateTensorInfo(const tensor::TensorPtr &new_tensor, const std::vectorget_param(MS_CTX_DEVICE_TARGET); for (auto &pre_tensor : pre_tensors) { MS_EXCEPTION_IF_NULL(pre_tensor); + MS_LOG(DEBUG) << "Replace Old tensor " << pre_tensor.get() << " id " << pre_tensor->id() + << " device_address: " << pre_tensor->device_address()->GetMutablePtr() << " shape and type " + << pre_tensor->GetShapeAndDataTypeInfo() << " with New tensor " << new_tensor.get() << " id " + << new_tensor->id() << " device_address " << new_tensor->device_address()->GetMutablePtr() + << " shape and dtype " << new_tensor->GetShapeAndDataTypeInfo(); pre_tensor->set_shape(new_tensor->shape()); pre_tensor->set_data_type(new_tensor->data_type()); if (device_target != kCPUDevice) { @@ -627,11 +632,6 @@ void UpdateTensorInfo(const tensor::TensorPtr &new_tensor, const std::vectorid() - << " device_address: " << pre_tensor->device_address()->GetMutablePtr() << " shape and type " - << pre_tensor->GetShapeAndDataTypeInfo() << " with New tensor " << new_tensor.get() << " id " - << new_tensor->id() << " device_address " << new_tensor->device_address()->GetMutablePtr() - << " shape and dtype " << new_tensor->GetShapeAndDataTypeInfo(); } } @@ -1243,6 +1243,16 @@ AnfNodePtr GradExecutor::MakeValueNode(const py::object &obj, const std::string return node; } +TopCellInfoPtr GradExecutor::GetTopCell(std::string cell_id) const { + for (const auto &top_cell : top_cell_list_) { + MS_EXCEPTION_IF_NULL(top_cell); + if (top_cell->cell_id() == cell_id) { + return top_cell; + } + } + return nullptr; +} + void GradExecutor::RecordGradOpInfo(const OpExecInfoPtr &op_exec_info) { MS_EXCEPTION_IF_NULL(op_exec_info); // Record op info for judge whether the construct of cell has been changed @@ -1924,12 +1934,6 @@ void GradExecutor::SetMakeTupleAsOutputNode(const TopCellInfoPtr &top_cell, cons // run ad for maketuple node ValuePtr out_value = parse::data_converter::PyDataToValue(out); ad::GradPynativeOp(top_cell->k_pynative_cell_ptr(), cnode, input_args, out_value); - // record op info - size_t curr_op_num = top_cell->op_num(); - std::string op_info = "MakeTuple-" + std::to_string(curr_op_num) + "-" + input_args_info; - std::string curr_op_info = top_cell->all_op_info() + "_" + op_info; - top_cell->set_all_op_info(curr_op_info); - top_cell->set_op_num(curr_op_num + 1); MS_LOG(DEBUG) << "Tuple output node info " << cnode->DebugString(); } @@ -2225,9 +2229,10 @@ py::object PynativeExecutor::CheckAlreadyRun(const py::object &cell, const py::a input_args_id = input_args_id + GetId(args[i]) + "_"; } // Check whether need to run forward process - auto top_cell = grad_executor()->top_cell_direct(); + auto top_cell = grad_executor()->GetTopCell(cell_id); if (top_cell != nullptr) { forward_run = top_cell->forward_already_run(); + grad_executor()->set_top_cell(top_cell); bool input_args_changed = !top_cell->input_args_id().empty() && top_cell->input_args_id() != input_args_id; if (forward_run && input_args_changed && top_cell->is_dynamic()) { MS_LOG(WARNING) << "The construct of running cell is dynamic and the input info of this cell has changed, " @@ -2235,7 +2240,7 @@ py::object PynativeExecutor::CheckAlreadyRun(const py::object &cell, const py::a forward_run = false; } } - MS_LOG(DEBUG) << "Graph have already run " << forward_run << " top cell id " << cell_id; + MS_LOG(DEBUG) << "Graph have already ran " << forward_run << " top cell id " << cell_id; return BaseRefToPyData(forward_run); } diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h index ec3d560430e..23c1c7883e0 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h @@ -180,6 +180,7 @@ class GradExecutor { std::string GetCellId(const py::object &obj, const py::args &args); std::stack &cell_stack() { return cell_stack_; } std::vector &top_cell_list() { return top_cell_list_; } + TopCellInfoPtr GetTopCell(std::string cell_id) const; void RecordGradOpInfo(const OpExecInfoPtr &op_exec_info); bool need_construct_graph() const { return !cell_stack_.empty() && grad_flag_; } void SaveOutputNodeMap(const std::string &obj_id, const py::object &out_real, const AnfNodePtr &cnode);