Skip to content

Commit 84dc4b9

Browse files
authored
Revert "[RtInfo/IR] Serialize non RuntimeAttribute rt_info entries of Node and Tensor" (#29036)
Reverts #27358 Merged by mistake in queue settings, there are unit tests failures on ARM in queue: https://github.com/openvinotoolkit/openvino/actions/runs/13375096810/job/37353191347
1 parent d7d43a0 commit 84dc4b9

File tree

4 files changed

+26
-441
lines changed

4 files changed

+26
-441
lines changed

src/core/src/pass/serialize.cpp

+6-31
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ void serialize_rt_info(pugi::xml_node& root, const std::string& name, const ov::
922922
child.append_attribute("name").set_value(name.c_str());
923923
}
924924
if (data.is<std::shared_ptr<ov::Meta>>()) {
925-
const auto& meta = data.as<std::shared_ptr<ov::Meta>>();
925+
auto meta = data.as<std::shared_ptr<ov::Meta>>();
926926
do {
927927
if (auto meta_with_pugixml_node = std::dynamic_pointer_cast<ov::MetaDataWithPugixml>(meta)) {
928928
if (auto pugi_node = meta_with_pugixml_node->get_pugi_node()) {
@@ -945,32 +945,11 @@ void serialize_rt_info(pugi::xml_node& root, const std::string& name, const ov::
945945
serialize_rt_info(child, it.first, it.second);
946946
}
947947
} else {
948-
const auto& value = data.as<std::string>();
948+
std::string value = data.as<std::string>();
949949
child.append_attribute("value").set_value(value.c_str());
950950
}
951951
}
952952

953-
bool append_custom_rt_info(pugi::xml_node& node, const std::string& name, const ov::Any& data) {
954-
auto custom_node = node.append_child("custom");
955-
custom_node.append_attribute("name").set_value(name.c_str());
956-
bool appended = false;
957-
958-
if (data.is<ov::AnyMap>()) {
959-
const auto& any_map = data.as<ov::AnyMap>();
960-
for (const auto& it : any_map)
961-
appended |= append_custom_rt_info(custom_node, it.first, it.second);
962-
963-
} else {
964-
const auto& value = data.as<std::string>();
965-
custom_node.append_attribute("value").set_value(value.c_str());
966-
appended = true;
967-
}
968-
969-
if (!appended)
970-
node.remove_child(custom_node);
971-
return appended;
972-
}
973-
974953
void ngfunction_2_ir(pugi::xml_node& netXml,
975954
const ov::Model& model,
976955
ConstantWriter& constant_node_write_handler,
@@ -1034,10 +1013,10 @@ void ngfunction_2_ir(pugi::xml_node& netXml,
10341013
// <layers/data> general attributes
10351014
pugi::xml_node data = layer.append_child("data");
10361015

1037-
auto append_runtime_info = [](pugi::xml_node& node, const ov::RTMap& attributes) {
1016+
auto append_runtime_info = [](pugi::xml_node& node, ov::RTMap& attributes) {
10381017
pugi::xml_node rt_node = node.append_child("rt_info");
10391018
bool has_attrs = false;
1040-
for (const auto& item : attributes) {
1019+
for (auto& item : attributes) {
10411020
if (item.second.is<ov::RuntimeAttribute>()) {
10421021
auto attribute_node = rt_node.append_child("attribute");
10431022
auto& rt_attribute = item.second.as<ov::RuntimeAttribute>();
@@ -1052,13 +1031,9 @@ void ngfunction_2_ir(pugi::xml_node& netXml,
10521031
}
10531032
}
10541033
}
1055-
1056-
for (const auto& item : attributes)
1057-
if (!item.second.is<ov::RuntimeAttribute>())
1058-
has_attrs |= append_custom_rt_info(rt_node, item.first, item.second);
1059-
1060-
if (!has_attrs)
1034+
if (!has_attrs) {
10611035
node.remove_child(rt_node);
1036+
}
10621037
};
10631038

10641039
if (version >= 11) {

src/core/tests/pass/serialization/rt_info_serialization.cpp

-180
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
#include <gtest/gtest.h>
66

7-
#include <iostream>
8-
#include <sstream>
9-
107
#include "common_test_utils/common_utils.hpp"
118
#include "common_test_utils/file_utils.hpp"
129
#include "common_test_utils/test_common.hpp"
@@ -302,180 +299,3 @@ TEST(OvSerializationTests, SerializeRawMeta) {
302299
EXPECT_EQ(0, serialized_model.compare(ir_with_rt_info));
303300
}
304301
}
305-
306-
namespace ov {
307-
namespace test {
308-
309-
TEST(RTInfoSerialization, custom_info) {
310-
std::string ref_ir_xml = R"V0G0N(<?xml version="1.0"?>
311-
<net name="CustomRTI" version="11">
312-
<layers>
313-
<layer id="0" name="node_A" type="Parameter" version="opset1">
314-
<data shape="10,10" element_type="f32" />
315-
<rt_info>
316-
<custom name="node_info_A" value="v_A" />
317-
</rt_info>
318-
<output>
319-
<port id="0" precision="FP32">
320-
<dim>10</dim>
321-
<dim>10</dim>
322-
<rt_info>
323-
<custom name="output_info_A" value="o_A" />
324-
</rt_info>
325-
</port>
326-
</output>
327-
</layer>
328-
<layer id="1" name="node_B" type="Const" version="opset1">
329-
<data element_type="f32" shape="1" offset="0" size="4" />
330-
<rt_info>
331-
<custom name="node_info_B" value="v_B" />
332-
</rt_info>
333-
<output>
334-
<port id="0" precision="FP32">
335-
<dim>1</dim>
336-
<rt_info>
337-
<custom name="output_info_B" value="o_B" />
338-
</rt_info>
339-
</port>
340-
</output>
341-
</layer>
342-
<layer id="2" name="node_C" type="Add" version="opset1">
343-
<data auto_broadcast="numpy" />
344-
<rt_info>
345-
<custom name="node_info_C" value="v_C" />
346-
</rt_info>
347-
<input>
348-
<port id="0" precision="FP32">
349-
<dim>10</dim>
350-
<dim>10</dim>
351-
</port>
352-
<port id="1" precision="FP32">
353-
<dim>1</dim>
354-
</port>
355-
</input>
356-
<output>
357-
<port id="2" precision="FP32">
358-
<dim>10</dim>
359-
<dim>10</dim>
360-
<rt_info>
361-
<custom name="output_info_C" value="o_C" />
362-
<custom name="output_info_D" value="o_D" />
363-
</rt_info>
364-
</port>
365-
</output>
366-
</layer>
367-
<layer id="3" name="node_D" type="Result" version="opset1">
368-
<rt_info>
369-
<custom name="node_info_D" value="v_D" />
370-
</rt_info>
371-
<input>
372-
<port id="0" precision="FP32">
373-
<dim>10</dim>
374-
<dim>10</dim>
375-
</port>
376-
</input>
377-
</layer>
378-
</layers>
379-
<edges>
380-
<edge from-layer="0" from-port="0" to-layer="2" to-port="0" />
381-
<edge from-layer="1" from-port="0" to-layer="2" to-port="1" />
382-
<edge from-layer="2" from-port="2" to-layer="3" to-port="0" />
383-
</edges>
384-
<rt_info />
385-
</net>
386-
)V0G0N";
387-
388-
const auto data = std::make_shared<op::v0::Parameter>(element::Type_t::f32, Shape{10, 10});
389-
const auto one = std::make_shared<op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.f});
390-
const auto add = std::make_shared<op::v1::Add>(data, one);
391-
const auto result = std::make_shared<op::v0::Result>(add);
392-
393-
const auto add_info = [](const std::shared_ptr<Node>& node, const std::string& value) {
394-
node->set_friendly_name("node_" + value);
395-
node->get_rt_info()["node_info_" + value] = "v_" + value;
396-
node->output(0).get_rt_info()["output_info_" + value] = "o_" + value;
397-
};
398-
add_info(data, "A");
399-
add_info(one, "B");
400-
add_info(add, "C");
401-
add_info(result, "D");
402-
403-
const auto model = std::make_shared<Model>(ResultVector{result}, ParameterVector{data});
404-
model->set_friendly_name("CustomRTI");
405-
406-
std::stringstream model_ss, weights_ss;
407-
EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model)));
408-
EXPECT_EQ(ref_ir_xml.compare(model_ss.str()), 0);
409-
}
410-
411-
TEST(RTInfoSerialization, AnyMap_info) {
412-
std::string ref_ir_xml = R"V0G0N(<?xml version="1.0"?>
413-
<net name="CustomRTI" version="11">
414-
<layers>
415-
<layer id="0" name="data" type="Parameter" version="opset1">
416-
<data shape="111" element_type="f64" />
417-
<output>
418-
<port id="0" precision="FP64">
419-
<dim>111</dim>
420-
</port>
421-
</output>
422-
</layer>
423-
<layer id="1" name="abs" type="Abs" version="opset1">
424-
<rt_info>
425-
<custom name="AnyMap">
426-
<custom name="a" value="b" />
427-
<custom name="i" value="7" />
428-
<custom name="nested">
429-
<custom name="c" value="d" />
430-
</custom>
431-
<custom name="x" value="3.14" />
432-
</custom>
433-
</rt_info>
434-
<input>
435-
<port id="0" precision="FP64">
436-
<dim>111</dim>
437-
</port>
438-
</input>
439-
<output>
440-
<port id="1" precision="FP64">
441-
<dim>111</dim>
442-
</port>
443-
</output>
444-
</layer>
445-
<layer id="2" name="result" type="Result" version="opset1">
446-
<input>
447-
<port id="0" precision="FP64">
448-
<dim>111</dim>
449-
</port>
450-
</input>
451-
</layer>
452-
</layers>
453-
<edges>
454-
<edge from-layer="0" from-port="0" to-layer="1" to-port="0" />
455-
<edge from-layer="1" from-port="1" to-layer="2" to-port="0" />
456-
</edges>
457-
<rt_info />
458-
</net>
459-
)V0G0N";
460-
461-
const auto data = std::make_shared<op::v0::Parameter>(element::Type_t::f64, Shape{111});
462-
const auto abs = std::make_shared<op::v0::Abs>(data);
463-
const auto result = std::make_shared<op::v0::Result>(abs);
464-
465-
data->set_friendly_name("data");
466-
abs->set_friendly_name("abs");
467-
result->set_friendly_name("result");
468-
469-
const auto empty = AnyMap{};
470-
const auto nested = AnyMap{{"c", "d"}};
471-
abs->get_rt_info()["AnyMap"] = AnyMap{{"a", "b"}, {"empty", empty}, {"i", 7}, {"x", 3.14}, {"nested", nested}};
472-
473-
const auto model = std::make_shared<Model>(ResultVector{result}, ParameterVector{data});
474-
model->set_friendly_name("CustomRTI");
475-
476-
std::stringstream model_ss, weights_ss;
477-
EXPECT_NO_THROW((ov::pass::Serialize{model_ss, weights_ss}.run_on_model(model)));
478-
EXPECT_EQ(ref_ir_xml.compare(model_ss.str()), 0);
479-
}
480-
} // namespace test
481-
} // namespace ov

