OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[core, IR FE] Extract xml deseializer as common util (#31593)
Pawel Raasz4c58d148a31a
diff --git a/src/common/util/src/xml_parse_utils.cpp b/src/common/util/src/xml_parse_utils.cppindex 3c347ca79f3..6c01ab91921 100644--- a/src/common/util/src/xml_parse_utils.cpp+++ b/src/common/util/src/xml_parse_utils.cpp@@ -233,4 +233,4 @@ int pugixml::get_int_child(const pugi::xml_node& node, const char* str, int defV}} // namespace util-} // namespace ov\ No newline at end of file+} // namespace ovdiff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txtindex e594fabc292..1dadebdf3e6 100644--- a/src/core/CMakeLists.txt+++ b/src/core/CMakeLists.txt@@ -17,6 +17,7 @@ file(GLOB_RECURSE DEV_HEADERS ${OV_CORE_DEV_API_PATH}/*.hpp)add_subdirectory(reference)add_subdirectory(shape_inference)+add_subdirectory(xml_util)set(MIXED_SRC"${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/allocator.cpp"diff --git a/src/core/xml_util/CMakeLists.txt b/src/core/xml_util/CMakeLists.txtnew file mode 100644index 00000000000..f1bbbe6eefc--- /dev/null+++ b/src/core/xml_util/CMakeLists.txt@@ -0,0 +1,42 @@+# Copyright (C) 2018-2025 Intel Corporation+# SPDX-License-Identifier: Apache-2.0+#++set(TARGET_NAME "openvino_xml_util")++set(TARGET_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")++file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)+file(GLOB_RECURSE PUBLIC_HEADERS ${TARGET_INCLUDE_DIR}/*.hpp)++# Create named folders for the sources within the .vcproj+# Empty name lists them directly under the .vcproj++source_group("src" FILES ${LIBRARY_SRC})+source_group("include" FILES ${PUBLIC_HEADERS})++# Create static library+add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS})++add_library(openvino::xml_util ALIAS ${TARGET_NAME})+set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME openvino_xml_util)++target_include_directories(${TARGET_NAME} PUBLIC+ $<BUILD_INTERFACE:${TARGET_INCLUDE_DIR}>+ $<TARGET_PROPERTY:openvino::core::dev,INTERFACE_INCLUDE_DIRECTORIES>)++ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})+target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime)++if(NOT BUILD_SHARED_LIBS)+ target_compile_definitions(${TARGET_NAME} PUBLIC OPENVINO_STATIC_LIBRARY)+endif()++ov_build_target_faster(${TARGET_NAME} PCH)++# developer package++ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE})++ov_developer_package_export_targets(TARGET ${TARGET_NAME}+ INSTALL_INCLUDE_DIRECTORIES "${TARGET_INCLUDE_DIR}/")diff --git a/src/frontends/ir/src/ir_deserializer.hpp b/src/core/xml_util/include/openvino/xml_util/xml_deserialize_util.hppsimilarity index 57%rename from src/frontends/ir/src/ir_deserializer.hpprename to src/core/xml_util/include/openvino/xml_util/xml_deserialize_util.hppindex 3e085562174..d7d9ea02b3d 100644--- a/src/frontends/ir/src/ir_deserializer.hpp+++ b/src/core/xml_util/include/openvino/xml_util/xml_deserialize_util.hpp@@ -4,58 +4,22 @@#pragma once-#include <cctype>-#include <istream>-#include <memory>+#include <functional>+#include <map>#include <pugixml.hpp>+#include <string>+#include <vector>-#include "input_model.hpp"-#include "openvino/core/attribute_visitor.hpp"#include "openvino/core/op_extension.hpp"+#include "openvino/core/type/element_type.hpp"+#include "openvino/core/visibility.hpp"#include "openvino/op/loop.hpp"-#include "openvino/op/util/sub_graph_base.hpp"+#include "openvino/op/util/multi_subgraph_base.hpp"#include "openvino/opsets/opset.hpp"#include "openvino/runtime/aligned_buffer.hpp"-#include "utils.hpp"-namespace ov {--struct GenericLayerParams {- struct LayerPortData {- size_t portId;- std::vector<ov::Dimension> dims;- ov::element::Type_t precision;- std::unordered_set<std::string> names;- };- size_t layerId;- std::string version;- std::string name;- std::string type;- std::vector<LayerPortData> inputPorts;- std::vector<LayerPortData> outputPorts;-- size_t get_real_input_port_id(size_t id) const {- size_t real_id = 0;- for (auto& it : inputPorts) {- if (it.portId == id) {- return real_id;- }- ++real_id;- }- OPENVINO_THROW("Can not find input port with id ", id, " in layer ", name);- }-- size_t get_real_output_port_id(size_t id) const {- size_t real_id = 0;- for (auto& it : outputPorts) {- if (it.portId == id) {- return real_id;- }- ++real_id;- }- OPENVINO_THROW("Can not find output port with id ", id, " in layer ", name);- }-};+namespace ov::util {+struct GenericLayerParams;class XmlDeserializer : public ov::AttributeVisitor {public:@@ -64,81 +28,31 @@ public:const std::unordered_map<std::string, ov::OpSet>& opsets,const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,std::unordered_map<std::string, std::shared_ptr<ov::op::util::Variable>>& variables,- size_t version)- : m_node(node),- m_weights(weights),- m_opsets(opsets),- m_extensions(extensions),- m_variables(variables),- m_version(version) {}-- void on_adapter(const std::string& name, ov::ValueAccessor<std::string>& value) override {- std::string val;- if (!getStrAttribute(m_node.child("data"), name, val))- return;- value.set(val);- }- void on_adapter(const std::string& name, ov::ValueAccessor<bool>& value) override {- std::string val;- if (!getStrAttribute(m_node.child("data"), name, val))- return;- std::transform(val.begin(), val.end(), val.begin(), [](char ch) {- return std::tolower(static_cast<unsigned char>(ch));- });- std::set<std::string> true_names{"true", "1"};- std::set<std::string> false_names{"false", "0"};-- bool is_true = true_names.find(val) != true_names.end();- bool is_false = false_names.find(val) != false_names.end();-- if (!is_true && !is_false)- return;- value.set(is_true);- }+ size_t version);++ void on_adapter(const std::string& name, ov::ValueAccessor<std::string>& value) override;++ void on_adapter(const std::string& name, ov::ValueAccessor<bool>& value) override;void on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) override;- void on_adapter(const std::string& name, ov::ValueAccessor<double>& adapter) override {- std::string val;- if (!getStrAttribute(m_node.child("data"), name, val))- return;- adapter.set(stringToType<double>(val));- }- void on_adapter(const std::string& name, ov::ValueAccessor<int64_t>& adapter) override {- std::string val;- if (!getStrAttribute(m_node.child("data"), name, val))- return;- adapter.set(stringToType<int64_t>(val));- }+ void on_adapter(const std::string& name, ov::ValueAccessor<double>& adapter) override;+ void on_adapter(const std::string& name, ov::ValueAccessor<int64_t>& adapter) override;void on_adapter(const std::string& name, ov::ValueAccessor<std::shared_ptr<ov::Model>>& adapter) override;- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int32_t>>& adapter) override {- std::vector<int32_t> value;- if (!getParameters<int32_t>(m_node.child("data"), name, value))- return;- adapter.set(value);- }+ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int32_t>>& adapter) override;- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int64_t>>& adapter) override {- std::vector<int64_t> value;- if (!getParameters<int64_t>(m_node.child("data"), name, value))- return;- adapter.set(value);- }+ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int64_t>>& adapter) override;- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<float>>& adapter) override {- std::vector<float> value;- if (!getParameters<float>(m_node.child("data"), name, value))- return;- adapter.set(value);- }+ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<float>>& adapter) override;- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<std::string>>& adapter) override {- std::vector<std::string> value;- if (!getParameters<std::string>(m_node.child("data"), name, value))- return;- adapter.set(value);- }+ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<std::string>>& adapter) override;++protected:+ virtual ov::Any parse_weightless_cache_attribute(const pugi::xml_node& node) const;+ virtual void set_constant_num_buffer(ov::AttributeAdapter<std::shared_ptr<ov::AlignedBuffer>>& adapter);++ const pugi::xml_node& get_node() const;private:struct IoMap {@@ -187,6 +101,16 @@ private:const std::unordered_set<std::string>& names,const pugi::xml_node& root_section);+ virtual std::unique_ptr<XmlDeserializer> make_visitor(+ const pugi::xml_node& node,+ const std::shared_ptr<ov::AlignedBuffer>& weights,+ const std::unordered_map<std::string, ov::OpSet>& opsets,+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,+ std::unordered_map<std::string, std::shared_ptr<ov::op::util::Variable>>& variables,+ size_t version) const {+ return std::make_unique<XmlDeserializer>(node, weights, opsets, extensions, variables, version);+ }+// -- DATA --const pugi::xml_node m_node;const std::shared_ptr<ov::AlignedBuffer>& m_weights;@@ -202,4 +126,5 @@ private:int64_t m_version;};-} // namespace ov++} // namespace ov::utildiff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/core/xml_util/src/xml_deserialize_util.cppsimilarity index 72%rename from src/frontends/ir/src/ir_deserializer.cpprename to src/core/xml_util/src/xml_deserialize_util.cppindex 0fcc105e8c3..540bde2374b 100644--- a/src/frontends/ir/src/ir_deserializer.cpp+++ b/src/core/xml_util/src/xml_deserialize_util.cpp@@ -2,40 +2,120 @@// SPDX-License-Identifier: Apache-2.0//-#include "ir_deserializer.hpp"+#include "openvino/xml_util/xml_deserialize_util.hpp"-#include <pugixml.hpp>#include <regex>#include <stack>#include <string_view>#include "openvino/core/descriptor_tensor.hpp"-#include "openvino/core/except.hpp"+#include "openvino/core/memory_util.hpp"#include "openvino/core/meta_data.hpp"#include "openvino/core/rt_info/weightless_caching_attributes.hpp"#include "openvino/core/type.hpp"-#include "openvino/core/type/element_type.hpp"+#include "openvino/core/type/element_type_traits.hpp"#include "openvino/op/constant.hpp"-#include "openvino/op/loop.hpp"#include "openvino/op/parameter.hpp"#include "openvino/op/result.hpp"#include "openvino/op/util/assign_base.hpp"#include "openvino/op/util/framework_node.hpp"#include "openvino/op/util/op_types.hpp"#include "openvino/op/util/read_value_base.hpp"-#include "openvino/op/util/sub_graph_base.hpp"#include "openvino/op/util/variable.hpp"-#include "openvino/runtime/aligned_buffer.hpp"#include "openvino/runtime/shared_buffer.hpp"#include "openvino/runtime/string_aligned_buffer.hpp"+#include "openvino/util/common_util.hpp"#include "openvino/util/xml_parse_utils.hpp"-#include "rt_info_deserializer.hpp"#include "transformations/rt_info/attributes.hpp"-#include "utils.hpp"--using namespace ov::util;+namespace ov::util {namespace {++bool getStrAttribute(const pugi::xml_node& node, const std::string& name, std::string& value) {+ if (!node)+ return false;++ auto attr = node.attribute(name.c_str());+ if (attr.empty())+ return false;+ value = std::string(attr.value());+ return true;+}++template <class T>+void str_to_container(const std::string& value, T& res) {+ std::stringstream ss(value);+ std::string field;+ while (getline(ss, field, ',')) {+ if (field.empty())+ OPENVINO_THROW("Cannot get vector of parameters! \"", value, "\" is incorrect");+ std::stringstream fs(field);+ typename T::value_type val;+ fs >> val;+ res.insert(res.end(), val);+ }+}++template <class T>+bool getParameters(const pugi::xml_node& node, const std::string& name, std::vector<T>& value) {+ std::string param;+ if (!getStrAttribute(node, name, param))+ return false;+ str_to_container(param, value);+ return true;+}++template <class T>+T stringToType(const std::string& valStr) {+ T ret{0};+ std::istringstream ss(valStr);+ if (!ss.eof()) {+ ss >> ret;+ }+ return ret;+}++bool get_partial_shape_from_attribute(const pugi::xml_node& node, const std::string& name, PartialShape& value) {+ std::string param;+ if (!getStrAttribute(node, name, param))+ return false;+ value = PartialShape(param);+ return true;+}++bool get_dimension_from_attribute(const pugi::xml_node& node, const std::string& name, Dimension& value) {+ std::string param;+ if (!getStrAttribute(node, name, param))+ return false;+ value = Dimension(param);+ return true;+}++void str_to_set_of_strings(const std::string& value, std::set<std::string>& res) {+ std::stringstream ss(value);+ std::string field;+ while (getline(ss, field, ',')) {+ // trim leading and trailing whitespaces+ auto strBegin = field.find_first_not_of(" ");+ if (strBegin == std::string::npos)+ OPENVINO_THROW("Cannot get a set of strings from \"", value, "\". Value \"", field, "\" is incorrect");+ auto strRange = field.find_last_not_of(" ") - strBegin + 1;++ res.insert(field.substr(strBegin, strRange));+ }+}++void str_to_container(const std::string& value, std::vector<std::string>& res) {+ std::stringstream ss(value);+ std::string field;+ while (getline(ss, field, ',')) {+ field = ov::util::trim(field);+ if (!field.empty()) {+ res.emplace_back(field);+ }+ }+}+/*** @brief Function deserializing tensor names.*@@ -58,7 +138,7 @@ std::unordered_set<std::string> deserialize_tensor_names(const std::string_view&*name_inserter = std::regex_replace(std::string(name_view), escaped_delim, delim);}start = pos;- } else if (pos > 0 && tensor_names[pos - 1] == esc_char) {+ } else if (auto delim_pos = pos - 1; delim_pos != std::string::npos && tensor_names[delim_pos] == esc_char) {++pos;} else {if (auto length = pos - start; length > 0) {@@ -73,8 +153,356 @@ std::unordered_set<std::string> deserialize_tensor_names(const std::string_view&}} // namespace-ov::XmlDeserializer::IoMap ov::XmlDeserializer::updated_io_map(const pugi::xml_node& node,- const pugi::xml_node& body_node) {+struct GenericLayerParams {+ struct LayerPortData {+ size_t portId;+ std::vector<ov::Dimension> dims;+ ov::element::Type_t precision;+ std::unordered_set<std::string> names;+ };+ size_t layerId;+ std::string version;+ std::string name;+ std::string type;+ std::vector<LayerPortData> inputPorts;+ std::vector<LayerPortData> outputPorts;++ size_t get_real_input_port_id(size_t id) const {+ size_t real_id = 0;+ for (auto& it : inputPorts) {+ if (it.portId == id) {+ return real_id;+ }+ ++real_id;+ }+ OPENVINO_THROW("Can not find input port with id ", id, " in layer ", name);+ }++ size_t get_real_output_port_id(size_t id) const {+ size_t real_id = 0;+ for (auto& it : outputPorts) {+ if (it.portId == id) {+ return real_id;+ }+ ++real_id;+ }+ OPENVINO_THROW("Can not find output port with id ", id, " in layer ", name);+ }+};++class MetaDataParser : public ov::MetaDataWithPugixml {+public:+ MetaDataParser(const std::string& name, const pugi::xml_node& meta, bool accessible_by_pugixml_node = true)+ : m_name(name),+ m_accessible_by_pugixml_node(accessible_by_pugixml_node) {+ m_meta.append_copy(meta);+ if (accessible_by_pugixml_node) {+ m_meta_node = m_meta.child(m_name.c_str());+ } else {+ m_meta_node = pugi::xml_node();+ }+ }++ operator const ov::AnyMap&() const override {+ parse();+ return m_parsed_map;+ }++ operator ov::AnyMap&() override {+ parse();+ return m_parsed_map;+ }++ const pugi::xml_node& get_pugi_node() const override {+ if (!m_meta_node.empty() && !m_accessible_by_pugixml_node) {+ // Meta cannot be accessed by pugixml node. Return empty node+ m_meta_node = pugi::xml_node();+ }+ return m_meta_node;+ };++private:+ bool has_attr(const pugi::xml_node& node, const std::string& name = "value") const {+ auto attr = node.attribute(name.c_str());+ return !attr.empty();+ }++ ov::Any parse_value(const pugi::xml_node& node) const {+ if (has_attr(node)) {+ return pugixml::get_str_attr(node, "value");+ } else if (std::string(node.name()) == "unset" && has_attr(node, "unset_cli_parameters")) {+ return pugixml::get_str_attr(node, "unset_cli_parameters");+ } else {+ return parse_node(node);+ }+ }++ ov::AnyMap parse_node(const pugi::xml_node& node) const {+ ov::AnyMap result;+ // Old version may produce nodes like <name value="..."/>, but it may brake xml-naming convention+ // Now it should look like <info name="..." value="..."/>.+ // Also we keep an option to read an old XMLs where it doesn't have name attribute+ const auto name_attr = node.attribute("name");+ const std::string node_name = name_attr.empty() ? node.name() : name_attr.value();+ for (const auto& data : node.children()) {+ const auto name_attr = data.attribute("name");+ const std::string data_name = name_attr.empty() ? data.name() : name_attr.value();+ // WA for legacy POT config+ if (data_name == "config" && node_name == "quantization_parameters") {+ // Read legacy pot config+ std::stringstream stream;+ data.print(stream);+ std::string str_config = stream.str();+ str_config = std::regex_replace(str_config, std::regex("<config>"), "");+ str_config = std::regex_replace(str_config, std::regex("</config>"), "");+ str_config = std::regex_replace(str_config, std::regex("\n"), "");+ str_config = std::regex_replace(str_config, std::regex("( +)"), " ");+ result[data_name] = str_config;+ } else {+ result[data_name] = parse_value(data);+ }+ }+ return result;+ }++ void parse() const {+ std::call_once(m_oc, [this]() {+ m_accessible_by_pugixml_node = false;+ const pugi::xml_node& node = m_meta.child(m_name.c_str());+ m_parsed_map = parse_node(node);+ });+ }++ pugi::xml_document m_meta;+ const std::string m_name;+ mutable ov::AnyMap m_parsed_map;+ mutable std::once_flag m_oc;+ mutable std::atomic_bool m_accessible_by_pugixml_node;+ mutable pugi::xml_node m_meta_node;+};++class RTInfoDeserializer : public ov::AttributeVisitor {+public:+ explicit RTInfoDeserializer(const pugi::xml_node& node) : m_node(node) {}++ void on_adapter(const std::string& name, ov::ValueAccessor<std::string>& value) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ value.set(val);+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<bool>& value) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ std::transform(val.begin(), val.end(), val.begin(), [](char ch) {+ return std::tolower(static_cast<unsigned char>(ch));+ });+ std::set<std::string> true_names{"true", "1"};+ std::set<std::string> false_names{"false", "0"};++ bool is_true = true_names.find(val) != true_names.end();+ bool is_false = false_names.find(val) != false_names.end();++ if (!is_true && !is_false)+ return;+ value.set(is_true);+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ if (auto a = as_type<AttributeAdapter<std::set<std::string>>>(&adapter)) {+ std::set<std::string> ss;+ str_to_set_of_strings(val, ss);+ a->set(ss);+ } else {+ OPENVINO_NOT_IMPLEMENTED;+ }+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<double>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ adapter.set(stringToType<double>(val));+ }+ void on_adapter(const std::string& name, ov::ValueAccessor<int64_t>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ adapter.set(stringToType<int64_t>(val));+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<std::shared_ptr<ov::Model>>& adapter) override {+ OPENVINO_THROW("Model type is unsupported for rt info deserialization");+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int32_t>>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ std::vector<int32_t> value;+ str_to_container(val, value);+ adapter.set(value);+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int64_t>>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ std::vector<int64_t> value;+ str_to_container(val, value);+ adapter.set(value);+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<float>>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ std::vector<float> value;+ str_to_container(val, value);+ adapter.set(value);+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<uint64_t>>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ std::vector<uint64_t> value;+ str_to_container(val, value);+ adapter.set(value);+ }++ void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<std::string>>& adapter) override {+ check_attribute_name(name);+ std::string val;+ if (!getStrAttribute(m_node, name, val))+ return;+ std::vector<std::string> value;+ str_to_container(val, value);+ adapter.set(value);+ }++ void check_attribute_name(const std::string& name) const {+ OPENVINO_ASSERT(name != "name" && name != "version",+ "Attribute key with name: ",+ name,+ " is not allowed. Please use another name");+ }++private:+ pugi::xml_node m_node;+};++XmlDeserializer::XmlDeserializer(const pugi::xml_node& node,+ const std::shared_ptr<ov::AlignedBuffer>& weights,+ const std::unordered_map<std::string, ov::OpSet>& opsets,+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,+ std::unordered_map<std::string, std::shared_ptr<ov::op::util::Variable>>& variables,+ size_t version)+ : m_node(node),+ m_weights(weights),+ m_opsets(opsets),+ m_extensions(extensions),+ m_variables(variables),+ m_version(version) {}++ov::Any XmlDeserializer::parse_weightless_cache_attribute(const pugi::xml_node& node) const {+ ov::Any wl_attr;+ if (const auto data_node = node.child("data")) {+ const auto size = data_node.attribute("size");+ const auto offset = data_node.attribute("offset");+ const auto element_type = data_node.attribute("element_type");+ if (size && offset && element_type) {+ wl_attr = ov::WeightlessCacheAttribute(static_cast<size_t>(pugixml::get_uint64_attr(data_node, "size")),+ static_cast<size_t>(pugixml::get_uint64_attr(data_node, "offset")),+ ov::element::Type(pugixml::get_str_attr(data_node, "element_type")));+ }+ }++ return wl_attr;+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<std::string>& value) {+ std::string val;+ if (!getStrAttribute(m_node.child("data"), name, val))+ return;+ value.set(val);+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<bool>& value) {+ std::string val;+ if (!getStrAttribute(m_node.child("data"), name, val))+ return;+ std::transform(val.begin(), val.end(), val.begin(), [](char ch) {+ return std::tolower(static_cast<unsigned char>(ch));+ });+ std::set<std::string> true_names{"true", "1"};+ std::set<std::string> false_names{"false", "0"};++ bool is_true = true_names.find(val) != true_names.end();+ bool is_false = false_names.find(val) != false_names.end();++ if (!is_true && !is_false)+ return;+ value.set(is_true);+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<double>& adapter) {+ std::string val;+ if (!getStrAttribute(m_node.child("data"), name, val))+ return;+ adapter.set(stringToType<double>(val));+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<int64_t>& adapter) {+ std::string val;+ if (!getStrAttribute(m_node.child("data"), name, val))+ return;+ adapter.set(stringToType<int64_t>(val));+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int32_t>>& adapter) {+ std::vector<int32_t> value;+ if (!getParameters<int32_t>(m_node.child("data"), name, value))+ return;+ adapter.set(value);+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int64_t>>& adapter) {+ std::vector<int64_t> value;+ if (!getParameters<int64_t>(m_node.child("data"), name, value))+ return;+ adapter.set(value);+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<std::vector<float>>& adapter) {+ std::vector<float> value;+ if (!getParameters<float>(m_node.child("data"), name, value))+ return;+ adapter.set(value);+}++void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<std::vector<std::string>>& adapter) {+ std::vector<std::string> value;+ if (!getParameters<std::string>(m_node.child("data"), name, value))+ return;+ adapter.set(value);+}++XmlDeserializer::IoMap XmlDeserializer::updated_io_map(const pugi::xml_node& node, const pugi::xml_node& body_node) {if (body_node.empty()) {OPENVINO_THROW("Missing body part.");}@@ -96,7 +524,7 @@ ov::XmlDeserializer::IoMap ov::XmlDeserializer::updated_io_map(const pugi::xml_nreturn extend_io_map;}-std::vector<std::shared_ptr<ov::op::util::SubGraphOp::InputDescription>> ov::XmlDeserializer::parse_input_description(+std::vector<std::shared_ptr<ov::op::util::SubGraphOp::InputDescription>> XmlDeserializer::parse_input_description(const pugi::xml_node& node,const std::string& body_name,const std::string& port_map_name) {@@ -170,9 +598,9 @@ std::vector<std::shared_ptr<ov::op::util::SubGraphOp::InputDescription>> ov::Xml}std::vector<std::shared_ptr<ov::op::util::MultiSubGraphOp::OutputDescription>>-ov::XmlDeserializer::parse_output_description(const pugi::xml_node& node,- const std::string& body_name,- const std::string& port_map_name) {+XmlDeserializer::parse_output_description(const pugi::xml_node& node,+ const std::string& body_name,+ const std::string& port_map_name) {std::vector<std::shared_ptr<ov::op::util::MultiSubGraphOp::OutputDescription>> outputs;auto body_node = node.child(body_name.c_str());const auto up_io_map = updated_io_map(node, body_node);@@ -226,7 +654,7 @@ ov::XmlDeserializer::parse_output_description(const pugi::xml_node& node,return outputs;}-ov::op::v5::Loop::SpecialBodyPorts ov::XmlDeserializer::parse_purpose_attribute(const pugi::xml_node& node) {+ov::op::v5::Loop::SpecialBodyPorts XmlDeserializer::parse_purpose_attribute(const pugi::xml_node& node) {ov::op::v5::Loop::SpecialBodyPorts result = {-1, -1};auto body_node = node.child("body");const auto up_io_map = updated_io_map(node, body_node);@@ -268,7 +696,7 @@ ov::op::v5::Loop::SpecialBodyPorts ov::XmlDeserializer::parse_purpose_attribute(return result;}-void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) {+void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) {static const std::unordered_set<std::string> skip_names = {"input_descriptions","output_descriptions","special_body_ports",@@ -380,36 +808,7 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<value.copy(data, value.size());a->set(buffer);} else if (name == "value" && type == "Const") {- std::vector<int64_t> shape;- std::string el_type_str;-- size_t offset = static_cast<size_t>(pugixml::get_uint64_attr(dn, "offset"));- size_t size = static_cast<size_t>(pugixml::get_uint64_attr(dn, "size"));- if (!getStrAttribute(dn, "element_type", el_type_str))- return;- if (!getParameters<int64_t>(dn, "shape", shape))- return;-- ov::element::Type el_type = ov::element::Type(el_type_str);-- if (!m_weights)- OPENVINO_THROW("Empty weights data in bin file or bin file cannot be found!");- if (m_weights->size() < offset + size)- OPENVINO_THROW("Incorrect weights in bin file!");- char* data = m_weights->get_ptr<char>() + offset;-- if (el_type == element::string) {- auto buffer =- ov::AttributeAdapter<std::shared_ptr<ov::StringAlignedBuffer>>::unpack_string_tensor(data, size);- a->set(buffer);- } else {- if (size < ((ov::shape_size(shape) * el_type.bitwidth() + 7) >> 3))- OPENVINO_THROW("Attribute and shape size are inconsistent for ", type, " op!");-- auto buffer =- std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::AlignedBuffer>>>(data, size, m_weights);- a->set(buffer);- }+ set_constant_num_buffer(*a);}} else if (auto a = ov::as_type<ov::AttributeAdapter<std::shared_ptr<ov::StringAlignedBuffer>>>(&adapter)) {pugi::xml_node dn = m_node.child("data");@@ -461,7 +860,7 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<}}-void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<std::shared_ptr<ov::Model>>& adapter) {+void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<std::shared_ptr<ov::Model>>& adapter) {std::shared_ptr<ov::Model> model;io_map = {};@@ -479,8 +878,49 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<adapter.set(model);}-std::shared_ptr<ov::Model> ov::XmlDeserializer::parse_function(const pugi::xml_node& root,- const std::shared_ptr<ov::AlignedBuffer>& weights) {+void XmlDeserializer::set_constant_num_buffer(ov::AttributeAdapter<std::shared_ptr<ov::AlignedBuffer>>& adapter) {+ OPENVINO_ASSERT(m_weights, "Empty weights data in bin file or bin file cannot be found!");+ std::vector<int64_t> shape;+ std::string el_type_str;+ const auto& dn = m_node.child("data");++ if (!getStrAttribute(dn, "element_type", el_type_str))+ return;++ if (!getParameters<int64_t>(dn, "shape", shape)) {+ return;+ }++ const auto size = static_cast<size_t>(pugixml::get_uint64_attr(dn, "size"));+ const auto offset = static_cast<size_t>(pugixml::get_uint64_attr(dn, "offset"));+ OPENVINO_ASSERT(m_weights->size() >= offset + size, "Incorrect weights in bin file!");++ char* data = m_weights->get_ptr<char>() + offset;++ const auto el_type = ov::element::Type(el_type_str);+ if (el_type == element::string) {+ auto buffer = ov::AttributeAdapter<std::shared_ptr<ov::StringAlignedBuffer>>::unpack_string_tensor(data, size);+ adapter.set(buffer);+ } else {+ if (size < ((ov::shape_size(shape) * el_type.bitwidth() + 7) >> 3)) {+ const auto type = pugixml::get_str_attr(m_node, "type");+ OPENVINO_THROW("Attribute and shape size are inconsistent for ",+ type,+ " op!",+ size,+ ", ",+ ((ov::shape_size(shape) * el_type.bitwidth() + 7) >> 3),+ ", ",+ ov::util::get_memory_size(el_type, ov::shape_size(shape)));+ }++ auto buffer = std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::AlignedBuffer>>>(data, size, m_weights);+ adapter.set(buffer);+ }+}++std::shared_ptr<ov::Model> XmlDeserializer::parse_function(const pugi::xml_node& root,+ const std::shared_ptr<ov::AlignedBuffer>& weights) {// OV_ITT_SCOPE_CHAIN(FIRST_INFERENCE, taskChain, itt::domains::V10Reader_RT, "V10Parser", "Parse");struct FunctionNodes {@@ -530,7 +970,7 @@ std::shared_ptr<ov::Model> ov::XmlDeserializer::parse_function(const pugi::xml_nedges[toLayer].push_back({fromLayer, fromPort, toPort});}- // Run DFS starting from outputs to get nodes topological order without recursion+ // Run DFS starting from outputs to get nodes topological orderstd::function<void(size_t)> dfs = [&edges, &order, &dfs_used_nodes](const size_t start_id) {std::stack<size_t> stack;std::unordered_set<size_t> visited;@@ -645,98 +1085,7 @@ std::shared_ptr<ov::Model> ov::XmlDeserializer::parse_function(const pugi::xml_nreturn function;}-class MetaDataParser : public ov::MetaDataWithPugixml {-public:- MetaDataParser(const std::string& name, const pugi::xml_node& meta, bool accessible_by_pugixml_node = true)- : m_name(name),- m_accessible_by_pugixml_node(accessible_by_pugixml_node) {- m_meta.append_copy(meta);- if (accessible_by_pugixml_node) {- m_meta_node = m_meta.child(m_name.c_str());- } else {- m_meta_node = pugi::xml_node();- }- }-- operator const ov::AnyMap&() const override {- parse();- return m_parsed_map;- }-- operator ov::AnyMap&() override {- parse();- return m_parsed_map;- }-- const pugi::xml_node& get_pugi_node() const override {- if (!m_meta_node.empty() && !m_accessible_by_pugixml_node) {- // Meta cannot be accessed by pugixml node. Return empty node- m_meta_node = pugi::xml_node();- }- return m_meta_node;- };--private:- bool has_attr(const pugi::xml_node& node, const std::string& name = "value") const {- auto attr = node.attribute(name.c_str());- return !attr.empty();- }-- ov::Any parse_value(const pugi::xml_node& node) const {- if (has_attr(node)) {- return pugixml::get_str_attr(node, "value");- } else if (std::string(node.name()) == "unset" && has_attr(node, "unset_cli_parameters")) {- return pugixml::get_str_attr(node, "unset_cli_parameters");- } else {- return parse_node(node);- }- }-- ov::AnyMap parse_node(const pugi::xml_node& node) const {- ov::AnyMap result;- // Old version may produce nodes like <name value="..."/>, but it may brake xml-naming convention- // Now it should look like <info name="..." value="..."/>.- // Also we keep an option to read an old XMLs where it doesn't have name attribute- const auto name_attr = node.attribute("name");- const std::string node_name = name_attr.empty() ? node.name() : name_attr.value();- for (const auto& data : node.children()) {- const auto name_attr = data.attribute("name");- const std::string data_name = name_attr.empty() ? data.name() : name_attr.value();- // WA for legacy POT config- if (data_name == "config" && node_name == "quantization_parameters") {- // Read legacy pot config- std::stringstream stream;- data.print(stream);- std::string str_config = stream.str();- str_config = std::regex_replace(str_config, std::regex("<config>"), "");- str_config = std::regex_replace(str_config, std::regex("</config>"), "");- str_config = std::regex_replace(str_config, std::regex("\n"), "");- str_config = std::regex_replace(str_config, std::regex("( +)"), " ");- result[data_name] = str_config;- } else {- result[data_name] = parse_value(data);- }- }- return result;- }-- void parse() const {- std::call_once(m_oc, [this]() {- m_accessible_by_pugixml_node = false;- const pugi::xml_node& node = m_meta.child(m_name.c_str());- m_parsed_map = parse_node(node);- });- }-- pugi::xml_document m_meta;- const std::string m_name;- mutable ov::AnyMap m_parsed_map;- mutable std::once_flag m_oc;- mutable std::atomic_bool m_accessible_by_pugixml_node;- mutable pugi::xml_node m_meta_node;-};--void ov::XmlDeserializer::read_meta_data(const std::shared_ptr<ov::Model>& model, const pugi::xml_node& meta_section) {+void XmlDeserializer::read_meta_data(const std::shared_ptr<ov::Model>& model, const pugi::xml_node& meta_section) {if (meta_section.empty())return;auto& rt_info = model->get_rt_info();@@ -758,9 +1107,9 @@ void ov::XmlDeserializer::read_meta_data(const std::shared_ptr<ov::Model>& model}}-void ov::XmlDeserializer::read_legacy_meta_data(const std::shared_ptr<ov::Model>& model,- const std::unordered_set<std::string>& names,- const pugi::xml_node& root_section) {+void XmlDeserializer::read_legacy_meta_data(const std::shared_ptr<ov::Model>& model,+ const std::unordered_set<std::string>& names,+ const pugi::xml_node& root_section) {const auto& read_meta =[](const std::shared_ptr<ov::Model>& model, const std::string& name, const pugi::xml_node& meta_section) {auto& rt_info = model->get_rt_info();@@ -790,7 +1139,7 @@ void ov::XmlDeserializer::read_legacy_meta_data(const std::shared_ptr<ov::Model>read_meta(model, it, root_section.child(it.c_str()));}-ov::GenericLayerParams ov::XmlDeserializer::parse_generic_params(const pugi::xml_node& node) {+GenericLayerParams XmlDeserializer::parse_generic_params(const pugi::xml_node& node) {const auto parsePort = [](const pugi::xml_node& parentNode,const GenericLayerParams& params,bool input) -> GenericLayerParams::LayerPortData {@@ -863,10 +1212,10 @@ static const std::string& translate_type_name(const std::string& name) {return name;}-std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov::Output<ov::Node>>& inputs,- const pugi::xml_node& node,- const std::shared_ptr<ov::AlignedBuffer>& weights,- const GenericLayerParams& params) {+std::shared_ptr<ov::Node> XmlDeserializer::create_node(const std::vector<ov::Output<ov::Node>>& inputs,+ const pugi::xml_node& node,+ const std::shared_ptr<ov::AlignedBuffer>& weights,+ const GenericLayerParams& params) {// Check that inputs are correctly definedfor (size_t i = 0; i < inputs.size(); i++) {if (!inputs[i].get_node())@@ -879,16 +1228,15 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:i,"!");}-const std::string& type_name = translate_type_name(params.type);std::shared_ptr<ov::Node> ovNode;ov::DiscreteTypeInfo type(type_name.c_str(), params.version.c_str());- auto extensionIt = m_extensions.find(type);+ const auto extensionIt = m_extensions.find(type);if (extensionIt != m_extensions.end()) {- XmlDeserializer visitor(node, weights, m_opsets, m_extensions, m_variables, m_version);- ovNode = (*extensionIt->second).create(inputs, visitor).at(0).get_node_shared_ptr();+ auto visitor = make_visitor(node, weights, m_opsets, m_extensions, m_variables, m_version);+ ovNode = (*extensionIt->second).create(inputs, *visitor).at(0).get_node_shared_ptr();}// Find registered opset@@ -929,7 +1277,6 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:}const auto& opset = opsetIt->second;-ovNode = std::shared_ptr<ov::Node>(opset.create_insensitive(type_name));if (!ovNode) {OPENVINO_THROW("Opset ", params.version, " doesn't contain the operation with type: ", type_name);@@ -939,9 +1286,8 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:constant->alloc_buffer_on_visit_attributes(false);}ovNode->set_arguments(inputs);- XmlDeserializer visitor(node, weights, m_opsets, m_extensions, m_variables, m_version);-- if (ovNode->visit_attributes(visitor)) {+ auto visitor = make_visitor(node, weights, m_opsets, m_extensions, m_variables, m_version);+ if (ovNode->visit_attributes(*visitor)) {ovNode->constructor_validate_and_infer_types();}@@ -950,8 +1296,10 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:}if (!ovNode && m_extensions.count(ov::op::util::FrameworkNode::get_type_info_static())) {ovNode = std::make_shared<ov::op::util::FrameworkNode>(inputs);- XmlDeserializer visitor(node, weights, m_opsets, m_extensions, m_variables, m_version);- ovNode->visit_attributes(visitor);+ // XmlDeserializer visitor(node, weights, m_opsets, m_extensions, m_variables, m_version);+ // ovNode->visit_attributes(visitor);+ auto visitor = make_visitor(node, weights, m_opsets, m_extensions, m_variables, m_version);+ ovNode->visit_attributes(*visitor);size_t index{0};for (const auto& output_params : params.outputPorts) {@@ -983,14 +1331,10 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:if (aw_data) {rtInfo["alt_width"] = aw_data.value();}- const auto size = dn.attribute("size");- const auto offset = dn.attribute("offset");- const auto element_type = dn.attribute("element_type");- if (size && offset && element_type) {- rtInfo[ov::WeightlessCacheAttribute::get_type_info_static()] =- ov::WeightlessCacheAttribute(static_cast<size_t>(pugixml::get_uint64_attr(dn, "size")),- static_cast<size_t>(pugixml::get_uint64_attr(dn, "offset")),- ov::element::Type(pugixml::get_str_attr(dn, "element_type")));++ if (auto wl_attribute = parse_weightless_cache_attribute(node); !wl_attribute.empty()) {+ ovNode->get_rt_info().emplace(ov::WeightlessCacheAttribute::get_type_info_static(),+ std::move(wl_attribute));}}@@ -1072,3 +1416,8 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:return ovNode;}++const pugi::xml_node& XmlDeserializer::get_node() const {+ return m_node;+}+} // namespace ov::utildiff --git a/src/frontends/ir/src/CMakeLists.txt b/src/frontends/ir/src/CMakeLists.txtindex 6cd7c061d71..315eec0faf3 100644--- a/src/frontends/ir/src/CMakeLists.txt+++ b/src/frontends/ir/src/CMakeLists.txt@@ -5,6 +5,7 @@ov_add_frontend(NAME irFILEDESCRIPTION "FrontEnd to load OpenVINO IR file format"LINK_LIBRARIES openvino::pugixml- openvino::core::dev)+ openvino::core::dev+ openvino::xml_util)ov_build_target_faster(openvino_ir_frontend PCH)diff --git a/src/frontends/ir/src/input_model.cpp b/src/frontends/ir/src/input_model.cppindex ad70be860aa..80f56f9e716 100644--- a/src/frontends/ir/src/input_model.cpp+++ b/src/frontends/ir/src/input_model.cpp@@ -6,7 +6,6 @@#include <pugixml.hpp>-#include "ir_deserializer.hpp"#include "openvino/core/except.hpp"#include "openvino/core/validation_util.hpp"#include "openvino/op/concat.hpp"@@ -17,6 +16,7 @@#include "openvino/opsets/opset.hpp"#include "openvino/util/common_util.hpp"#include "openvino/util/xml_parse_utils.hpp"+#include "openvino/xml_util/xml_deserialize_util.hpp"#include "utils.hpp"namespace {@@ -266,7 +266,7 @@ std::shared_ptr<ov::Model> InputModel::InputModelIRImpl::convert() {// Load default opsetssize_t version = static_cast<size_t>(ov::util::pugixml::get_uint64_attr(m_root, "version", 0));- ov::XmlDeserializer visitor(m_root, m_weights, m_opsets, m_extensions, variables, version);+ ov::util::XmlDeserializer visitor(m_root, m_weights, m_opsets, m_extensions, variables, version);std::shared_ptr<ov::Model> model;visitor.on_attribute("net", model);model->get_rt_info()["version"] = int64_t(version);diff --git a/src/frontends/ir/src/rt_info_deserializer.cpp b/src/frontends/ir/src/rt_info_deserializer.cppdeleted file mode 100644index b052ec84415..00000000000--- a/src/frontends/ir/src/rt_info_deserializer.cpp+++ /dev/null@@ -1,25 +0,0 @@-// Copyright (C) 2018-2025 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#include "rt_info_deserializer.hpp"--#include <pugixml.hpp>--#include "openvino/frontend/exception.hpp"--using namespace ov;--void RTInfoDeserializer::on_adapter(const std::string& name, ValueAccessor<void>& adapter) {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- if (auto a = as_type<AttributeAdapter<std::set<std::string>>>(&adapter)) {- std::set<std::string> ss;- str_to_set_of_strings(val, ss);- a->set(ss);- } else {- OPENVINO_NOT_IMPLEMENTED;- }-}diff --git a/src/frontends/ir/src/rt_info_deserializer.hpp b/src/frontends/ir/src/rt_info_deserializer.hppdeleted file mode 100644index 6d981d56739..00000000000--- a/src/frontends/ir/src/rt_info_deserializer.hpp+++ /dev/null@@ -1,127 +0,0 @@-// Copyright (C) 2018-2025 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#pragma once--#include <cctype>-#include <istream>-#include <memory>--#include "openvino/core/attribute_visitor.hpp"-#include "utils.hpp"--namespace ov {-class RTInfoDeserializer : public ov::AttributeVisitor {-public:- explicit RTInfoDeserializer(const pugi::xml_node& node) : m_node(node) {}-- void on_adapter(const std::string& name, ov::ValueAccessor<std::string>& value) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- value.set(val);- }-- void on_adapter(const std::string& name, ov::ValueAccessor<bool>& value) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- std::transform(val.begin(), val.end(), val.begin(), [](char ch) {- return std::tolower(static_cast<unsigned char>(ch));- });- std::set<std::string> true_names{"true", "1"};- std::set<std::string> false_names{"false", "0"};-- bool is_true = true_names.find(val) != true_names.end();- bool is_false = false_names.find(val) != false_names.end();-- if (!is_true && !is_false)- return;- value.set(is_true);- }-- void on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) override;-- void on_adapter(const std::string& name, ov::ValueAccessor<double>& adapter) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- adapter.set(stringToType<double>(val));- }- void on_adapter(const std::string& name, ov::ValueAccessor<int64_t>& adapter) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- adapter.set(stringToType<int64_t>(val));- }-- void on_adapter(const std::string& name, ov::ValueAccessor<std::shared_ptr<ov::Model>>& adapter) override {- OPENVINO_THROW("Model type is unsupported for rt info deserialization");- }-- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int32_t>>& adapter) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- std::vector<int32_t> value;- str_to_container(val, value);- adapter.set(value);- }-- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int64_t>>& adapter) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- std::vector<int64_t> value;- str_to_container(val, value);- adapter.set(value);- }-- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<float>>& adapter) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- std::vector<float> value;- str_to_container(val, value);- adapter.set(value);- }-- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<uint64_t>>& adapter) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- std::vector<uint64_t> value;- str_to_container(val, value);- adapter.set(value);- }-- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<std::string>>& adapter) override {- check_attribute_name(name);- std::string val;- if (!getStrAttribute(m_node, name, val))- return;- std::vector<std::string> value;- str_to_container(val, value);- adapter.set(value);- }-- void check_attribute_name(const std::string& name) const {- OPENVINO_ASSERT(name != "name" && name != "version",- "Attribute key with name: ",- name,- " is not allowed. Please use another name");- }--private:- pugi::xml_node m_node;-};-} // namespace ovdiff --git a/src/frontends/ir/src/utils.cpp b/src/frontends/ir/src/utils.cppindex 030a10c05c3..9fefc479f36 100644--- a/src/frontends/ir/src/utils.cpp+++ b/src/frontends/ir/src/utils.cpp@@ -13,56 +13,4 @@ void operator>>(const std::stringstream& in, ov::element::Type& type) {type = ov::element::Type(ov::util::trim(in.str()));}-bool getStrAttribute(const pugi::xml_node& node, const std::string& name, std::string& value) {- if (!node)- return false;-- auto attr = node.attribute(name.c_str());- if (attr.empty())- return false;- value = std::string(attr.value());- return true;-}--bool get_partial_shape_from_attribute(const pugi::xml_node& node, const std::string& name, PartialShape& value) {- std::string param;- if (!getStrAttribute(node, name, param))- return false;- value = PartialShape(param);- return true;-}--bool get_dimension_from_attribute(const pugi::xml_node& node, const std::string& name, Dimension& value) {- std::string param;- if (!getStrAttribute(node, name, param))- return false;- value = Dimension(param);- return true;-}--void str_to_set_of_strings(const std::string& value, std::set<std::string>& res) {- std::stringstream ss(value);- std::string field;- while (getline(ss, field, ',')) {- // trim leading and trailing whitespaces- auto strBegin = field.find_first_not_of(" ");- if (strBegin == std::string::npos)- OPENVINO_THROW("Cannot get a set of strings from \"", value, "\". Value \"", field, "\" is incorrect");- auto strRange = field.find_last_not_of(" ") - strBegin + 1;-- res.insert(field.substr(strBegin, strRange));- }-}--void str_to_container(const std::string& value, std::vector<std::string>& res) {- std::stringstream ss(value);- std::string field;- while (getline(ss, field, ',')) {- field = ov::util::trim(field);- if (!field.empty()) {- res.emplace_back(field);- }- }-}-} // namespace ovdiff --git a/src/frontends/ir/src/utils.hpp b/src/frontends/ir/src/utils.hppindex 8f3336bad1a..ec0bc1e28d6 100644--- a/src/frontends/ir/src/utils.hpp+++ b/src/frontends/ir/src/utils.hpp@@ -13,12 +13,6 @@namespace ov {void operator>>(const std::stringstream& in, ov::element::Type& type);-bool getStrAttribute(const pugi::xml_node& node, const std::string& name, std::string& value);-bool get_dimension_from_attribute(const pugi::xml_node& node, const std::string& name, Dimension& value);-bool get_partial_shape_from_attribute(const pugi::xml_node& node, const std::string& name, PartialShape& value);--void str_to_container(const std::string& value, std::vector<std::string>& res);-template <class T>void str_to_container(const std::string& value, T& res) {std::stringstream ss(value);@@ -33,19 +27,6 @@ void str_to_container(const std::string& value, T& res) {}}-// separated function for set<string> to keep whitespaces in values-// because stringstream splits its values with whitespace delimiter-void str_to_set_of_strings(const std::string& value, std::set<std::string>& res);--template <class T>-bool getParameters(const pugi::xml_node& node, const std::string& name, std::vector<T>& value) {- std::string param;- if (!getStrAttribute(node, name, param))- return false;- str_to_container(param, value);- return true;-}-template <class T>T stringToType(const std::string& valStr) {T ret{0};