From 2fd4a3fc3a3030d353de8e388b95371ea70e1b0a Mon Sep 17 00:00:00 2001 From: simson <526422051@qq.com> Date: Tue, 15 Sep 2020 14:30:07 +0800 Subject: [PATCH] fix bugs which lead to segment fault --- mindspore/ccsrc/pipeline/jit/pipeline.cc | 11 ++++++++--- .../ccsrc/pipeline/pynative/pynative_execute.cc | 12 ++++++++++++ mindspore/common/parameter.py | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.cc b/mindspore/ccsrc/pipeline/jit/pipeline.cc index 23e89d3d42..fe09f9f968 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline.cc @@ -710,9 +710,14 @@ void ProcessVmArgInner(const py::tuple &args, const ResourcePtr &res, VectorRef if (!succ) { MS_LOG(EXCEPTION) << "The " << i << "th arg convert failed."; } - if (MsContext::GetInstance()->get_param(MS_CTX_EXECUTION_MODE) == 0 && !converted->isa()) { - MS_EXCEPTION(TypeError) << "For 'graph mode', the " << i << "th arg: " << converted->ToString() - << " is not tensor."; + if (MsContext::GetInstance()->get_param(MS_CTX_EXECUTION_MODE) == 0) { + if (!converted->isa()) { + MS_EXCEPTION(TypeError) << "For 'graph mode', the " << i << "th arg: " << converted->ToString() + << " is not tensor."; + } + if (converted->cast()->is_parameter()) { + MS_EXCEPTION(TypeError) << "The inputs could not be Parameter."; + } } arg_list->push_back(converted); } diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc index 09b2b2b662..2f0a9441bf 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc @@ -1064,6 +1064,14 @@ void PynativeExecutor::NewGraphInner(const py::object &cell, const py::args &arg auto g = std::make_shared(); if (graph_context_.empty()) { + for (auto arg : args) { + if (py::isinstance(arg)) { + auto tensor = arg.cast(); + if (tensor && tensor->is_parameter()) { + MS_EXCEPTION(TypeError) << "The inputs could not be Parameter."; + } + } + } // a df builder is built for every top function graph df_builder_ = std::make_shared(); df_builder_map_[cell_id] = df_builder_; @@ -1279,6 +1287,10 @@ void PynativeExecutor::EndGraphByOutId(const std::string &out_id, const py::obje if (need_replace_param) { auto params = newfg->parameters(); auto manager = Manage({newfg}, false); + if (args.size() > params.size()) { + MS_EXCEPTION(ValueError) << "The number of arguments " << args.size() + << " is more than the number of parameters required, which is " << params.size(); + } for (size_t i = 0; i < args.size(); i++) { ValuePtr value = PyAttrValue(args[i]); auto v_node = NewValueNode(value); diff --git a/mindspore/common/parameter.py b/mindspore/common/parameter.py index 69cdee9a1a..781a931dd3 100644 --- a/mindspore/common/parameter.py +++ b/mindspore/common/parameter.py @@ -47,6 +47,7 @@ class Parameter(MetaTensor): Note: Each parameter of Cell is represented by Parameter class. + A Parameter has to belong to a Cell. Args: default_input (Union[Tensor, Initializer, Number]): Parameter data, to be set initialized.