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
[ONNX] Added experimental support of WeightlessCache attribute (#31448)
Georgy Krivoruchkobd2c669d6c9a
diff --git a/src/frontends/onnx/frontend/src/frontend.cpp b/src/frontends/onnx/frontend/src/frontend.cppindex c46909b3693..0165f6f9476 100644--- a/src/frontends/onnx/frontend/src/frontend.cpp+++ b/src/frontends/onnx/frontend/src/frontend.cpp@@ -22,6 +22,7 @@#include "input_model.hpp"#include "onnx_common/onnx_model_validator.hpp"+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"#include "openvino/core/so_extension.hpp"#include "openvino/frontend/exception.hpp"#include "openvino/frontend/extension/telemetry.hpp"@@ -40,6 +41,21 @@ using namespace ov::frontend::onnx::common;using ::ONNX_NAMESPACE::ModelProto;using ::ONNX_NAMESPACE::Version;+namespace {+// !!! Experimental feature, it may be changed or removed in the future !!!+void enumerate_constants(const std::shared_ptr<ov::Model>& model) {+ const auto& operations = model->get_ordered_ops();+ for (uint32_t idx = 0; idx < operations.size(); ++idx) {+ const auto& const_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(operations[idx]);+ if (const_node == nullptr)+ continue;+ const_node->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] =+ ov::WeightlessCacheAttribute(0, idx, const_node->get_element_type());+ }+}+// !!! End of Experimental feature+} // namespace+ONNX_FRONTEND_C_API ov::frontend::FrontEndVersion get_api_version() {return OV_FRONTEND_API_VERSION;}@@ -131,6 +147,10 @@ std::shared_ptr<ov::Model> FrontEnd::convert_partially(const InputModel::Ptr& in}void FrontEnd::normalize(const std::shared_ptr<ov::Model>& model) const {+ // !!! Experimental feature, it may be changed or removed in the future !!!+ enumerate_constants(model);+ // !!! End of Experimental feature+// Here, you can register transformations as a second step of importing process// In particular, you can operate on not supported ops (it allows to N:N ONNX->OV mapping).ov::pass::Manager manager("Frontend:ONNX:normalize");diff --git a/src/frontends/onnx/tests/onnx_reader_external_data.cpp b/src/frontends/onnx/tests/onnx_reader_external_data.cppindex 8b8a7f1e100..c7f43f39d86 100644--- a/src/frontends/onnx/tests/onnx_reader_external_data.cpp+++ b/src/frontends/onnx/tests/onnx_reader_external_data.cpp@@ -14,6 +14,7 @@#include "common_test_utils/test_case.hpp"#include "common_test_utils/unicode_utils.hpp"#include "onnx_utils.hpp"+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"#include "openvino/frontend/manager.hpp"#include "openvino/op/constant.hpp"@@ -38,6 +39,29 @@ TEST_P(OnnxFeMmapFixture, onnx_external_data) {test_case.run();}+// !!! Experimental feature, it may be changed or removed in the future !!!+TEST_P(OnnxFeMmapFixture, onnx_external_data_enumerating) {+ const auto path =+ test::utils::getModelFromTestModelZoo(string(TEST_ONNX_MODELS_DIRNAME) + "external_data/external_data.onnx");+ Core core;+ core.set_property(enable_mmap(GetParam()));+ const auto model = core.read_model(path);+ const auto& operations = model->get_ordered_ops();+ for (uint32_t idx = 0; idx < operations.size(); ++idx) {+ const auto& const_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(operations[idx]);+ if (const_node == nullptr)+ continue;+ EXPECT_TRUE(const_node->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()]+ .is<ov::WeightlessCacheAttribute>());+ const auto& weightless_cache = const_node->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()]+ .as<ov::WeightlessCacheAttribute>();+ EXPECT_EQ(weightless_cache.original_size, 0);+ EXPECT_EQ(weightless_cache.bin_offset, idx);+ EXPECT_EQ(weightless_cache.original_dtype, const_node->get_element_type());+ }+}+// !!! End of Experimental feature+TEST_P(OnnxFeMmapFixture, onnx_external_data_from_stream) {const auto path =test::utils::getModelFromTestModelZoo(string(TEST_ONNX_MODELS_DIRNAME) + "external_data/external_data.onnx");