Skip to content

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

[Plugin batch] Dynamic unbounded cases (#32609)

Daria Mityagina1b37ad1e199d
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 ac4f56a8044..b9327420431 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
@@ -630,6 +630,62 @@ TEST_P(DynamicBatchedTensorsRunTests, DynamicSetInputRemoteTensorsDynamicBatchDe
}
}
+TEST_P(DynamicBatchedTensorsRunTests, DynamicSetInputRemoteTensorsDynamicUnboundedBatchInflation) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+
+ size_t batch = 4;
+ auto one_shape = Shape{1, 2, 2, 2};
+ auto batch_shape = Shape{batch, 2, 2, 2};
+ size_t model_batch_bottom_bound = 1;
+ size_t model_batch_upper_bound = 10;
+ auto modelShape = PartialShape{ov::Dimension(-1), 2, 2, 2};
+ auto model = BatchedTensorsRunTests::create_n_inputs(2, element::f32, batch_shape, "N...");
+
+ const std::string tensor_name_0 = "tensor_input0";
+ const std::string tensor_name_1 = "tensor_input1";
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[tensor_name_0] = modelShape;
+ shapes[tensor_name_1] = modelShape;
+ model->reshape(shapes);
+ auto execNet = core->compile_model(model, target_device, configuration);
+ auto context = core->get_default_context(target_device);
+ // Create InferRequest
+ ov::InferRequest req;
+ req = execNet.create_infer_request();
+ std::vector<ov::Tensor> tensors;
+ for (size_t tensor_batch = model_batch_bottom_bound; tensor_batch <= model_batch_upper_bound; ++tensor_batch) {
+ executeMutlipleTensorsBatchInfer(req, tensor_batch, one_shape, context);
+ }
+}
+
+TEST_P(DynamicBatchedTensorsRunTests, DynamicSetInputRemoteTensorsDynamicUnboundedBatchDeflation) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+
+ size_t batch = 4;
+ auto one_shape = Shape{1, 2, 2, 2};
+ auto batch_shape = Shape{batch, 2, 2, 2};
+ size_t model_batch_bottom_bound = 1;
+ size_t model_batch_upper_bound = 10;
+ auto modelShape = PartialShape{ov::Dimension(-1), 2, 2, 2};
+ auto model = BatchedTensorsRunTests::create_n_inputs(2, element::f32, batch_shape, "N...");
+
+ const std::string tensor_name_0 = "tensor_input0";
+ const std::string tensor_name_1 = "tensor_input1";
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[tensor_name_0] = modelShape;
+ shapes[tensor_name_1] = modelShape;
+ model->reshape(shapes);
+ auto execNet = core->compile_model(model, target_device, configuration);
+ auto context = core->get_default_context(target_device);
+ // Create InferRequest
+ ov::InferRequest req;
+ req = execNet.create_infer_request();
+ std::vector<ov::Tensor> tensors;
+ for (size_t tensor_batch = model_batch_upper_bound; tensor_batch >= model_batch_bottom_bound; tensor_batch--) {
+ executeMutlipleTensorsBatchInfer(req, tensor_batch, one_shape, context);
+ }
+}
+
TEST_P(DynamicBatchedTensorsRunTests, SetInputRemoteSingleBatchedTensorSingleInfer) {
SKIP_IF_CURRENT_TEST_IS_DISABLED();
@@ -740,6 +796,67 @@ TEST_P(DynamicBatchedTensorsRunTests, SetInputRemoteSingleBatchedTensorSingleInf
}
}
+TEST_P(DynamicBatchedTensorsRunTests, SetInputRemoteSingleUnboundedBatchedTensorSingleInferWithExportImport) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+
+ size_t batch = 4;
+ size_t tensor_batch = 3;
+ auto one_shape = Shape{1, 2, 2, 2};
+ auto batch_shape = Shape{batch, 2, 2, 2};
+ auto one_shape_size = ov::shape_size(one_shape);
+ auto tensor_shape = Shape{tensor_batch, 2, 2, 2};
+ auto tensor_shape_size = ov::shape_size(tensor_shape);
+ auto modelShape = PartialShape{ov::Dimension(-1), 2, 2, 2};
+ auto model = BatchedTensorsRunTests::create_n_inputs(2, element::f32, batch_shape, "N...");
+
+ const std::string tensor_name_0 = "tensor_input0";
+ const std::string tensor_name_1 = "tensor_input1";
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[tensor_name_0] = modelShape;
+ shapes[tensor_name_1] = modelShape;
+ model->reshape(shapes);
+
+ // Compile model
+ auto execNet = core->compile_model(model, target_device, configuration);
+
+ // Export model
+ std::stringstream modelStream;
+ execNet.export_model(modelStream);
+
+ // Import model
+ auto importedExecNet = core->import_model(modelStream, target_device, configuration);
+
+ auto context = core->get_default_context(target_device);
+
+ // Create InferRequest from imported model
+ ov::InferRequest req;
+ req = importedExecNet.create_infer_request();
+ std::vector<ov::Tensor> tensors;
+
+ // contiguous memory
+ auto tensor = context.create_host_tensor(ov::element::f32, tensor_shape);
+ tensors.push_back(std::move(tensor));
+
+ req.set_tensors("tensor_input0", tensors);
+
+ auto actual_tensor = req.get_tensor("tensor_output0");
+ auto* actual = actual_tensor.data<float>();
+
+ for (auto testNum = 0; testNum < 5; testNum++) {
+ auto* f = tensors[0].data<float>();
+ for (size_t j = 0; j < tensor_shape_size; ++j) {
+ f[j] = static_cast<float>(testNum + 20 * (j / one_shape_size + 1));
+ }
+ req.infer(); // Adds '1' to each element
+ for (size_t j = 0; j < tensor_shape_size; ++j) {
+ auto expected = testNum + 20 * (j / one_shape_size + 1) + 1;
+ ASSERT_EQ(actual[j], expected)
+ << "Infer " << testNum << ": Expected=" << expected << ", actual=" << actual[j] << " for index " << j
+ << ", batch: " << j / one_shape_size;
+ }
+ }
+}
+
void executeContiguousTensorBatchInfer(ov::InferRequest req,
size_t batch_value,
const Shape& non_batched_shape,