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
Propagate WeightlessCacheAttribute from replaced Convert's input (#30085)
Tomasz Krupab722c857985d
diff --git a/src/core/src/op/util/weightless_caching_attributes.cpp b/src/core/src/op/util/weightless_caching_attributes.cppindex 1b2745ce0ae..f3f61fe5689 100644--- a/src/core/src/op/util/weightless_caching_attributes.cpp+++ b/src/core/src/op/util/weightless_caching_attributes.cpp@@ -4,6 +4,9 @@#include "openvino/core/rt_info/weightless_caching_attributes.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+bool ov::WeightlessCacheAttribute::is_copyable() const {return false;}@@ -15,5 +18,12 @@ OPENVINO_API void ov::copy_weightless_cache_attr(const std::shared_ptr<ov::Node>if (weightless_caching_attr != rt_info.end()) {to->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] = weightless_caching_attr->second;+ } else if (ov::is_type<ov::op::v0::Convert>(from) && ov::is_type<ov::op::v0::Constant>(to)) {+ auto convert_node = ov::as_type_ptr<ov::op::v0::Convert>(from);+ auto const_node = convert_node->get_input_node_ptr(0);+ weightless_caching_attr = const_node->get_rt_info().find(ov::WeightlessCacheAttribute::get_type_info_static());+ if (weightless_caching_attr != const_node->get_rt_info().end()) {+ to->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] = weightless_caching_attr->second;+ }}}\ No newline at end of filediff --git a/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cppindex 190f3257582..5b92e2cf1fc 100644--- a/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp+++ b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp@@ -15,6 +15,11 @@#include "common_test_utils/subgraph_builders/single_concat_with_constant.hpp"#include "common_test_utils/subgraph_builders/ti_with_lstm_cell.hpp"#include "common_test_utils/test_common.hpp"+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/util/op_types.hpp"+#include "openvino/pass/constant_folding.hpp"+#include "openvino/pass/manager.hpp"#include "openvino/pass/serialize.hpp"#include "openvino/util/codec_xor.hpp"#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"@@ -305,4 +310,34 @@ INSTANTIATE_TEST_SUITE_P(smoke_CheckWeightlessCacheAccuracyLowPrecision,::testing::ValuesIn(low_precision_dtypes)),CheckWeightlessCacheAccuracy::get_test_case_name);+TEST(smoke_CheckWeightlessCacheAccuracy, ConstantFoldingAttrPropagation) {+ const auto num_elements = 4;+ std::vector<ov::float16> data(num_elements, 0.f);+ auto constant = std::make_shared<ov::op::v0::Constant>(ov::element::f16, ov::Shape{num_elements}, data);+ auto attr = ov::WeightlessCacheAttribute(num_elements * sizeof(ov::float16), 0, ov::element::f16);+ constant->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] = attr;++ ov::ParameterVector inputParams;+ ov::ResultVector results;+ ov::pass::Manager manager("ConstantFoldingAttrPropagationTest");+ std::shared_ptr<ov::Model> model = nullptr;++ auto convert_op = std::make_shared<ov::op::v0::Convert>(constant, ov::element::f32);+ results.push_back(std::make_shared<ov::op::v0::Result>(convert_op->output(0)));+ model = std::make_shared<ov::Model>(results, inputParams, "aux");+ manager.register_pass<ov::pass::ConstantFolding>();+ manager.run_passes(model);++ const auto& ops = model->get_ops();+ auto constant_it = std::find_if(ops.begin(), ops.end(), [](const std::shared_ptr<ov::Node>& node) {+ return ov::op::util::is_constant(node);+ });+ ASSERT_NE(constant_it, ops.end());+ ASSERT_NE(constant, *constant_it);+ auto transformed_constant_rt_info = (*constant_it)->get_rt_info();+ auto attr_it = transformed_constant_rt_info.find(ov::WeightlessCacheAttribute::get_type_info_static());+ ASSERT_NE(attr_it, transformed_constant_rt_info.end());+ ASSERT_EQ(attr_it->second.as<ov::WeightlessCacheAttribute>().original_size, num_elements * sizeof(ov::float16));+}+} // namespace