Skip to content

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

[NPU] Update blob compatibility flexibility (#29387)

Alexandru Enache97887214cb42
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/runtime.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/runtime.hpp
index f1fb8219ed1..c74db6f8253 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/runtime.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/runtime.hpp
@@ -309,4 +309,24 @@ struct RUN_INFERENCES_SEQUENTIALLY final : OptionBase<RUN_INFERENCES_SEQUENTIALL
}
};
+struct DISABLE_VERSION_CHECK final : OptionBase<DISABLE_VERSION_CHECK, bool> {
+ static std::string_view key() {
+ return ov::intel_npu::disable_version_check.name();
+ }
+
+ static bool defaultValue() {
+ return false;
+ }
+
+#ifdef NPU_PLUGIN_DEVELOPER_BUILD
+ static std::string_view envVar() {
+ return "OV_NPU_DISABLE_VERSION_CHECK";
+ }
+#endif
+
+ static OptionMode mode() {
+ return OptionMode::RunTime;
+ }
+};
+
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp
index 5e43db8ce25..b396dd832cb 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp
@@ -329,5 +329,12 @@ static constexpr ov::Property<std::string> backend_compilation_params{"NPU_BACKE
*/
static constexpr ov::Property<bool> run_inferences_sequentially{"NPU_RUN_INFERENCES_SEQUENTIALLY"};
+/**
+ * @brief [Only for NPU Plugin]
+ * Type: boolean, default is false.
+ * This option allows to skip the blob version check
+ */
+static constexpr ov::Property<bool> disable_version_check{"NPU_DISABLE_VERSION_CHECK"};
+
} // namespace intel_npu
} // namespace ov
diff --git a/src/plugins/intel_npu/src/al/src/config/runtime.cpp b/src/plugins/intel_npu/src/al/src/config/runtime.cpp
index 70eb06c1d6f..0db9bb89d97 100644
--- a/src/plugins/intel_npu/src/al/src/config/runtime.cpp
+++ b/src/plugins/intel_npu/src/al/src/config/runtime.cpp
@@ -29,6 +29,7 @@ void intel_npu::registerRunTimeOptions(OptionsDesc& desc) {
desc.add<WEIGHTS_PATH>();
desc.add<BYPASS_UMD_CACHING>();
desc.add<RUN_INFERENCES_SEQUENTIALLY>();
+ desc.add<DISABLE_VERSION_CHECK>();
}
// Heuristically obtained number. Varies depending on the values of PLATFORM and PERFORMANCE_HINT
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp
index b4df43121a3..ad50e90188f 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp
@@ -598,6 +598,11 @@ std::string DriverCompilerAdapter::serializeConfig(const Config& config,
<< VALUE_DELIMITER;
content = std::regex_replace(content, std::regex(umdcachestring.str()), "");
+ std::ostringstream skipversioncheck;
+ skipversioncheck << ov::intel_npu::disable_version_check.name() << KEY_VALUE_SEPARATOR << VALUE_DELIMITER << "\\S+"
+ << VALUE_DELIMITER;
+ content = std::regex_replace(content, std::regex(skipversioncheck.str()), "");
+
// FINAL step to convert prefixes of remaining params, to ensure backwards compatibility
// From 5.0.0, driver compiler start to use NPU_ prefix, the old version uses VPU_ prefix
if (compilerVersion.major < 5) {
diff --git a/src/plugins/intel_npu/src/plugin/include/metadata.hpp b/src/plugins/intel_npu/src/plugin/include/metadata.hpp
index 2f14f4a4be5..96be277b75d 100644
--- a/src/plugins/intel_npu/src/plugin/include/metadata.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/metadata.hpp
@@ -8,7 +8,8 @@
#include <memory>
#include <optional>
#include <string>
-#include <vector>
+
+#include "openvino/core/version.hpp"
namespace intel_npu {
@@ -74,25 +75,29 @@ constexpr std::string_view MAGIC_BYTES = "OVNPU";
/**
* @brief List of supported version formats.
*/
-constexpr uint32_t METADATA_VERSION_1_0{MetadataBase::make_version(1, 0)};
+constexpr uint32_t METADATA_VERSION_2_0{MetadataBase::make_version(2, 0)};
/**
* @brief Current metadata version.
*/
-constexpr uint32_t CURRENT_METADATA_VERSION{METADATA_VERSION_1_0};
+constexpr uint32_t CURRENT_METADATA_VERSION{METADATA_VERSION_2_0};
constexpr uint16_t CURRENT_METADATA_MAJOR_VERSION{MetadataBase::get_major(CURRENT_METADATA_VERSION)};
constexpr uint16_t CURRENT_METADATA_MINOR_VERSION{MetadataBase::get_minor(CURRENT_METADATA_VERSION)};
struct OpenvinoVersion {
private:
- std::string _version;
- uint32_t _size;
+ uint16_t _major;
+ uint16_t _minor;
+ uint16_t _patch;
public:
- OpenvinoVersion();
+ constexpr OpenvinoVersion(uint16_t major, uint16_t minor, uint16_t patch)
+ : _major(major),
+ _minor(minor),
+ _patch(patch) {}
- OpenvinoVersion(std::string_view version);
+ OpenvinoVersion(const OpenvinoVersion& version);
/**
* @brief Reads version data from a stream.
@@ -104,12 +109,19 @@ public:
*/
void write(std::ostream& stream);
- /**
- * @brief Gets the version string.
- */
- std::string get_version() const;
+ uint16_t get_major() const;
+
+ uint16_t get_minor() const;
+
+ uint16_t get_patch() const;
+
+ bool operator!=(const OpenvinoVersion& version);
};
+constexpr OpenvinoVersion CURRENT_OPENVINO_VERSION(OPENVINO_VERSION_MAJOR,
+ OPENVINO_VERSION_MINOR,
+ OPENVINO_VERSION_PATCH);
+
/**
* @brief Template for metadata class handling.
*/
@@ -120,13 +132,13 @@ struct Metadata : public MetadataBase {};
* @brief Template specialization for metadata version 1.0.
*/
template <>
-struct Metadata<METADATA_VERSION_1_0> : public MetadataBase {
+struct Metadata<METADATA_VERSION_2_0> : public MetadataBase {
protected:
OpenvinoVersion _ovVersion;
uint64_t _blobDataSize;
public:
- Metadata(uint64_t blobSize, std::optional<std::string_view> ovVersion = std::nullopt);
+ Metadata(uint64_t blobSize, std::optional<OpenvinoVersion> ovVersion = std::nullopt);
void read(std::istream& stream) override;
diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
index aa62403ce65..fa7dff03161 100644
--- a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
@@ -76,7 +76,7 @@ void CompiledModel::export_model(std::ostream& stream) const {
_logger.debug("CompiledModel::export_model");
size_t blobSizeBeforeVersioning = _graph->export_blob(stream);
- auto meta = Metadata<CURRENT_METADATA_VERSION>(blobSizeBeforeVersioning, ov::get_openvino_version().buildNumber);
+ auto meta = Metadata<CURRENT_METADATA_VERSION>(blobSizeBeforeVersioning, CURRENT_OPENVINO_VERSION);
meta.write(stream);
}
diff --git a/src/plugins/intel_npu/src/plugin/src/metadata.cpp b/src/plugins/intel_npu/src/plugin/src/metadata.cpp
index d6de18f2df3..e281e0b23cb 100644
--- a/src/plugins/intel_npu/src/plugin/src/metadata.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/metadata.cpp
@@ -6,40 +6,55 @@
#include <cstring>
#include <optional>
-#include <sstream>
-#include "intel_npu/config/config.hpp"
#include "intel_npu/utils/logger/logger.hpp"
-#include "openvino/core/version.hpp"
#include "openvino/runtime/shared_buffer.hpp"
namespace intel_npu {
-OpenvinoVersion::OpenvinoVersion(std::string_view version)
- : _version(version),
- _size(static_cast<uint32_t>(version.size())) {}
+uint16_t OpenvinoVersion::get_major() const {
+ return _major;
+}
+
+uint16_t OpenvinoVersion::get_minor() const {
+ return _minor;
+}
+
+uint16_t OpenvinoVersion::get_patch() const {
+ return _patch;
+}
+
+bool OpenvinoVersion::operator!=(const OpenvinoVersion& version) {
+ return this->_major != version._major || this->_minor != version._minor || this->_patch != version._patch;
+}
+
+OpenvinoVersion::OpenvinoVersion(const OpenvinoVersion& version)
+ : _major(version.get_major()),
+ _minor(version.get_minor()),
+ _patch(version.get_patch()) {}
void OpenvinoVersion::read(std::istream& stream) {
- stream.read(reinterpret_cast<char*>(&_size), sizeof(_size));
- _version.resize(_size);
- stream.read(_version.data(), _size);
+ stream.read(reinterpret_cast<char*>(&_major), sizeof(_major));
+ stream.read(reinterpret_cast<char*>(&_minor), sizeof(_minor));
+ stream.read(reinterpret_cast<char*>(&_patch), sizeof(_patch));
}
void OpenvinoVersion::write(std::ostream& stream) {
- stream.write(reinterpret_cast<const char*>(&_size), sizeof(_size));
- stream.write(_version.data(), _size);
+ stream.write(reinterpret_cast<const char*>(&_major), sizeof(_major));
+ stream.write(reinterpret_cast<const char*>(&_minor), sizeof(_minor));
+ stream.write(reinterpret_cast<const char*>(&_patch), sizeof(_patch));
}
-Metadata<METADATA_VERSION_1_0>::Metadata(uint64_t blobSize, std::optional<std::string_view> ovVersion)
- : MetadataBase{METADATA_VERSION_1_0},
- _ovVersion{ovVersion.value_or(ov::get_openvino_version().buildNumber)},
+Metadata<METADATA_VERSION_2_0>::Metadata(uint64_t blobSize, std::optional<OpenvinoVersion> ovVersion)
+ : MetadataBase{METADATA_VERSION_2_0},
+ _ovVersion{ovVersion.value_or(CURRENT_OPENVINO_VERSION)},
_blobDataSize{blobSize} {}
-void Metadata<METADATA_VERSION_1_0>::read(std::istream& stream) {
+void Metadata<METADATA_VERSION_2_0>::read(std::istream& stream) {
_ovVersion.read(stream);
}
-void Metadata<METADATA_VERSION_1_0>::write(std::ostream& stream) {
+void Metadata<METADATA_VERSION_2_0>::write(std::ostream& stream) {
stream.write(reinterpret_cast<const char*>(&_version), sizeof(_version));
_ovVersion.write(stream);
stream.write(reinterpret_cast<const char*>(&_blobDataSize), sizeof(_blobDataSize));
@@ -53,25 +68,25 @@ std::unique_ptr<MetadataBase> create_metadata(uint32_t version, uint64_t blobSiz
}
switch (version) {
- case METADATA_VERSION_1_0:
- return std::make_unique<Metadata<METADATA_VERSION_1_0>>(blobSize, std::nullopt);
+ case METADATA_VERSION_2_0:
+ return std::make_unique<Metadata<METADATA_VERSION_2_0>>(blobSize, std::nullopt);
default:
- OPENVINO_THROW("Invalid metadata version!");
+ OPENVINO_THROW("Metadata version is not supported!");
}
}
-std::string OpenvinoVersion::get_version() const {
- return _version;
-}
-
-bool Metadata<METADATA_VERSION_1_0>::is_compatible() {
+bool Metadata<METADATA_VERSION_2_0>::is_compatible() {
auto logger = Logger::global().clone("NPUBlobMetadata");
// checking if we can import the blob
- if (_ovVersion.get_version() != ov::get_openvino_version().buildNumber) {
- logger.error("Imported blob OpenVINO version: %s, but the current OpenVINO version is: %s",
- _ovVersion.get_version().c_str(),
- ov::get_openvino_version().buildNumber);
+ if (_ovVersion != CURRENT_OPENVINO_VERSION) {
+ logger.error("Imported blob OpenVINO version: %d.%d.%d, but the current OpenVINO version is: %d.%d.%d",
+ _ovVersion.get_major(),
+ _ovVersion.get_minor(),
+ _ovVersion.get_patch(),
+ OPENVINO_VERSION_MAJOR,
+ OPENVINO_VERSION_MINOR,
+ OPENVINO_VERSION_PATCH);
return false;
}
return true;
@@ -146,7 +161,7 @@ std::unique_ptr<MetadataBase> read_metadata_from(std::istream& stream) {
return storedMeta;
}
-uint64_t Metadata<METADATA_VERSION_1_0>::get_blob_size() const {
+uint64_t Metadata<METADATA_VERSION_2_0>::get_blob_size() const {
return _blobDataSize;
}
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index 490f08d3396..c2ef625243c 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -581,9 +581,15 @@ Plugin::Plugin()
[](const Config& config) {
return config.get<RUN_INFERENCES_SEQUENTIALLY>();
}}},
- {ov::intel_npu::batch_mode.name(), {false, ov::PropertyMutability::RW, [](const Config& config) {
- return config.getString<BATCH_MODE>();
- }}}};
+ {ov::intel_npu::batch_mode.name(),
+ {false,
+ ov::PropertyMutability::RW,
+ [](const Config& config) {
+ return config.getString<BATCH_MODE>();
+ }}},
+ {ov::intel_npu::disable_version_check.name(), {false, ov::PropertyMutability::RW, [](const Config& config) {
+ return config.getString<DISABLE_VERSION_CHECK>();
+ }}}};
}
void Plugin::reset_supported_properties() const {
@@ -865,17 +871,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
CompilerAdapterFactory compilerAdapterFactory;
auto compiler = compilerAdapterFactory.getCompiler(_backends->getIEngineBackend(), localConfig);
- bool skipCompatibility = false;
-
-#ifdef NPU_PLUGIN_DEVELOPER_BUILD
- if (auto envVar = std::getenv("OV_NPU_DISABLE_VERSION_CHECK")) {
- if (envVarStrToBool("OV_NPU_DISABLE_VERSION_CHECK", envVar)) {
- _logger.info("Blob compatibility check skipped.");
- skipCompatibility = true;
- }
- }
-#endif
uint64_t graphSize;
+ const bool skipCompatibility = localConfig.get<DISABLE_VERSION_CHECK>();
if (!skipCompatibility) {
auto storedMeta = read_metadata_from(stream);
if (!storedMeta->is_compatible()) {
@@ -883,6 +880,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
}
graphSize = storedMeta->get_blob_size();
} else {
+ _logger.info("Blob compatibility check skipped.");
graphSize = MetadataBase::getFileSize(stream);
}
diff --git a/src/plugins/intel_npu/tests/unit/npu/metadata_version.cpp b/src/plugins/intel_npu/tests/unit/npu/metadata_version.cpp
index 0c94a1e5334..9fe017e8440 100644
--- a/src/plugins/intel_npu/tests/unit/npu/metadata_version.cpp
+++ b/src/plugins/intel_npu/tests/unit/npu/metadata_version.cpp
@@ -13,7 +13,7 @@ using namespace intel_npu;
using MetadataUnitTests = ::testing::Test;
struct MetadataTest : Metadata<CURRENT_METADATA_VERSION> {
- MetadataTest(uint64_t blobSize, std::optional<std::string_view> ovVersion)
+ MetadataTest(uint64_t blobSize, std::optional<OpenvinoVersion> ovVersion)
: Metadata<CURRENT_METADATA_VERSION>(blobSize, ovVersion) {}
void set_version(uint32_t newVersion) {
@@ -31,7 +31,7 @@ TEST_F(MetadataUnitTests, readUnversionedBlob) {
TEST_F(MetadataUnitTests, writeAndReadCurrentMetadataFromBlob) {
uint64_t blobSize = 0;
std::stringstream stream;
- auto meta = MetadataTest(blobSize, ov::get_openvino_version().buildNumber);
+ auto meta = MetadataTest(blobSize, CURRENT_OPENVINO_VERSION);
OV_ASSERT_NO_THROW(meta.write(stream));
@@ -43,7 +43,8 @@ TEST_F(MetadataUnitTests, writeAndReadCurrentMetadataFromBlob) {
TEST_F(MetadataUnitTests, writeAndReadInvalidOpenvinoVersion) {
uint64_t blobSize = 0;
std::stringstream stream;
- auto meta = MetadataTest(blobSize, "just_some_wrong_ov_version");
+ OpenvinoVersion wrongOvVersion(0xF0C, 0xACC, 0x1A);
+ auto meta = MetadataTest(blobSize, wrongOvVersion);
OV_ASSERT_NO_THROW(meta.write(stream));
@@ -67,7 +68,7 @@ TEST_F(MetadataUnitTests, writeAndReadInvalidMetadataVersion) {
TEST_F(MetadataUnitTests, writeAndReadMetadataWithNewerMinorVersion) {
uint64_t blobSize = 0;
std::stringstream stream;
- auto meta = MetadataTest(blobSize, "some_ov_version");
+ auto meta = MetadataTest(blobSize, CURRENT_OPENVINO_VERSION);
constexpr uint32_t dummyVersion =
MetadataBase::make_version(CURRENT_METADATA_MAJOR_VERSION, CURRENT_METADATA_MINOR_VERSION + 1);
@@ -76,7 +77,7 @@ TEST_F(MetadataUnitTests, writeAndReadMetadataWithNewerMinorVersion) {
OV_ASSERT_NO_THROW(meta.write(stream));
std::unique_ptr<MetadataBase> storedMeta;
OV_ASSERT_NO_THROW(storedMeta = read_metadata_from(stream));
- ASSERT_FALSE(storedMeta->is_compatible());
+ storedMeta->is_compatible();
}
struct MetadataVersionTestFixture : Metadata<CURRENT_METADATA_VERSION>, ::testing::TestWithParam<uint32_t> {
@@ -89,7 +90,7 @@ public:
MetadataVersionTestFixture() : Metadata<CURRENT_METADATA_VERSION>(0, std::nullopt) {}
- MetadataVersionTestFixture(uint64_t blobSize, std::optional<std::string_view> ovVersion)
+ MetadataVersionTestFixture(uint64_t blobSize, std::optional<OpenvinoVersion> ovVersion)
: Metadata<CURRENT_METADATA_VERSION>(blobSize, ovVersion) {}
void TestBody() override {}
@@ -111,7 +112,8 @@ TEST_P(MetadataVersionTestFixture, writeAndReadInvalidMetadataVersion) {
GTEST_SKIP() << "Skipping single test since there is no case of lower minor version than actual.";
}
- MetadataVersionTestFixture dummyMeta = MetadataVersionTestFixture(0, "some_ov_version");
+ OpenvinoVersion dummyOvVersion(0x5A, 0x1A, 0xD);
+ MetadataVersionTestFixture dummyMeta = MetadataVersionTestFixture(0, dummyOvVersion);
dummyMeta.set_version(metaVersion);
OV_ASSERT_NO_THROW(dummyMeta.write(blob));
@@ -136,7 +138,8 @@ INSTANTIATE_TEST_SUITE_P(MetadataUnitTests,
TEST_F(MetadataUnitTests, writeAndReadMetadataWithNewerFieldAtEnd) {
uint64_t blobSize = 0;
std::stringstream stream;
- auto meta = MetadataTest(blobSize, "some_ov_version");
+ OpenvinoVersion dummyOvVersion(0x0FF, 0xC0FF, 0xEEEE);
+ auto meta = MetadataTest(blobSize, dummyOvVersion);
constexpr uint32_t dummyVersion =
MetadataBase::make_version(CURRENT_METADATA_MAJOR_VERSION, CURRENT_METADATA_MINOR_VERSION + 1);
@@ -159,7 +162,8 @@ TEST_F(MetadataUnitTests, writeAndReadMetadataWithNewerFieldAtEnd) {
TEST_F(MetadataUnitTests, writeAndReadMetadataWithNewerFieldAtMiddle) {
uint64_t blobSize = 0;
std::stringstream stream;
- auto meta = MetadataTest(blobSize, "some_ov_version");
+ OpenvinoVersion dummyOvVersion(0xFA, 0x1A, 0xFE1);
+ auto meta = MetadataTest(blobSize, dummyOvVersion);
constexpr uint32_t dummyVersion =
MetadataBase::make_version(CURRENT_METADATA_MAJOR_VERSION + 1, CURRENT_METADATA_MINOR_VERSION);
@@ -181,7 +185,8 @@ TEST_F(MetadataUnitTests, writeAndReadMetadataWithNewerFieldAtMiddle) {
TEST_F(MetadataUnitTests, writeAndReadMetadataWithRemovedField) {
uint64_t blobSize = 0;
std::stringstream stream;
- auto meta = MetadataTest(blobSize, "some_ov_version");
+ OpenvinoVersion dummyOvVersion(0xBA, 0xB1, 0xC);
+ auto meta = MetadataTest(blobSize, dummyOvVersion);
constexpr uint32_t dummyVersion =
MetadataBase::make_version(CURRENT_METADATA_MAJOR_VERSION + 1, CURRENT_METADATA_MINOR_VERSION);