Skip to content

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

[GPU] Weightless caching - propagate weights_path from IR FE to the plugin (#27162)

Tomasz Krupaa9dee49482b1
diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp
index 3af6d2c4b53..f179630b155 100644
--- a/src/core/src/pass/serialize.cpp
+++ b/src/core/src/pass/serialize.cpp
@@ -1173,7 +1173,7 @@ void ngfunction_2_ir(pugi::xml_node& netXml,
pugi::xml_node rt_info_node = netXml.append_child("rt_info");
for (const auto& it : model.get_rt_info()) {
// Skip IR version
- if (it.first == "version")
+ if (it.first == "version" || it.first == "__weights_path")
continue;
serialize_rt_info(rt_info_node, it.first, it.second);
}
diff --git a/src/frontends/ir/src/frontend.cpp b/src/frontends/ir/src/frontend.cpp
index db979a35d93..c5e137e1dec 100644
--- a/src/frontends/ir/src/frontend.cpp
+++ b/src/frontends/ir/src/frontend.cpp
@@ -168,15 +168,21 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& variants) const
return exts;
};
- auto create_input_model = [&]() -> std::shared_ptr<InputModel> {
+ auto create_input_model = [&](std::string weights_path) -> std::shared_ptr<InputModel> {
if (provided_model_stream) {
- return std::make_shared<InputModel>(*provided_model_stream, weights, create_extensions_map());
+ return std::make_shared<InputModel>(*provided_model_stream,
+ weights,
+ create_extensions_map(),
+ std::move(weights_path));
} else if (local_model_stream.is_open()) {
- auto input_model = std::make_shared<InputModel>(local_model_stream, weights, create_extensions_map());
+ auto input_model = std::make_shared<InputModel>(local_model_stream,
+ weights,
+ create_extensions_map(),
+ std::move(weights_path));
local_model_stream.close();
return input_model;
} else if (model_buf) {
- return std::make_shared<InputModel>(model_buf, weights, create_extensions_map());
+ return std::make_shared<InputModel>(model_buf, weights, create_extensions_map(), std::move(weights_path));
}
return nullptr;
};
@@ -278,7 +284,7 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& variants) const
}
}
- return create_input_model();
+ return create_input_model(ov::util::path_to_string(weights_path));
}
std::shared_ptr<ov::Model> FrontEnd::convert(const InputModel::Ptr& model) const {
diff --git a/src/frontends/ir/src/input_model.cpp b/src/frontends/ir/src/input_model.cpp
index 6c59617c69a..b4d9ef164e9 100644
--- a/src/frontends/ir/src/input_model.cpp
+++ b/src/frontends/ir/src/input_model.cpp
@@ -205,13 +205,16 @@ class InputModel::InputModelIRImpl {
std::unordered_map<std::string, ov::OpSet> m_opsets;
pugi::xml_node m_root;
pugi::xml_document m_xml_doc;
+ std::string m_weights_path;
public:
InputModelIRImpl(std::istream& model,
const std::shared_ptr<ov::AlignedBuffer>& weights,
- const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions)
+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,
+ std::string weights_path)
: m_weights(weights),
- m_extensions(extensions) {
+ m_extensions(extensions),
+ m_weights_path(std::move(weights_path)) {
pugi::xml_parse_result res = m_xml_doc.load(model);
OPENVINO_ASSERT(res.status == pugi::status_ok, res.description(), " at offset ", res.offset);
init_opset();
@@ -219,9 +222,11 @@ public:
InputModelIRImpl(const std::shared_ptr<ov::AlignedBuffer>& model,
const std::shared_ptr<ov::AlignedBuffer>& weights,
- const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions)
+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,
+ std::string weights_path)
: m_weights(weights),
- m_extensions(extensions) {
+ m_extensions(extensions),
+ m_weights_path(std::move(weights_path)) {
auto res = m_xml_doc.load_buffer(model->get_ptr(), model->size(), pugi::parse_default, pugi::encoding_utf8);
OPENVINO_ASSERT(res.status == pugi::status_ok, res.description(), " at offset ", res.offset);
init_opset();
@@ -240,14 +245,16 @@ private:
InputModel::InputModel(std::istream& model,
const std::shared_ptr<ov::AlignedBuffer>& weights,
- const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions) {
- _impl = std::make_shared<InputModelIRImpl>(model, weights, extensions);
+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,
+ std::string weights_path) {
+ _impl = std::make_shared<InputModelIRImpl>(model, weights, extensions, std::move(weights_path));
}
InputModel::InputModel(const std::shared_ptr<ov::AlignedBuffer>& model,
const std::shared_ptr<ov::AlignedBuffer>& weights,
- const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions) {
- _impl = std::make_shared<InputModelIRImpl>(model, weights, extensions);
+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,
+ std::string weights_path) {
+ _impl = std::make_shared<InputModelIRImpl>(model, weights, extensions, std::move(weights_path));
}
std::shared_ptr<ov::Model> InputModel::convert() {
@@ -263,6 +270,8 @@ std::shared_ptr<ov::Model> InputModel::InputModelIRImpl::convert() {
std::shared_ptr<ov::Model> model;
visitor.on_attribute("net", model);
model->get_rt_info()["version"] = int64_t(version);
+ if (!m_weights_path.empty())
+ model->get_rt_info()["__weights_path"] = m_weights_path;
parse_pre_process(m_root, m_weights, model);
return model;
diff --git a/src/frontends/ir/src/input_model.hpp b/src/frontends/ir/src/input_model.hpp
index 331092749bb..a9ad1224c6c 100644
--- a/src/frontends/ir/src/input_model.hpp
+++ b/src/frontends/ir/src/input_model.hpp
@@ -22,11 +22,13 @@ class InputModel : public ov::frontend::InputModel {
public:
InputModel(std::istream& stream,
const std::shared_ptr<ov::AlignedBuffer>& weights,
- const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions);
+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,
+ std::string weights_path = {});
InputModel(const std::shared_ptr<ov::AlignedBuffer>& model_buf,
const std::shared_ptr<ov::AlignedBuffer>& weights,
- const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions);
+ const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions,
+ std::string weights_path = {});
std::shared_ptr<Model> convert();
};
diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
index 28a20fa737d..49a45ec9ffa 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
@@ -44,6 +44,7 @@ private:
bool is_metric(const std::string& name) const;
ov::Any get_metric(const std::string& name, const ov::AnyMap& arguments) const;
+ void set_cache_info(const std::shared_ptr<const ov::Model>& model, ExecutionConfig& properties) const;
public:
Plugin();
diff --git a/src/plugins/intel_gpu/src/plugin/plugin.cpp b/src/plugins/intel_gpu/src/plugin/plugin.cpp
index 2d29601ef0b..9aba7ee1a11 100644
--- a/src/plugins/intel_gpu/src/plugin/plugin.cpp
+++ b/src/plugins/intel_gpu/src/plugin/plugin.cpp
@@ -162,6 +162,22 @@ Plugin::Plugin() {
m_compiled_model_runtime_properties["OV_VERSION"] = ov_version.buildNumber;
}
+void Plugin::set_cache_info(const std::shared_ptr<const ov::Model>& model, ExecutionConfig& config) const {
+ // WEIGHTS_PATH is used for the weightless cache mechanism which is used only with
+ // ov::CacheMode::OPTIMIZE_SIZE setting. Not setting WEIGHTS_PATH will result in not
+ // using that mechanism.
+ if (config.get_property(ov::cache_mode) != ov::CacheMode::OPTIMIZE_SIZE) {
+ return;
+ }
+
+ const auto& rt_info = model->get_rt_info();
+ auto weights_path = rt_info.find("__weights_path");
+ if (weights_path != rt_info.end()) {
+ ov::AnyMap weights_path_property{{"WEIGHTS_PATH", weights_path->second}};
+ config.set_property(weights_path_property);
+ }
+}
+
std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<const ov::Model>& model, const ov::AnyMap& orig_config) const {
OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "Plugin::compile_model");
std::string device_id = get_device_id(orig_config);
@@ -174,6 +190,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
config.set_user_property(orig_config);
config.apply_user_properties(context->get_engine().get_device_info());
+ set_cache_info(model, config);
+
auto transformed_model = clone_and_transform_model(model, config, context);
{
OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "Plugin::compile_model::CreateCompiledModel");
@@ -193,6 +211,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
config.set_user_property(orig_config);
config.apply_user_properties(context_impl->get_engine().get_device_info());
+ set_cache_info(model, config);
+
auto transformed_model = clone_and_transform_model(model, config, context_impl);
return std::make_shared<CompiledModel>(transformed_model, shared_from_this(), context_impl, config);
}
diff --git a/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp
index bcb6be2fe30..880868d8666 100644
--- a/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp
+++ b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp
@@ -60,7 +60,8 @@ void CheckWeightlessCacheAccuracy::TearDown() {
}
void CheckWeightlessCacheAccuracy::run() {
- ov::AnyMap config = { ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE), ov::weights_path(bin_path) };
+ ov::AnyMap config = { ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE) };
+ ov::AnyMap config_with_weights_path = { 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);
@@ -73,7 +74,7 @@ void CheckWeightlessCacheAccuracy::run() {
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));
+ OV_ASSERT_NO_THROW(imported_model = core->import_model(ifstr, ov::test::utils::DEVICE_GPU, config_with_weights_path));
ifstr.close();
auto orig_req = compiled_model.create_infer_request();