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
[NPUW]: Adding functional tests for NPUW with partitioning (#25997)
Anastasiya(Asya) Pronina6570afa03067
diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cppindex 3471d832d3b..31d83e4f0d2 100644--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cpp@@ -3,36 +3,58 @@//#include "behavior_tests.hpp"-#include "openvino/opsets/opset11.hpp"-#include "openvino/runtime/exec_model_info.hpp"-#include "openvino/runtime/internal_properties.hpp"-#include "openvino/runtime/make_tensor.hpp"-#include "openvino/runtime/properties.hpp"-#include "openvino/util/file_util.hpp"+#include "comparators/nrmse.hpp"#include "openvino/util/shared_object.hpp"-#include "npuw_private_properties.hpp"+#include "openvino/util/file_util.hpp"++#include <filesystem>using namespace testing;using namespace ov::npuw::tests;+using namespace ov::intel_npu::npuw;-std::shared_ptr<ov::Model> BehaviorTestsNPUW::create_example_model() {- auto param = std::make_shared<ov::opset11::Parameter>(ov::element::i64, ov::PartialShape{1, 3, 2, 2});- param->set_friendly_name("input");- auto const_value = ov::opset11::Constant::create(ov::element::i64, ov::Shape{1, 1, 1, 1}, {1});- const_value->set_friendly_name("const_val");- auto add = std::make_shared<ov::opset11::Add>(param, const_value);- add->set_friendly_name("add");- auto result = std::make_shared<ov::opset11::Result>(add);- result->set_friendly_name("res");- return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});-}+#define TIMES(times) times++#define THROW(...) \+ .WillOnce(Throw(std::runtime_error(__VA_ARGS__)))++#define EXPECT_COMPILE_MODEL(device, times, ...) \+ EXPECT_CALL(*device##_plugin, \+ compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)) \+ .Times(times) \+ __VA_ARGS__ \++#define MODEL(idx) idx++#define INFER_REQ(idx) idx++#define EXPECT_CREATE_SYNC_INFER_REQ(device, model_idx, times, ...) \+ device##_plugin->set_expectations_to_comp_models(model_idx, [](MockCompiledModel& model) { \+ EXPECT_CALL(model, create_sync_infer_request()) \+ .Times(times) \+ __VA_ARGS__; \+ })++#define EXPECT_INFER(device, model_idx, times, ...) \+ device##_plugin->set_expectations_to_infer_reqs(model_idx, 0, [](MockInferRequest& request) { \+ EXPECT_CALL(request, infer()) \+ .Times(times) \+ __VA_ARGS__; \+ });++#define EXPECT_INFER_FOR(device, model_idx, req_idx, times, ...) \+ device##_plugin->set_expectations_to_infer_reqs(model_idx, req_idx, [](MockInferRequest& request) { \+ EXPECT_CALL(request, infer()) \+ .Times(times) \+ __VA_ARGS__; \+ });TEST_F(BehaviorTestsNPUW, TestInfrastructureIsCorrect) {// Set expectations first:- EXPECT_CALL(*npu_plugin, get_property).Times(AnyNumber());- EXPECT_CALL(*npu_plugin, get_property(std::string("AVAILABLE_DEVICES"), _)).Times(1);- EXPECT_CALL(*cpu_plugin, get_property).Times(AnyNumber());- EXPECT_CALL(*cpu_plugin, get_property(std::string("AVAILABLE_DEVICES"), _)).Times(1);+ EXPECT_CALL(*mock_npu_plugin, get_property).Times(AnyNumber());+ EXPECT_CALL(*mock_npu_plugin, get_property(std::string("AVAILABLE_DEVICES"), _)).Times(1);+ EXPECT_CALL(*mock_cpu_plugin, get_property).Times(AnyNumber());+ EXPECT_CALL(*mock_cpu_plugin, get_property(std::string("AVAILABLE_DEVICES"), _)).Times(1);// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();@@ -53,209 +75,602 @@ TEST_F(BehaviorTestsNPUW, TestInfrastructureIsCorrect) {}TEST_F(BehaviorTestsNPUW, CompilationIsSuccessful) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:- EXPECT_CALL(*npu_plugin,- compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);- EXPECT_CALL(*cpu_plugin,- compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0);+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU")};- EXPECT_NO_THROW(core.compile_model(model, "NPU", npuw_properties));+ use_npuw_props.emplace(devices("MockNPU"));+ EXPECT_NO_THROW(core.compile_model(model, "NPU", use_npuw_props));}TEST_F(BehaviorTestsNPUW, CompilationIsFailSafe) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:{InSequence s;- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _))- .Times(1)- .WillOnce(Throw(std::runtime_error("Compilation on MockNPU is failed")));- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1), THROW("Compilation on MockNPU is failed"));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(1));}// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU,MockCPU")};- EXPECT_NO_THROW(core.compile_model(model, "NPU", npuw_properties));+ use_npuw_props.emplace(devices("MockNPU,MockCPU"));+ EXPECT_NO_THROW(core.compile_model(model, "NPU", use_npuw_props));}TEST_F(BehaviorTestsNPUW, CompilationIsFailed) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _))- .Times(1)- .WillOnce(Throw(std::runtime_error("Compilation on MockNPU is failed")));- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0);+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1), THROW("Compilation on MockNPU is failed"));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU")};- EXPECT_ANY_THROW(core.compile_model(model, "NPU", npuw_properties));+ use_npuw_props.emplace(devices("MockNPU"));+ EXPECT_ANY_THROW(core.compile_model(model, "NPU", use_npuw_props));}TEST_F(BehaviorTestsNPUW, InferRequestCreationIsSuccessful) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0);- npu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request()).Times(1);- });+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(0), TIMES(1));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU")};- auto compiled_model = core.compile_model(model, "NPU", npuw_properties);+ use_npuw_props.emplace(devices("MockNPU"));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);EXPECT_NO_THROW(compiled_model.create_infer_request());}TEST_F(BehaviorTestsNPUW, InferRequestCreationIsFailSafe) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:{InSequence s;- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(1));}- npu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request())- .Times(1)- .WillOnce(Throw(std::runtime_error("Infer request creation on MockNPU is failed")));- });- cpu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request()).Times(1);- });+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(0), TIMES(1), THROW("Infer request creation on MockNPU is failed"));+ EXPECT_CREATE_SYNC_INFER_REQ(mock_cpu, MODEL(0), TIMES(1));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU,MockCPU")};- auto compiled_model = core.compile_model(model, "NPU", npuw_properties);+ use_npuw_props.emplace(devices("MockNPU,MockCPU"));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);EXPECT_NO_THROW(compiled_model.create_infer_request());}TEST_F(BehaviorTestsNPUW, InferRequestCreationIsFailed) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0);+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));- npu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request())- .Times(1)- .WillOnce(Throw(std::runtime_error("Infer request creation on MockNPU is failed")));- });+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(0), TIMES(1), THROW("Infer request creation on MockNPU is failed"));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU")};- auto compiled_model = core.compile_model(model, "NPU", npuw_properties);+ use_npuw_props.emplace(devices("MockNPU"));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);EXPECT_ANY_THROW(compiled_model.create_infer_request());}TEST_F(BehaviorTestsNPUW, InferIsSuccessful) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0);- npu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request()).Times(1);- });- npu_plugin->set_expectations_to_infer_reqs(0, [](MockInferRequest& request) {- EXPECT_CALL(request, infer()).Times(1);- });+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(0), TIMES(1));+ EXPECT_INFER(mock_npu, MODEL(0), TIMES(1));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU")};- auto compiled_model = core.compile_model(model, "NPU", npuw_properties);+ use_npuw_props.emplace(devices("MockNPU"));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);auto infer_request = compiled_model.create_infer_request();EXPECT_NO_THROW(infer_request.infer());}TEST_F(BehaviorTestsNPUW, InferIsFailSafe) {+ model = model_generator.get_model_with_one_op();+// Set expectations first:{InSequence seq;- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(1));}- npu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request()).Times(1);- });- npu_plugin->set_expectations_to_infer_reqs(0, [](MockInferRequest& request) {- EXPECT_CALL(request, infer())- .Times(1)- .WillOnce(Throw(std::runtime_error("Infer on MockNPU is failed")));- });- cpu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request()).Times(1);- });- cpu_plugin->set_expectations_to_infer_reqs(0, [](MockInferRequest& request) {- EXPECT_CALL(request, infer()).Times(1);- });+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(0), TIMES(1));+ EXPECT_INFER(mock_npu, MODEL(0), TIMES(1), THROW("Infer on MockNPU is failed"));+ EXPECT_CREATE_SYNC_INFER_REQ(mock_cpu, MODEL(0), TIMES(1));+ EXPECT_INFER(mock_cpu, MODEL(0), TIMES(1));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU,MockCPU")};- auto compiled_model = core.compile_model(model, "NPU", npuw_properties);+ use_npuw_props.emplace(devices("MockNPU,MockCPU"));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);auto infer_request = compiled_model.create_infer_request();EXPECT_NO_THROW(infer_request.infer());}TEST_F(BehaviorTestsNPUW, InferIsFailed) {+ model = model_generator.get_model_with_one_op();++ // Set expectations first:+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(0), TIMES(1));+ EXPECT_INFER(mock_npu, MODEL(0), TIMES(1), THROW("Infer on MockNPU is failed"));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ auto infer_request = compiled_model.create_infer_request();+ EXPECT_ANY_THROW(infer_request.infer());+}++using BehaviorTestsNPUWOnlinePartitioning = BehaviorTestsNPUW;+TEST_F(BehaviorTestsNPUWOnlinePartitioning, CompilationIsSuccessful) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ EXPECT_NO_THROW(core.compile_model(model, "NPU", use_npuw_props));+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, CompilationIsFailSafe) {+ model = model_generator.get_model_with_repeated_blocks();+ // Set expectations first:+ {+ InSequence s;++ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1), THROW("Compilation on MockNPU is failed"));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(1));+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(11));++ }++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU,MockCPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ EXPECT_NO_THROW(core.compile_model(model, "NPU", use_npuw_props));+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, CompilationIsFailed) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1), THROW("Compilation on MockNPU is failed"));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ EXPECT_ANY_THROW(core.compile_model(model, "NPU", use_npuw_props));+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, InferRequestCreationIsSuccessful) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ for (int i = 0; i < 12; i++) {+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(1));+ }++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ EXPECT_NO_THROW(compiled_model.create_infer_request());+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, InferRequestCreationIsFailSafe) {+ model = model_generator.get_model_with_repeated_blocks();+ // Set expectations first:+ {+ InSequence s;++ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(1));+ }++ for (int i = 0; i < 11; i++) {+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(1));+ }+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(11), TIMES(1), THROW("Infer request creation on MockNPU is failed"));+ EXPECT_CREATE_SYNC_INFER_REQ(mock_cpu, MODEL(0), TIMES(1));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU,MockCPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ EXPECT_NO_THROW(compiled_model.create_infer_request());+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, InferRequestCreationIsFailed) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ for (int i = 0; i < 11; i++) {+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(1));+ }+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(11), TIMES(1), THROW("Infer request creation on MockNPU is failed"));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ EXPECT_ANY_THROW(compiled_model.create_infer_request());+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, InferIsSuccessful) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ for (int i = 0; i < 12; i++) {+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(1));+ EXPECT_INFER(mock_npu, MODEL(i), TIMES(1));+ }++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ auto infer_request = compiled_model.create_infer_request();+ EXPECT_NO_THROW(infer_request.infer());+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, InferIsFailSafe) {+ model = model_generator.get_model_with_repeated_blocks();+// Set expectations first:{InSequence seq;- EXPECT_CALL(*npu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(1);- EXPECT_CALL(*cpu_plugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0);+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(1));}- npu_plugin->set_expectations_to_comp_models(0, [](MockCompiledModel& model) {- EXPECT_CALL(model, create_sync_infer_request()).Times(1);- });- npu_plugin->set_expectations_to_infer_reqs(0, [](MockInferRequest& request) {- EXPECT_CALL(request, infer())- .Times(1)- .WillOnce(Throw(std::runtime_error("Infer on MockNPU is failed")));- });+ for (int i = 0; i < 12; i++) {+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(1));+ }+ for (int i = 0; i < 11; i++) {+ EXPECT_INFER(mock_npu, MODEL(i), TIMES(1));+ }+ EXPECT_INFER(mock_npu, MODEL(11), TIMES(1), THROW("Infer on MockNPU is failed"));++ EXPECT_CREATE_SYNC_INFER_REQ(mock_cpu, MODEL(0), TIMES(1));+ EXPECT_INFER(mock_cpu, MODEL(0), TIMES(1));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU,MockCPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ auto infer_request = compiled_model.create_infer_request();+ EXPECT_NO_THROW(infer_request.infer());+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, InferIsFailed) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ {+ InSequence seq;+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));+ }+ for (int i = 0; i < 12; i++) {+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(1));+ }+ for (int i = 0; i < 11; i++) {+ EXPECT_INFER(mock_npu, MODEL(i), TIMES(1));+ }+ EXPECT_INFER(mock_npu, MODEL(11), TIMES(1), THROW("Infer on MockNPU is failed"));// Register mock objects as plugins in OpenVINO:register_mock_plugins_in_ov();// Do the actual test:- auto npuw_properties =- ov::AnyMap{ov::intel_npu::use_npuw(true),- ov::intel_npu::npuw::devices("MockNPU")};- auto compiled_model = core.compile_model(model, "NPU", npuw_properties);+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);auto infer_request = compiled_model.create_infer_request();EXPECT_ANY_THROW(infer_request.infer());}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, RepeatedBlocksAreFolded) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ {+ InSequence seq;+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(3));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));+ }+ for (int i = 0; i < 3; i++) {+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(1));+ }++ // 1st model infer request is called once -- head+ EXPECT_INFER(mock_npu, MODEL(0), TIMES(1));+ // 2nd model infer request is called 10 times -- repeated block+ EXPECT_INFER(mock_npu, MODEL(1), TIMES(10));+ // 3rd model infer request is called once -- tail+ EXPECT_INFER(mock_npu, MODEL(2), TIMES(1));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ use_npuw_props.emplace(partitioning::fold(true));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ auto infer_request = compiled_model.create_infer_request();+ EXPECT_NO_THROW(infer_request.infer());+}++TEST_F(BehaviorTestsNPUWOnlinePartitioning, FoldingAndPipelining) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ {+ InSequence seq;+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(3));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));+ }++ for (int i = 0; i < 3; i++) {+ // Here we will create 2 infer requests per model,+ // so `create_sync_infer_request()` should be called twice+ // per model:+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i), TIMES(2));+ }++ // 1st model 1st infer request is called once -- head+ EXPECT_INFER_FOR(mock_npu, MODEL(0), INFER_REQ(0), TIMES(1));+ // 1st model 2nd infer request is never called,+ // it is not a function and is not repeated+ EXPECT_INFER_FOR(mock_npu, MODEL(0), INFER_REQ(1), TIMES(0));++ // Repeated block+ // 2nd model 1st infer request is called 5 times+ EXPECT_INFER_FOR(mock_npu, MODEL(1), INFER_REQ(0), TIMES(5));+ // 2nd model 2nd infer request (brother of 1st one) is called 5 times+ EXPECT_INFER_FOR(mock_npu, MODEL(1), INFER_REQ(1), TIMES(5));++ // 3rd model 1st infer request is called once -- tail+ EXPECT_INFER_FOR(mock_npu, MODEL(2), INFER_REQ(0), TIMES(1));+ // 3rd model 2nd infer request is never called,+ // it is not a function and is not repeated+ EXPECT_INFER_FOR(mock_npu, MODEL(2), INFER_REQ(1), TIMES(0));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Do the actual test:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::min_size(12));+ use_npuw_props.emplace(partitioning::fold(true));+ use_npuw_props.emplace(partitioning::dcoff_type("f16"));+ use_npuw_props.emplace(partitioning::dcoff_with_scale(true));+ use_npuw_props.emplace(funcall_async(true));+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);+ auto infer_request = compiled_model.create_infer_request();+ EXPECT_NO_THROW(infer_request.infer());+}++using BehaviorTestsNPUWOfflinePartitioning = BehaviorTestsNPUW;+TEST_F(BehaviorTestsNPUWOfflinePartitioning, CompilationIsSuccessful) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ // For plan generation and execution (twice compiled):+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(24));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Generate plan:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::dump_plan("test_partitioning.xml"));++ EXPECT_NO_THROW(core.compile_model(model, "NPU", use_npuw_props));+ EXPECT_TRUE(std::filesystem::exists("test_partitioning.xml"));++ // Do the actual test:+ ov::AnyMap offline_plan_props = { ::ov::intel_npu::use_npuw(true),+ devices("MockNPU"),+ partitioning::plan("test_partitioning.xml") };+ ov::CompiledModel compiled_model;+ EXPECT_NO_THROW(compiled_model = core.compile_model(model, "NPU", offline_plan_props));+ EXPECT_EQ("test_partitioning.xml",+ compiled_model.get_property(partitioning::plan.name()).as<std::string>());+ EXPECT_TRUE(std::filesystem::remove("test_partitioning.xml"));+}++TEST_F(BehaviorTestsNPUWOfflinePartitioning, InferRequestCreationIsSuccessful) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ // For plan generation and execution (twice compiled):+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(24));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ for (int i = 0; i < 12; i++) {+ // First 12 models are compiled only to generate partitioning plan:+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i + 12), 1);+ }++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Generate plan:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::dump_plan("test_partitioning.xml"));+ use_npuw_props.emplace(partitioning::online::pipeline("REP"));++ EXPECT_NO_THROW(core.compile_model(model, "NPU", use_npuw_props));+ EXPECT_TRUE(std::filesystem::exists("test_partitioning.xml"));++ // Do the actual test:+ ov::AnyMap offline_plan_props = { ::ov::intel_npu::use_npuw(true),+ devices("MockNPU"),+ partitioning::plan("test_partitioning.xml") };+ auto compiled_model = core.compile_model(model, "NPU", offline_plan_props);+ EXPECT_NO_THROW(compiled_model.create_infer_request());+ EXPECT_EQ("test_partitioning.xml",+ compiled_model.get_property(partitioning::plan.name()).as<std::string>());+ EXPECT_TRUE(std::filesystem::remove("test_partitioning.xml"));+}++TEST_F(BehaviorTestsNPUWOfflinePartitioning, InferIsSuccessful) {+ model = model_generator.get_model_with_repeated_blocks();++ // Set expectations first:+ // For plan generation and execution (twice compiled):+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(24));+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));++ for (int i = 0; i < 12; i++) {+ // First 12 models are compiled only to generate partitioning plan:+ EXPECT_CREATE_SYNC_INFER_REQ(mock_npu, MODEL(i + 12), 1);+ EXPECT_INFER(mock_npu, MODEL(i + 12), 1);+ }++ // Register mock objects as plugins in OpenVINO:+ register_mock_plugins_in_ov();++ // Generate plan:+ use_npuw_props.emplace(devices("MockNPU"));+ use_npuw_props.emplace(partitioning::online::dump_plan("test_partitioning.xml"));+ use_npuw_props.emplace(partitioning::online::pipeline("REP"));++ EXPECT_NO_THROW(core.compile_model(model, "NPU", use_npuw_props));+ EXPECT_TRUE(std::filesystem::exists("test_partitioning.xml"));++ // Do the actual test:+ ov::AnyMap offline_plan_props = { ::ov::intel_npu::use_npuw(true),+ devices("MockNPU"),+ partitioning::plan("test_partitioning.xml") };+ auto compiled_model = core.compile_model(model, "NPU", offline_plan_props);+ auto infer_request = compiled_model.create_infer_request();+ EXPECT_NO_THROW(infer_request.infer());+ EXPECT_EQ("test_partitioning.xml",+ compiled_model.get_property(partitioning::plan.name()).as<std::string>());+ EXPECT_TRUE(std::filesystem::remove("test_partitioning.xml"));+}++TEST(BehaviorTestsNPUWAccuracy, RepAndNonePartPipesGiveSameResults) {+ // Register TEMPLATE plugin in OpenVINO:+ ov::Core core;+ auto plugin_path =+ ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),+ std::string(ov::test::utils::TEMPLATE_LIB)+ + OV_BUILD_POSTFIX);+ if (!ov::util::file_exists(plugin_path)) {+ OPENVINO_THROW("Plugin: " + plugin_path + " does not exists!");+ }+ core.register_plugin(plugin_path, ov::test::utils::DEVICE_TEMPLATE);++ // Create model:+ ModelGenerator model_generator;+ const auto &model = model_generator.get_model_with_repeated_blocks(32);++ // Do the test:+ ov::AnyMap online_rep_props { ::ov::intel_npu::use_npuw(true),+ devices("TEMPLATE"),+ partitioning::online::pipeline("REP") };+ ov::AnyMap online_none_props { ::ov::intel_npu::use_npuw(true),+ devices("TEMPLATE"),+ partitioning::online::pipeline("NONE") };++ auto rep_compiled_model = core.compile_model(model, "NPU", online_rep_props);+ auto none_compiled_model = core.compile_model(model, "NPU", online_none_props);+ auto rep_infer_request = rep_compiled_model.create_infer_request();+ auto none_infer_request = rep_compiled_model.create_infer_request();++ set_random_inputs<int32_t>(rep_infer_request);+ set_random_inputs<int32_t>(none_infer_request);++ rep_infer_request.infer();+ none_infer_request.infer();++ metrics::NRMSE nrmse(0.01);++ for (const auto& output : rep_infer_request.get_compiled_model().outputs()) {+ const auto& rep_tensor = rep_infer_request.get_tensor(output);+ const auto& none_tensor = none_infer_request.get_tensor(output);+ EXPECT_TRUE(nrmse(rep_tensor, none_tensor));+ }+}diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.hpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.hppindex eb2cce0673f..85658ac4a42 100644--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.hpp+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.hpp@@ -4,15 +4,18 @@#pragma once#include <memory>+#include <random>#include <gtest/gtest.h>#include "openvino/runtime/core.hpp"#include "openvino/runtime/iplugin.hpp"#include "openvino/runtime/make_tensor.hpp"+#include "npuw_private_properties.hpp"#include "mocks/mock_plugins.hpp"#include "mocks/register_in_ov.hpp"+#include "generators/model_generator.hpp"namespace ov {namespace npuw {@@ -21,31 +24,63 @@ namespace tests {class BehaviorTestsNPUW : public ::testing::Test {public:ov::Core core;- std::shared_ptr<MockNpuPlugin> npu_plugin;- std::shared_ptr<MockCpuPlugin> cpu_plugin;- std::shared_ptr<ov::Model> model;+ std::shared_ptr<MockNpuPlugin> mock_npu_plugin;+ std::shared_ptr<MockCpuPlugin> mock_cpu_plugin;+ ov::AnyMap use_npuw_props;+ std::shared_ptr<ov::Model> model;+ ModelGenerator model_generator;void SetUp() override {- model = create_example_model();- npu_plugin = std::make_shared<MockNpuPlugin>();- npu_plugin->create_implementation();- cpu_plugin = std::make_shared<MockCpuPlugin>();- cpu_plugin->create_implementation();+ mock_npu_plugin = std::make_shared<MockNpuPlugin>();+ mock_npu_plugin->create_implementation();+ mock_cpu_plugin = std::make_shared<MockCpuPlugin>();+ mock_cpu_plugin->create_implementation();+ use_npuw_props = ov::AnyMap{ov::intel_npu::use_npuw(true)};}// Make sure it is called after expectations are set!void register_mock_plugins_in_ov() {- m_shared_objects.push_back(reg_plugin<MockNpuPlugin>(core, npu_plugin));- m_shared_objects.push_back(reg_plugin<MockCpuPlugin>(core, cpu_plugin));+ m_shared_objects.push_back(reg_plugin<MockNpuPlugin>(core, mock_npu_plugin));+ m_shared_objects.push_back(reg_plugin<MockCpuPlugin>(core, mock_cpu_plugin));}- std::shared_ptr<ov::Model> create_example_model();-private:std::vector<std::shared_ptr<void>> m_shared_objects;};+template <typename T>+using uniform_distribution_common = typename std::conditional<+ std::is_floating_point<T>::value,+ std::uniform_real_distribution<T>,+ typename std::conditional<std::is_integral<T>::value, std::uniform_int_distribution<T>, void>::type>::type;+template <typename T, typename T2>++ov::Tensor make_random_tensor(ov::element::Type type,+ ov::Shape shape,+ T rand_min = std::numeric_limits<uint8_t>::min(),+ T rand_max = std::numeric_limits<uint8_t>::max()) {+ size_t tensor_size =+ std::accumulate(shape.begin(), shape.end(), std::size_t(1), std::multiplies<size_t>());+ auto tensor = ov::Tensor(type, shape);+ auto data = tensor.data<T>();++ std::mt19937 gen(0);+ uniform_distribution_common<T2> distribution(rand_min, rand_max);+ for (size_t i = 0; i < tensor_size; i++) {+ data[i] = static_cast<T>(distribution(gen));+ }+ return tensor;+}++template<typename T>+void set_random_inputs(ov::InferRequest infer_request) {+ for (const auto& input : infer_request.get_compiled_model().inputs()) {+ // TODO: Extend template header to two types.+ // For float16 call should be make_random_tensor<ov::float16, float>+ infer_request.set_tensor(input, make_random_tensor<T, T>(input.get_element_type(), input.get_shape()));+ }+}} // namespace tests} // namespace npuw} // namespace ovdiff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/comparators/nrmse.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/comparators/nrmse.cppnew file mode 100644index 00000000000..925352669b6--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/comparators/nrmse.cpp@@ -0,0 +1,137 @@+// Copyright (C) 2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "nrmse.hpp"++#include <algorithm>+#include <openvino/runtime/make_tensor.hpp>+#include <openvino/core/parallel.hpp>++namespace {+template <typename InT>+void to_f32(const ov::Tensor& in, ov::Tensor& out) {+ OPENVINO_ASSERT(in.is_continuous());+ OPENVINO_ASSERT(out.is_continuous());+ OPENVINO_ASSERT(in.get_shape() == out.get_shape());++ if (ov::element::Type_t::f32 == in.get_element_type()) {+ in.copy_to(out);+ return;+ }++ const InT* in_buffer = in.data<InT>();+ OPENVINO_ASSERT(in_buffer != nullptr);+ const auto out_buffer = out.data<float>();+ OPENVINO_ASSERT(out_buffer != nullptr);++ // NOTE: ov::parallel_for takes care of splitting the work among threads such way,+ // that the passed lambda function will be called sequentially+ // on some part of "in.get_size()" range inside the each thread+ ov::parallel_for(in.get_size(), [in_buffer, out_buffer](int64_t index) {+ out_buffer[index] = static_cast<float>(in_buffer[index]);+ });+}++void to_f32(const ov::Tensor& in, ov::Tensor& out) {+ switch (in.get_element_type()) {+ case ov::element::Type_t::f32:+ ::to_f32<float>(in, out);+ break;+ case ov::element::Type_t::u64:+ ::to_f32<uint64_t>(in, out);+ break;+ case ov::element::Type_t::i64:+ ::to_f32<int64_t>(in, out);+ break;+ case ov::element::Type_t::u32:+ ::to_f32<uint32_t>(in, out);+ break;+ case ov::element::Type_t::i32:+ ::to_f32<int32_t>(in, out);+ break;+ case ov::element::Type_t::u16:+ ::to_f32<uint16_t>(in, out);+ break;+ case ov::element::Type_t::i16:+ ::to_f32<int16_t>(in, out);+ break;+ case ov::element::Type_t::u8:+ ::to_f32<uint8_t>(in, out);+ break;+ case ov::element::Type_t::i8:+ ::to_f32<int8_t>(in, out);+ break;+ case ov::element::Type_t::f16:+ ::to_f32<ov::float16>(in, out);+ break;+ case ov::element::Type_t::bf16:+ ::to_f32<ov::bfloat16>(in, out);+ break;+ default:+ OPENVINO_THROW("Unsupported precision {0}", in.get_element_type().get_type_name());+ break;+ }+}+} // anynomous namespace++ov::npuw::tests::metrics::NRMSE::NRMSE(double threshold) : m_threshold(threshold) {}++bool ov::npuw::tests::metrics::NRMSE::operator()(const ov::Tensor& actual,+ const ov::Tensor& reference) const {+ OPENVINO_ASSERT(actual.is_continuous());+ OPENVINO_ASSERT(reference.is_continuous());+ OPENVINO_ASSERT(actual.get_shape() == reference.get_shape());+ // Check for alignment:+ OPENVINO_ASSERT(actual.get_byte_size() == reference.get_byte_size());+ // FIXME: Check for strides++ ov::Tensor actual_f32;+ ov::Tensor reference_f32;++ if (ov::element::Type_t::f32 == actual.get_element_type()) {+ actual_f32 = actual;+ } else {+ ov::Tensor dst(ov::element::Type_t::f32, actual.get_shape());+ to_f32(actual, dst);+ actual_f32 = std::move(dst);+ }++ if (ov::element::Type_t::f32 == reference.get_element_type()) {+ reference_f32 = reference;+ } else {+ ov::Tensor dst(ov::element::Type_t::f32, reference.get_shape());+ to_f32(reference, dst);+ reference_f32 = dst;+ }++ float* actual_data = actual_f32.data<float>();+ float* reference_data = reference_f32.data<float>();+ const std::size_t size = actual_f32.get_size();++ double squared_error{};+ for (size_t i = 0; i < size; ++i) {+ double diff = (actual_data[i] - reference_data[i]);+ squared_error += (diff * diff);+ }++ if (squared_error <= std::numeric_limits<double>::epsilon()) {+ std::cout << "NRMSE loss: 0.0, threshold: " << m_threshold << ".\n";+ return true;+ }++ double rmse = sqrt(squared_error / size);+ OPENVINO_ASSERT(rmse >= 0.0);++ auto actual_min_max = std::minmax_element(actual_data, actual_data + size);+ auto reference_min_max = std::minmax_element(reference_data, reference_data + size);+ double den = std::max({0.001f,+ std::max(0.f, *reference_min_max.second) - std::min(0.f, *reference_min_max.first),+ std::max(0.f, *actual_min_max.second) - std::min(0.f, *actual_min_max.first)});++ double nrmse = rmse / den;+ std::cout << "NRMSE loss: " << nrmse << ", threshold: " << m_threshold << ".\n";++ bool success = nrmse <= m_threshold;+ return success;+}diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/comparators/nrmse.hpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/comparators/nrmse.hppnew file mode 100644index 00000000000..dcf59292c87--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/comparators/nrmse.hpp@@ -0,0 +1,27 @@+// Copyright (C) 2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/openvino.hpp"+#include "openvino/runtime/icompiled_model.hpp"+#include "openvino/runtime/so_ptr.hpp"++namespace ov {+namespace npuw {+namespace tests {+namespace metrics {+class NRMSE {+public:+ explicit NRMSE(double threshold);+ bool operator()(const ov::Tensor& actual, const ov::Tensor& reference) const;++private:+ double m_threshold{};+};++} // namespace metrics+} // namespace tests+} // namespace npuw+} // namespace ovdiff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/generators/model_generator.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/generators/model_generator.cppnew file mode 100644index 00000000000..39f7f9c1569--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/generators/model_generator.cpp@@ -0,0 +1,180 @@+// Copyright (C) 2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "model_generator.hpp"++#include "openvino/openvino.hpp"+#include "openvino/opsets/opset11.hpp"+#include "openvino/op/ops.hpp"+++std::shared_ptr<ov::Model> ModelGenerator::get_model_with_one_op() {+ auto param = std::make_shared<ov::opset11::Parameter>(ov::element::i64, ov::PartialShape{1, 3, 2, 2});+ param->set_friendly_name("input");+ auto const_value = ov::opset11::Constant::create(ov::element::i64, ov::Shape{1, 1, 1, 1}, {1});+ const_value->set_friendly_name("const_val");+ auto add = std::make_shared<ov::opset11::Add>(param, const_value);+ add->set_friendly_name("add");+ auto result = std::make_shared<ov::opset11::Result>(add);+ result->set_friendly_name("res");+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});+}++std::shared_ptr<ov::Model> ModelGenerator::get_model_without_repeated_blocks() {+ std::shared_ptr<ov::op::v0::Parameter> input = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{1, 1, 40});+ m_nodes.push_back(input);+ set_name(input);++ std::shared_ptr<ov::Node> res = get_block(input);++ auto result = std::make_shared<ov::op::v0::Result>(res);+ m_nodes.push_back(result);+ set_name(result);++ ov::ParameterVector params = {input};+ ov::ResultVector results = {result};++ return std::make_shared<ov::Model>(results, params);+}++std::shared_ptr<ov::Model> ModelGenerator::get_model_with_repeated_blocks(std::size_t repetitions) {+ // Generate head+ std::shared_ptr<ov::op::v0::Parameter> input = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{1, 1, 40});+ m_nodes.push_back(input);+ set_name(input);++ std::vector<std::shared_ptr<ov::Node>> head(7, nullptr);+ head[0] = std::make_shared<ov::op::v1::Add>(input, input);+ head[1] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1}, std::vector<int>{2});+ head[2] = std::make_shared<ov::op::v1::Divide>(head[0], head[1], true);+ head[3] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int>{1, 1, 4, 10});+ head[4] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{3}, std::vector<int>{1, 1, 40});+ head[5] = std::make_shared<ov::op::v1::Reshape>(head[2], head[3], false);+ head[6] = std::make_shared<ov::op::v1::Reshape>(head[5], head[4], false);++ for (const auto& h : head) {+ m_nodes.push_back(h);+ set_name(h);+ }++ // Generate repeated blocks+ std::shared_ptr<ov::Node> output = get_block(head[6]);+ std::vector<std::shared_ptr<ov::Node>> outputs;+ outputs.push_back(output);++ for (size_t i = 0; i < repetitions - 1; ++i) {+ output = get_block(output);+ outputs.push_back(output);+ }++ // Generate tail+ std::vector<std::shared_ptr<ov::Node>> tail(6, nullptr);+ tail[0] = std::make_shared<ov::op::v0::Concat>(outputs, -1);+ tail[1] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, std::vector<int>{1, 40, int(repetitions)});+ tail[2] = std::make_shared<ov::op::v1::Reshape>(tail[0], tail[1], false);+ tail[3] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1, 1, 1});+ tail[4] = std::make_shared<ov::op::v1::Multiply>(tail[2], tail[3]);+ tail[5] = std::make_shared<ov::op::v1::Add>(tail[4], tail[4]);++ for (const auto& t : tail) {+ m_nodes.push_back(t);+ set_name(t);+ }++ // Create model+ auto result = std::make_shared<ov::op::v0::Result>(tail[5]);+ m_nodes.push_back(result);+ set_name(result);++ ov::ParameterVector params = {input};+ ov::ResultVector results = {result};++ return std::make_shared<ov::Model>(results, params);+}++std::shared_ptr<ov::Model> ModelGenerator::get_model_with_repeated_blocks() {+ return get_model_with_repeated_blocks(10);+}++std::shared_ptr<ov::Node> ModelGenerator::get_block(const std::shared_ptr<ov::Node>& input) {+ // Parameters+ // input++ // Constants+ std::vector<std::shared_ptr<ov::Node>> model_c(18, nullptr);+ model_c[0] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{4}, std::vector<int>{0, 2, 1, 3});+ model_c[1] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int>{1});+ model_c[2] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int>{0});+ model_c[3] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int>{2});+ model_c[4] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int>{0});+ model_c[5] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int>{1, 1, 1, 1});+ model_c[6] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int>{1});+ model_c[7] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int>{0});+ model_c[8] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int>{1, 1, 1, 1});+ model_c[9] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{4}, std::vector<int>{1, 1, 1, 2});+ model_c[10] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{4}, std::vector<int>{1, 1, 1, 1});+ model_c[11] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{4}, std::vector<int>{1, 1, 1, 2});+ model_c[12] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1, 1, 1, 1});+ model_c[13] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1, 1, 1, 1});+ model_c[14] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1, 1, 1, 1});+ model_c[15] = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{40, 40});+ model_c[16] = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int>{1, 1, 4, 10});+ model_c[17] = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, std::vector<int>{1, 1, 40});++ for (const auto& c : model_c) {+ m_nodes.push_back(c);+ set_name(c);+ }++ // Converts+ std::vector<std::shared_ptr<ov::Node>> convert(3, nullptr);+ convert[0] = std::make_shared<ov::op::v0::Convert>(model_c[15], ov::element::f16);+ convert[1] = std::make_shared<ov::op::v0::Convert>(convert[0], ov::element::i32);+ convert[2] = std::make_shared<ov::op::v0::Convert>(model_c[12], ov::element::i32);++ for (const auto& c : convert) {+ m_nodes.push_back(c);+ set_name(c);+ }++ // Ops+ std::vector<std::shared_ptr<ov::Node>> op(16, nullptr);+ op[0] = std::make_shared<ov::op::v0::MatMul>(input, convert[1], false, true);+ op[1] = std::make_shared<ov::op::v1::Reshape>(op[0], model_c[16], false);+ op[2] = std::make_shared<ov::op::v1::Transpose>(op[1], model_c[0]);+ op[3] = std::make_shared<ov::op::v0::ShapeOf>(op[2]);+ op[4] = std::make_shared<ov::op::v1::Gather>(op[3], model_c[1], model_c[2]);+ op[5] = std::make_shared<ov::op::v1::Divide>(op[4], model_c[3], true);+ op[6] = std::make_shared<ov::op::v0::Floor>(op[5]);+ op[7] = std::make_shared<ov::op::v3::ScatterUpdate>(model_c[5], model_c[6], op[6], model_c[7]);+ op[8] = std::make_shared<ov::op::v1::StridedSlice>(op[2],+ model_c[8],+ op[7],+ model_c[9],+ std::vector<int64_t>{1, 1, 1, 1},+ std::vector<int64_t>{1, 1, 1, 1});+ op[9] = std::make_shared<ov::op::v1::StridedSlice>(op[2],+ op[7],+ model_c[10],+ model_c[11],+ std::vector<int64_t>{1, 1, 1, 1},+ std::vector<int64_t>{1, 1, 1, 1});+ op[10] = std::make_shared<ov::op::v1::Multiply>(op[9], convert[2]);+ op[11] = std::make_shared<ov::op::v0::Concat>(std::vector<std::shared_ptr<ov::Node>>{op[10], op[8]}, -1);+ op[12] = std::make_shared<ov::op::v1::Multiply>(model_c[13], op[11]);+ op[13] = std::make_shared<ov::op::v1::Multiply>(model_c[14], op[2]);+ op[14] = std::make_shared<ov::op::v1::Add>(op[13], op[12]);+ op[15] = std::make_shared<ov::op::v1::Reshape>(op[14], model_c[17], false);++ for (const auto& o : op) {+ m_nodes.push_back(o);+ set_name(o);+ }++ return op[15];+}++void ModelGenerator::set_name(const std::shared_ptr<ov::Node>& node) {+ node->set_friendly_name("node_" + std::to_string(m_name_idx++));+}diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/generators/model_generator.hpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/generators/model_generator.hppnew file mode 100644index 00000000000..ca5cd8a38bc--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/generators/model_generator.hpp@@ -0,0 +1,25 @@+// Copyright (C) 2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/openvino.hpp"++class ModelGenerator {+public:+ ModelGenerator() = default;++ std::shared_ptr<ov::Model> get_model_with_one_op();+ std::shared_ptr<ov::Model> get_model_without_repeated_blocks();+ std::shared_ptr<ov::Model> get_model_with_repeated_blocks(std::size_t repetitions);+ std::shared_ptr<ov::Model> get_model_with_repeated_blocks();++private:+ std::shared_ptr<ov::Node> get_block(const std::shared_ptr<ov::Node>& input);+ void set_name(const std::shared_ptr<ov::Node>& node);++private:+ std::vector<std::shared_ptr<ov::Node>> m_nodes;+ size_t m_name_idx;+};diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.cppindex 666776a22d6..ed4bf72a945 100644--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.cpp@@ -52,9 +52,9 @@ void MockInferRequestBase::create_implementation() {MockCompiledModelBase::MockCompiledModelBase(const std::shared_ptr<const ov::Model>& model,std::shared_ptr<ov::IPlugin> plugin,const ov::AnyMap& config,- std::shared_ptr<std::pair<std::function<void(MockInferRequest&)>, bool>> infer_req_expectations_ptr)+ std::shared_ptr<std::map<int, std::pair<std::function<void(MockInferRequest&)>, bool>>> infer_reqs_to_expectations_ptr): ov::ICompiledModel(model, plugin),- m_infer_req_expectations_ptr(infer_req_expectations_ptr),+ m_infer_reqs_to_expectations_ptr(infer_reqs_to_expectations_ptr),m_model(model),m_config(config) {}@@ -99,12 +99,17 @@ void MockCompiledModelBase::create_implementation() {auto mock_sync_infer_request = std::make_shared<MockInferRequest>(std::dynamic_pointer_cast<const MockCompiledModel>(shared_from_this()));mock_sync_infer_request->create_implementation();- if (m_infer_req_expectations_ptr) {- auto& expectation = m_infer_req_expectations_ptr->first;- auto& status = m_infer_req_expectations_ptr->second;+ if (m_infer_reqs_to_expectations_ptr &&+ m_infer_reqs_to_expectations_ptr->count(m_num_created_infer_requests)) {+ auto& expectation_and_status = (*m_infer_reqs_to_expectations_ptr)[m_num_created_infer_requests];+ auto& expectation = expectation_and_status.first;+ auto& status = expectation_and_status.second;expectation(*mock_sync_infer_request);status = true; // Expectation will be checked}++ ++m_num_created_infer_requests;+return mock_sync_infer_request;});}@@ -134,14 +139,14 @@ void MockPluginBase<DeviceType>::create_implementation() {.WillByDefault([this](const std::shared_ptr<const ov::Model>& model, const ov::AnyMap& properties) {std::lock_guard<std::mutex> lock(m_mock_creation_mutex);- std::shared_ptr<std::pair<std::function<void(MockInferRequest&)>, bool>> infer_req_expectations;- if (m_infer_reqs_to_expectations.count(m_num_compiled_models)) {- infer_req_expectations = m_infer_reqs_to_expectations[m_num_compiled_models];+ std::shared_ptr<std::map<int, std::pair<std::function<void(MockInferRequest&)>, bool>>> infer_reqs_to_expectations;+ if (m_models_to_reqs_to_expectations.count(m_num_compiled_models)) {+ infer_reqs_to_expectations = m_models_to_reqs_to_expectations[m_num_compiled_models];}auto mock_compiled_model = std::make_shared<MockCompiledModel>(model, shared_from_this(), properties,- infer_req_expectations);+ infer_reqs_to_expectations);mock_compiled_model->create_implementation();@@ -265,10 +270,14 @@ void MockPluginBase<DeviceType>::set_expectations_to_comp_models(int model_idx,}template <typename DeviceType>-void MockPluginBase<DeviceType>::set_expectations_to_infer_reqs(int req_idx,+void MockPluginBase<DeviceType>::set_expectations_to_infer_reqs(int model_idx, int req_idx,std::function<void(MockInferRequest&)> expectations) {- m_infer_reqs_to_expectations[req_idx] =- std::make_shared<std::pair<std::function<void(MockInferRequest&)>, bool>>(expectations, false);+ if (!m_models_to_reqs_to_expectations.count(model_idx)) {+ m_models_to_reqs_to_expectations[model_idx] =+ std::make_shared<std::map<int, std::pair<std::function<void(MockInferRequest&)>, bool>>>();+ }+ m_models_to_reqs_to_expectations[model_idx]->insert(+ {req_idx, std::pair<std::function<void(MockInferRequest&)>, bool>(expectations, false)});}template <typename DeviceType>@@ -277,16 +286,21 @@ MockPluginBase<DeviceType>::~MockPluginBase() {auto idx = idx_to_expectation_and_status.first;auto expectation_and_status = idx_to_expectation_and_status.second;if (!expectation_and_status.second) {- ADD_FAILURE() << DeviceType::name << ": Expectation for model with index " << idx- << " was set, but model with that idx was not compiled";+ ADD_FAILURE() << DeviceType::name << ": Expectation for model[" << idx+ << "] was set, but that model was not compiled";}}- for (auto const& idx_to_expectation_and_status : m_infer_reqs_to_expectations) {- auto idx = idx_to_expectation_and_status.first;- auto expectation_and_status = *idx_to_expectation_and_status.second;- if (!expectation_and_status.second) {- ADD_FAILURE() << DeviceType::name << ": Expectation for request with index " << idx- << " was set, but request with that idx was not created";+ for (auto const& idx_to_reqs_to_expectation_and_status : m_models_to_reqs_to_expectations) {+ OPENVINO_ASSERT(idx_to_reqs_to_expectation_and_status.second);+ for (auto const& req_to_expectation_and_status : *idx_to_reqs_to_expectation_and_status.second) {+ auto req_idx = req_to_expectation_and_status.first;+ auto expectation_and_status = req_to_expectation_and_status.second;+ if (!expectation_and_status.second) {+ auto model_idx = idx_to_reqs_to_expectation_and_status.first;+ ADD_FAILURE() << DeviceType::name << ": Expectation for request[" << req_idx+ << "] of model[" << model_idx << "] was set, but that request was "+ << "not created";+ }}}}diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.hpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.hppindex 5c02f96ebd5..4d720796c6a 100644--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.hpp+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/mocks/mock_plugins.hpp@@ -57,7 +57,7 @@ public:MockCompiledModelBase(const std::shared_ptr<const ov::Model>& model, std::shared_ptr<ov::IPlugin> plugin,const ov::AnyMap& config,- std::shared_ptr<std::pair<std::function<void(MockInferRequest&)>, bool>> infer_req_expectations);+ std::shared_ptr<std::map<int, std::pair<std::function<void(MockInferRequest&)>, bool>>> infer_reqs_to_expectations);// Methods from a base class ov::ICompiledModelMOCK_METHOD(const std::vector<ov::Output<const ov::Node>>&, outputs, (), (const, override));@@ -74,7 +74,8 @@ public:private:std::mutex m_mock_creation_mutex;- std::shared_ptr<std::pair<std::function<void(MockInferRequest&)>, bool>> m_infer_req_expectations_ptr;+ int m_num_created_infer_requests{};+ std::shared_ptr<std::map<int, std::pair<std::function<void(MockInferRequest&)>, bool>>> m_infer_reqs_to_expectations_ptr;std::shared_ptr<const ov::Model> m_model;ov::AnyMap m_config;@@ -119,7 +120,7 @@ public:// This must be called *before* the custom ON_CALL() statements.void create_implementation();void set_expectations_to_comp_models(int model_idx, std::function<void(MockCompiledModel&)> expectations);- void set_expectations_to_infer_reqs(int req_idx, std::function<void(MockInferRequest&)> expectations);+ void set_expectations_to_infer_reqs(int model_idx, int req_idx, std::function<void(MockInferRequest&)> expectations);~MockPluginBase() override;@@ -129,7 +130,7 @@ private:int m_num_compiled_models{};// TODO: Make thread-safe and simplify.std::map<int, std::pair<std::function<void(MockCompiledModel&)>, bool>> m_models_to_expectations;- std::map<int, std::shared_ptr<std::pair<std::function<void(MockInferRequest&)>, bool>>> m_infer_reqs_to_expectations;+ std::map<int, std::shared_ptr<std::map<int, std::pair<std::function<void(MockInferRequest&)>, bool>>>> m_models_to_reqs_to_expectations;// Propertiesint32_t num_streams{0};