Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Weightless caching (#25731)

Tomasz Krupadd16602824c6
diff --git a/src/bindings/python/src/openvino/runtime/properties/__init__.py b/src/bindings/python/src/openvino/runtime/properties/__init__.py
index caaa93f3722..3269ea42e32 100644
--- a/src/bindings/python/src/openvino/runtime/properties/__init__.py
+++ b/src/bindings/python/src/openvino/runtime/properties/__init__.py
@@ -29,6 +29,7 @@ from openvino._pyopenvino.properties import range_for_async_infer_requests
from openvino._pyopenvino.properties import execution_devices
from openvino._pyopenvino.properties import loaded_from_cache
from openvino._pyopenvino.properties import cache_encryption_callbacks
+from openvino._pyopenvino.properties import weights_path
# Submodules
from openvino.runtime.properties import hint
diff --git a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
index 470161d9779..a6b30bd7730 100644
--- a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
+++ b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
@@ -43,6 +43,7 @@ void regmodule_properties(py::module m) {
OPENVINO_SUPPRESS_DEPRECATED_END
wrap_property_RW(m_properties, ov::force_tbb_terminate, "force_tbb_terminate");
wrap_property_RW(m_properties, ov::enable_mmap, "enable_mmap");
+ wrap_property_RW(m_properties, ov::weights_path, "weights_path");
wrap_property_RO(m_properties, ov::supported_properties, "supported_properties");
wrap_property_RO(m_properties, ov::available_devices, "available_devices");
diff --git a/src/bindings/python/tests/test_runtime/test_properties.py b/src/bindings/python/tests/test_runtime/test_properties.py
index e8d3162c362..32eb48f6765 100644
--- a/src/bindings/python/tests/test_runtime/test_properties.py
+++ b/src/bindings/python/tests/test_runtime/test_properties.py
@@ -266,6 +266,11 @@ def test_properties_ro(ov_property_ro, expected_value):
),
(props.force_tbb_terminate, "FORCE_TBB_TERMINATE", ((True, True), (False, False))),
(props.enable_mmap, "ENABLE_MMAP", ((True, True), (False, False))),
+ (
+ props.weights_path,
+ "WEIGHTS_PATH",
+ (("./model.bin", "./model.bin"),),
+ ),
(hints.inference_precision, "INFERENCE_PRECISION_HINT", ((Type.f32, Type.f32),)),
(
hints.model_priority,
diff --git a/src/core/dev_api/openvino/core/rt_info/weightless_caching_attributes.hpp b/src/core/dev_api/openvino/core/rt_info/weightless_caching_attributes.hpp
new file mode 100644
index 00000000000..fedcb030fb5
--- /dev/null
+++ b/src/core/dev_api/openvino/core/rt_info/weightless_caching_attributes.hpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/core/core_visibility.hpp"
+#include "openvino/core/runtime_attribute.hpp"
+
+namespace ov {
+
+/**
+ * @brief Holds weightless caching attributes of a single constant.
+ *
+ * WeightlessCacheAttribute class represents runtime info attribute that holds
+ * the values of original size of the constant in bytes and the binary offset of the
+ * constant's data in the weights file used by the weightless caching mechanism. It's
+ * not copyable in case the data was changed (the original node was replaced by a new
+ * one produced during the tranformation pipeline) - in that case weightless caching
+ * can't be used for that constant.
+ */
+class OPENVINO_API WeightlessCacheAttribute : public RuntimeAttribute {
+public:
+ OPENVINO_RTTI("WeightlessCacheAttribute");
+
+ WeightlessCacheAttribute() = delete;
+
+ WeightlessCacheAttribute(size_t original_size, size_t bin_offset)
+ : original_size(original_size),
+ bin_offset(bin_offset) {}
+
+ bool is_copyable() const override;
+
+ size_t original_size;
+ size_t bin_offset;
+};
+
+} // namespace ov
diff --git a/src/core/src/op/util/weightless_caching_attributes.cpp b/src/core/src/op/util/weightless_caching_attributes.cpp
new file mode 100644
index 00000000000..7c540f8a3be
--- /dev/null
+++ b/src/core/src/op/util/weightless_caching_attributes.cpp
@@ -0,0 +1,9 @@
+// Copyright (C) 2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
+
+bool ov::WeightlessCacheAttribute::is_copyable() const {
+ return false;
+}
diff --git a/src/core/tests/pass/serialization/deterministicity.cpp b/src/core/tests/pass/serialization/deterministicity.cpp
index 5bcfbf97b77..8441da501eb 100644
--- a/src/core/tests/pass/serialization/deterministicity.cpp
+++ b/src/core/tests/pass/serialization/deterministicity.cpp
@@ -193,6 +193,7 @@ TEST_P(SerializationDeterministicityInputOutputTest, FromOvModel) {
auto& expected1 = modelRef;
ov::pass::Serialize(m_out_xml_path_1, m_out_bin_path_1, irVersion).run_on_model(modelRef);
auto expected2 = ov::test::readModel(m_out_xml_path_1, m_out_bin_path_1);
+
ov::pass::Serialize(m_out_xml_path_2, m_out_bin_path_2, irVersion).run_on_model(expected2);
EXPECT_EQ(input0Name, expected1->input(0).get_node()->get_friendly_name());
diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cpp
index 68900b15051..f9ddcf1e8c1 100644
--- a/src/frontends/ir/src/ir_deserializer.cpp
+++ b/src/frontends/ir/src/ir_deserializer.cpp
@@ -9,6 +9,7 @@
#include "openvino/core/except.hpp"
#include "openvino/core/meta_data.hpp"
+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/core/type/element_type.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/loop.hpp"
@@ -944,6 +945,13 @@ 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");
+ if (size && offset) {
+ 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")));
+ }
}
ovNode->set_friendly_name(params.name);
diff --git a/src/inference/include/openvino/runtime/properties.hpp b/src/inference/include/openvino/runtime/properties.hpp
index 621c0074fc9..627314748bb 100644
--- a/src/inference/include/openvino/runtime/properties.hpp
+++ b/src/inference/include/openvino/runtime/properties.hpp
@@ -1345,4 +1345,10 @@ static constexpr Property<Affinity> affinity{"AFFINITY"};
*/
static constexpr Property<std::vector<std::string>, PropertyMutability::RO> execution_devices{"EXECUTION_DEVICES"};
+/**
+ * @brief Path to the file with model's weights.
+ *
+ * @note This property is used for weightless caching. Only used when ov::CacheMode Property is set to "OPTIMIZE_SIZE".
+ */
+static constexpr Property<std::string, PropertyMutability::RW> weights_path{"WEIGHTS_PATH"};
} // namespace ov
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/data.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/data.hpp
index 7bc020c2529..461f063ec26 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/primitives/data.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/data.hpp
@@ -3,9 +3,13 @@
//
#pragma once
-#include "primitive.hpp"
-#include "intel_gpu/runtime/memory.hpp"
+#include <climits>
+
#include "intel_gpu/runtime/engine.hpp"
+#include "intel_gpu/runtime/memory.hpp"
+#include "openvino/runtime/shared_buffer.hpp"
+#include "openvino/util/mmap_object.hpp"
+#include "primitive.hpp"
namespace cldnn {
@@ -29,6 +33,9 @@ struct data : public primitive_base<data> {
/// @note If memory is attached by memory::attach(), the attached buffer should be valid till network build.
memory::ptr mem;
+ size_t original_size = SIZE_MAX;
+ size_t bin_offset = SIZE_MAX;
+
size_t hash() const override {
size_t seed = primitive::hash();
seed = hash_combine(seed, id);
@@ -46,20 +53,30 @@ struct data : public primitive_base<data> {
size_t data_size = mem->size();
ob << make_data(&data_size, sizeof(size_t));
- if (_allocation_type == allocation_type::usm_host || _allocation_type == allocation_type::usm_shared) {
- ob << make_data(mem->buffer_ptr(), data_size);
+ bool is_cache_without_weights = bin_offset != SIZE_MAX && data_size == original_size;
+
+ if (is_cache_without_weights) {
+ ob << true;
+ ob << bin_offset;
} else {
- std::vector<uint8_t> _buf;
- _buf.resize(data_size);
- stream* strm = reinterpret_cast<stream*>(ob.get_stream());
- mem->copy_to(*strm, _buf.data());
- ob << make_data(_buf.data(), data_size);
+ ob << false;
+ if (_allocation_type == allocation_type::usm_host || _allocation_type == allocation_type::usm_shared) {
+ ob << make_data(mem->buffer_ptr(), data_size);
+ } else {
+ std::vector<uint8_t> _buf;
+ _buf.resize(data_size);
+ stream* strm = reinterpret_cast<stream*>(ob.get_stream());
+ mem->copy_to(*strm, _buf.data());
+ ob << make_data(_buf.data(), data_size);
+ }
}
}
void load(BinaryInputBuffer& ib) override {
primitive_base<data>::load(ib);
+ }
+ void load_weights(BinaryInputBuffer& ib, std::shared_ptr<ov::MappedMemory> mapped_weights) {
layout output_layout = layout();
ib >> output_layout;
@@ -71,14 +88,39 @@ struct data : public primitive_base<data> {
mem = ib.get_engine().allocate_memory(output_layout, _allocation_type, false);
+ bool is_cache_without_weights;
+ ib >> is_cache_without_weights;
+ if (is_cache_without_weights && mapped_weights == nullptr) {
+ OPENVINO_THROW("mmap object is null");
+ }
+
+ std::shared_ptr<ov::SharedBuffer<std::shared_ptr<ov::MappedMemory>>> shared_buf;
+ if (is_cache_without_weights) {
+ ib >> bin_offset;
+ original_size = data_size;
+
+ shared_buf = std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::MappedMemory>>>(
+ mapped_weights->data() + bin_offset,
+ data_size,
+ mapped_weights);
+ }
+
if (_allocation_type == allocation_type::usm_host || _allocation_type == allocation_type::usm_shared) {
- ib >> make_data(mem->buffer_ptr(), data_size);
+ if (is_cache_without_weights) {
+ std::memcpy(reinterpret_cast<uint8_t*>(mem->buffer_ptr()), shared_buf->get_ptr<uint8_t>(), data_size);
+ } else {
+ ib >> make_data(mem->buffer_ptr(), data_size);
+ }
} else {
const size_t DATA_BLOCK_SIZE = 2 * 1024 * 1024;
auto& strm = ib.get_engine().get_service_stream();
if (data_size < DATA_BLOCK_SIZE || output_layout.format.is_image_2d()) {
std::vector<uint8_t> _buf(data_size);
- ib >> make_data(_buf.data(), data_size);
+ if (is_cache_without_weights) {
+ std::memcpy(reinterpret_cast<uint8_t*>(_buf.data()), shared_buf->get_ptr<uint8_t>(), data_size);
+ } else {
+ ib >> make_data(_buf.data(), data_size);
+ }
mem->copy_from(strm, _buf.data());
} else {
std::vector<uint8_t> _buf1(DATA_BLOCK_SIZE);
@@ -86,21 +128,33 @@ struct data : public primitive_base<data> {
bool buf_flag = true;
event::ptr ev1, ev2;
ev1 = ev2 = nullptr;
-
size_t dst_offset = 0;
while (dst_offset < data_size) {
const bool is_blocking = false;
const size_t src_offset = 0;
- size_t copy_size = (data_size > (dst_offset + DATA_BLOCK_SIZE)) ? DATA_BLOCK_SIZE : (data_size - dst_offset);
+ size_t copy_size =
+ (data_size > (dst_offset + DATA_BLOCK_SIZE)) ? DATA_BLOCK_SIZE : (data_size - dst_offset);
if (buf_flag) {
- ib >> make_data(_buf1.data(), copy_size);
+ if (is_cache_without_weights) {
+ std::memcpy(reinterpret_cast<uint8_t*>(_buf1.data()),
+ shared_buf->get_ptr<uint8_t>() + dst_offset,
+ copy_size);
+ } else {
+ ib >> make_data(_buf1.data(), copy_size);
+ }
if (ev2 != nullptr) {
ev2->wait();
ev2 = nullptr;
}
ev1 = mem->copy_from(strm, _buf1.data(), src_offset, dst_offset, copy_size, is_blocking);
} else {
- ib >> make_data(_buf2.data(), copy_size);
+ if (is_cache_without_weights) {
+ std::memcpy(reinterpret_cast<uint8_t*>(_buf2.data()),
+ shared_buf->get_ptr<uint8_t>() + dst_offset,
+ copy_size);
+ } else {
+ ib >> make_data(_buf2.data(), copy_size);
+ }
if (ev1 != nullptr) {
ev1->wait();
ev1 = nullptr;
diff --git a/src/plugins/intel_gpu/src/graph/program.cpp b/src/plugins/intel_gpu/src/graph/program.cpp
index d4461b8aad9..1e2e84043dc 100644
--- a/src/plugins/intel_gpu/src/graph/program.cpp
+++ b/src/plugins/intel_gpu/src/graph/program.cpp
@@ -1720,6 +1720,7 @@ void program::cancel_compilation_context() {
void program::save(cldnn::BinaryOutputBuffer& ob) const {
std::map<cldnn::memory::ptr, std::vector<const cldnn::program_node*>> mutable_datas_ptrs;
ob << nodes_map.size();
+
for (auto& node : nodes_map) {
ob.setKernelImplParams(node.second->get_kernel_impl_params().get());
@@ -1732,6 +1733,7 @@ void program::save(cldnn::BinaryOutputBuffer& ob) const {
node.second->as<data>().typed_desc()->mem = data_node.get_attached_memory_ptr();
}
}
+
ob << true;
ob << node.second->desc;
@@ -1835,6 +1837,12 @@ void program::save(cldnn::BinaryOutputBuffer& ob) const {
void program::load(cldnn::BinaryInputBuffer& ib) {
init_program();
+ std::shared_ptr<ov::MappedMemory> mapped_memory = nullptr;
+ std::string weights_path = _config.get_property(ov::weights_path);
+ if (!weights_path.empty()) {
+ mapped_memory = ov::load_mmap_object(weights_path);
+ }
+
size_t num_nodes;
ib >> num_nodes;
bool is_valid_data_node;
@@ -1845,6 +1853,9 @@ void program::load(cldnn::BinaryInputBuffer& ib) {
std::shared_ptr<cldnn::primitive> prim;
ib >> prim;
+ if (auto data_prim = dynamic_cast<cldnn::data*>(prim.get())) {
+ data_prim->load_weights(ib, mapped_memory);
+ }
get_or_create(prim);
}
diff --git a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp
index b9729ca7bf0..15ff4447b4b 100644
--- a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp
+++ b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp
@@ -42,18 +42,15 @@ CompiledModel::CompiledModel(std::shared_ptr<ov::Model> model,
const std::shared_ptr<const ov::IPlugin>& plugin,
RemoteContextImpl::Ptr context,
const ExecutionConfig& config)
- : ov::ICompiledModel(model,
- plugin,
- context,
- create_task_executor(plugin, config),
- nullptr)
- , m_context(context)
- , m_config(config)
- , m_wait_executor(std::make_shared<ov::threading::CPUStreamsExecutor>(ov::threading::IStreamsExecutor::Config{"Intel GPU plugin wait executor"}))
- , m_model_name(model->get_friendly_name())
- , m_inputs(ov::ICompiledModel::inputs())
- , m_outputs(ov::ICompiledModel::outputs())
- , m_loaded_from_cache(false) {
+ : ov::ICompiledModel(model, plugin, context, create_task_executor(plugin, config), nullptr),
+ m_context(context),
+ m_config(config),
+ m_wait_executor(std::make_shared<ov::threading::CPUStreamsExecutor>(
+ ov::threading::IStreamsExecutor::Config{"Intel GPU plugin wait executor"})),
+ m_model_name(model->get_friendly_name()),
+ m_inputs(ov::ICompiledModel::inputs()),
+ m_outputs(ov::ICompiledModel::outputs()),
+ m_loaded_from_cache(false) {
auto graph_base = std::make_shared<Graph>(model, m_context, m_config, 0);
for (uint16_t n = 0; n < m_config.get_property(ov::num_streams); n++) {
auto graph = n == 0 ? graph_base : std::make_shared<Graph>(graph_base, n);
@@ -170,7 +167,10 @@ std::shared_ptr<ov::IAsyncInferRequest> CompiledModel::create_infer_request() co
// [ ov::Node::Input/ ov::Node::Output ]
// [ ov::intel_gpu::Graph ]
void CompiledModel::export_model(std::ostream& model) const {
- if (m_config.get_property(ov::cache_mode) == ov::CacheMode::OPTIMIZE_SIZE)
+ // If ov::CacheMode::OPTIMIZE_SIZE is set, do the export iff it's possible to do weightless caching
+ // which requires the weights_path.
+ if (m_config.get_property(ov::cache_mode) == ov::CacheMode::OPTIMIZE_SIZE &&
+ m_config.get_property(ov::weights_path).empty())
return;
OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "CompiledModel::export_model");
diff --git a/src/plugins/intel_gpu/src/plugin/plugin.cpp b/src/plugins/intel_gpu/src/plugin/plugin.cpp
index 4ea7851b3f8..2d29601ef0b 100644
--- a/src/plugins/intel_gpu/src/plugin/plugin.cpp
+++ b/src/plugins/intel_gpu/src/plugin/plugin.cpp
@@ -308,10 +308,13 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& model,
config.set_user_property(_orig_config);
config.apply_user_properties(context_impl->get_engine().get_device_info());
- if (config.get_property(ov::cache_mode) == ov::CacheMode::OPTIMIZE_SIZE)
+ cldnn::BinaryInputBuffer ib(model, context_impl->get_engine());
+
+ if (config.get_property(ov::cache_mode) == ov::CacheMode::OPTIMIZE_SIZE &&
+ config.get_property(ov::weights_path).empty()) {
return nullptr;
+ }
- cldnn::BinaryInputBuffer ib(model, context_impl->get_engine());
return std::make_shared<CompiledModel>(ib, shared_from_this(), context_impl, config, loaded_from_cache);
}
diff --git a/src/plugins/intel_gpu/src/plugin/program_builder.cpp b/src/plugins/intel_gpu/src/plugin/program_builder.cpp
index aae9b163b4f..510d715e7ac 100644
--- a/src/plugins/intel_gpu/src/plugin/program_builder.cpp
+++ b/src/plugins/intel_gpu/src/plugin/program_builder.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/split.hpp"
#include "openvino/op/variadic_split.hpp"
@@ -304,6 +305,15 @@ void ProgramBuilder::add_primitive(const ov::Node& op, std::shared_ptr<cldnn::pr
prim->origin_op_name = op.get_friendly_name();
prim->origin_op_type_name = op.get_type_name();
+ if (auto data_prim = dynamic_cast<cldnn::data*>(prim.get())) {
+ auto rt_info = op.get_rt_info();
+ auto weightless_cache_attr = rt_info.find(ov::WeightlessCacheAttribute::get_type_info_static());
+ if (weightless_cache_attr != rt_info.end()) {
+ data_prim->bin_offset = weightless_cache_attr->second.as<ov::WeightlessCacheAttribute>().bin_offset;
+ data_prim->original_size = weightless_cache_attr->second.as<ov::WeightlessCacheAttribute>().original_size;
+ }
+ }
+
bool should_profile = prim->type != cldnn::mutable_data::type_id() &&
prim->type != cldnn::data::type_id();
diff --git a/src/plugins/intel_gpu/src/runtime/execution_config.cpp b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
index a498dad24aa..9c24fae1d67 100644
--- a/src/plugins/intel_gpu/src/runtime/execution_config.cpp
+++ b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
@@ -60,6 +60,7 @@ void ExecutionConfig::set_default() {
std::make_tuple(ov::cache_encryption_callbacks, EncryptionCallbacks{}),
std::make_tuple(ov::hint::dynamic_quantization_group_size, 0),
std::make_tuple(ov::intel_gpu::hint::enable_kernels_reuse, false),
+ std::make_tuple(ov::weights_path, ""),
// Legacy API properties
std::make_tuple(ov::intel_gpu::nv12_two_inputs, false),
diff --git a/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp
new file mode 100644
index 00000000000..573d275da84
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp
@@ -0,0 +1,210 @@
+// Copyright (C) 2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <cstdio>
+
+#include "base/ov_behavior_test_utils.hpp"
+#include "common_test_utils/common_utils.hpp"
+#include "common_test_utils/file_utils.hpp"
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "common_test_utils/subgraph_builders/2_input_subtract.hpp"
+#include "common_test_utils/subgraph_builders/concat_with_params.hpp"
+#include "common_test_utils/subgraph_builders/conv_bias.hpp"
+#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"
+#include "common_test_utils/subgraph_builders/conv_pool_relu_no_reshapes.hpp"
+#include "common_test_utils/subgraph_builders/conv_pool_relu_non_zero.hpp"
+#include "common_test_utils/subgraph_builders/convert_transpose.hpp"
+#include "common_test_utils/subgraph_builders/detection_output.hpp"
+#include "common_test_utils/subgraph_builders/kso_func.hpp"
+#include "common_test_utils/subgraph_builders/matmul_bias.hpp"
+#include "common_test_utils/subgraph_builders/multi_single_conv.hpp"
+#include "common_test_utils/subgraph_builders/multiple_input_outpput_double_concat.hpp"
+#include "common_test_utils/subgraph_builders/nested_branch_conv_concat.hpp"
+#include "common_test_utils/subgraph_builders/nested_split_conv_concat.hpp"
+#include "common_test_utils/subgraph_builders/read_concat_split_assign.hpp"
+#include "common_test_utils/subgraph_builders/single_concat_with_constant.hpp"
+#include "common_test_utils/subgraph_builders/single_conv.hpp"
+#include "common_test_utils/subgraph_builders/single_split.hpp"
+#include "common_test_utils/subgraph_builders/split_concat.hpp"
+#include "common_test_utils/subgraph_builders/split_conv_concat.hpp"
+#include "common_test_utils/subgraph_builders/split_multi_conv_concat.hpp"
+#include "common_test_utils/subgraph_builders/ti_with_lstm_cell.hpp"
+#include "common_test_utils/test_common.hpp"
+#include "openvino/pass/serialize.hpp"
+
+namespace {
+class CheckWeightlessCacheAccuracy : public ::testing::Test {
+protected:
+ std::shared_ptr<ov::Model> model;
+ std::string xml_path;
+ std::string bin_path;
+ std::string cache_path;
+
+ void SetUp() override;
+ void TearDown() override;
+ void run();
+};
+
+void CheckWeightlessCacheAccuracy::SetUp() {
+ std::string filePrefix = ov::test::utils::generateTestFilePrefix();
+ xml_path = filePrefix + ".xml";
+ bin_path = filePrefix + ".bin";
+ cache_path = filePrefix + ".blob";
+}
+
+void CheckWeightlessCacheAccuracy::TearDown() {
+ std::remove(xml_path.c_str());
+ std::remove(bin_path.c_str());
+ std::remove(cache_path.c_str());
+}
+
+void CheckWeightlessCacheAccuracy::run() {
+ ov::AnyMap config = { ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE), ov::weights_path(bin_path) };
+ auto core = ov::test::utils::PluginCache::get().core();
+ ov::pass::Serialize(xml_path, bin_path).run_on_model(model);
+
+ ov::CompiledModel compiled_model;
+ OV_ASSERT_NO_THROW(compiled_model = core->compile_model(xml_path, ov::test::utils::DEVICE_GPU, config));
+
+ auto ofstr = std::ofstream(cache_path, std::ofstream::binary);
+ OV_ASSERT_NO_THROW(compiled_model.export_model(ofstr));
+ ofstr.close();
+
+ auto ifstr = std::ifstream(cache_path, std::ifstream::binary);
+ ov::CompiledModel imported_model;
+ OV_ASSERT_NO_THROW(imported_model = core->import_model(ifstr, ov::test::utils::DEVICE_GPU, config));
+ ifstr.close();
+
+ auto orig_req = compiled_model.create_infer_request();
+ auto new_req = imported_model.create_infer_request();
+
+ for (size_t param_idx = 0; param_idx < model->get_parameters().size(); ++param_idx) {
+ auto input = model->get_parameters().at(param_idx);
+ auto tensor = ov::test::utils::create_and_fill_tensor(input->get_element_type(), input->get_shape());
+ orig_req.set_tensor(input, tensor);
+ new_req.set_tensor(input, tensor);
+ }
+
+ OV_ASSERT_NO_THROW(orig_req.infer());
+ OV_ASSERT_NO_THROW(new_req.infer());
+
+ auto result_vector = model->get_results();
+ for (auto& res : result_vector) {
+ auto orig_out = orig_req.get_tensor(res);
+ auto new_out = new_req.get_tensor(res);
+ ov::test::utils::compare(orig_out, new_out);
+ }
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, 2InputSubtract) {
+ model = ov::test::utils::make_2_input_subtract();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, ConcatWithParams) {
+ model = ov::test::utils::make_concat_with_params();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, ConvBias) {
+ model = ov::test::utils::make_conv_bias();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, ConvPoolRelu) {
+ model = ov::test::utils::make_conv_pool_relu();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, ConvPoolReluNoReshapes) {
+ model = ov::test::utils::make_conv_pool_relu_no_reshapes();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, ConvPoolReluNonZero) {
+ model = ov::test::utils::make_conv_pool_relu_non_zero();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, ConvertTranspose) {
+ model = ov::test::utils::make_convert_transpose();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, DetectionOutput) {
+ model = ov::test::utils::make_detection_output();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, KsoFunction) {
+ model = ov::test::utils::make_kso_function();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, MatmulBias) {
+ model = ov::test::utils::make_matmul_bias();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, MultiSingleConv) {
+ model = ov::test::utils::make_multi_single_conv();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, MultipleInputOutputDoubleConcat) {
+ model = ov::test::utils::make_multiple_input_output_double_concat();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, NestedBranchConvConcat) {
+ model = ov::test::utils::make_nested_branch_conv_concat();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, NestedSplitConvConcat) {
+ model = ov::test::utils::make_nested_split_conv_concat();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, ReadConcatSplitAssign) {
+ model = ov::test::utils::make_read_concat_split_assign();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, SingleConcatWithConstant) {
+ model = ov::test::utils::make_single_concat_with_constant();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, SingleConv) {
+ model = ov::test::utils::make_single_conv();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, SingleSplit) {
+ model = ov::test::utils::make_single_split();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, SplitConcat) {
+ model = ov::test::utils::make_split_concat();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, SplitConvConcat) {
+ model = ov::test::utils::make_split_conv_concat();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, SplitMultiConvConcat) {
+ model = ov::test::utils::make_split_multi_conv_concat();
+ run();
+}
+
+TEST_F(CheckWeightlessCacheAccuracy, TiWithLstmCell) {
+ model = ov::test::utils::make_ti_with_lstm_cell();
+ run();
+}
+
+} // namespace