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
[`intel_npu`] [`import_model(tensor) API`] [`TESTS`] Activate `import_model(tensor)` tests (#31587)
Mircea-Aurelian Dan939a83a63398
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.cppindex 11799ffa7d8..204a413097b 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@@ -371,6 +371,12 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::parse(OV_ITT_TASK_NEXT(PARSE_BLOB, "getNetworkMeta");auto networkMeta = _zeGraphExt->getNetworkMeta(mainGraphDesc);+ // exporting the blob when we get it from cache or ov::hint::compiled_blob property+ // shall be available+ const bool blobIsPersistent = config.has<COMPILED_BLOB>() ? true+ : config.has<LOADED_FROM_CACHE>() ? config.get<LOADED_FROM_CACHE>()+ : false;+if (!initBlobs.has_value()) {return std::make_shared<Graph>(_zeGraphExt,_zeroInitStruct,@@ -378,9 +384,7 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::parse(std::move(networkMeta),std::move(mainBlob),config,- config.has<LOADED_FROM_CACHE>()- ? config.get<LOADED_FROM_CACHE>()- : false); // exporting the blob when we get it from cache shall be available+ blobIsPersistent);}// The presence of init schedules means weights separation has been enabled at compilation time. Use a specific@@ -395,19 +399,17 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::parse(initMetadata.push_back(_zeGraphExt->getNetworkMeta(initGraphDesc));}- return std::make_shared<WeightlessGraph>(- _zeGraphExt,- _zeroInitStruct,- mainGraphDesc,- std::move(networkMeta),- std::move(mainBlob),- initGraphDescriptors,- std::move(initMetadata),- std::move(initBlobs),- model.value(),- config,- config.has<LOADED_FROM_CACHE>() ? config.get<LOADED_FROM_CACHE>()- : false); // exporting the blob when we get it from cache shall be available+ return std::make_shared<WeightlessGraph>(_zeGraphExt,+ _zeroInitStruct,+ mainGraphDesc,+ std::move(networkMeta),+ std::move(mainBlob),+ initGraphDescriptors,+ std::move(initMetadata),+ std::move(initBlobs),+ model.value(),+ config,+ blobIsPersistent);}ov::SupportedOpsMap DriverCompilerAdapter::query(const std::shared_ptr<const ov::Model>& model,diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cppindex 65a7a486118..466eea02dd3 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp@@ -272,6 +272,12 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::parse(_logger.debug("main schedule parse end");+ // exporting the blob when we get it from cache or ov::hint::compiled_blob property+ // shall be available+ const bool blobIsPersistent = config.has<COMPILED_BLOB>() ? true+ : config.has<LOADED_FROM_CACHE>() ? config.get<LOADED_FROM_CACHE>()+ : false;+if (!initBlobs.has_value()) {return std::make_shared<Graph>(_zeGraphExt,_zeroInitStruct,@@ -279,9 +285,7 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::parse(std::move(networkMeta),std::move(mainBlob),config,- config.has<LOADED_FROM_CACHE>()- ? config.get<LOADED_FROM_CACHE>()- : false, // exporting the blob when we get it from cache shall be available+ blobIsPersistent,_compiler);}@@ -306,20 +310,18 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::parse(}_logger.debug("init schedules parse end");- return std::make_shared<WeightlessGraph>(- _zeGraphExt,- _zeroInitStruct,- mainGraphDesc,- std::move(networkMeta),- std::move(mainBlob),- initGraphDescriptors,- std::move(initMetadata),- std::move(initBlobs),- model.value(),- config,- config.has<LOADED_FROM_CACHE>() ? config.get<LOADED_FROM_CACHE>()- : false, // exporting the blob when we get it from cache shall be available- _compiler);+ return std::make_shared<WeightlessGraph>(_zeGraphExt,+ _zeroInitStruct,+ mainGraphDesc,+ std::move(networkMeta),+ std::move(mainBlob),+ initGraphDescriptors,+ std::move(initMetadata),+ std::move(initBlobs),+ model.value(),+ config,+ blobIsPersistent,+ _compiler);}ov::SupportedOpsMap PluginCompilerAdapter::query(const std::shared_ptr<const ov::Model>& model,diff --git a/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/blob_compatibility.hpp b/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/blob_compatibility.hppindex 8ee4e8a8a1d..6873e46f1fa 100644--- a/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/blob_compatibility.hpp+++ b/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/blob_compatibility.hpp@@ -120,9 +120,7 @@ using OVBlobCompatibilityNPU_PV_Driver_No_Throw = OVBlobCompatibilityNPU;std::ifstream blobStream(blobPath, std::ios::binary | std::ios::in); \ASSERT_TYPE(core.import_model(blobStream, target_device, {ov::intel_npu::disable_version_check(true)}), \##__VA_ARGS__); \- // CVS-166953: skip compile_model(model, {compiled_blob(tensor)}) scenario until ov::hint::compiled_blob- // is passed to fallback on import_model(tensor)- // APPEND_EXPORT_HELPER(ASSERT_TYPE, ##__VA_ARGS__)+ APPEND_EXPORT_HELPER(ASSERT_TYPE, ##__VA_ARGS__)TEST_P(OVBlobCompatibilityNPU, CanImportAllPrecompiledBlobsForAllOVVersionsAndDrivers) {if (auto current_driver =diff --git a/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/import_export.hpp b/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/import_export.hppindex 32a3aca6c95..be9be0012d3 100644--- a/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/import_export.hpp+++ b/src/plugins/intel_npu/tests/functional/internal/overload/compiled_model/import_export.hpp@@ -41,7 +41,7 @@ TEST_P(OVCompiledGraphImportExportTestNPU, CanImportModelWithApplicationHeaderAnsstream.seekg(headerView.size(), std::ios::beg); // skip headerOV_ASSERT_NO_THROW(auto compiledModel = core.import_model(sstream, target_device, configuration));- // OV_ASSERT_NO_THROW(auto compiledModel = core.import_model(tensor, target_device, configuration));+ OV_ASSERT_NO_THROW(auto compiledModel = core.import_model(tensor, target_device, configuration));}// suffix tests, application correctly manages ov::Tensor offsets or disables metadata checking@@ -59,7 +59,7 @@ TEST_P(OVCompiledGraphImportExportTestNPU, CanImportModelWithApplicationHeaderAnconfiguration.emplace(ov::intel_npu::disable_version_check(true));OV_ASSERT_NO_THROW(auto compiledModel = core.import_model(sstream, target_device, configuration));configuration.erase(ov::intel_npu::disable_version_check.name());- // OV_ASSERT_NO_THROW(auto compiledModel = core.import_model(tensor, target_device, configuration));+ OV_ASSERT_NO_THROW(auto compiledModel = core.import_model(tensor, target_device, configuration));OV_EXPECT_THROW(auto compiledModel = core.import_model(sstream, target_device, configuration),ov::Exception,testing::HasSubstr("metadata")); // OVNPU suffix cannot be parsed from metadatadiff --git a/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hpp b/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hppindex c979a9de690..8ef55c8f7aa 100644--- a/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hpp+++ b/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hpp@@ -7,6 +7,7 @@#include "behavior/ov_plugin/life_time.hpp"#include "common/npu_test_env_cfg.hpp"#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"+#include "intel_npu/utils/zero/zero_init.hpp"#include "openvino/runtime/make_tensor.hpp"using CompilationParams = std::tuple<std::string, // Device name@@ -224,7 +225,7 @@ TEST_P(OVHoldersTestOnImportedNetworkNPU, CreateRequestWithCoreRemoved) {auto request = compiled_model.create_infer_request();}-TEST_P(OVHoldersTestOnImportedNetworkNPU, DISABLED_CanInferAfterTensorIsDestroyed) {+TEST_P(OVHoldersTestOnImportedNetworkNPU, CanInferAfterTensorIsDestroyed) {ov::Core core = createCoreWithTemplate();for (size_t i = 0; i < 2; ++i) {@@ -240,15 +241,21 @@ TEST_P(OVHoldersTestOnImportedNetworkNPU, DISABLED_CanInferAfterTensorIsDestroyeauto impl = ov::get_tensor_impl(tensor);impl._so = strSO;tensor = ov::make_tensor(impl);- // compiled_model = core.import_model(tensor, target_device, configuration);+ compiled_model = core.import_model(tensor, target_device, configuration);}// check if the shared object (strSO destroyed above) persists in compiled_model{std::ostringstream sstream;ov::InferRequest infer_request;- OV_ASSERT_NO_THROW(compiled_model.export_model(sstream));- EXPECT_TRUE(sstream.tellp() > 0);+ if (i == 0 && std::make_shared<::intel_npu::ZeroInitStructsHolder>()->getGraphDdiTable().version() >=+ ZE_MAKE_VERSION(1, 8)) { // older drivers will own the blob and not deallocate+ ASSERT_THROW(compiled_model.export_model(sstream), ov::Exception); // model was imported, not compiled+ } else {+ OV_ASSERT_NO_THROW(+ compiled_model.export_model(sstream)); // weights load deferred, blob still accessible+ EXPECT_TRUE(sstream.tellp() > 0);+ }OV_ASSERT_NO_THROW(infer_request = compiled_model.create_infer_request());compiled_model = {}; // dtor of compiled model won't affect created infer requestOV_ASSERT_NO_THROW(infer_request.infer());