diff --git a/mindspore/ccsrc/pynative/pynative_execute.cc b/mindspore/ccsrc/pynative/pynative_execute.cc index 4f2a961394..9df920e94d 100644 --- a/mindspore/ccsrc/pynative/pynative_execute.cc +++ b/mindspore/ccsrc/pynative/pynative_execute.cc @@ -319,6 +319,27 @@ void ConvertValueTupleToTensor(const py::object &input_object, std::vectorpush_back(tensor_ptr); } +void ConvertMultiPyObjectToTensor(const py::object &input_object, const PrimitivePtr &op_prim, + std::vector *input_tensors, int *tensor_mask) { + MS_EXCEPTION_IF_NULL(op_prim); + MS_EXCEPTION_IF_NULL(input_tensors); + MS_EXCEPTION_IF_NULL(tensor_mask); + + if (!py::isinstance(input_object)) { + MS_LOG(EXCEPTION) << "The input should be a tuple!"; + } + auto tuple_inputs = py::cast(input_object); + if (tuple_inputs.size() == 0) { + MS_LOG(EXCEPTION) << "The size of input list or tuple is 0!"; + } + if (py::isinstance(tuple_inputs[0])) { + PlantTensorTupleToVector(tuple_inputs, op_prim, input_tensors); + } else { + ConvertValueTupleToTensor(input_object, input_tensors); + *tensor_mask = kValueNodeTensorMask; + } +} + void ConvertPyObjectToTensor(const py::object &input_object, const PrimitivePtr &op_prim, std::vector *input_tensors, int *tensor_mask) { MS_EXCEPTION_IF_NULL(op_prim); @@ -333,20 +354,20 @@ void ConvertPyObjectToTensor(const py::object &input_object, const PrimitivePtr } else if (py::isinstance(input_object)) { tensor_ptr = std::make_shared(py::cast(input_object), kInt32); *tensor_mask = kValueNodeTensorMask; - } else if (py::isinstance(input_object)) { - tensor_ptr = std::make_shared(py::cast(input_object), nullptr); } else if (py::isinstance(input_object)) { tensor_ptr = std::make_shared(py::cast(input_object), nullptr); - } else if (py::isinstance(input_object)) { + } else if (py::isinstance(input_object)) { + auto list_inputs = py::cast(input_object); + py::tuple tuple_inputs(list_inputs.size()); + for (size_t i = 0; i < tuple_inputs.size(); ++i) { + tuple_inputs[i] = list_inputs[i]; + } + ConvertMultiPyObjectToTensor(tuple_inputs, op_prim, input_tensors, tensor_mask); return; } else if (py::isinstance(input_object)) { - auto tuple_inputs = py::cast(input_object); - if (py::isinstance(tuple_inputs[0])) { - PlantTensorTupleToVector(tuple_inputs, op_prim, input_tensors); - } else { - ConvertValueTupleToTensor(input_object, input_tensors); - *tensor_mask = kValueNodeTensorMask; - } + ConvertMultiPyObjectToTensor(input_object, op_prim, input_tensors, tensor_mask); + return; + } else if (py::isinstance(input_object)) { return; } else { MS_LOG(EXCEPTION) << "Run op inputs type is invalid!";