From 6b305f8b06d6f2f0a05693d18e01423df998b6fb Mon Sep 17 00:00:00 2001 From: Daniil Vlasenko Date: Wed, 1 May 2024 23:23:52 +0200 Subject: [PATCH 1/7] Runtime. ICompiledModel. Added a check or a batch dimension size and a notification message with information about wrong values. --- src/inference/src/dev/icompiled_model.cpp | 13 +++++++ .../tests/unit/compiled_model_test.cpp | 36 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/inference/src/dev/icompiled_model.cpp b/src/inference/src/dev/icompiled_model.cpp index 0079826cdeb..b4774139f83 100644 --- a/src/inference/src/dev/icompiled_model.cpp +++ b/src/inference/src/dev/icompiled_model.cpp @@ -50,6 +50,19 @@ ov::ICompiledModel::ICompiledModel(const std::shared_ptr& model std::unordered_map, std::shared_ptr> tensor_map; for (const auto& param : model->get_parameters()) { + { + const auto& p_shape = param->get_partial_shape(); + const auto& layout = param->get_layout(); + const auto batch_idx = ov::layout::has_batch(layout) ? ov::layout::batch_idx(layout) : 0; + const auto batch_dim = p_shape[batch_idx]; + OPENVINO_ASSERT(batch_dim.is_dynamic() || batch_dim.get_length() > 0, + "Batch size for parameter ", + param->get_friendly_name(), + " has wrong value ", + batch_dim.get_length(), + ". Batch size must be a positive value."); + } + const auto& param_name = param->get_friendly_name(); auto new_param = ov::as_type_ptr(param->copy_with_new_inputs({})); new_param->set_friendly_name(param_name); diff --git a/src/inference/tests/unit/compiled_model_test.cpp b/src/inference/tests/unit/compiled_model_test.cpp index 55e08444037..e5b382d8155 100644 --- a/src/inference/tests/unit/compiled_model_test.cpp +++ b/src/inference/tests/unit/compiled_model_test.cpp @@ -185,3 +185,39 @@ TEST_F(CompiledModelBaseTests, canReportErrorInExport) { EXPECT_CALL(*mock_compiled_model.get(), export_model(_)).WillOnce(Throw(std::runtime_error("compare"))); OV_EXPECT_THROW_HAS_SUBSTRING(compiled_model.export_model(out_model), std::runtime_error, "compare"); } + +class CompiledModelZeroBatch : public ::testing::Test { +protected: + std::shared_ptr model; + std::shared_ptr plugin; + + void SetUp() override { + auto param = std::make_shared(ov::element::f32, ov::PartialShape{0, 3, 2, 2}); + param->set_friendly_name("Param"); + param->output(0).set_names({"param"}); + auto relu = std::make_shared(param); + relu->set_friendly_name("ReLU"); + relu->output(0).set_names({"relu"}); + model = std::make_shared(ov::OutputVector{relu->output(0)}, ov::ParameterVector{param}); + plugin = std::make_shared(); + } +}; + +TEST_F(CompiledModelZeroBatch, BatchSizeZeroThrows) { + model->get_parameters()[0]->set_layout("NCWH"); + OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(model, plugin), + std::runtime_error, + "Batch size for parameter Param"); +} + +TEST_F(CompiledModelZeroBatch, BatchSizeDynamicNoThrow) { + model->get_parameters()[0]->set_layout("NCWH"); + ov::set_batch(model, ov::Dimension::dynamic()); + ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); +} + +TEST_F(CompiledModelZeroBatch, BatchSizeZeroNoLayoutThrows) { + OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(model, plugin), + std::runtime_error, + "Batch size for parameter Param"); +} \ No newline at end of file From cd48b4f2a99d73c72a5a6e0c454f7f9c596af8b7 Mon Sep 17 00:00:00 2001 From: Daniil Vlasenko Date: Mon, 6 May 2024 19:56:23 +0200 Subject: [PATCH 2/7] Runtime. ICompiledModel. Changed the behavior of the Batch Size check to do the actual check only if there is a layout on a parameter that allows to locate BS. --- src/inference/src/dev/icompiled_model.cpp | 18 ++++--- .../tests/unit/compiled_model_test.cpp | 51 +++++++++++++++---- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/inference/src/dev/icompiled_model.cpp b/src/inference/src/dev/icompiled_model.cpp index b4774139f83..11603e400a0 100644 --- a/src/inference/src/dev/icompiled_model.cpp +++ b/src/inference/src/dev/icompiled_model.cpp @@ -53,14 +53,16 @@ ov::ICompiledModel::ICompiledModel(const std::shared_ptr& model { const auto& p_shape = param->get_partial_shape(); const auto& layout = param->get_layout(); - const auto batch_idx = ov::layout::has_batch(layout) ? ov::layout::batch_idx(layout) : 0; - const auto batch_dim = p_shape[batch_idx]; - OPENVINO_ASSERT(batch_dim.is_dynamic() || batch_dim.get_length() > 0, - "Batch size for parameter ", - param->get_friendly_name(), - " has wrong value ", - batch_dim.get_length(), - ". Batch size must be a positive value."); + if (p_shape.rank().is_static() && p_shape.rank() != 0 && ov::layout::has_batch(layout)) { + const auto batch_idx = ov::layout::batch_idx(layout); + const auto batch_dim = p_shape[batch_idx]; + OPENVINO_ASSERT(batch_dim.is_dynamic() || batch_dim.get_length() > 0, + "Batch size for parameter ", + param->get_friendly_name(), + " has wrong value ", + batch_dim.get_length(), + ". Batch size must be a positive value."); + } } const auto& param_name = param->get_friendly_name(); diff --git a/src/inference/tests/unit/compiled_model_test.cpp b/src/inference/tests/unit/compiled_model_test.cpp index e5b382d8155..810fd0c83ff 100644 --- a/src/inference/tests/unit/compiled_model_test.cpp +++ b/src/inference/tests/unit/compiled_model_test.cpp @@ -189,35 +189,66 @@ TEST_F(CompiledModelBaseTests, canReportErrorInExport) { class CompiledModelZeroBatch : public ::testing::Test { protected: std::shared_ptr model; + std::shared_ptr modelZero; std::shared_ptr plugin; void SetUp() override { - auto param = std::make_shared(ov::element::f32, ov::PartialShape{0, 3, 2, 2}); + model = create_model(ov::PartialShape{1, 3, 2, 2}); + modelZero = create_model(ov::PartialShape{0, 3, 2, 2}); + plugin = std::make_shared(); + } + +private: + std::shared_ptr create_model(const ov::PartialShape &p_shape) { + auto param = std::make_shared(ov::element::f32, p_shape); param->set_friendly_name("Param"); param->output(0).set_names({"param"}); auto relu = std::make_shared(param); relu->set_friendly_name("ReLU"); relu->output(0).set_names({"relu"}); - model = std::make_shared(ov::OutputVector{relu->output(0)}, ov::ParameterVector{param}); - plugin = std::make_shared(); + return std::make_shared(ov::OutputVector{relu->output(0)}, ov::ParameterVector{param}); } }; -TEST_F(CompiledModelZeroBatch, BatchSizeZeroThrows) { +TEST_F(CompiledModelZeroBatch, batchSizeZeroWithLayoutThrows) { + modelZero->get_parameters()[0]->set_layout("NCWH"); + OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(modelZero, plugin), + std::runtime_error, + "Batch size for parameter Param"); +} + +TEST_F(CompiledModelZeroBatch, batchSizeReshapeToZeroWithLayoutThrows) { model->get_parameters()[0]->set_layout("NCWH"); + model->reshape(ov::PartialShape{0, 3, 2, 2}); OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(model, plugin), std::runtime_error, "Batch size for parameter Param"); } -TEST_F(CompiledModelZeroBatch, BatchSizeDynamicNoThrow) { +TEST_F(CompiledModelZeroBatch, batchSizeReshapeToNonZeroWithLayoutThrows) { + modelZero->get_parameters()[0]->set_layout("NCWH"); + modelZero->reshape(ov::PartialShape{1, 3, 2, 2}); + ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); +} + +TEST_F(CompiledModelZeroBatch, batchSizeNonZeroWithLayoutNoThrow) { model->get_parameters()[0]->set_layout("NCWH"); - ov::set_batch(model, ov::Dimension::dynamic()); ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); } -TEST_F(CompiledModelZeroBatch, BatchSizeZeroNoLayoutThrows) { - OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(model, plugin), - std::runtime_error, - "Batch size for parameter Param"); +TEST_F(CompiledModelZeroBatch, batchSizeDynamicWithLayoutNoThrow) { + model->get_parameters()[0]->set_layout("NCWH"); + modelZero->get_parameters()[0]->set_layout("NCWH"); + ov::set_batch(model, ov::Dimension::dynamic()); + ov::set_batch(modelZero, ov::Dimension::dynamic()); + ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); + ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); +} + +TEST_F(CompiledModelZeroBatch, batchSizeZeroNoLayoutNoThrow) { + ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); +} + +TEST_F(CompiledModelZeroBatch, batchSizeNonZeroNoLayoutNoThrow) { + ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); } \ No newline at end of file From df86ec69e866c0c902e3ea026f2b86f31a0a439f Mon Sep 17 00:00:00 2001 From: Daniil Vlasenko Date: Mon, 6 May 2024 19:59:45 +0200 Subject: [PATCH 3/7] Runtime. ICompiledModel. Additional SetBatch tests --- src/inference/tests/unit/compiled_model_test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/inference/tests/unit/compiled_model_test.cpp b/src/inference/tests/unit/compiled_model_test.cpp index 810fd0c83ff..4633c65335a 100644 --- a/src/inference/tests/unit/compiled_model_test.cpp +++ b/src/inference/tests/unit/compiled_model_test.cpp @@ -231,6 +231,20 @@ TEST_F(CompiledModelZeroBatch, batchSizeReshapeToNonZeroWithLayoutThrows) { ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); } +TEST_F(CompiledModelZeroBatch, batchSizeSetBatchToZeroWithLayoutThrows) { + model->get_parameters()[0]->set_layout("NCWH"); + ov::set_batch(model, 0); + OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(model, plugin), + std::runtime_error, + "Batch size for parameter Param"); +} + +TEST_F(CompiledModelZeroBatch, batchSizeSetBatchToNonZeroWithLayoutThrows) { + modelZero->get_parameters()[0]->set_layout("NCWH"); + ov::set_batch(modelZero, 1); + ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); +} + TEST_F(CompiledModelZeroBatch, batchSizeNonZeroWithLayoutNoThrow) { model->get_parameters()[0]->set_layout("NCWH"); ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); From 8e6e896d2db78ea4380692e3cf6ea3f98879d145 Mon Sep 17 00:00:00 2001 From: Daniil Vlasenko Date: Tue, 7 May 2024 09:58:13 +0200 Subject: [PATCH 4/7] Clang format fixes --- src/inference/src/dev/icompiled_model.cpp | 2 +- src/inference/tests/unit/compiled_model_test.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/inference/src/dev/icompiled_model.cpp b/src/inference/src/dev/icompiled_model.cpp index 11603e400a0..0a365011d29 100644 --- a/src/inference/src/dev/icompiled_model.cpp +++ b/src/inference/src/dev/icompiled_model.cpp @@ -64,7 +64,7 @@ ov::ICompiledModel::ICompiledModel(const std::shared_ptr& model ". Batch size must be a positive value."); } } - + const auto& param_name = param->get_friendly_name(); auto new_param = ov::as_type_ptr(param->copy_with_new_inputs({})); new_param->set_friendly_name(param_name); diff --git a/src/inference/tests/unit/compiled_model_test.cpp b/src/inference/tests/unit/compiled_model_test.cpp index 4633c65335a..5e57f01d35e 100644 --- a/src/inference/tests/unit/compiled_model_test.cpp +++ b/src/inference/tests/unit/compiled_model_test.cpp @@ -193,13 +193,13 @@ protected: std::shared_ptr plugin; void SetUp() override { - model = create_model(ov::PartialShape{1, 3, 2, 2}); - modelZero = create_model(ov::PartialShape{0, 3, 2, 2}); + model = create_model(ov::PartialShape{1, 3, 2, 2}); + modelZero = create_model(ov::PartialShape{0, 3, 2, 2}); plugin = std::make_shared(); } private: - std::shared_ptr create_model(const ov::PartialShape &p_shape) { + std::shared_ptr create_model(const ov::PartialShape& p_shape) { auto param = std::make_shared(ov::element::f32, p_shape); param->set_friendly_name("Param"); param->output(0).set_names({"param"}); From 723c0b769676be511995eefc9e5d8d60a394e38b Mon Sep 17 00:00:00 2001 From: Daniil Vlasenko Date: Tue, 21 May 2024 08:47:15 +0200 Subject: [PATCH 5/7] InferenceTests. CompiledModel. Removed redundant test --- src/inference/tests/unit/compiled_model_test.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/inference/tests/unit/compiled_model_test.cpp b/src/inference/tests/unit/compiled_model_test.cpp index 5e57f01d35e..5bd2dccd32c 100644 --- a/src/inference/tests/unit/compiled_model_test.cpp +++ b/src/inference/tests/unit/compiled_model_test.cpp @@ -245,11 +245,6 @@ TEST_F(CompiledModelZeroBatch, batchSizeSetBatchToNonZeroWithLayoutThrows) { ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); } -TEST_F(CompiledModelZeroBatch, batchSizeNonZeroWithLayoutNoThrow) { - model->get_parameters()[0]->set_layout("NCWH"); - ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); -} - TEST_F(CompiledModelZeroBatch, batchSizeDynamicWithLayoutNoThrow) { model->get_parameters()[0]->set_layout("NCWH"); modelZero->get_parameters()[0]->set_layout("NCWH"); From 12d5f110abd5bfe22bd6638f1bfc5ef4f9254e94 Mon Sep 17 00:00:00 2001 From: Daniil Vlasenko Date: Wed, 22 May 2024 09:59:36 +0200 Subject: [PATCH 6/7] Whitespace differenceMoved the check for BS=0 from ICompiledModel constructor to the validation pass of model, namely to the validate_nodes_and_infer_types() function --- src/core/src/model.cpp | 15 ++++ src/core/tests/model.cpp | 17 +++++ src/inference/src/dev/icompiled_model.cpp | 15 ---- .../tests/unit/compiled_model_test.cpp | 76 ------------------- 4 files changed, 32 insertions(+), 91 deletions(-) diff --git a/src/core/src/model.cpp b/src/core/src/model.cpp index 315c3ab870f..5b3bcb6c23f 100644 --- a/src/core/src/model.cpp +++ b/src/core/src/model.cpp @@ -251,6 +251,21 @@ void ov::Model::validate_nodes_and_infer_types() const { "Model references undeclared Variables: ", unregistered_variables.str()); + for (const auto& input : inputs()) { + const auto& p_shape = input.get_partial_shape(); + const auto& layout = ov::layout::get_layout(input); + if (p_shape.rank().is_static() && p_shape.rank() != 0 && ov::layout::has_batch(layout)) { + const auto batch_idx = ov::layout::batch_idx(layout); + const auto batch_dim = p_shape[batch_idx]; + OPENVINO_ASSERT(batch_dim.is_dynamic() || batch_dim.get_length() > 0, + "Batch size for input ", + input, + " has wrong value ", + batch_dim.get_length(), + ". Batch size must be a positive value."); + } + } + for (const auto& output : outputs()) { OPENVINO_ASSERT(ov::layout::utils::is_compatible(ov::layout::get_layout(output), output.get_partial_shape()), "Result '", diff --git a/src/core/tests/model.cpp b/src/core/tests/model.cpp index 2b566cd2323..5b0e69db89e 100644 --- a/src/core/tests/model.cpp +++ b/src/core/tests/model.cpp @@ -2137,3 +2137,20 @@ TEST(model, create_model) { EXPECT_THROW(ov::Model(ov::ResultVector{}, {}, {}, {nullptr}, ""), ov::Exception); EXPECT_THROW(ov::Model(ov::OutputVector{ov::Output{nullptr, 0}}, {}, {}, {}, ""), ov::Exception); } + +TEST(model, batch_size_zero) { + OV_EXPECT_THROW_HAS_SUBSTRING(bs_utils::create_n_inputs(ov::element::f32, {{0, 3, 16, 16}}, {"NCHW"}), + ov::Exception, + "Batch size for input opset1::Parameter input0"); + OV_EXPECT_THROW_HAS_SUBSTRING( + bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}, {0, 3, 16, 16}}, {"NCHW", "NCHW"}), + ov::Exception, + "Batch size for input opset1::Parameter input1"); + OV_EXPECT_THROW_HAS_SUBSTRING( + bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}}, {"NCHW"})->reshape({0, 3, 16, 16}), + ov::Exception, + "Batch size for input opset1::Parameter input0"); + OV_EXPECT_THROW_HAS_SUBSTRING(set_batch(bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}}, {"NCHW"}), 0), + ov::Exception, + "Batch size for input opset1::Parameter input0"); +} diff --git a/src/inference/src/dev/icompiled_model.cpp b/src/inference/src/dev/icompiled_model.cpp index 0a365011d29..0079826cdeb 100644 --- a/src/inference/src/dev/icompiled_model.cpp +++ b/src/inference/src/dev/icompiled_model.cpp @@ -50,21 +50,6 @@ ov::ICompiledModel::ICompiledModel(const std::shared_ptr& model std::unordered_map, std::shared_ptr> tensor_map; for (const auto& param : model->get_parameters()) { - { - const auto& p_shape = param->get_partial_shape(); - const auto& layout = param->get_layout(); - if (p_shape.rank().is_static() && p_shape.rank() != 0 && ov::layout::has_batch(layout)) { - const auto batch_idx = ov::layout::batch_idx(layout); - const auto batch_dim = p_shape[batch_idx]; - OPENVINO_ASSERT(batch_dim.is_dynamic() || batch_dim.get_length() > 0, - "Batch size for parameter ", - param->get_friendly_name(), - " has wrong value ", - batch_dim.get_length(), - ". Batch size must be a positive value."); - } - } - const auto& param_name = param->get_friendly_name(); auto new_param = ov::as_type_ptr(param->copy_with_new_inputs({})); new_param->set_friendly_name(param_name); diff --git a/src/inference/tests/unit/compiled_model_test.cpp b/src/inference/tests/unit/compiled_model_test.cpp index 5bd2dccd32c..55e08444037 100644 --- a/src/inference/tests/unit/compiled_model_test.cpp +++ b/src/inference/tests/unit/compiled_model_test.cpp @@ -185,79 +185,3 @@ TEST_F(CompiledModelBaseTests, canReportErrorInExport) { EXPECT_CALL(*mock_compiled_model.get(), export_model(_)).WillOnce(Throw(std::runtime_error("compare"))); OV_EXPECT_THROW_HAS_SUBSTRING(compiled_model.export_model(out_model), std::runtime_error, "compare"); } - -class CompiledModelZeroBatch : public ::testing::Test { -protected: - std::shared_ptr model; - std::shared_ptr modelZero; - std::shared_ptr plugin; - - void SetUp() override { - model = create_model(ov::PartialShape{1, 3, 2, 2}); - modelZero = create_model(ov::PartialShape{0, 3, 2, 2}); - plugin = std::make_shared(); - } - -private: - std::shared_ptr create_model(const ov::PartialShape& p_shape) { - auto param = std::make_shared(ov::element::f32, p_shape); - param->set_friendly_name("Param"); - param->output(0).set_names({"param"}); - auto relu = std::make_shared(param); - relu->set_friendly_name("ReLU"); - relu->output(0).set_names({"relu"}); - return std::make_shared(ov::OutputVector{relu->output(0)}, ov::ParameterVector{param}); - } -}; - -TEST_F(CompiledModelZeroBatch, batchSizeZeroWithLayoutThrows) { - modelZero->get_parameters()[0]->set_layout("NCWH"); - OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(modelZero, plugin), - std::runtime_error, - "Batch size for parameter Param"); -} - -TEST_F(CompiledModelZeroBatch, batchSizeReshapeToZeroWithLayoutThrows) { - model->get_parameters()[0]->set_layout("NCWH"); - model->reshape(ov::PartialShape{0, 3, 2, 2}); - OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(model, plugin), - std::runtime_error, - "Batch size for parameter Param"); -} - -TEST_F(CompiledModelZeroBatch, batchSizeReshapeToNonZeroWithLayoutThrows) { - modelZero->get_parameters()[0]->set_layout("NCWH"); - modelZero->reshape(ov::PartialShape{1, 3, 2, 2}); - ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); -} - -TEST_F(CompiledModelZeroBatch, batchSizeSetBatchToZeroWithLayoutThrows) { - model->get_parameters()[0]->set_layout("NCWH"); - ov::set_batch(model, 0); - OV_EXPECT_THROW_HAS_SUBSTRING(ov::MockICompiledModel(model, plugin), - std::runtime_error, - "Batch size for parameter Param"); -} - -TEST_F(CompiledModelZeroBatch, batchSizeSetBatchToNonZeroWithLayoutThrows) { - modelZero->get_parameters()[0]->set_layout("NCWH"); - ov::set_batch(modelZero, 1); - ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); -} - -TEST_F(CompiledModelZeroBatch, batchSizeDynamicWithLayoutNoThrow) { - model->get_parameters()[0]->set_layout("NCWH"); - modelZero->get_parameters()[0]->set_layout("NCWH"); - ov::set_batch(model, ov::Dimension::dynamic()); - ov::set_batch(modelZero, ov::Dimension::dynamic()); - ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); - ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); -} - -TEST_F(CompiledModelZeroBatch, batchSizeZeroNoLayoutNoThrow) { - ASSERT_NO_THROW(ov::MockICompiledModel(modelZero, plugin)); -} - -TEST_F(CompiledModelZeroBatch, batchSizeNonZeroNoLayoutNoThrow) { - ASSERT_NO_THROW(ov::MockICompiledModel(model, plugin)); -} \ No newline at end of file From dbfea68280ac0d7d9a614951945454bb6422df70 Mon Sep 17 00:00:00 2001 From: Daniil Vlasenko Date: Thu, 23 May 2024 09:48:50 +0200 Subject: [PATCH 7/7] Minor fixes after review --- src/core/src/model.cpp | 9 ++++----- src/core/tests/model.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/src/model.cpp b/src/core/src/model.cpp index 5b3bcb6c23f..e6d528cd801 100644 --- a/src/core/src/model.cpp +++ b/src/core/src/model.cpp @@ -256,13 +256,12 @@ void ov::Model::validate_nodes_and_infer_types() const { const auto& layout = ov::layout::get_layout(input); if (p_shape.rank().is_static() && p_shape.rank() != 0 && ov::layout::has_batch(layout)) { const auto batch_idx = ov::layout::batch_idx(layout); - const auto batch_dim = p_shape[batch_idx]; + const auto& batch_dim = p_shape[batch_idx]; OPENVINO_ASSERT(batch_dim.is_dynamic() || batch_dim.get_length() > 0, - "Batch size for input ", + "Batch size must be a positive value for input '", input, - " has wrong value ", - batch_dim.get_length(), - ". Batch size must be a positive value."); + "', but has got: ", + batch_dim.get_length()); } } diff --git a/src/core/tests/model.cpp b/src/core/tests/model.cpp index 5b0e69db89e..66ac7e7e4e9 100644 --- a/src/core/tests/model.cpp +++ b/src/core/tests/model.cpp @@ -2141,16 +2141,16 @@ TEST(model, create_model) { TEST(model, batch_size_zero) { OV_EXPECT_THROW_HAS_SUBSTRING(bs_utils::create_n_inputs(ov::element::f32, {{0, 3, 16, 16}}, {"NCHW"}), ov::Exception, - "Batch size for input opset1::Parameter input0"); + "Batch size must be a positive value for input 'opset1::Parameter input0"); OV_EXPECT_THROW_HAS_SUBSTRING( bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}, {0, 3, 16, 16}}, {"NCHW", "NCHW"}), ov::Exception, - "Batch size for input opset1::Parameter input1"); + "Batch size must be a positive value for input 'opset1::Parameter input1"); OV_EXPECT_THROW_HAS_SUBSTRING( bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}}, {"NCHW"})->reshape({0, 3, 16, 16}), ov::Exception, - "Batch size for input opset1::Parameter input0"); + "Batch size must be a positive value for input 'opset1::Parameter input0"); OV_EXPECT_THROW_HAS_SUBSTRING(set_batch(bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}}, {"NCHW"}), 0), ov::Exception, - "Batch size for input opset1::Parameter input0"); + "Batch size must be a positive value for input 'opset1::Parameter input0"); }