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
[NPU] Return ov::Any for WO properties (#39681)
Bogdan Pereanu452ed9862db9
diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cppindex f293442ef73..027bfb36d31 100644--- a/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cpp+++ b/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cpp@@ -261,8 +261,8 @@ void CompiledModelPropertyManager::registerProperties() {[this](const ov::AnyMap&) {return _config.hasOpt(ov::cache_encryption_callbacks.name());},- [](const ov::AnyMap&) {- return ov::EncryptionCallbacks{nullptr, nullptr};+ [](const ov::AnyMap&) -> ov::Any {+ return ov::Any{};},[this](const ov::Any& value) {_config.update(ov::cache_encryption_callbacks.name(), value);diff --git a/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp b/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cppindex bcb3573a929..28a07c0e82b 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp@@ -658,8 +658,8 @@ void PluginPropertyManager::registerProperties() {[this](const ov::AnyMap&) {return _config.hasOpt(ov::cache_encryption_callbacks.name());},- [](const ov::AnyMap&) {- return ov::EncryptionCallbacks{nullptr, nullptr};+ [](const ov::AnyMap&) -> ov::Any {+ return ov::Any{};},[this](const ov::Any& value) {_config.update(ov::cache_encryption_callbacks.name(), value);@@ -811,7 +811,7 @@ void PluginPropertyManager::registerProperties() {return _config.hasOpt(ov::hint::model.name());},[this](const ov::AnyMap&) -> ov::Any {- return std::shared_ptr<const ov::Model>{};+ return ov::Any{};},[](const ov::Any&) {OPENVINO_THROW("Property '", ov::hint::model.name(),"' can only be provided when importing a compiled model, it cannot be set otherwise");@@ -837,7 +837,7 @@ void PluginPropertyManager::registerProperties() {return _config.hasOpt(ov::loaded_from_cache.name());},[](const ov::AnyMap&) -> ov::Any {- return false;+ return ov::Any{};},[](const ov::Any&) {OPENVINO_THROW("Property '", ov::loaded_from_cache.name(),"' can only be provided when importing a compiled model from OpenVINO Cache, it cannot be set otherwise");diff --git a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cppindex 64711b1b086..ab8de686b0c 100644--- a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp@@ -981,6 +981,39 @@ TEST_P(CheckSecureCompilationFlag, EncryptionCallbacksForOlderDriverThrows) {}}+using CheckWriteOnlyPropertiesAreEmpty = ClassExecutableNetworkGetPropertiesTestNPU;++// Write-only properties cannot be handed back to the user (e.g. the Python bindings have no Any -> object conversion+// for ov::EncryptionCallbacks), so reading them must succeed and return an empty ov::Any.+TEST_P(CheckWriteOnlyPropertiesAreEmpty, AllSupportedWriteOnlyPropertiesReturnEmptyAny) {+ // Encryption callbacks require L0 graph ext version >= 1.17+ NPU_SKIP_IF_GRAPH_EXT_LOWER_THAN(1, 17);++ // Write-only properties are only reported by the compiled model if they were provided through the configuration+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = ie.compile_model(model, deviceName, {{configKey, configValue}}));++ std::vector<ov::PropertyName> supported_properties;+ OV_ASSERT_NO_THROW(supported_properties = compiled_model.get_property(ov::supported_properties));++ size_t write_only_count = 0;+ for (const auto& property : supported_properties) {+ if (property.get_mutability() != ov::PropertyMutability::WO) {+ continue;+ }+ ++write_only_count;++ ov::Any value;+ OV_ASSERT_NO_THROW(value = compiled_model.get_property(property));+ EXPECT_TRUE(value.empty()) << "Write-only property " << property << " must return an empty ov::Any";+ }++ // The property provided through the configuration must have been reported as write-only+ ASSERT_GT(write_only_count, 0u);+ ASSERT_NE(std::find(supported_properties.cbegin(), supported_properties.cend(), configKey),+ supported_properties.cend());+}+} // namespacenamespace {@@ -1152,4 +1185,10 @@ INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTests_CheckSecureCompilatio::testing::ValuesIn(exe_network_public_mutable_properties)),CheckSecureCompilationFlag::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests_CheckWriteOnlyPropertiesAreEmpty,+ CheckWriteOnlyPropertiesAreEmpty,+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),+ ::testing::ValuesIn(exe_network_public_mutable_properties)),+ CheckWriteOnlyPropertiesAreEmpty::getTestCaseName);+} // namespacediff --git a/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.cpp b/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.cppindex 8c04e967c60..dc897d1cd9c 100644--- a/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.cpp+++ b/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.cpp@@ -797,6 +797,42 @@ TEST_P(WSCompileCallNumberPropertyTests, RemainsAvailableAsInternalCompilerOptioASSERT_EQ(filteredConfig.get<::intel_npu::WS_COMPILE_CALL_NUMBER>(), 3);}+using WriteOnlyPropertyTests = PropertiesManagerTests;++// Write-only properties cannot be handed back to the user (e.g. the Python bindings have no Any -> object conversion+// for ov::EncryptionCallbacks or std::shared_ptr<const ov::Model>), so reading them must succeed and return an empty+// ov::Any.+TEST_P(WriteOnlyPropertyTests, AllSupportedWriteOnlyPropertiesReturnEmptyAny) {+ std::vector<ov::PropertyName> supportedProperties;+ OV_ASSERT_NO_THROW(+ supportedProperties =+ propertiesManager->getProperty(ov::supported_properties.name()).as<std::vector<ov::PropertyName>>());++ size_t writeOnlyCount = 0;+ for (const auto& property : supportedProperties) {+ if (property.get_mutability() != ov::PropertyMutability::WO) {+ continue;+ }+ ++writeOnlyCount;++ ov::Any value;+ OV_ASSERT_NO_THROW(value = propertiesManager->getProperty(property));+ EXPECT_TRUE(value.empty()) << "Write-only property " << property << " must return an empty ov::Any";+ }++ ASSERT_GT(writeOnlyCount, 0u);+}++// Private (non-public) write-only properties are not part of supported_properties, so they are queried by name. The+// property name is the test parameter.+using PrivateWriteOnlyPropertyTests = PropertiesManagerTests;++TEST_P(PrivateWriteOnlyPropertyTests, ReturnsEmptyAny) {+ ov::Any value;+ OV_ASSERT_NO_THROW(value = propertiesManager->getProperty(configuration));+ EXPECT_TRUE(value.empty()) << configuration;+}+using ExpectLoadingCompilerPropertySupported = PropertiesManagerTests;TEST_P(ExpectLoadingCompilerPropertySupported, ExpectCompilerPropertyIsSupported) {@@ -1083,6 +1119,20 @@ INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTest,::testing::Values(std::string{})),PropertiesManagerTests::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTest,+ WriteOnlyPropertyTests,+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),+ ::testing::Values(std::string{})),+ PropertiesManagerTests::getTestCaseName);++const std::vector<std::string> private_write_only_properties = {{ov::loaded_from_cache.name()}};++INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTest,+ PrivateWriteOnlyPropertyTests,+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),+ ::testing::ValuesIn(private_write_only_properties)),+ PropertiesManagerTests::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,ExpectLoadingCompilerPropertySupported,::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),