Skip to content

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

[Plugin batch] BatchMode::PLUGIN shouldn't send a model to the compiler if we failed to process it in the plugin (#34041)

Daria Mityagina10801e65d28a
diff --git a/src/plugins/intel_npu/src/plugin/src/transformations.cpp b/src/plugins/intel_npu/src/plugin/src/transformations.cpp
index 9699ff721ff..1ee096c1747 100644
--- a/src/plugins/intel_npu/src/plugin/src/transformations.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/transformations.cpp
@@ -203,8 +203,8 @@ std::tuple<std::shared_ptr<ov::Model>, bool> handlePluginBatching(
return {reshapedModel, successfullyDebatched};
}
} else {
- // If the compiler doesn't support BATCH_MODE, we can still try using the PLUGIN batch
- batchMode = ov::intel_npu::BatchMode::PLUGIN;
+ // If the compiler doesn't support BATCH_MODE, we can still try using batching
+ batchMode = ov::intel_npu::BatchMode::AUTO;
}
try {
@@ -241,8 +241,18 @@ std::tuple<std::shared_ptr<ov::Model>, bool> handlePluginBatching(
updateBatchMode(ov::intel_npu::BatchMode::COMPILER);
}
} catch (const std::exception& ex) {
- logger.info("Couldn't validate and reshape the model. Batching will be handled by compiler. Error: %s",
- ex.what());
+ if (batchMode == ov::intel_npu::BatchMode::AUTO) {
+ logger.info("Couldn't validate and reshape the model. Batching will be handled by compiler. Error: %s",
+ ex.what());
+ if (batchModeIsAvailable) {
+ // If we failed to handle batching on the plugin side, we should reset the batch mode to default
+ // COMPILER But only if the batch mode is available, otherwise we might be running on older compiler
+ // which doesn't support batch mode at all
+ updateBatchMode(ov::intel_npu::BatchMode::COMPILER);
+ }
+ } else {
+ OPENVINO_THROW("Couldn't validate and reshape the model for PLUGIN batch mode. Error: %s", ex.what());
+ }
}
return {reshapedModel, successfullyDebatched};
diff --git a/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.cpp b/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.cpp
index c1cb78a0a6c..da5febbb574 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.cpp
@@ -20,11 +20,17 @@ INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,
::testing::ValuesIn(batchedConfigs)),
BatchedTensorsRunTests::getTestCaseName);
-const std::vector<ov::AnyMap> DynamicBatchedConfigs = {
+const std::vector<ov::AnyMap> PluginBatchedConfigs = {
{ov::intel_npu::batch_mode(ov::intel_npu::BatchMode::PLUGIN)}};
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,
DynamicBatchedTensorsRunTests,
::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),
- ::testing::ValuesIn(DynamicBatchedConfigs)),
+ ::testing::ValuesIn(PluginBatchedConfigs)),
+ BatchedTensorsRunTests::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,
+ BatchedTensorsRunFailureTests,
+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),
+ ::testing::ValuesIn(PluginBatchedConfigs)),
BatchedTensorsRunTests::getTestCaseName);
diff --git a/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.hpp b/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.hpp
index 20643cf6590..d48a64e97e1 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.hpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/batched_tensors_tests/batched_run.hpp
@@ -1049,6 +1049,17 @@ TEST_P(DynamicBatchedTensorsRunTests, DynamicSetInputDifferentTensorsMultipleInf
}
}
+using BatchedTensorsRunFailureTests = BatchedTensorsRunTests;
+
+TEST_P(BatchedTensorsRunFailureTests, FailedToDetectBatch) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+
+ auto shape = Shape{4, 2, 2};
+ auto model = BatchedTensorsRunTests::create_n_inputs(1, element::f32, shape, "");
+
+ EXPECT_THROW(auto execNet = core->compile_model(model, target_device, configuration);, std::exception);
+}
+
} // namespace behavior
} // namespace test
} // namespace ov