From 6f502e5d8642f3a7fa7a60f8007868e9f24634c6 Mon Sep 17 00:00:00 2001 From: "River,Li" Date: Sun, 2 Jul 2023 08:52:43 +0800 Subject: [PATCH] Fix python segmentfault issue of plugin api 2.0 --- src/inference/src/dev/icompiled_model.cpp | 45 +++++++++++++++-------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/inference/src/dev/icompiled_model.cpp b/src/inference/src/dev/icompiled_model.cpp index 8f1a64060b0..b6821509719 100644 --- a/src/inference/src/dev/icompiled_model.cpp +++ b/src/inference/src/dev/icompiled_model.cpp @@ -48,34 +48,47 @@ ov::ICompiledModel::ICompiledModel(const std::shared_ptr& model } } - if (add_operation_names) { - for (const auto& param : model->get_parameters()) { - const auto& param_name = param->get_friendly_name(); + for (const auto& param : model->get_parameters()) { + const auto& param_name = param->get_friendly_name(); + auto new_param = ov::as_type_ptr(param->copy_with_new_inputs({})); + new_param->set_friendly_name(param_name); + if (add_operation_names) { OPENVINO_ASSERT(!m_plugin->is_new_api() || leaf_names.find(param_name) == leaf_names.end() || param->output(0).get_names().find(param_name) != param->output(0).get_names().end(), "Model operation names have collisions with tensor names.", " Please use MO to generate new IR version, it should allow to avoid the issue"); leaf_names.insert(param_name); - param->output(0).get_tensor().add_names({param_name}); - m_inputs.emplace_back( - ov::Output{param->output(0).get_node(), param->output(0).get_index()}); } - for (const auto& result : model->get_results()) { - auto fake_param = std::make_shared(result->get_output_element_type(0), - result->get_output_partial_shape(0)); - const std::string res_name = ov::op::util::create_ie_output_name(result->input_value(0)); + param->output(0).get_tensor().set_names({param_name}); + new_param->set_element_type(param->get_element_type()); + new_param->set_layout(param->get_layout()); + new_param->output(0).get_rt_info() = param->output(0).get_rt_info(); + new_param->validate_and_infer_types(); + m_inputs.emplace_back( + ov::Output{new_param->output(0).get_node(), param->output(0).get_index()}); + } + for (const auto& result : model->get_results()) { + auto fake_param = std::make_shared(result->get_output_element_type(0), + result->get_output_partial_shape(0)); + const std::string res_name = ov::op::util::create_ie_output_name(result->input_value(0)); + fake_param->set_friendly_name(res_name); + fake_param->set_element_type(result->get_element_type()); + fake_param->validate_and_infer_types(); + auto new_result = result->copy_with_new_inputs({fake_param}); + new_result->set_friendly_name(result->get_friendly_name()); + if (add_operation_names) { OPENVINO_ASSERT(!m_plugin->is_new_api() || leaf_names.find(res_name) == leaf_names.end() || result->output(0).get_names().find(res_name) != result->output(0).get_names().end(), "Model operation names have collisions with tensor names.", " Please use MO to generate new IR version, it should allow to avoid the issue"); leaf_names.insert(res_name); - result->output(0).get_tensor().add_names({res_name}); - m_outputs.emplace_back( - ov::Output{result->output(0).get_node(), result->output(0).get_index()}); } - } else { - m_inputs = model->inputs(); - m_outputs = model->outputs(); + new_result->output(0).get_tensor().add_names({res_name}); + auto r = std::dynamic_pointer_cast(new_result); + OPENVINO_ASSERT(r, "Internal error. set outputs failure casting output copy to Result"); + r->set_layout(result->get_layout()); + m_outputs.emplace_back( + ov::Output{new_result->output(0).get_node(), result->output(0).get_index()}); } } }