src/frontends/ir/src/ir_deserializer.cpp

+20-42
Original file line numberDiff line numberDiff line change
@@ -833,25 +833,6 @@ static const std::string& translate_type_name(const std::string& name) {
833833
return name;
834834
}
835835

836-
namespace {
837-
void set_custom_rt_info(const pugi::xml_node& rt_attrs, ov::AnyMap& rt_info) {
838-
std::string custom_name, custom_value;
839-
for (const auto& item : rt_attrs) {
840-
if (std::strcmp(item.name(), "custom") == 0) {
841-
if (ov::getStrAttribute(item, "name", custom_name)) {
842-
if (ov::getStrAttribute(item, "value", custom_value)) {
843-
rt_info.emplace(custom_name, custom_value);
844-
} else {
845-
rt_info.emplace(custom_name, ov::AnyMap{});
846-
auto& nested = rt_info[custom_name].as<ov::AnyMap>();
847-
set_custom_rt_info(item, nested);
848-
}
849-
}
850-
}
851-
}
852-
}
853-
} // namespace
854-
855836
std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov::Output<ov::Node>>& inputs,
856837
const pugi::xml_node& node,
857838
const std::shared_ptr<ov::AlignedBuffer>& weights,
@@ -1005,36 +986,33 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:
1005986
if (!rt_attrs)
1006987
return;
1007988
for (const auto& item : rt_attrs) {
1008-
if (std::strcmp(item.name(), "attribute") == 0) {
1009-
std::string attribute_name, attribute_version;
1010-
if (!getStrAttribute(item, "name", attribute_name) ||
1011-
!getStrAttribute(item, "version", attribute_version))
1012-
continue;
1013-
1014-
const auto& type_info = ov::DiscreteTypeInfo(attribute_name.c_str(), attribute_version.c_str());
1015-
auto attr = attrs_factory.create_by_type_info(type_info);
1016-
if (!attr.empty()) {
1017-
if (attr.is<ov::RuntimeAttribute>()) {
1018-
RTInfoDeserializer attribute_visitor(item);
1019-
if (attr.as<ov::RuntimeAttribute>().visit_attributes(attribute_visitor)) {
1020-
auto res = rt_info.emplace(type_info, attr);
1021-
if (!res.second) {
1022-
OPENVINO_THROW("multiple rt_info attributes are detected: ", attribute_name);
1023-
}
1024-
} else {
1025-
OPENVINO_THROW("VisitAttributes is not supported for: ", item.name(), " attribute");
989+
std::string attribute_name, attribute_version;
990+
// For view:
991+
// <attribute name="old_api_map_order" version="0" value="0,3,1,2"/>
992+
if (!getStrAttribute(item, "name", attribute_name) || !getStrAttribute(item, "version", attribute_version))
993+
continue;
994+
995+
const auto& type_info = ov::DiscreteTypeInfo(attribute_name.c_str(), attribute_version.c_str());
996+
auto attr = attrs_factory.create_by_type_info(type_info);
997+
if (!attr.empty()) {
998+
if (attr.is<ov::RuntimeAttribute>()) {
999+
RTInfoDeserializer attribute_visitor(item);
1000+
if (attr.as<ov::RuntimeAttribute>().visit_attributes(attribute_visitor)) {
1001+
auto res = rt_info.emplace(type_info, attr);
1002+
if (!res.second) {
1003+
OPENVINO_THROW("multiple rt_info attributes are detected: ", attribute_name);
10261004
}
10271005
} else {
1028-
OPENVINO_THROW("Attribute: ", item.name(), " is not recognized as runtime attribute");
1006+
OPENVINO_THROW("VisitAttributes is not supported for: ", item.name(), " attribute");
10291007
}
10301008
} else {
1031-
// As runtime attributes are optional, so we skip attribute if it is unknown to avoid exception
1032-
// when loading new IR with new attribute in old OV version.
1009+
OPENVINO_THROW("Attribute: ", item.name(), " is not recognized as runtime attribute");
10331010
}
1011+
} else {
1012+
// As runtime attributes are optional, so we skip attribute if it is unknown to avoid exception
1013+
// when loading new IR with new attribute in old OV version.
10341014
}
10351015
}
1036-
1037-
set_custom_rt_info(rt_attrs, rt_info);
10381016
};
10391017

10401018
// read runtime info only for IR v11+

0 commit comments

Comments
 (0)