From 23b7a716e27152eaaf616eba390c6913b6241840 Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Tue, 27 Aug 2024 14:27:36 +0200 Subject: [PATCH 1/6] Add custom info (de)serialization Signed-off-by: Tomasz Jankowski --- src/core/src/pass/serialize.cpp | 37 +++- .../serialization/rt_info_serialization.cpp | 181 ++++++++++++++++++ src/frontends/ir/src/ir_deserializer.cpp | 60 ++++-- src/frontends/ir/tests/rt_info_custom.cpp | 101 ++++++++++ 4 files changed, 353 insertions(+), 26 deletions(-) create mode 100644 src/frontends/ir/tests/rt_info_custom.cpp diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index f179630b155d22..16d5450757575c 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -921,7 +921,7 @@ void serialize_rt_info(pugi::xml_node& root, const std::string& name, const ov:: child.append_attribute("name").set_value(name.c_str()); } if (data.is>()) { - auto meta = data.as>(); + const auto& meta = data.as>(); do { if (auto meta_with_pugixml_node = std::dynamic_pointer_cast(meta)) { if (auto pugi_node = meta_with_pugixml_node->get_pugi_node()) { @@ -944,11 +944,32 @@ void serialize_rt_info(pugi::xml_node& root, const std::string& name, const ov:: serialize_rt_info(child, it.first, it.second); } } else { - std::string value = data.as(); + const auto& value = data.as(); child.append_attribute("value").set_value(value.c_str()); } } +bool append_custom_info(pugi::xml_node& node, const std::string& name, const ov::Any& data) { + auto custom_node = node.append_child("custom"); + custom_node.append_attribute("name").set_value(name.c_str()); + bool has_value = false; + + if (data.is()) { + const auto& any_map = data.as(); + for (const auto& it : any_map) + has_value |= append_custom_info(custom_node, it.first, it.second); + + } else { + const auto& value = data.as(); + custom_node.append_attribute("value").set_value(value.c_str()); + has_value = true; + } + + if (!has_value) + node.remove_child(custom_node); + return has_value; +} + void ngfunction_2_ir(pugi::xml_node& netXml, const ov::Model& model, ConstantWriter& constant_node_write_handler, @@ -1012,10 +1033,10 @@ void ngfunction_2_ir(pugi::xml_node& netXml, // general attributes pugi::xml_node data = layer.append_child("data"); - auto append_runtime_info = [](pugi::xml_node& node, ov::RTMap& attributes) { + auto append_runtime_info = [](pugi::xml_node& node, const ov::RTMap& attributes) { pugi::xml_node rt_node = node.append_child("rt_info"); bool has_attrs = false; - for (auto& item : attributes) { + for (const auto& item : attributes) { if (item.second.is()) { auto attribute_node = rt_node.append_child("attribute"); auto& rt_attribute = item.second.as(); @@ -1030,9 +1051,13 @@ void ngfunction_2_ir(pugi::xml_node& netXml, } } } - if (!has_attrs) { + + for (const auto& item : attributes) + if (!item.second.is()) + has_attrs |= append_custom_info(rt_node, item.first, item.second); + + if (!has_attrs) node.remove_child(rt_node); - } }; if (version >= 11) { diff --git a/src/core/tests/pass/serialization/rt_info_serialization.cpp b/src/core/tests/pass/serialization/rt_info_serialization.cpp index 412625d45d53d9..89145c8ea6e5d3 100644 --- a/src/core/tests/pass/serialization/rt_info_serialization.cpp +++ b/src/core/tests/pass/serialization/rt_info_serialization.cpp @@ -299,3 +299,184 @@ TEST(OvSerializationTests, SerializeRawMeta) { EXPECT_EQ(0, serialized_model.compare(ir_with_rt_info)); } } + +#include +#include + +using namespace ov; +using ov::op::v0::Abs; +using ov::op::v0::Parameter; +using ov::op::v0::Result; +using ov::op::v1::Add; + +TEST(SerializeCustomRTI, basic_RENAMEME) { + std::string ir = R"V0G0N( + + + + + + + + + + 10 + 10 + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + 10 + 10 + + + 1 + + + + + 10 + 10 + + + + + + + + + + + + + + 10 + 10 + + + + + + + + + + + +)V0G0N"; + + const auto data = std::make_shared(element::Type_t::f32, Shape{10, 10}); + const auto one = std::make_shared(element::f32, Shape{1}, std::vector{1.f}); + const auto add = std::make_shared(data, one); + const auto result = std::make_shared(add); + + const auto add_info = [](const std::shared_ptr& node, const std::string& value) { + const_cast(node->get_name()) = "node_" + value; + node->get_rt_info()["node_info_" + value] = "v_" + value; + node->output(0).get_rt_info()["output_info_" + value] = "o_" + value; + }; + add_info(data, "A"); + add_info(one, "B"); + add_info(add, "C"); + add_info(result, "D"); + + const auto model = std::make_shared(ResultVector{result}, ParameterVector{data}); + const_cast(model->get_name()) = "CustomRTI"; + + std::stringstream model_ss, weights_ss; + EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model))); + EXPECT_EQ(ir.compare(model_ss.str()), 0); +} + +TEST(SerializeCustomRTI, AnyMap_RENAMEME) { + std::string ir = R"V0G0N( + + + + + + + 111 + + + + + + + + + + + + + + + + + 111 + + + + + 111 + + + + + + + 111 + + + + + + + + + + +)V0G0N"; + + const auto data = std::make_shared(element::Type_t::f64, Shape{111}); + const auto abs = std::make_shared(data); + const auto result = std::make_shared(abs); + + const_cast(data->get_name()) = "data"; + const_cast(abs->get_name()) = "abs"; + const_cast(result->get_name()) = "result"; + + const auto empty = AnyMap{}; + const auto nested = AnyMap{{"c", "d"}}; + abs->get_rt_info()["AnyMap"] = AnyMap{{"a", "b"}, {"empty", empty}, {"i", 7}, {"x", 3.14}, {"nested", nested}}; + + const auto model = std::make_shared(ResultVector{result}, ParameterVector{data}); + const_cast(model->get_name()) = "CustomRTI"; + + std::stringstream model_ss, weights_ss; + EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model))); + EXPECT_EQ(ir.compare(model_ss.str()), 0); +} diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cpp index 7c8b6e9d4b97ab..7f96359abadf44 100644 --- a/src/frontends/ir/src/ir_deserializer.cpp +++ b/src/frontends/ir/src/ir_deserializer.cpp @@ -965,31 +965,51 @@ std::shared_ptr ov::XmlDeserializer::create_node(const std::vector - if (!getStrAttribute(item, "name", attribute_name) || !getStrAttribute(item, "version", attribute_version)) - continue; - - const auto& type_info = ov::DiscreteTypeInfo(attribute_name.c_str(), attribute_version.c_str()); - auto attr = attrs_factory.create_by_type_info(type_info); - if (!attr.empty()) { - if (attr.is()) { - RTInfoDeserializer attribute_visitor(item); - if (attr.as().visit_attributes(attribute_visitor)) { - auto res = rt_info.emplace(type_info, attr); - if (!res.second) { - OPENVINO_THROW("multiple rt_info attributes are detected: ", attribute_name); + if (std::strcmp(item.name(), "attribute") == 0) { + std::string attribute_name, attribute_version; + // For view: + // + if (!getStrAttribute(item, "name", attribute_name)) { + std::stringstream ss; + item.print(ss); + OPENVINO_THROW("rt_info attribute has no \"name\" field: ", ss.str()); + } + if (!getStrAttribute(item, "version", attribute_version)) { + std::stringstream ss; + item.print(ss); + OPENVINO_THROW("rt_info attribute: ", attribute_name, " has no \"version\" field: ", ss.str()); + } + const auto& type_info = ov::DiscreteTypeInfo(attribute_name.c_str(), attribute_version.c_str()); + auto attr = attrs_factory.create_by_type_info(type_info); + if (!attr.empty()) { + if (attr.is()) { + RTInfoDeserializer attribute_visitor(item); + if (attr.as().visit_attributes(attribute_visitor)) { + auto res = rt_info.emplace(type_info, attr); + if (!res.second) { + OPENVINO_THROW("multiple rt_info attributes are detected: ", attribute_name); + } + } else { + OPENVINO_THROW("VisitAttributes is not supported for: ", item.name(), " attribute"); } } else { - OPENVINO_THROW("VisitAttributes is not supported for: ", item.name(), " attribute"); + OPENVINO_THROW("Attribute: ", item.name(), " is not recognized as runtime attribute"); } } else { - OPENVINO_THROW("Attribute: ", item.name(), " is not recognized as runtime attribute"); + // As runtime attributes are optional, so we skip attribute if it is unknown to avoid exception + // when loading new IR with new attribute in old OV version. + } + } + } + + // Predefined attributes take precedence over custom rt info + for (const auto& item : rt_attrs) { + if (std::strcmp(item.name(), "custom") == 0) { + std::string custom_name, custom_value; + if (getStrAttribute(item, "name", custom_name) && getStrAttribute(item, "value", custom_value)) { + // Duplicates are not added and are ignored + rt_info.emplace(custom_name, custom_value); } - } else { - // As runtime attributes are optional, so we skip attribute if it is unknown to avoid exception - // when loading new IR with new attribute in old OV version. } } }; diff --git a/src/frontends/ir/tests/rt_info_custom.cpp b/src/frontends/ir/tests/rt_info_custom.cpp new file mode 100644 index 00000000000000..aef76e1c5b4059 --- /dev/null +++ b/src/frontends/ir/tests/rt_info_custom.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "common_test_utils/test_assertions.hpp" +#include "openvino/runtime/core.hpp" + +TEST(RTInfoCustom, basic_RENAMEME) { + std::string ir = R"V0G0N( + + + + + + + + + + + + + + 27 + + + + + + + + + + + 27 + + + + + + + + 27 + + + + + + + + + + + 27 + + + + + + + + + +)V0G0N"; + + ov::Core core; + auto model = core.read_model(ir, ov::Tensor()); + ASSERT_NE(nullptr, model); + std::string value; + + const auto& param_rti = model->get_parameters().at(0)->get_rt_info(); + EXPECT_EQ(param_rti.size(), 3); + + OV_ASSERT_NO_THROW(value = param_rti.at("fused_names_0").as()); + EXPECT_EQ(value.compare("the_name"), 0); + + OV_ASSERT_NO_THROW(value = param_rti.at("infoA").as()); + EXPECT_EQ(value.compare("A"), 0); + + OV_ASSERT_NO_THROW(value = param_rti.at("infoB").as()); + EXPECT_EQ(value.compare("B"), 0); + + const auto& result = model->get_results().at(0); + const auto abs = result->get_input_node_ptr(0); + + const auto& abs_rti = abs->get_rt_info(); + EXPECT_EQ(abs_rti.size(), 2); + OV_ASSERT_NO_THROW(value = abs_rti.at("infoC").as()); + EXPECT_EQ(value.compare("C"), 0); + + const auto& abs_output_rti = abs->output(0).get_rt_info(); + EXPECT_EQ(abs_output_rti.size(), 1); + OV_ASSERT_NO_THROW(value = abs_output_rti.at("infoD").as()); + EXPECT_EQ(value.compare("D"), 0); + + const auto& result_rti = result->get_rt_info(); + EXPECT_EQ(result_rti.size(), 1); + OV_ASSERT_NO_THROW(value = result_rti.at("primitives_priority_0").as()); + EXPECT_EQ(value.compare("the_prior"), 0); +} From 5d986c101857958cdae70f79833510e762fc3f0b Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Tue, 29 Oct 2024 13:53:07 +0100 Subject: [PATCH 2/6] Fix RTInfoDeserialization.node_v11 test Signed-off-by: Tomasz Jankowski --- .../pass/serialization/rt_info_serialization.cpp | 12 ++++++------ src/frontends/ir/src/ir_deserializer.cpp | 16 ++++------------ src/frontends/ir/tests/rt_info_custom.cpp | 14 ++++++++++---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/core/tests/pass/serialization/rt_info_serialization.cpp b/src/core/tests/pass/serialization/rt_info_serialization.cpp index 89145c8ea6e5d3..bf82b46dcd7ee5 100644 --- a/src/core/tests/pass/serialization/rt_info_serialization.cpp +++ b/src/core/tests/pass/serialization/rt_info_serialization.cpp @@ -309,8 +309,8 @@ using ov::op::v0::Parameter; using ov::op::v0::Result; using ov::op::v1::Add; -TEST(SerializeCustomRTI, basic_RENAMEME) { - std::string ir = R"V0G0N( +TEST(RTInfoSerialization, custom_info) { + std::string ref_ir_xml = R"V0G0N( @@ -408,11 +408,11 @@ TEST(SerializeCustomRTI, basic_RENAMEME) { std::stringstream model_ss, weights_ss; EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model))); - EXPECT_EQ(ir.compare(model_ss.str()), 0); + EXPECT_EQ(ref_ir_xml.compare(model_ss.str()), 0); } -TEST(SerializeCustomRTI, AnyMap_RENAMEME) { - std::string ir = R"V0G0N( +TEST(RTInfoSerialization, AnyMap_info) { + std::string ref_ir_xml = R"V0G0N( @@ -478,5 +478,5 @@ TEST(SerializeCustomRTI, AnyMap_RENAMEME) { std::stringstream model_ss, weights_ss; EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model))); - EXPECT_EQ(ir.compare(model_ss.str()), 0); + EXPECT_EQ(ref_ir_xml.compare(model_ss.str()), 0); } diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cpp index 7f96359abadf44..1218e9be890ab2 100644 --- a/src/frontends/ir/src/ir_deserializer.cpp +++ b/src/frontends/ir/src/ir_deserializer.cpp @@ -967,18 +967,10 @@ std::shared_ptr ov::XmlDeserializer::create_node(const std::vector - if (!getStrAttribute(item, "name", attribute_name)) { - std::stringstream ss; - item.print(ss); - OPENVINO_THROW("rt_info attribute has no \"name\" field: ", ss.str()); - } - if (!getStrAttribute(item, "version", attribute_version)) { - std::stringstream ss; - item.print(ss); - OPENVINO_THROW("rt_info attribute: ", attribute_name, " has no \"version\" field: ", ss.str()); - } + if (!getStrAttribute(item, "name", attribute_name) || + !getStrAttribute(item, "version", attribute_version)) + continue; + const auto& type_info = ov::DiscreteTypeInfo(attribute_name.c_str(), attribute_version.c_str()); auto attr = attrs_factory.create_by_type_info(type_info); if (!attr.empty()) { diff --git a/src/frontends/ir/tests/rt_info_custom.cpp b/src/frontends/ir/tests/rt_info_custom.cpp index aef76e1c5b4059..682c18ebf40547 100644 --- a/src/frontends/ir/tests/rt_info_custom.cpp +++ b/src/frontends/ir/tests/rt_info_custom.cpp @@ -7,8 +7,11 @@ #include "common_test_utils/test_assertions.hpp" #include "openvino/runtime/core.hpp" -TEST(RTInfoCustom, basic_RENAMEME) { - std::string ir = R"V0G0N( +namespace ov { +namespace test { + +TEST(RTInfoCustom, simple_entries) { + std::string ref_ir_xml = R"V0G0N( @@ -64,8 +67,8 @@ TEST(RTInfoCustom, basic_RENAMEME) { )V0G0N"; - ov::Core core; - auto model = core.read_model(ir, ov::Tensor()); + Core core; + auto model = core.read_model(ref_ir_xml, Tensor()); ASSERT_NE(nullptr, model); std::string value; @@ -99,3 +102,6 @@ TEST(RTInfoCustom, basic_RENAMEME) { OV_ASSERT_NO_THROW(value = result_rti.at("primitives_priority_0").as()); EXPECT_EQ(value.compare("the_prior"), 0); } + +} // namespace test +} // namespace ov From 00a26494be305728b2afd86b4502cbdcada4057e Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Thu, 31 Oct 2024 14:03:56 +0100 Subject: [PATCH 3/6] Deserialize nested maps Signed-off-by: Tomasz Jankowski --- src/core/src/pass/serialize.cpp | 14 ++-- src/frontends/ir/src/ir_deserializer.cpp | 30 +++++--- src/frontends/ir/tests/rt_info_custom.cpp | 83 ++++++++++++++++++++++- 3 files changed, 109 insertions(+), 18 deletions(-) diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index 16d5450757575c..025bdca44fe754 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -949,25 +949,25 @@ void serialize_rt_info(pugi::xml_node& root, const std::string& name, const ov:: } } -bool append_custom_info(pugi::xml_node& node, const std::string& name, const ov::Any& data) { +bool append_custom_rt_info(pugi::xml_node& node, const std::string& name, const ov::Any& data) { auto custom_node = node.append_child("custom"); custom_node.append_attribute("name").set_value(name.c_str()); - bool has_value = false; + bool appended = false; if (data.is()) { const auto& any_map = data.as(); for (const auto& it : any_map) - has_value |= append_custom_info(custom_node, it.first, it.second); + appended |= append_custom_rt_info(custom_node, it.first, it.second); } else { const auto& value = data.as(); custom_node.append_attribute("value").set_value(value.c_str()); - has_value = true; + appended = true; } - if (!has_value) + if (!appended) node.remove_child(custom_node); - return has_value; + return appended; } void ngfunction_2_ir(pugi::xml_node& netXml, @@ -1054,7 +1054,7 @@ void ngfunction_2_ir(pugi::xml_node& netXml, for (const auto& item : attributes) if (!item.second.is()) - has_attrs |= append_custom_info(rt_node, item.first, item.second); + has_attrs |= append_custom_rt_info(rt_node, item.first, item.second); if (!has_attrs) node.remove_child(rt_node); diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cpp index 1218e9be890ab2..b93093f65c4228 100644 --- a/src/frontends/ir/src/ir_deserializer.cpp +++ b/src/frontends/ir/src/ir_deserializer.cpp @@ -816,6 +816,25 @@ static const std::string& translate_type_name(const std::string& name) { return name; } +namespace { +void set_custom_rt_info(const pugi::xml_node& rt_attrs, ov::AnyMap& rt_info) { + std::string custom_name, custom_value; + for (const auto& item : rt_attrs) { + if (std::strcmp(item.name(), "custom") == 0) { + if (ov::getStrAttribute(item, "name", custom_name)) { + if (ov::getStrAttribute(item, "value", custom_value)) { + rt_info.emplace(custom_name, custom_value); + } else { + rt_info.emplace(custom_name, ov::AnyMap{}); + auto& nested = rt_info.at(custom_name).as(); + set_custom_rt_info(item, nested); + } + } + } + } +} +} // namespace + std::shared_ptr ov::XmlDeserializer::create_node(const std::vector>& inputs, const pugi::xml_node& node, const std::shared_ptr& weights, @@ -994,16 +1013,7 @@ std::shared_ptr ov::XmlDeserializer::create_node(const std::vector + + + + + + + + + + + + + 27 + + + + + + + 27 + + + + + + + + + + + + 27 + + + + + + + 27 + + + + + + + + + +)V0G0N"; + + Core core; + auto model = core.read_model(ref_ir_xml, Tensor{}); + ASSERT_NE(nullptr, model); + std::string value; + AnyMap any_map; + + const auto& param_rti = model->get_parameters().at(0)->get_rt_info(); + EXPECT_EQ(param_rti.size(), 2); + OV_ASSERT_NO_THROW(any_map = param_rti.at("nested").as()); + EXPECT_EQ(any_map.size(), 2); + OV_ASSERT_NO_THROW(value = any_map.at("infoB").as()); + EXPECT_EQ(value.compare("B"), 0); + OV_ASSERT_NO_THROW(value = any_map.at("infoC").as()); + EXPECT_EQ(value.compare("C"), 0); + + const auto abs = model->get_results().at(0)->get_input_node_ptr(0); + const auto& abs_rti = abs->output(0).get_rt_info(); + EXPECT_EQ(abs_rti.size(), 1); + OV_ASSERT_NO_THROW(any_map = abs_rti.at("nested_0").as()); + EXPECT_EQ(any_map.size(), 1); + + AnyMap nested_map; + OV_ASSERT_NO_THROW(nested_map = any_map.at("nested_1").as()); + EXPECT_EQ(nested_map.size(), 1); + OV_ASSERT_NO_THROW(value = nested_map.at("infoD").as()); + EXPECT_EQ(value.compare("D"), 0); +} + } // namespace test } // namespace ov From 52c6d264d15a7025f23f55b226295b4cb2f4763d Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Mon, 4 Nov 2024 11:25:54 +0100 Subject: [PATCH 4/6] Fix MO IR reader Signed-off-by: Tomasz Jankowski --- tools/mo/openvino/tools/mo/utils/ir_engine/ir_engine.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/mo/openvino/tools/mo/utils/ir_engine/ir_engine.py b/tools/mo/openvino/tools/mo/utils/ir_engine/ir_engine.py index aec4049c6b32e8..a8b97ead81ab5c 100644 --- a/tools/mo/openvino/tools/mo/utils/ir_engine/ir_engine.py +++ b/tools/mo/openvino/tools/mo/utils/ir_engine/ir_engine.py @@ -539,6 +539,10 @@ def __read_old_api_map_element_type(attr, layer_type): @staticmethod def __read_rt_info_common(attr): + # ignore custom info, MO is deprecated so there's no needed for compatibility + if 'version' not in attr.attrib: + return {} + attr_name = attr.attrib['name'] version = int(attr.attrib['version']) rt_info = OrderedDict() From cc000fc562dd737599c33789e08be7a3390c244b Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Tue, 19 Nov 2024 14:56:20 +0100 Subject: [PATCH 5/6] Use namepaces for test code Signed-off-by: Tomasz Jankowski --- .../serialization/rt_info_serialization.cpp | 27 +++++++++---------- src/frontends/ir/src/ir_deserializer.cpp | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/core/tests/pass/serialization/rt_info_serialization.cpp b/src/core/tests/pass/serialization/rt_info_serialization.cpp index bf82b46dcd7ee5..a9823014567e12 100644 --- a/src/core/tests/pass/serialization/rt_info_serialization.cpp +++ b/src/core/tests/pass/serialization/rt_info_serialization.cpp @@ -4,6 +4,9 @@ #include +#include +#include + #include "common_test_utils/common_utils.hpp" #include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_common.hpp" @@ -300,14 +303,8 @@ TEST(OvSerializationTests, SerializeRawMeta) { } } -#include -#include - -using namespace ov; -using ov::op::v0::Abs; -using ov::op::v0::Parameter; -using ov::op::v0::Result; -using ov::op::v1::Add; +namespace ov { +namespace test { TEST(RTInfoSerialization, custom_info) { std::string ref_ir_xml = R"V0G0N( @@ -388,10 +385,10 @@ TEST(RTInfoSerialization, custom_info) { )V0G0N"; - const auto data = std::make_shared(element::Type_t::f32, Shape{10, 10}); + const auto data = std::make_shared(element::Type_t::f32, Shape{10, 10}); const auto one = std::make_shared(element::f32, Shape{1}, std::vector{1.f}); - const auto add = std::make_shared(data, one); - const auto result = std::make_shared(add); + const auto add = std::make_shared(data, one); + const auto result = std::make_shared(add); const auto add_info = [](const std::shared_ptr& node, const std::string& value) { const_cast(node->get_name()) = "node_" + value; @@ -461,9 +458,9 @@ TEST(RTInfoSerialization, AnyMap_info) { )V0G0N"; - const auto data = std::make_shared(element::Type_t::f64, Shape{111}); - const auto abs = std::make_shared(data); - const auto result = std::make_shared(abs); + const auto data = std::make_shared(element::Type_t::f64, Shape{111}); + const auto abs = std::make_shared(data); + const auto result = std::make_shared(abs); const_cast(data->get_name()) = "data"; const_cast(abs->get_name()) = "abs"; @@ -480,3 +477,5 @@ TEST(RTInfoSerialization, AnyMap_info) { EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model))); EXPECT_EQ(ref_ir_xml.compare(model_ss.str()), 0); } +} // namespace test +} // namespace ov diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cpp index b93093f65c4228..12cd171db03e01 100644 --- a/src/frontends/ir/src/ir_deserializer.cpp +++ b/src/frontends/ir/src/ir_deserializer.cpp @@ -826,7 +826,7 @@ void set_custom_rt_info(const pugi::xml_node& rt_attrs, ov::AnyMap& rt_info) { rt_info.emplace(custom_name, custom_value); } else { rt_info.emplace(custom_name, ov::AnyMap{}); - auto& nested = rt_info.at(custom_name).as(); + auto& nested = rt_info[custom_name].as(); set_custom_rt_info(item, nested); } } From 937d0e7e5977d2e5debcf621a33f5b33aed474b6 Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Fri, 29 Nov 2024 11:22:32 +0100 Subject: [PATCH 6/6] Remove const_cast on name Signed-off-by: Tomasz Jankowski --- .../pass/serialization/rt_info_serialization.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/tests/pass/serialization/rt_info_serialization.cpp b/src/core/tests/pass/serialization/rt_info_serialization.cpp index a9823014567e12..a18dea19c70bd8 100644 --- a/src/core/tests/pass/serialization/rt_info_serialization.cpp +++ b/src/core/tests/pass/serialization/rt_info_serialization.cpp @@ -391,7 +391,7 @@ TEST(RTInfoSerialization, custom_info) { const auto result = std::make_shared(add); const auto add_info = [](const std::shared_ptr& node, const std::string& value) { - const_cast(node->get_name()) = "node_" + value; + node->set_friendly_name("node_" + value); node->get_rt_info()["node_info_" + value] = "v_" + value; node->output(0).get_rt_info()["output_info_" + value] = "o_" + value; }; @@ -401,7 +401,7 @@ TEST(RTInfoSerialization, custom_info) { add_info(result, "D"); const auto model = std::make_shared(ResultVector{result}, ParameterVector{data}); - const_cast(model->get_name()) = "CustomRTI"; + model->set_friendly_name("CustomRTI"); std::stringstream model_ss, weights_ss; EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model))); @@ -462,16 +462,16 @@ TEST(RTInfoSerialization, AnyMap_info) { const auto abs = std::make_shared(data); const auto result = std::make_shared(abs); - const_cast(data->get_name()) = "data"; - const_cast(abs->get_name()) = "abs"; - const_cast(result->get_name()) = "result"; + data->set_friendly_name("data"); + abs->set_friendly_name("abs"); + result->set_friendly_name("result"); const auto empty = AnyMap{}; const auto nested = AnyMap{{"c", "d"}}; abs->get_rt_info()["AnyMap"] = AnyMap{{"a", "b"}, {"empty", empty}, {"i", 7}, {"x", 3.14}, {"nested", nested}}; const auto model = std::make_shared(ResultVector{result}, ParameterVector{data}); - const_cast(model->get_name()) = "CustomRTI"; + model->set_friendly_name("CustomRTI"); std::stringstream model_ss, weights_ss; EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model)));