Upgrade CPU func tests to 2.0 (#21384)
* [CPU Plugin][Func Test] Upgrade NonInputInPlaceTest to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade InputOutputTensorReuse to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade InputTensorROI to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade IntertactionCPUTest to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade EdgeWithSameNameInTwoModels to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade MHATest to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade NgramCPUTest to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade ParameterResultCustomBlobTest to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] Upgrade RemoveUselessBF16ConvertCPUTest to API 2.0 Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] remove ngraph & opset Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] fix review comments Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * [CPU Plugin][Func Test] fix snippets mode error Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> --------- Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
This commit is contained in:
parent
0d05f87004
commit
5dda9f333b
@ -2,16 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <shared_test_classes/base/ov_subgraph.hpp>
|
||||
#include "common_test_utils/node_builders/eltwise.hpp"
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
#include "shared_test_classes/base/layer_test_utils.hpp"
|
||||
#include "ov_models/utils/ov_helpers.hpp"
|
||||
#include "ov_models/builders.hpp"
|
||||
|
||||
using namespace CPUTestUtils;
|
||||
using namespace InferenceEngine;
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
namespace ov {
|
||||
namespace test {
|
||||
// If a node (CumSum) with constant parents has several non-constant nodes (Eltwises) than the edge is broken.
|
||||
// The fix is to check node type - is should be Input.
|
||||
// Subgraph:
|
||||
@ -30,10 +27,7 @@ namespace SubgraphTestsDefinitions {
|
||||
* Result
|
||||
*/
|
||||
|
||||
using namespace ov::test;
|
||||
|
||||
class NonInputInPlaceTest : public testing::WithParamInterface<ElementType>,
|
||||
virtual public SubgraphBaseTest {
|
||||
class NonInputInPlaceTest : public testing::WithParamInterface<ElementType>, virtual public SubgraphBaseTest {
|
||||
public:
|
||||
static std::string getTestCaseName(testing::TestParamInfo<ElementType> obj) {
|
||||
std::ostringstream result;
|
||||
@ -44,34 +38,36 @@ public:
|
||||
void SetUp() override {
|
||||
targetDevice = utils::DEVICE_CPU;
|
||||
configuration.insert({ov::hint::inference_precision.name(), ov::element::f16.to_string()});
|
||||
const std::vector<size_t> inputShape = {1, 11, 3, 3};
|
||||
const ov::Shape inputShape = {1, 11, 3, 3};
|
||||
targetStaticShapes = {{inputShape, inputShape}};
|
||||
ElementType prc = this->GetParam();
|
||||
|
||||
ov::ParameterVector inputParams {std::make_shared<ov::op::v0::Parameter>(prc, ov::Shape(inputShape)),
|
||||
std::make_shared<ov::op::v0::Parameter>(prc, ov::Shape(inputShape))};
|
||||
ov::ParameterVector inputParams{std::make_shared<ov::op::v0::Parameter>(prc, ov::Shape(inputShape)),
|
||||
std::make_shared<ov::op::v0::Parameter>(prc, ov::Shape(inputShape))};
|
||||
|
||||
auto cumsum_tensor = ngraph::opset8::Constant::create(prc, inputShape, {10.0f});
|
||||
auto axis_node = ngraph::opset8::Constant::create(ngraph::element::i32, {}, {0});
|
||||
auto cumsum_tensor = ov::op::v0::Constant::create(prc, inputShape, {10.0f});
|
||||
auto axis_node = ov::op::v0::Constant::create(ov::element::i32, {}, {0});
|
||||
const auto cumsum = std::make_shared<ov::op::v0::CumSum>(cumsum_tensor, axis_node);
|
||||
|
||||
auto eltwiseMul = ngraph::builder::makeEltwise(inputParams[0], cumsum, ngraph::helpers::EltwiseTypes::MULTIPLY);
|
||||
auto eltwiseAdd1 = ngraph::builder::makeEltwise(inputParams[1], cumsum, ngraph::helpers::EltwiseTypes::ADD);
|
||||
auto eltwiseAdd2 = ngraph::builder::makeEltwise(eltwiseAdd1, eltwiseMul, ngraph::helpers::EltwiseTypes::ADD);
|
||||
auto eltwiseMul = ov::test::utils::makeEltwise(inputParams[0], cumsum, ov::test::utils::EltwiseTypes::MULTIPLY);
|
||||
auto eltwiseAdd1 = ov::test::utils::makeEltwise(inputParams[1], cumsum, ov::test::utils::EltwiseTypes::ADD);
|
||||
auto eltwiseAdd2 = ov::test::utils::makeEltwise(eltwiseAdd1, eltwiseMul, ov::test::utils::EltwiseTypes::ADD);
|
||||
|
||||
ngraph::ResultVector results{std::make_shared<ngraph::opset8::Result>(eltwiseAdd2)};
|
||||
function = std::make_shared<ngraph::Function>(results, inputParams, "NonInputInPlaceT");
|
||||
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(eltwiseAdd2)};
|
||||
function = std::make_shared<ov::Model>(results, inputParams, "NonInputInPlaceT");
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
TEST_P(NonInputInPlaceTest, CompareWithRefs) {
|
||||
run();
|
||||
}
|
||||
TEST_P(NonInputInPlaceTest, CompareWithRefs) {
|
||||
run();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_NonInputInPlaceTest_CPU, NonInputInPlaceTest,
|
||||
testing::Values(ngraph::element::f32, ngraph::element::f16),
|
||||
NonInputInPlaceTest::getTestCaseName);
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_NonInputInPlaceTest_CPU,
|
||||
NonInputInPlaceTest,
|
||||
testing::Values(ov::element::f32, ov::element::f16),
|
||||
NonInputInPlaceTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
@ -3,11 +3,9 @@
|
||||
//
|
||||
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "ov_models/utils/ov_helpers.hpp"
|
||||
#include "ov_models/builders.hpp"
|
||||
|
||||
using namespace InferenceEngine;
|
||||
using namespace ov::test;
|
||||
namespace ov {
|
||||
namespace test {
|
||||
|
||||
/*This test runs the following subgraph:
|
||||
|
||||
@ -29,7 +27,6 @@ using namespace ov::test;
|
||||
next infer request.
|
||||
*/
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
class InputOutputTensorReuse : public SubgraphBaseTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
@ -45,16 +42,17 @@ public:
|
||||
input_params[1]->set_friendly_name("Param_1");
|
||||
|
||||
auto first_soft_max = std::make_shared<ov::op::v1::Softmax>(input_params[1], softmax_axis);
|
||||
auto concat = std::make_shared<ov::op::v0::Concat>(ov::NodeVector{input_params[0], first_soft_max}, concat_axis);
|
||||
auto concat =
|
||||
std::make_shared<ov::op::v0::Concat>(ov::NodeVector{input_params[0], first_soft_max}, concat_axis);
|
||||
auto last_soft_max = std::make_shared<ov::op::v1::Softmax>(concat, softmax_axis);
|
||||
|
||||
ngraph::ResultVector results;
|
||||
ov::ResultVector results;
|
||||
for (size_t i = 0; i < last_soft_max->get_output_size(); i++)
|
||||
results.push_back(std::make_shared<ngraph::opset1::Result>(last_soft_max->output(i)));
|
||||
results.push_back(std::make_shared<ov::op::v0::Result>(last_soft_max->output(i)));
|
||||
|
||||
results.front()->set_friendly_name("Output_1");
|
||||
|
||||
function = std::make_shared<ngraph::Function>(results, input_params, "InputOutputTensorReuseTest");
|
||||
function = std::make_shared<ov::Model>(results, input_params, "InputOutputTensorReuseTest");
|
||||
}
|
||||
};
|
||||
|
||||
@ -68,9 +66,11 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Binding) {
|
||||
for (size_t i = 0; i < num_iter; i++) {
|
||||
auto outputTensor = inferRequest.get_output_tensor(0);
|
||||
inputShapes.back() = outputTensor.get_shape();
|
||||
auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
auto itr = std::find_if(inputs.begin(),
|
||||
inputs.end(),
|
||||
[](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
ASSERT_NE(itr, inputs.end());
|
||||
itr->second = outputTensor;
|
||||
const auto& expectedOutputs = calculate_refs();
|
||||
@ -91,9 +91,10 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once) {
|
||||
|
||||
auto outputTensor = inferRequest.get_output_tensor(0);
|
||||
inputShapes.back() = outputTensor.get_shape();
|
||||
auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
auto itr =
|
||||
std::find_if(inputs.begin(), inputs.end(), [](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
ASSERT_NE(itr, inputs.end());
|
||||
itr->second = outputTensor;
|
||||
|
||||
@ -107,9 +108,11 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once) {
|
||||
|
||||
inferRequest.infer();
|
||||
compare(expectedOutputs, {outputTensor});
|
||||
auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
auto itr = std::find_if(inputs.begin(),
|
||||
inputs.end(),
|
||||
[](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
ASSERT_NE(itr, inputs.end());
|
||||
itr->second = expectedOutputs.front();
|
||||
}
|
||||
@ -123,9 +126,10 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once_Empty_Tensor) {
|
||||
|
||||
auto outputTensor = inferRequest.get_output_tensor(0);
|
||||
inputShapes.back() = outputTensor.get_shape();
|
||||
auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
auto itr =
|
||||
std::find_if(inputs.begin(), inputs.end(), [](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
ASSERT_NE(itr, inputs.end());
|
||||
itr->second = outputTensor;
|
||||
|
||||
@ -139,12 +143,15 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once_Empty_Tensor) {
|
||||
|
||||
inferRequest.infer();
|
||||
compare(expectedOutputs, {outputTensor});
|
||||
auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
auto itr = std::find_if(inputs.begin(),
|
||||
inputs.end(),
|
||||
[](const std::pair<std::shared_ptr<ov::Node>, ov::Tensor>& item) {
|
||||
return item.first->get_friendly_name() == "Param_1";
|
||||
});
|
||||
ASSERT_NE(itr, inputs.end());
|
||||
itr->second = expectedOutputs.front();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
@ -2,16 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "ov_models/builders.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
#include "functional_test_utils/ov_plugin_cache.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
using namespace ngraph::op;
|
||||
using namespace InferenceEngine;
|
||||
using namespace CPUTestUtils;
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
namespace ov {
|
||||
namespace test {
|
||||
|
||||
struct InputTensorROIParamType {
|
||||
ov::PartialShape shape;
|
||||
@ -30,24 +27,23 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ov::Model>
|
||||
create_test_function(element::Type type,
|
||||
const ov::PartialShape & shape,
|
||||
const ov::Layout & layout) {
|
||||
std::shared_ptr<ov::Model> create_test_function(element::Type type,
|
||||
const ov::PartialShape& shape,
|
||||
const ov::Layout& layout) {
|
||||
ResultVector res;
|
||||
ParameterVector params;
|
||||
|
||||
auto param = std::make_shared<opset8::Parameter>(type, shape);
|
||||
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
|
||||
param->set_friendly_name("input_0");
|
||||
param->get_output_tensor(0).set_names({"tensor_input_0"});
|
||||
param->set_layout(layout);
|
||||
|
||||
auto constant = opset8::Constant::create(type, {1}, {1});
|
||||
auto constant = ov::op::v0::Constant::create(type, {1}, {1});
|
||||
|
||||
auto add = std::make_shared<opset8::Add>(param, constant);
|
||||
auto add = std::make_shared<ov::op::v1::Add>(param, constant);
|
||||
add->set_friendly_name("Add");
|
||||
|
||||
auto result = std::make_shared<opset8::Result>(add);
|
||||
auto result = std::make_shared<ov::op::v0::Result>(add);
|
||||
result->set_friendly_name("result_0");
|
||||
result->get_output_tensor(0).set_names({"tensor_output_0"});
|
||||
|
||||
@ -57,7 +53,7 @@ protected:
|
||||
return std::make_shared<ov::Model>(res, params);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
void Run() {
|
||||
std::shared_ptr<ov::Core> ie = ov::test::utils::PluginCache::get().core();
|
||||
|
||||
@ -70,14 +66,14 @@ protected:
|
||||
ov::InferRequest req = compiled_model.create_infer_request();
|
||||
|
||||
// Create input tensor
|
||||
auto input_shape = Shape{ 1, 4, 4, 4 };
|
||||
auto input_shape = Shape{1, 4, 4, 4};
|
||||
auto input_shape_size = ov::shape_size(input_shape);
|
||||
std::vector<T> data(input_shape_size);
|
||||
std::iota(data.begin(), data.end(), 0);
|
||||
auto input_tensor = ov::Tensor(GetParam().type, input_shape, &data[0]);
|
||||
|
||||
// Set ROI
|
||||
auto roi = ov::Tensor(input_tensor, { 0, 1, 1, 1 }, { 1, 3, 3, 3 });
|
||||
auto roi = ov::Tensor(input_tensor, {0, 1, 1, 1}, {1, 3, 3, 3});
|
||||
req.set_tensor("tensor_input_0", roi);
|
||||
|
||||
// Infer
|
||||
@ -99,24 +95,24 @@ protected:
|
||||
|
||||
TEST_P(InputTensorROI, SetInputTensorROI) {
|
||||
switch (GetParam().type) {
|
||||
case ov::element::Type_t::f32: {
|
||||
Run<float>();
|
||||
break;
|
||||
}
|
||||
case ov::element::Type_t::u8: {
|
||||
Run<uint8_t>();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
case ov::element::Type_t::f32: {
|
||||
Run<float>();
|
||||
break;
|
||||
}
|
||||
case ov::element::Type_t::u8: {
|
||||
Run<uint8_t>();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static InputTensorROI::ParamType InputTensorROIParams[] = {
|
||||
{ ov::PartialShape{ 1, 2, 2, 2 }, element::f32, "NCHW" },
|
||||
{ ov::PartialShape{ 1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic() }, element::f32, "NCHW" },
|
||||
{ ov::PartialShape{ 1, 2, 2, 2 }, element::u8, "NCHW" },
|
||||
{ ov::PartialShape{ 1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic() }, element::u8, "NCHW" },
|
||||
{ov::PartialShape{1, 2, 2, 2}, element::f32, "NCHW"},
|
||||
{ov::PartialShape{1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, element::f32, "NCHW"},
|
||||
{ov::PartialShape{1, 2, 2, 2}, element::u8, "NCHW"},
|
||||
{ov::PartialShape{1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, element::u8, "NCHW"},
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_InputTensorROI,
|
||||
@ -124,4 +120,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_InputTensorROI,
|
||||
::testing::ValuesIn(InputTensorROIParams),
|
||||
InputTensorROI::getTestCaseName);
|
||||
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
@ -2,49 +2,37 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "ie_precision.hpp"
|
||||
#include "test_utils/fusing_test_utils.hpp"
|
||||
#include <openvino/opsets/opset1.hpp>
|
||||
#include <openvino/opsets/opset8.hpp>
|
||||
#include <common_test_utils/ov_tensor_utils.hpp>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <debug.h>
|
||||
#include <shared_test_classes/base/ov_subgraph.hpp>
|
||||
#include <ov_models/builders.hpp>
|
||||
#include "common_test_utils/common_utils.hpp"
|
||||
#include <common_test_utils/ov_tensor_utils.hpp>
|
||||
#include "functional_test_utils/skip_tests_config.hpp"
|
||||
#include "common_test_utils/ov_tensor_utils.hpp"
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
|
||||
using namespace CPUTestUtils;
|
||||
using namespace ov::test;
|
||||
using namespace ov;
|
||||
|
||||
static std::shared_ptr<opset8::FakeQuantize> createFQ(const std::shared_ptr<ov::Node>& input) {
|
||||
auto input_low = std::make_shared<opset1::Constant>(element::f32, ov::Shape{1}, std::vector<float>{0});
|
||||
auto input_high = std::make_shared<opset1::Constant>(element::f32, ov::Shape{1}, std::vector<float>{49.4914f});
|
||||
auto output_low = std::make_shared<opset1::Constant>(element::f32, ov::Shape{1}, std::vector<float>{0});
|
||||
auto output_high = std::make_shared<opset1::Constant>(element::f32, ov::Shape{1}, std::vector<float>{49.4914f});
|
||||
return std::make_shared<opset8::FakeQuantize>(input, input_low, input_high, output_low, output_high, 256);
|
||||
static std::shared_ptr<ov::op::v0::FakeQuantize> createFQ(const std::shared_ptr<ov::Node>& input) {
|
||||
auto input_low = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{0});
|
||||
auto input_high = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{49.4914f});
|
||||
auto output_low = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{0});
|
||||
auto output_high = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{49.4914f});
|
||||
return std::make_shared<ov::op::v0::FakeQuantize>(input, input_low, input_high, output_low, output_high, 256);
|
||||
}
|
||||
|
||||
static std::shared_ptr<ov::Model> makeInteraction(const ElementType inType, const ov::PartialShape& inputShape) {
|
||||
bool intraFQ = inType == ElementType::i8;
|
||||
auto paramType = intraFQ ? ElementType::f32 : inType;
|
||||
std::shared_ptr<ov::opset1::Parameter> input = std::make_shared<ov::opset1::Parameter>(paramType, inputShape);
|
||||
std::shared_ptr<ov::op::v0::Parameter> input = std::make_shared<ov::op::v0::Parameter>(paramType, inputShape);
|
||||
std::shared_ptr<ov::Node> dense_feature = nullptr;
|
||||
if (intraFQ) {
|
||||
dense_feature = createFQ(input);
|
||||
} else {
|
||||
dense_feature = input;
|
||||
}
|
||||
NodeVector features{dense_feature};
|
||||
ParameterVector inputsParams{input};
|
||||
ov::NodeVector features{dense_feature};
|
||||
ov::ParameterVector inputsParams{input};
|
||||
const size_t sparse_feature_num = 26;
|
||||
for (size_t i = 0; i < sparse_feature_num; i++) {
|
||||
auto sparse_input = std::make_shared<ov::opset1::Parameter>(paramType, inputShape);
|
||||
auto sparse_input = std::make_shared<ov::op::v0::Parameter>(paramType, inputShape);
|
||||
std::shared_ptr<ov::Node> sparse_feat = nullptr;
|
||||
if (intraFQ) {
|
||||
sparse_feat = createFQ(sparse_input);
|
||||
@ -55,23 +43,24 @@ static std::shared_ptr<ov::Model> makeInteraction(const ElementType inType, cons
|
||||
inputsParams.push_back(sparse_input);
|
||||
}
|
||||
auto shapeof = std::make_shared<ov::op::v3::ShapeOf>(dense_feature);
|
||||
auto gather_batch_indices = std::make_shared<opset1::Constant>(element::i32, ov::Shape{1}, std::vector<int32_t>{0});
|
||||
auto gather_batch_axis = std::make_shared<opset1::Constant>(element::i32, ov::Shape{}, 0);
|
||||
auto gather_batch = std::make_shared<opset8::Gather>(shapeof, gather_batch_indices, gather_batch_axis);
|
||||
auto gather_batch_indices = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1}, std::vector<int32_t>{0});
|
||||
auto gather_batch_axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 0);
|
||||
auto gather_batch = std::make_shared<ov::op::v8::Gather>(shapeof, gather_batch_indices, gather_batch_axis);
|
||||
|
||||
auto gather_feature_indices = std::make_shared<opset1::Constant>(element::i32, ov::Shape{1}, std::vector<int32_t>{1});
|
||||
auto gather_feature_axis = std::make_shared<opset1::Constant>(element::i32, ov::Shape{1}, 0);
|
||||
auto gather_feature = std::make_shared<opset8::Gather>(shapeof, gather_feature_indices, gather_feature_axis);
|
||||
auto gather_feature_indices =
|
||||
std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1}, std::vector<int32_t>{1});
|
||||
auto gather_feature_axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{1}, 0);
|
||||
auto gather_feature = std::make_shared<ov::op::v8::Gather>(shapeof, gather_feature_indices, gather_feature_axis);
|
||||
|
||||
auto reshape_dim2 = std::make_shared<opset1::Constant>(element::i64, ov::Shape{1}, std::vector<int64_t>{-1});
|
||||
auto reshape_shape = std::make_shared<opset1::Concat>(NodeVector{gather_batch, reshape_dim2, gather_feature}, 0);
|
||||
auto reshape_dim2 = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1});
|
||||
auto reshape_shape = std::make_shared<ov::op::v0::Concat>(ov::NodeVector{gather_batch, reshape_dim2, gather_feature}, 0);
|
||||
|
||||
auto concat1 = std::make_shared<opset1::Concat>(features, 1);
|
||||
auto reshape = std::make_shared<opset1::Reshape>(concat1, reshape_shape, true);
|
||||
auto concat1 = std::make_shared<ov::op::v0::Concat>(features, 1);
|
||||
auto reshape = std::make_shared<ov::op::v1::Reshape>(concat1, reshape_shape, true);
|
||||
std::vector<int32_t> transpose1_value = {0, 2, 1};
|
||||
auto transpose1_shape = std::make_shared<opset1::Constant>(element::i32, ov::Shape{3}, transpose1_value);
|
||||
auto transpose1 = std::make_shared<opset1::Transpose>(reshape, transpose1_shape);
|
||||
auto matmul = std::make_shared<opset1::MatMul>(reshape, transpose1);
|
||||
auto transpose1_shape = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, transpose1_value);
|
||||
auto transpose1 = std::make_shared<ov::op::v1::Transpose>(reshape, transpose1_shape);
|
||||
auto matmul = std::make_shared<ov::op::v0::MatMul>(reshape, transpose1);
|
||||
std::shared_ptr<ov::Node> inter = nullptr;
|
||||
if (intraFQ) {
|
||||
inter = createFQ(matmul);
|
||||
@ -79,42 +68,42 @@ static std::shared_ptr<ov::Model> makeInteraction(const ElementType inType, cons
|
||||
inter = matmul;
|
||||
}
|
||||
std::vector<int32_t> transpose2_value = {1, 2, 0};
|
||||
auto transpose2_shape = std::make_shared<opset1::Constant>(element::i32, ov::Shape{3}, transpose2_value);
|
||||
auto transpose2 = std::make_shared<opset1::Transpose>(inter, transpose2_shape);
|
||||
auto transpose2_shape = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, transpose2_value);
|
||||
auto transpose2 = std::make_shared<ov::op::v1::Transpose>(inter, transpose2_shape);
|
||||
std::vector<int32_t> reshape2_value = {729, -1};
|
||||
auto reshape2_shape = std::make_shared<opset1::Constant>(element::i32, ov::Shape{2}, reshape2_value);
|
||||
auto reshape2 = std::make_shared<opset1::Reshape>(transpose2, reshape2_shape, true);
|
||||
auto reshape2_shape = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{2}, reshape2_value);
|
||||
auto reshape2 = std::make_shared<ov::op::v1::Reshape>(transpose2, reshape2_shape, true);
|
||||
|
||||
std::vector<int32_t> gather_indices_value;
|
||||
for (int i = 1; i < 27; i++) {
|
||||
for (int j = 0; j < i; j ++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
gather_indices_value.push_back(i * 27 + j);
|
||||
}
|
||||
}
|
||||
auto gather_indices = std::make_shared<opset1::Constant>(element::i32, ov::Shape{351}, gather_indices_value);
|
||||
auto gather_axis = std::make_shared<opset1::Constant>(element::i32, ov::Shape{}, 0);
|
||||
auto gather = std::make_shared<opset8::Gather>(reshape2, gather_indices, gather_axis);
|
||||
auto reshape3_dim1 = std::make_shared<opset1::Constant>(element::i64, ov::Shape{1}, std::vector<int64_t>{-1});
|
||||
auto reshape3_shape = std::make_shared<opset1::Concat>(NodeVector{reshape3_dim1, gather_batch}, 0);
|
||||
auto reshape3 = std::make_shared<opset1::Reshape>(gather, reshape3_shape, true);
|
||||
auto gather_indices = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{351}, gather_indices_value);
|
||||
auto gather_axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 0);
|
||||
auto gather = std::make_shared<ov::op::v8::Gather>(reshape2, gather_indices, gather_axis);
|
||||
auto reshape3_dim1 = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1});
|
||||
auto reshape3_shape = std::make_shared<ov::op::v0::Concat>(ov::NodeVector{reshape3_dim1, gather_batch}, 0);
|
||||
auto reshape3 = std::make_shared<ov::op::v1::Reshape>(gather, reshape3_shape, true);
|
||||
|
||||
std::vector<int32_t> transpose3_value = {1, 0};
|
||||
auto transpose3_shape = std::make_shared<opset1::Constant>(element::i32, ov::Shape{2}, transpose3_value);
|
||||
auto transpose3 = std::make_shared<opset1::Transpose>(reshape3, transpose3_shape);
|
||||
auto transpose3_shape = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{2}, transpose3_value);
|
||||
auto transpose3 = std::make_shared<ov::op::v1::Transpose>(reshape3, transpose3_shape);
|
||||
|
||||
std::vector<int32_t> reshape4_value = {-1, 351};
|
||||
auto reshape4_shape = std::make_shared<opset1::Constant>(element::i32, ov::Shape{2}, reshape4_value);
|
||||
auto reshape4 = std::make_shared<opset1::Reshape>(transpose3, reshape4_shape, true);
|
||||
auto concat2 = std::make_shared<opset1::Concat>(NodeVector{dense_feature, reshape4}, 1);
|
||||
auto reshape4_shape = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{2}, reshape4_value);
|
||||
auto reshape4 = std::make_shared<ov::op::v1::Reshape>(transpose3, reshape4_shape, true);
|
||||
auto concat2 = std::make_shared<ov::op::v0::Concat>(ov::NodeVector{dense_feature, reshape4}, 1);
|
||||
std::shared_ptr<ov::Model> model;
|
||||
if (intraFQ) {
|
||||
auto add_const = std::make_shared<opset1::Constant>(element::i8, ov::Shape{355, 1}, 3);
|
||||
auto convert = std::make_shared<opset8::Convert>(add_const, element::f32);
|
||||
auto zp_const = std::make_shared<opset1::Constant>(element::f32, ov::Shape{1}, 0);
|
||||
auto scale_const = std::make_shared<opset1::Constant>(element::f32, ov::Shape{1}, 1);
|
||||
auto sub = std::make_shared<opset1::Subtract>(convert, zp_const);
|
||||
auto multipy = std::make_shared<opset1::Multiply>(sub, scale_const);
|
||||
const auto matmul = std::make_shared<ngraph::opset1::MatMul>(concat2, multipy);
|
||||
auto add_const = std::make_shared<ov::op::v0::Constant>(ov::element::i8, ov::Shape{355, 1}, 3);
|
||||
auto convert = std::make_shared<ov::op::v0::Convert>(add_const, ov::element::f32);
|
||||
auto zp_const = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{1}, 0);
|
||||
auto scale_const = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{1}, 1);
|
||||
auto sub = std::make_shared<ov::op::v1::Subtract>(convert, zp_const);
|
||||
auto multipy = std::make_shared<ov::op::v1::Multiply>(sub, scale_const);
|
||||
const auto matmul = std::make_shared<ov::op::v0::MatMul>(concat2, multipy);
|
||||
model = std::make_shared<ov::Model>(matmul, inputsParams, "interaction");
|
||||
} else {
|
||||
model = std::make_shared<ov::Model>(concat2, inputsParams, "interaction");
|
||||
@ -122,7 +111,6 @@ static std::shared_ptr<ov::Model> makeInteraction(const ElementType inType, cons
|
||||
return model;
|
||||
}
|
||||
|
||||
namespace CPULayerTestsDefinitions {
|
||||
using InteractionLayerCPUTestParams = std::tuple<ElementType, InputShape>;
|
||||
|
||||
class IntertactionCPUTest : public testing::WithParamInterface<InteractionLayerCPUTestParams>,
|
||||
@ -146,7 +134,11 @@ public:
|
||||
const auto& funcInput = funcInputs[i];
|
||||
ov::Tensor tensor;
|
||||
|
||||
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 15, 0, 32768);
|
||||
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
|
||||
targetInputStaticShapes[i],
|
||||
15,
|
||||
0,
|
||||
32768);
|
||||
|
||||
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
|
||||
}
|
||||
@ -157,7 +149,7 @@ protected:
|
||||
ElementType inType;
|
||||
InputShape inputShape;
|
||||
std::tie(inType, inputShape) = this->GetParam();
|
||||
bool with_bf16 = InferenceEngine::with_cpu_x86_bfloat16();
|
||||
bool with_bf16 = ov::with_cpu_x86_bfloat16();
|
||||
if (with_bf16 && (inType == ov::element::bf16 || inType == ov::element::i32)) {
|
||||
selectedType = makeSelectedTypeStr("ref_any", ov::element::bf16);
|
||||
} else {
|
||||
@ -166,7 +158,7 @@ protected:
|
||||
targetDevice = ov::test::utils::DEVICE_CPU;
|
||||
inputDynamicShapes.push_back(inputShape.first);
|
||||
const auto& targetInput = inputShape.second;
|
||||
for (size_t i = 0; i < targetInput.size(); i++) {
|
||||
for (size_t i = 0; i < targetInput.size(); i++) {
|
||||
targetStaticShapes.push_back(std::vector<ov::Shape>(27, targetInput[i]));
|
||||
}
|
||||
|
||||
@ -180,15 +172,10 @@ TEST_P(IntertactionCPUTest, CompareWithRefs) {
|
||||
}
|
||||
|
||||
namespace {
|
||||
const std::vector<ElementType> inPrecisions = {
|
||||
ElementType::f32,
|
||||
ElementType::bf16,
|
||||
ElementType::i32,
|
||||
ElementType::i8
|
||||
};
|
||||
const std::vector<ElementType> inPrecisions = {ElementType::f32, ElementType::bf16, ElementType::i32, ElementType::i8};
|
||||
// the model has 27 inputs with same shape
|
||||
const std::vector<InputShape> input_shapes = {
|
||||
// temporarily disable dynamic shape for performance issue
|
||||
// temporarily disable dynamic shape for performance issue
|
||||
// // dynamic batch
|
||||
// {
|
||||
// {-1, 4},
|
||||
@ -200,22 +187,11 @@ const std::vector<InputShape> input_shapes = {
|
||||
// {{3, 4}, {5, 6}, {7, 8}}
|
||||
// },
|
||||
// static shape
|
||||
{
|
||||
{6, 4},
|
||||
{{6, 4}}
|
||||
},
|
||||
{
|
||||
{3, 4},
|
||||
{{3, 4}}
|
||||
}
|
||||
};
|
||||
{{6, 4}, {{6, 4}}},
|
||||
{{3, 4}, {{3, 4}}}};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Interaction, IntertactionCPUTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(inPrecisions),
|
||||
::testing::ValuesIn(input_shapes)),
|
||||
IntertactionCPUTest::getTestCaseName);
|
||||
} // namespace
|
||||
|
||||
|
||||
} // namespace CPULayerTestsDefinitions
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Interaction,
|
||||
IntertactionCPUTest,
|
||||
::testing::Combine(::testing::ValuesIn(inPrecisions), ::testing::ValuesIn(input_shapes)),
|
||||
IntertactionCPUTest::getTestCaseName);
|
||||
} // namespace
|
||||
|
@ -2,14 +2,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "common_test_utils/node_builders/convolution.hpp"
|
||||
#include "openvino/openvino.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
#include "ov_models/builders.hpp"
|
||||
#include "test_utils/convolution_params.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
|
||||
using namespace CPUTestUtils;
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
namespace ov {
|
||||
namespace test {
|
||||
|
||||
class EdgeWithSameNameInTwoModels : public ::testing::Test, public CPUTestsBase {};
|
||||
|
||||
@ -24,36 +25,52 @@ TEST_F(EdgeWithSameNameInTwoModels, smoke_CompareWithRef) {
|
||||
const std::vector<ptrdiff_t> padsBegin{0, 0};
|
||||
const std::vector<ptrdiff_t> padsEnd{0, 0};
|
||||
const std::vector<size_t> dilations{1, 1};
|
||||
const ngraph::op::PadType autoPad(ngraph::op::PadType::EXPLICIT);
|
||||
const ov::op::PadType autoPad(ov::op::PadType::EXPLICIT);
|
||||
|
||||
if (InferenceEngine::with_cpu_x86_avx512f()) {
|
||||
if (ov::with_cpu_x86_avx512f()) {
|
||||
std::tie(inFmts, outFmts, priority, selectedType) = conv_avx512_2D;
|
||||
} else if (InferenceEngine::with_cpu_x86_avx2()) {
|
||||
} else if (ov::with_cpu_x86_avx2()) {
|
||||
std::tie(inFmts, outFmts, priority, selectedType) = conv_avx2_2D;
|
||||
} else if (InferenceEngine::with_cpu_x86_sse42()) {
|
||||
} else if (ov::with_cpu_x86_sse42()) {
|
||||
std::tie(inFmts, outFmts, priority, selectedType) = conv_sse42_2D;
|
||||
}
|
||||
|
||||
// first model
|
||||
const std::vector<std::vector<size_t>> shapes1{{1, 16, 720, 1280}};
|
||||
const std::vector<ov::Shape> shapes1{{1, 16, 720, 1280}};
|
||||
ov::ParameterVector params1;
|
||||
for (auto&& shape : shapes1) {
|
||||
params1.push_back(std::make_shared<ov::op::v0::Parameter>(type, ov::Shape(shape)));
|
||||
params1.push_back(std::make_shared<ov::op::v0::Parameter>(type, shape));
|
||||
}
|
||||
const size_t convOutCh1 = 32;
|
||||
auto conv1 = ngraph::builder::makeConvolution(params1.front(), type, kernel, strides, padsBegin, padsEnd, dilations, autoPad, convOutCh1);
|
||||
auto conv1 = ov::test::utils::make_convolution(params1.front(),
|
||||
type,
|
||||
kernel,
|
||||
strides,
|
||||
padsBegin,
|
||||
padsEnd,
|
||||
dilations,
|
||||
autoPad,
|
||||
convOutCh1);
|
||||
conv1->set_friendly_name(convName);
|
||||
conv1->get_input_node_shared_ptr(1)->set_friendly_name(weightName);
|
||||
auto model1 = makeNgraphFunction(type, params1, conv1, "Model1");
|
||||
|
||||
// second model
|
||||
const std::vector<std::vector<size_t>> shapes2{{1, 32, 24, 24}};
|
||||
const std::vector<ov::Shape> shapes2{{1, 32, 24, 24}};
|
||||
ov::ParameterVector params2;
|
||||
for (auto&& shape : shapes2) {
|
||||
params2.push_back(std::make_shared<ov::op::v0::Parameter>(type, ov::Shape(shape)));
|
||||
params2.push_back(std::make_shared<ov::op::v0::Parameter>(type, shape));
|
||||
}
|
||||
const size_t convOutCh2 = 16;
|
||||
auto conv2 = ngraph::builder::makeConvolution(params2.front(), type, kernel, strides, padsBegin, padsEnd, dilations, autoPad, convOutCh2);
|
||||
auto conv2 = ov::test::utils::make_convolution(params2.front(),
|
||||
type,
|
||||
kernel,
|
||||
strides,
|
||||
padsBegin,
|
||||
padsEnd,
|
||||
dilations,
|
||||
autoPad,
|
||||
convOutCh2);
|
||||
conv2->set_friendly_name(convName);
|
||||
conv2->get_input_node_shared_ptr(1)->set_friendly_name(weightName);
|
||||
auto model2 = makeNgraphFunction(type, params2, conv2, "Model2");
|
||||
@ -78,4 +95,5 @@ TEST_F(EdgeWithSameNameInTwoModels, smoke_CompareWithRef) {
|
||||
inferReq2.infer();
|
||||
}
|
||||
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
@ -2,49 +2,41 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <debug.h>
|
||||
#include <shared_test_classes/base/ov_subgraph.hpp>
|
||||
#include <ov_models/builders.hpp>
|
||||
#include "common_test_utils/common_utils.hpp"
|
||||
#include <common_test_utils/ov_tensor_utils.hpp>
|
||||
#include "common_test_utils/ov_tensor_utils.hpp"
|
||||
#include "functional_test_utils/skip_tests_config.hpp"
|
||||
#include "ov_models/builders.hpp"
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp"
|
||||
|
||||
using namespace CPUTestUtils;
|
||||
using namespace ov::test;
|
||||
using namespace ngraph::helpers;
|
||||
|
||||
namespace CPUSubgraphTestsDefinitions {
|
||||
|
||||
using ExpectedNodes = std::vector<std::pair<std::string, size_t>>;
|
||||
|
||||
typedef std::tuple<
|
||||
std::vector<InputShape>, // Input shapes
|
||||
std::vector<ElementType>, // Input precisions
|
||||
std::vector<ElementType>, // MatMul input #0 precisions
|
||||
size_t, // pattern type #
|
||||
ExpectedNodes, // Expected node -> count
|
||||
std::string // Device name
|
||||
> MHATuple;
|
||||
typedef std::tuple<std::vector<InputShape>, // Input shapes
|
||||
std::vector<ElementType>, // Input precisions
|
||||
std::vector<ElementType>, // MatMul input #0 precisions
|
||||
size_t, // pattern type #
|
||||
ExpectedNodes, // Expected node -> count
|
||||
std::string // Device name
|
||||
>
|
||||
MHATuple;
|
||||
|
||||
static std::shared_ptr<ov::Model> initMHASubgraph0(std::vector<ov::PartialShape>& inputDynamicShapes, std::vector<ElementType>& inputPrecisions) {
|
||||
ngraph::ParameterVector ngraphParam;
|
||||
static std::shared_ptr<ov::Model> initMHASubgraph0(std::vector<ov::PartialShape>& inputDynamicShapes,
|
||||
std::vector<ElementType>& inputPrecisions) {
|
||||
ov::ParameterVector ngraphParam;
|
||||
|
||||
auto transpose0Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
auto transpose0Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
ngraphParam.push_back(transpose0Param);
|
||||
|
||||
auto transpose1Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
auto transpose1Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
ngraphParam.push_back(transpose1Param);
|
||||
|
||||
auto addParam = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
auto addParam = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
ngraphParam.push_back(addParam);
|
||||
|
||||
auto transpose2Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
auto transpose2Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
ngraphParam.push_back(transpose2Param);
|
||||
|
||||
std::vector<ov::Shape> constantShapes;
|
||||
@ -62,12 +54,13 @@ static std::shared_ptr<ov::Model> initMHASubgraph0(std::vector<ov::PartialShape>
|
||||
std::vector<int64_t> transpose1ConstData = {0, 2, 3, 1};
|
||||
auto transpose1Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[1], transpose1ConstData);
|
||||
|
||||
std::vector<float> mulConstData(ngraph::shape_size(constantShapes[2]));
|
||||
std::vector<float> mulConstData(ov::shape_size(constantShapes[2]));
|
||||
auto mulConst = ngraph::builder::makeConstant(inputPrecisions[0], constantShapes[2], mulConstData, true);
|
||||
|
||||
std::vector<int64_t> reshape0ConstData = {static_cast<int64_t>(inputDynamicShapes[0].get_shape()[0] *
|
||||
inputDynamicShapes[0].get_shape()[1] * inputDynamicShapes[0].get_shape()[2]),
|
||||
-1};
|
||||
std::vector<int64_t> reshape0ConstData = {
|
||||
static_cast<int64_t>(inputDynamicShapes[0].get_shape()[0] * inputDynamicShapes[0].get_shape()[1] *
|
||||
inputDynamicShapes[0].get_shape()[2]),
|
||||
-1};
|
||||
auto reshape0Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[3], reshape0ConstData);
|
||||
|
||||
std::vector<int64_t> reshape1ConstData = {static_cast<int64_t>(inputDynamicShapes[0].get_shape()[0]),
|
||||
@ -86,33 +79,34 @@ static std::shared_ptr<ov::Model> initMHASubgraph0(std::vector<ov::PartialShape>
|
||||
float transB = false;
|
||||
const auto transpose0 = std::make_shared<ov::op::v1::Transpose>(transpose0Param, transpose0Const);
|
||||
const auto transpose1 = std::make_shared<ov::op::v1::Transpose>(transpose1Param, transpose1Const);
|
||||
const auto mul = std::make_shared<ngraph::opset3::Multiply>(transpose1, mulConst);
|
||||
const auto matMul0 = std::make_shared<ngraph::opset3::MatMul>(transpose0, mul, transA, transB);
|
||||
const auto add = std::make_shared<ngraph::opset3::Add>(matMul0, addParam);
|
||||
const auto reshape0 = std::make_shared<ngraph::opset1::Reshape>(add, reshape0Const, true);
|
||||
const auto softMax = std::make_shared<ngraph::opset1::Softmax>(reshape0, 1);
|
||||
const auto reshape1 = std::make_shared<ngraph::opset1::Reshape>(softMax, reshape1Const, true);
|
||||
const auto mul = std::make_shared<ov::op::v1::Multiply>(transpose1, mulConst);
|
||||
const auto matMul0 = std::make_shared<ov::op::v0::MatMul>(transpose0, mul, transA, transB);
|
||||
const auto add = std::make_shared<ov::op::v1::Add>(matMul0, addParam);
|
||||
const auto reshape0 = std::make_shared<ov::op::v1::Reshape>(add, reshape0Const, true);
|
||||
const auto softMax = std::make_shared<ov::op::v1::Softmax>(reshape0, 1);
|
||||
const auto reshape1 = std::make_shared<ov::op::v1::Reshape>(softMax, reshape1Const, true);
|
||||
const auto transpose2 = std::make_shared<ov::op::v1::Transpose>(transpose2Param, transpose2Const);
|
||||
const auto matMul1 = std::make_shared<ngraph::opset3::MatMul>(reshape1, transpose2, transA, transB);
|
||||
const auto matMul1 = std::make_shared<ov::op::v0::MatMul>(reshape1, transpose2, transA, transB);
|
||||
const auto transpose3 = std::make_shared<ov::op::v1::Transpose>(matMul1, transpose3Const);
|
||||
|
||||
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(transpose3)};
|
||||
return std::make_shared<ngraph::Function>(results, ngraphParam, "mha");
|
||||
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose3)};
|
||||
return std::make_shared<ov::Model>(results, ngraphParam, "mha");
|
||||
}
|
||||
|
||||
static std::shared_ptr<ov::Model> initMHASubgraph1(std::vector<ov::PartialShape>& inputDynamicShapes, std::vector<ElementType>& inputPrecisions) {
|
||||
ngraph::ParameterVector ngraphParam;
|
||||
static std::shared_ptr<ov::Model> initMHASubgraph1(std::vector<ov::PartialShape>& inputDynamicShapes,
|
||||
std::vector<ElementType>& inputPrecisions) {
|
||||
ov::ParameterVector ngraphParam;
|
||||
|
||||
auto transpose0Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
auto transpose0Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
ngraphParam.push_back(transpose0Param);
|
||||
|
||||
auto transpose1Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
auto transpose1Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
ngraphParam.push_back(transpose1Param);
|
||||
|
||||
auto addParam = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
auto addParam = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
ngraphParam.push_back(addParam);
|
||||
|
||||
auto transpose2Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
auto transpose2Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
ngraphParam.push_back(transpose2Param);
|
||||
|
||||
std::vector<ov::Shape> constantShapes;
|
||||
@ -140,21 +134,20 @@ static std::shared_ptr<ov::Model> initMHASubgraph1(std::vector<ov::PartialShape>
|
||||
float transB = false;
|
||||
const auto transpose0 = std::make_shared<ov::op::v1::Transpose>(transpose0Param, transpose0Const);
|
||||
const auto transpose1 = std::make_shared<ov::op::v1::Transpose>(transpose1Param, transpose1Const);
|
||||
const auto matMul0 = std::make_shared<ngraph::opset3::MatMul>(transpose0, transpose1, transA, transB);
|
||||
const auto add = std::make_shared<ngraph::opset3::Add>(matMul0, addParam);
|
||||
const auto softMax = std::make_shared<ngraph::opset1::Softmax>(add, 3);
|
||||
const auto matMul0 = std::make_shared<ov::op::v0::MatMul>(transpose0, transpose1, transA, transB);
|
||||
const auto add = std::make_shared<ov::op::v1::Add>(matMul0, addParam);
|
||||
const auto softMax = std::make_shared<ov::op::v1::Softmax>(add, 3);
|
||||
const auto transpose2 = std::make_shared<ov::op::v1::Transpose>(transpose2Param, transpose2Const);
|
||||
const auto matMul1 = std::make_shared<ngraph::opset3::MatMul>(softMax, transpose2, transA, transB);
|
||||
const auto matMul1 = std::make_shared<ov::op::v0::MatMul>(softMax, transpose2, transA, transB);
|
||||
const auto transpose3 = std::make_shared<ov::op::v1::Transpose>(matMul1, transpose3Const);
|
||||
|
||||
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(transpose3)};
|
||||
return std::make_shared<ngraph::Function>(results, ngraphParam, "mha");
|
||||
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose3)};
|
||||
return std::make_shared<ov::Model>(results, ngraphParam, "mha");
|
||||
}
|
||||
|
||||
class MHATest : public testing::WithParamInterface<MHATuple>,
|
||||
virtual public SubgraphBaseTest, public CPUTestsBase {
|
||||
class MHATest : public testing::WithParamInterface<MHATuple>, virtual public SubgraphBaseTest, public CPUTestsBase {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<MHATuple> &obj) {
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<MHATuple>& obj) {
|
||||
std::vector<InputShape> inputShapes;
|
||||
std::vector<ElementType> inputPrecisions;
|
||||
std::vector<ElementType> matMulIn0Precisions;
|
||||
@ -180,23 +173,31 @@ public:
|
||||
results << "patternType=" << patternType;
|
||||
results << "expect=";
|
||||
for (const auto& node : expectedNodes) {
|
||||
results << node.first << "[" << node.second << "]" << "_";
|
||||
results << node.first << "[" << node.second << "]"
|
||||
<< "_";
|
||||
}
|
||||
results << "targetDevice=" << targetName;
|
||||
|
||||
return results.str();
|
||||
}
|
||||
|
||||
void generate_inputs(const std::vector<ngraph::Shape>& targetInputStaticShapes) override {
|
||||
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
|
||||
inputs.clear();
|
||||
const auto& funcInputs = function->inputs();
|
||||
for (size_t i = 0; i < funcInputs.size(); ++i) {
|
||||
const auto& funcInput = funcInputs[i];
|
||||
ov::Tensor tensor;
|
||||
if (funcInput.get_element_type() == ov::element::bf16)
|
||||
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 2, -1, 256);
|
||||
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
|
||||
targetInputStaticShapes[i],
|
||||
2,
|
||||
-1,
|
||||
256);
|
||||
else
|
||||
tensor = ov::test::utils::create_and_fill_tensor_unique_sequence(funcInput.get_element_type(), targetInputStaticShapes[i], -1, 5);
|
||||
tensor = ov::test::utils::create_and_fill_tensor_unique_sequence(funcInput.get_element_type(),
|
||||
targetInputStaticShapes[i],
|
||||
-1,
|
||||
5);
|
||||
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
|
||||
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
|
||||
}
|
||||
@ -209,7 +210,8 @@ protected:
|
||||
std::vector<InputShape> inputShapes;
|
||||
std::vector<ElementType> inputPrecisions;
|
||||
std::vector<ElementType> matMulIn0Precisions;
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam();
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) =
|
||||
this->GetParam();
|
||||
|
||||
init_input_shapes(inputShapes);
|
||||
|
||||
@ -227,14 +229,14 @@ protected:
|
||||
abs_threshold = 0.1f;
|
||||
rel_threshold = 10.f;
|
||||
|
||||
configuration.insert({{ InferenceEngine::PluginConfigParams::KEY_ENFORCE_BF16, InferenceEngine::PluginConfigParams::YES }});
|
||||
configuration.insert({ov::hint::inference_precision(ov::element::bf16)});
|
||||
}
|
||||
|
||||
// Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on target machine.
|
||||
// Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all machines for validation.
|
||||
if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) {
|
||||
configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE,
|
||||
InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK});
|
||||
// Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on
|
||||
// target machine. Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all
|
||||
// machines for validation.
|
||||
if (!configuration.count("SNIPPETS_MODE")) {
|
||||
configuration.insert({"SNIPPETS_MODE", "IGNORE_CALLBACK"});
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -245,12 +247,13 @@ TEST_P(MHATest, CompareWithRefs) {
|
||||
std::vector<ElementType> matMulIn0Precisions;
|
||||
size_t patternType;
|
||||
ExpectedNodes expectedNodes;
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam();
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) =
|
||||
this->GetParam();
|
||||
|
||||
if (inputPrecisions[0] == ElementType::bf16 && !InferenceEngine::with_cpu_x86_bfloat16())
|
||||
if (inputPrecisions[0] == ElementType::bf16 && !ov::with_cpu_x86_bfloat16())
|
||||
GTEST_SKIP();
|
||||
|
||||
if (!InferenceEngine::with_cpu_x86_avx512_core())
|
||||
if (!ov::with_cpu_x86_avx512_core())
|
||||
GTEST_SKIP();
|
||||
|
||||
run();
|
||||
@ -262,61 +265,66 @@ TEST_P(MHATest, CompareWithRefs) {
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<std::vector<ngraph::Shape>> inputShapes = {
|
||||
std::vector<std::vector<ov::Shape>> inputShapes = {
|
||||
{{2, 8, 16, 64}, {2, 8, 16, 64}, {2, 1, 1, 8}, {2, 8, 16, 64}},
|
||||
{{1, 384, 16, 64}, {1, 384, 16, 64}, {1, 1, 1, 384}, {1, 384, 16, 64}},
|
||||
{{2, 64, 16, 80}, {2, 64, 16, 80}, {2, 1, 1, 64}, {2, 64, 16, 80}},
|
||||
{{3, 96, 16, 64}, {3, 96, 16, 64}, {3, 1, 1, 96}, {3, 96, 16, 64}},
|
||||
{{2, 192, 16, 160}, {2, 192, 16, 160}, {2, 1, 1, 192}, {2, 192, 16, 160}},
|
||||
{{2, 4, 16, 8}, {2, 4, 16, 8}, {2, 1, 1, 4}, {2, 4, 16, 8}},
|
||||
{{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}},
|
||||
{{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}},
|
||||
};
|
||||
|
||||
std::vector<std::vector<ElementType>> matMulIn0Precisions = {
|
||||
{},
|
||||
};
|
||||
|
||||
std::vector<size_t> patternTypes = {
|
||||
0, 1
|
||||
};
|
||||
std::vector<size_t> patternTypes = {0, 1};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHA, MHATest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)),
|
||||
::testing::Values(std::vector<ElementType>{ ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32 }),
|
||||
::testing::ValuesIn(matMulIn0Precisions),
|
||||
::testing::ValuesIn(patternTypes),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 1}}),
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHATest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHA_BF16, MHATest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)),
|
||||
::testing::Values(std::vector<ElementType>{ ElementType::bf16, ElementType::bf16, ElementType::bf16, ElementType::bf16 }),
|
||||
::testing::ValuesIn(matMulIn0Precisions),
|
||||
::testing::ValuesIn(patternTypes),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 1},
|
||||
{"Transpose", 1}}), // Plugin disables tokenization of Transpose on output
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHA,
|
||||
MHATest,
|
||||
::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)),
|
||||
::testing::Values(std::vector<ElementType>{ElementType::f32,
|
||||
ElementType::f32,
|
||||
ElementType::f32,
|
||||
ElementType::f32}),
|
||||
::testing::ValuesIn(matMulIn0Precisions),
|
||||
::testing::ValuesIn(patternTypes),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 1}}),
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHATest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_MHA_BF16,
|
||||
MHATest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)),
|
||||
::testing::Values(
|
||||
std::vector<ElementType>{ElementType::bf16, ElementType::bf16, ElementType::bf16, ElementType::bf16}),
|
||||
::testing::ValuesIn(matMulIn0Precisions),
|
||||
::testing::ValuesIn(patternTypes),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 1},
|
||||
{"Transpose", 1}}), // Plugin disables tokenization of Transpose on output
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHATest::getTestCaseName);
|
||||
|
||||
static std::shared_ptr<ov::Model> initMHAQuantSubgraph0(std::vector<ov::PartialShape>& inputDynamicShapes, std::vector<ElementType>& inputPrecisions,
|
||||
} // namespace
|
||||
|
||||
static std::shared_ptr<ov::Model> initMHAQuantSubgraph0(std::vector<ov::PartialShape>& inputDynamicShapes,
|
||||
std::vector<ElementType>& inputPrecisions,
|
||||
std::vector<ElementType>& matMulIn0Precisions) {
|
||||
ngraph::ParameterVector ngraphParam;
|
||||
ov::ParameterVector ngraphParam;
|
||||
|
||||
auto transpose0Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
auto transpose0Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
ngraphParam.push_back(transpose0Param);
|
||||
|
||||
auto transpose1Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
auto transpose1Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
ngraphParam.push_back(transpose1Param);
|
||||
|
||||
auto addParam = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
auto addParam = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
ngraphParam.push_back(addParam);
|
||||
|
||||
auto transpose2Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
auto transpose2Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
ngraphParam.push_back(transpose2Param);
|
||||
|
||||
std::vector<ov::Shape> constantShapes;
|
||||
@ -333,9 +341,10 @@ static std::shared_ptr<ov::Model> initMHAQuantSubgraph0(std::vector<ov::PartialS
|
||||
std::vector<int64_t> transpose1ConstData = {0, 2, 3, 1};
|
||||
auto transpose1Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[1], transpose1ConstData);
|
||||
|
||||
std::vector<int64_t> reshape0ConstData = {static_cast<int64_t>(inputDynamicShapes[0].get_shape()[0] *
|
||||
inputDynamicShapes[0].get_shape()[1] * inputDynamicShapes[0].get_shape()[2]),
|
||||
-1};
|
||||
std::vector<int64_t> reshape0ConstData = {
|
||||
static_cast<int64_t>(inputDynamicShapes[0].get_shape()[0] * inputDynamicShapes[0].get_shape()[1] *
|
||||
inputDynamicShapes[0].get_shape()[2]),
|
||||
-1};
|
||||
auto reshape0Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[2], reshape0ConstData);
|
||||
|
||||
std::vector<int64_t> reshape1ConstData = {static_cast<int64_t>(inputDynamicShapes[0].get_shape()[0]),
|
||||
@ -355,52 +364,96 @@ static std::shared_ptr<ov::Model> initMHAQuantSubgraph0(std::vector<ov::PartialS
|
||||
|
||||
std::shared_ptr<ov::Node> fakeQuantize0;
|
||||
if (matMulIn0Precisions[0] == ElementType::u8)
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f});
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param,
|
||||
inputPrecisions[0],
|
||||
256,
|
||||
{},
|
||||
{0.0f},
|
||||
{2.55f},
|
||||
{0.0f},
|
||||
{2.55f});
|
||||
else
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param,
|
||||
inputPrecisions[0],
|
||||
256,
|
||||
{},
|
||||
{-1.28f},
|
||||
{1.27f},
|
||||
{-1.28f},
|
||||
{1.27f});
|
||||
|
||||
const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1Param, inputPrecisions[1], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
const auto fakeQuantize2 = ngraph::builder::makeFakeQuantize(transpose2Param, inputPrecisions[3], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1Param,
|
||||
inputPrecisions[1],
|
||||
256,
|
||||
{},
|
||||
{-1.28f},
|
||||
{1.27f},
|
||||
{-1.28f},
|
||||
{1.27f});
|
||||
const auto fakeQuantize2 = ngraph::builder::makeFakeQuantize(transpose2Param,
|
||||
inputPrecisions[3],
|
||||
256,
|
||||
{},
|
||||
{-1.28f},
|
||||
{1.27f},
|
||||
{-1.28f},
|
||||
{1.27f});
|
||||
|
||||
std::shared_ptr<ov::Node> fakeQuantize4;
|
||||
|
||||
const auto transpose0 = std::make_shared<ov::op::v1::Transpose>(fakeQuantize0, transpose0Const);
|
||||
const auto transpose1 = std::make_shared<ov::op::v1::Transpose>(fakeQuantize1, transpose1Const);
|
||||
const auto matMul0 = std::make_shared<ngraph::opset3::MatMul>(transpose0, transpose1, transA, transB);
|
||||
const auto fakeQuantize3 = ngraph::builder::makeFakeQuantize(matMul0, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
const auto add = std::make_shared<ngraph::opset3::Add>(fakeQuantize3, addParam);
|
||||
const auto reshape0 = std::make_shared<ngraph::opset1::Reshape>(add, reshape0Const, true);
|
||||
const auto softMax = std::make_shared<ngraph::opset1::Softmax>(reshape0, 1);
|
||||
const auto reshape1 = std::make_shared<ngraph::opset1::Reshape>(softMax, reshape1Const, true);
|
||||
const auto matMul0 = std::make_shared<ov::op::v0::MatMul>(transpose0, transpose1, transA, transB);
|
||||
const auto fakeQuantize3 =
|
||||
ngraph::builder::makeFakeQuantize(matMul0, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
const auto add = std::make_shared<ov::op::v1::Add>(fakeQuantize3, addParam);
|
||||
const auto reshape0 = std::make_shared<ov::op::v1::Reshape>(add, reshape0Const, true);
|
||||
const auto softMax = std::make_shared<ov::op::v1::Softmax>(reshape0, 1);
|
||||
const auto reshape1 = std::make_shared<ov::op::v1::Reshape>(softMax, reshape1Const, true);
|
||||
if (matMulIn0Precisions[1] == ElementType::u8)
|
||||
fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, inputPrecisions[0], 256, {}, {0.0f}, {0.255f}, {0.0f}, {0.255f});
|
||||
fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1,
|
||||
inputPrecisions[0],
|
||||
256,
|
||||
{},
|
||||
{0.0f},
|
||||
{0.255f},
|
||||
{0.0f},
|
||||
{0.255f});
|
||||
else
|
||||
fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, inputPrecisions[0], 256, {}, {-0.128f}, {0.127f}, {-0.128f}, {0.127f});
|
||||
fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1,
|
||||
inputPrecisions[0],
|
||||
256,
|
||||
{},
|
||||
{-0.128f},
|
||||
{0.127f},
|
||||
{-0.128f},
|
||||
{0.127f});
|
||||
const auto transpose2 = std::make_shared<ov::op::v1::Transpose>(fakeQuantize2, transpose2Const);
|
||||
const auto matMul1 = std::make_shared<ngraph::opset3::MatMul>(fakeQuantize4, transpose2, transA, transB);
|
||||
const auto fakeQuantize5 = ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
const auto matMul1 = std::make_shared<ov::op::v0::MatMul>(fakeQuantize4, transpose2, transA, transB);
|
||||
const auto fakeQuantize5 =
|
||||
ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
const auto transpose3 = std::make_shared<ov::op::v1::Transpose>(fakeQuantize5, transpose3Const);
|
||||
|
||||
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(transpose3)};
|
||||
return std::make_shared<ngraph::Function>(results, ngraphParam, "mha");
|
||||
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose3)};
|
||||
return std::make_shared<ov::Model>(results, ngraphParam, "mha");
|
||||
}
|
||||
|
||||
static std::shared_ptr<ov::Model> initMHAQuantSubgraph1(const std::vector<ov::PartialShape>& inputDynamicShapes,
|
||||
const std::vector<ElementType>& inputPrecisions,
|
||||
const std::vector<ElementType>& matMulIn0Precisions,
|
||||
const bool fakeQuantize3Exists) {
|
||||
ngraph::ParameterVector ngraphParam;
|
||||
ov::ParameterVector ngraphParam;
|
||||
|
||||
auto transpose0Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
auto transpose0Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[0], inputDynamicShapes[0]);
|
||||
ngraphParam.push_back(transpose0Param);
|
||||
|
||||
auto transpose1Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
auto transpose1Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[1], inputDynamicShapes[1]);
|
||||
ngraphParam.push_back(transpose1Param);
|
||||
|
||||
auto addParam = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
auto addParam = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[2], inputDynamicShapes[2]);
|
||||
ngraphParam.push_back(addParam);
|
||||
|
||||
auto transpose2Param = std::make_shared<ngraph::opset1::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
auto transpose2Param = std::make_shared<ov::op::v0::Parameter>(inputPrecisions[3], inputDynamicShapes[3]);
|
||||
ngraphParam.push_back(transpose2Param);
|
||||
|
||||
std::vector<ov::Shape> constantShapes;
|
||||
@ -422,7 +475,7 @@ static std::shared_ptr<ov::Model> initMHAQuantSubgraph1(const std::vector<ov::Pa
|
||||
std::vector<int64_t> transpose3ConstData = {0, 2, 1, 3};
|
||||
auto transpose3Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[3], transpose3ConstData);
|
||||
|
||||
std::vector<float> mulConstData(ngraph::shape_size(constantShapes[4]));
|
||||
std::vector<float> mulConstData(ov::shape_size(constantShapes[4]));
|
||||
auto mulConst = ngraph::builder::makeConstant(inputPrecisions[0], constantShapes[4], mulConstData, true);
|
||||
|
||||
float transA = false;
|
||||
@ -430,33 +483,55 @@ static std::shared_ptr<ov::Model> initMHAQuantSubgraph1(const std::vector<ov::Pa
|
||||
|
||||
std::shared_ptr<ov::Node> fakeQuantize0;
|
||||
if (matMulIn0Precisions[0] == ElementType::u8)
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f});
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param,
|
||||
inputPrecisions[0],
|
||||
256,
|
||||
{},
|
||||
{0.0f},
|
||||
{2.55f},
|
||||
{0.0f},
|
||||
{2.55f});
|
||||
else
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param,
|
||||
inputPrecisions[0],
|
||||
256,
|
||||
{},
|
||||
{-1.28f},
|
||||
{1.27f},
|
||||
{-1.28f},
|
||||
{1.27f});
|
||||
|
||||
const auto transpose0 = std::make_shared<ov::op::v1::Transpose>(fakeQuantize0, transpose0Const);
|
||||
const auto transpose1 = std::make_shared<ov::op::v1::Transpose>(transpose1Param, transpose1Const);
|
||||
const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1, inputPrecisions[1], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
|
||||
const auto matMul0 = std::make_shared<ngraph::opset3::MatMul>(transpose0, fakeQuantize1, transA, transB);
|
||||
const auto mul = std::make_shared<ngraph::opset3::Multiply>(addParam, mulConst);
|
||||
const auto add = std::make_shared<ngraph::opset3::Add>(matMul0, mul);
|
||||
const auto softMax = std::make_shared<ngraph::opset1::Softmax>(add, 3);
|
||||
const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1,
|
||||
inputPrecisions[1],
|
||||
256,
|
||||
{},
|
||||
{-1.28f},
|
||||
{1.27f},
|
||||
{-1.28f},
|
||||
{1.27f});
|
||||
const auto matMul0 = std::make_shared<ov::op::v0::MatMul>(transpose0, fakeQuantize1, transA, transB);
|
||||
const auto mul = std::make_shared<ov::op::v1::Multiply>(addParam, mulConst);
|
||||
const auto add = std::make_shared<ov::op::v1::Add>(matMul0, mul);
|
||||
const auto softMax = std::make_shared<ov::op::v1::Softmax>(add, 3);
|
||||
const auto transpose2 = std::make_shared<ov::op::v1::Transpose>(transpose2Param, transpose2Const);
|
||||
const auto matMul1 = std::make_shared<ngraph::opset3::MatMul>(softMax, transpose2, transA, transB);
|
||||
const auto matMul1 = std::make_shared<ov::op::v0::MatMul>(softMax, transpose2, transA, transB);
|
||||
const auto transpose3 = std::make_shared<ov::op::v1::Transpose>(
|
||||
fakeQuantize3Exists ?
|
||||
ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, { 0.0f }, { 2.55f }, { 0.0f }, { 2.55f }) :
|
||||
matMul1,
|
||||
fakeQuantize3Exists
|
||||
? ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f})
|
||||
: matMul1,
|
||||
transpose3Const);
|
||||
|
||||
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(transpose3)};
|
||||
return std::make_shared<ngraph::Function>(results, ngraphParam, "mha");
|
||||
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose3)};
|
||||
return std::make_shared<ov::Model>(results, ngraphParam, "mha");
|
||||
}
|
||||
|
||||
class MHAQuantTest : public testing::WithParamInterface<MHATuple>,
|
||||
virtual public SubgraphBaseTest, public CPUTestsBase {
|
||||
virtual public SubgraphBaseTest,
|
||||
public CPUTestsBase {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<MHATuple> &obj) {
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<MHATuple>& obj) {
|
||||
std::vector<InputShape> inputShapes;
|
||||
std::vector<ElementType> inputPrecisions;
|
||||
std::vector<ElementType> matMulIn0Precisions;
|
||||
@ -485,24 +560,31 @@ public:
|
||||
results << "patternType=" << patternType;
|
||||
results << "expect=";
|
||||
for (const auto& node : expectedNodes) {
|
||||
results << node.first << "[" << node.second << "]" << "_";
|
||||
results << node.first << "[" << node.second << "]"
|
||||
<< "_";
|
||||
}
|
||||
results << "targetDevice=" << targetName;
|
||||
|
||||
return results.str();
|
||||
}
|
||||
|
||||
void generate_inputs(const std::vector<ngraph::Shape>& targetInputStaticShapes) override {
|
||||
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
|
||||
inputs.clear();
|
||||
const auto& funcInputs = function->inputs();
|
||||
for (size_t i = 0; i < funcInputs.size(); ++i) {
|
||||
const auto& funcInput = funcInputs[i];
|
||||
ov::Tensor tensor;
|
||||
if (funcInput.get_element_type().is_real())
|
||||
tensor = ov::test::utils::create_and_fill_tensor_normal_distribution(funcInput.get_element_type(), targetInputStaticShapes[i], 0.0f, 1.5f);
|
||||
tensor = ov::test::utils::create_and_fill_tensor_normal_distribution(funcInput.get_element_type(),
|
||||
targetInputStaticShapes[i],
|
||||
0.0f,
|
||||
1.5f);
|
||||
else
|
||||
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 255, 0, 1);
|
||||
|
||||
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
|
||||
targetInputStaticShapes[i],
|
||||
255,
|
||||
0,
|
||||
1);
|
||||
|
||||
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
|
||||
}
|
||||
@ -517,7 +599,8 @@ protected:
|
||||
std::vector<ElementType> matMulIn0Precisions;
|
||||
size_t patternType;
|
||||
ExpectedNodes expectedNodes;
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam();
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) =
|
||||
this->GetParam();
|
||||
|
||||
init_input_shapes(inputShapes);
|
||||
|
||||
@ -531,11 +614,11 @@ protected:
|
||||
FAIL() << "Unsupported MHA pattern type";
|
||||
}
|
||||
|
||||
// Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on target machine.
|
||||
// Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all machines for validation.
|
||||
if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) {
|
||||
configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE,
|
||||
InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK});
|
||||
// Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on
|
||||
// target machine. Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all
|
||||
// machines for validation.
|
||||
if (!configuration.count("SNIPPETS_MODE")) {
|
||||
configuration.insert({"SNIPPETS_MODE", "IGNORE_CALLBACK"});
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -546,12 +629,13 @@ TEST_P(MHAQuantTest, CompareWithRefs) {
|
||||
std::vector<ElementType> matMulIn0Precisions;
|
||||
size_t patternType;
|
||||
ExpectedNodes expectedNodes;
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam();
|
||||
std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) =
|
||||
this->GetParam();
|
||||
|
||||
if (inputPrecisions[0] == ElementType::bf16 && !InferenceEngine::with_cpu_x86_bfloat16())
|
||||
if (inputPrecisions[0] == ElementType::bf16 && !ov::with_cpu_x86_bfloat16())
|
||||
GTEST_SKIP();
|
||||
|
||||
if (!InferenceEngine::with_cpu_x86_avx512_core_vnni())
|
||||
if (!ov::with_cpu_x86_avx512_core_vnni())
|
||||
GTEST_SKIP();
|
||||
|
||||
run();
|
||||
@ -563,7 +647,7 @@ TEST_P(MHAQuantTest, CompareWithRefs) {
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<std::vector<ngraph::Shape>> inputShapesQuant = {
|
||||
std::vector<std::vector<ov::Shape>> inputShapesQuant = {
|
||||
{{2, 7, 16, 9}, {2, 7, 16, 9}, {2, 1, 1, 7}, {2, 7, 16, 9}},
|
||||
{{2, 8, 16, 64}, {2, 8, 16, 64}, {2, 1, 1, 8}, {2, 8, 16, 64}},
|
||||
{{1, 384, 16, 64}, {1, 384, 16, 64}, {1, 1, 1, 384}, {1, 384, 16, 64}},
|
||||
@ -571,52 +655,52 @@ std::vector<std::vector<ngraph::Shape>> inputShapesQuant = {
|
||||
{{3, 96, 16, 64}, {3, 96, 16, 64}, {3, 1, 1, 96}, {3, 96, 16, 64}},
|
||||
{{2, 192, 16, 160}, {2, 192, 16, 160}, {2, 1, 1, 192}, {2, 192, 16, 160}},
|
||||
{{2, 4, 16, 8}, {2, 4, 16, 8}, {2, 1, 1, 4}, {2, 4, 16, 8}},
|
||||
{{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}},
|
||||
{{1, 207, 13, 211}, {1, 207, 13, 211}, {1, 1, 1, 207}, {1, 207, 13, 211}},
|
||||
{{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}},
|
||||
{{1, 207, 13, 211}, {1, 207, 13, 211}, {1, 1, 1, 207}, {1, 207, 13, 211}},
|
||||
};
|
||||
|
||||
std::vector<std::vector<ElementType>> inputPrecisionsQuant = {
|
||||
{ ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32 },
|
||||
{ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32},
|
||||
};
|
||||
|
||||
std::vector<std::vector<ElementType>> matMulIn0PrecisionsQuant = {
|
||||
{ ElementType::i8, ElementType::i8 },
|
||||
{ ElementType::i8, ElementType::u8 },
|
||||
{ElementType::i8, ElementType::i8},
|
||||
{ElementType::i8, ElementType::u8},
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern0, MHAQuantTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)),
|
||||
::testing::ValuesIn(inputPrecisionsQuant),
|
||||
::testing::ValuesIn(matMulIn0PrecisionsQuant),
|
||||
::testing::Values(0),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 5}, // FQs on inputs x 3 + MHA + Deq Mul
|
||||
{"Transpose", 1}}), // Transpose between MHA and Deq Mul
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHAQuantTest::getTestCaseName);
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern0,
|
||||
MHAQuantTest,
|
||||
::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)),
|
||||
::testing::ValuesIn(inputPrecisionsQuant),
|
||||
::testing::ValuesIn(matMulIn0PrecisionsQuant),
|
||||
::testing::Values(0),
|
||||
::testing::Values(ExpectedNodes{
|
||||
{"Subgraph", 5}, // FQs on inputs x 3 + MHA + Deq Mul
|
||||
{"Transpose", 1}}), // Transpose between MHA and Deq Mul
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHAQuantTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern1,
|
||||
MHAQuantTest,
|
||||
::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)),
|
||||
::testing::ValuesIn(inputPrecisionsQuant),
|
||||
::testing::ValuesIn(matMulIn0PrecisionsQuant),
|
||||
::testing::Values(1),
|
||||
::testing::Values(ExpectedNodes{
|
||||
{"Subgraph", 3}, // FQ on input + MHA + Deq Mul
|
||||
{"Transpose", 1}}), // Transpose between MHA and Deq Mul
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHAQuantTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern1, MHAQuantTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)),
|
||||
::testing::ValuesIn(inputPrecisionsQuant),
|
||||
::testing::ValuesIn(matMulIn0PrecisionsQuant),
|
||||
::testing::Values(1),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 3}, // FQ on input + MHA + Deq Mul
|
||||
{"Transpose", 1}}), // Transpose between MHA and Deq Mul
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHAQuantTest::getTestCaseName);
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern2,
|
||||
MHAQuantTest,
|
||||
::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)),
|
||||
::testing::ValuesIn(inputPrecisionsQuant),
|
||||
::testing::ValuesIn(matMulIn0PrecisionsQuant),
|
||||
::testing::Values(2),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 2}, // MHA + Deq Mul
|
||||
{"Transpose", 0}}), // Transpose is fused
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHAQuantTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern2, MHAQuantTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)),
|
||||
::testing::ValuesIn(inputPrecisionsQuant),
|
||||
::testing::ValuesIn(matMulIn0PrecisionsQuant),
|
||||
::testing::Values(2),
|
||||
::testing::Values(ExpectedNodes{{"Subgraph", 2}, // MHA + Deq Mul
|
||||
{"Transpose", 0}}), // Transpose is fused
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
MHAQuantTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
} // namespace CPUSubgraphTestsDefinitions
|
||||
} // namespace
|
||||
|
@ -2,46 +2,37 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <debug.h>
|
||||
#include <shared_test_classes/base/ov_subgraph.hpp>
|
||||
#include <ov_models/builders.hpp>
|
||||
#include "common_test_utils/common_utils.hpp"
|
||||
#include <common_test_utils/ov_tensor_utils.hpp>
|
||||
#include "common_test_utils/ov_tensor_utils.hpp"
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
#include <openvino/opsets/opset1.hpp>
|
||||
#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp"
|
||||
|
||||
using namespace CPUTestUtils;
|
||||
using namespace ov::test;
|
||||
using namespace ngraph::helpers;
|
||||
|
||||
namespace CPUSubgraphTestsDefinitions {
|
||||
namespace ov {
|
||||
namespace test {
|
||||
|
||||
typedef std::tuple<
|
||||
std::vector<InputShape>,
|
||||
ElementType,
|
||||
ElementType,
|
||||
size_t
|
||||
> NgramTestParams;
|
||||
typedef std::tuple<std::vector<InputShape>, ElementType, ElementType, size_t> NgramTestParams;
|
||||
|
||||
static std::shared_ptr<ov::Node> getStridedSlice(const std::shared_ptr<ov::Node>& data,
|
||||
const std::shared_ptr<ov::Node>& begin,
|
||||
const std::shared_ptr<ov::Node>& end,
|
||||
const std::vector<int64_t>& shrink_axis_mask = {}) {
|
||||
std::vector<int64_t> default_mask(begin->get_shape()[0], 0);
|
||||
return std::make_shared<ov::opset1::StridedSlice>(data, begin, end, default_mask, default_mask,
|
||||
std::vector<int64_t>{}, shrink_axis_mask);
|
||||
return std::make_shared<ov::op::v1::StridedSlice>(data,
|
||||
begin,
|
||||
end,
|
||||
default_mask,
|
||||
default_mask,
|
||||
std::vector<int64_t>{},
|
||||
shrink_axis_mask);
|
||||
}
|
||||
|
||||
static std::shared_ptr<ov::Node> getReshape(const std::shared_ptr<ov::Node>& data,
|
||||
const std::vector<int64_t>& requested_shape,
|
||||
const ov::element::Type& prc) {
|
||||
auto requested_shape_node = ov::opset1::Constant::create(prc, {requested_shape.size()}, requested_shape);
|
||||
return std::make_shared<ov::opset1::Reshape>(data, requested_shape_node, true);
|
||||
auto requested_shape_node = ov::op::v0::Constant::create(prc, {requested_shape.size()}, requested_shape);
|
||||
return std::make_shared<ov::op::v1::Reshape>(data, requested_shape_node, true);
|
||||
}
|
||||
|
||||
static std::shared_ptr<ov::Model> initNgram(std::vector<ov::PartialShape>& input_shapes,
|
||||
@ -58,78 +49,80 @@ static std::shared_ptr<ov::Model> initNgram(std::vector<ov::PartialShape>& input
|
||||
auto param_node = std::make_shared<ov::op::v0::Parameter>(input_precisions[i], input_shapes[i]);
|
||||
params.push_back(param_node);
|
||||
}
|
||||
auto shape_of = std::make_shared<ov::opset10::ShapeOf>(params[0], idces_et);
|
||||
auto shape_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {0});
|
||||
auto shape_ss_end = ov::opset1::Constant::create(idces_et, {1}, {1});
|
||||
auto shape_of = std::make_shared<ov::op::v3::ShapeOf>(params[0], idces_et);
|
||||
auto shape_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {0});
|
||||
auto shape_ss_end = ov::op::v0::Constant::create(idces_et, {1}, {1});
|
||||
auto shape_ss = getStridedSlice(shape_of, shape_ss_begin, shape_ss_end, {1});
|
||||
|
||||
auto getInputsToPad = [&](const ov::Output<ov::Node> data, const int pad_value) {
|
||||
const size_t length = data.get_partial_shape()[1].get_length();
|
||||
ov::OutputVector inputs;
|
||||
if (left_pad > 0) {
|
||||
inputs.push_back(ov::opset1::Constant::create(data.get_element_type(), {left_pad, length}, {pad_value}));
|
||||
inputs.push_back(ov::op::v0::Constant::create(data.get_element_type(), {left_pad, length}, {pad_value}));
|
||||
}
|
||||
inputs.push_back(data);
|
||||
if (right_pad > 0) {
|
||||
inputs.push_back(ov::opset1::Constant::create(data.get_element_type(), {right_pad, length}, {pad_value}));
|
||||
inputs.push_back(ov::op::v0::Constant::create(data.get_element_type(), {right_pad, length}, {pad_value}));
|
||||
}
|
||||
return inputs;
|
||||
};
|
||||
|
||||
auto data_padded = std::make_shared<ov::opset1::Concat>(getInputsToPad(params[0], 0), 0);
|
||||
auto idces_padded = std::make_shared<ov::opset1::Concat>(getInputsToPad(params[1], -1), 0);
|
||||
auto data_padded = std::make_shared<ov::op::v0::Concat>(getInputsToPad(params[0], 0), 0);
|
||||
auto idces_padded = std::make_shared<ov::op::v0::Concat>(getInputsToPad(params[1], -1), 0);
|
||||
|
||||
std::shared_ptr<ov::Node> as_is_bias = shape_ss;
|
||||
if (mid_idx != 0) {
|
||||
auto bias_const = ov::opset1::Constant::create(idces_et, {}, {mid_idx});
|
||||
as_is_bias = std::make_shared<ov::opset1::Add>(shape_ss, bias_const);
|
||||
auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {mid_idx});
|
||||
as_is_bias = std::make_shared<ov::op::v1::Add>(shape_ss, bias_const);
|
||||
}
|
||||
auto as_is_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {mid_idx});
|
||||
auto as_is_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {mid_idx});
|
||||
auto as_is_ss_end = getReshape(as_is_bias, {1}, idces_et);
|
||||
auto as_is_ss = getStridedSlice(data_padded, as_is_ss_begin, as_is_ss_end);
|
||||
|
||||
auto getSelectBranch = [&](const size_t cur_idx, const size_t mid_idx) {
|
||||
std::shared_ptr<ov::Node> eq_left_bias = shape_ss;
|
||||
if (cur_idx != 0) {
|
||||
auto bias_const = ov::opset1::Constant::create(idces_et, {}, {cur_idx});
|
||||
eq_left_bias = std::make_shared<ov::opset1::Add>(shape_ss, bias_const);
|
||||
auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {cur_idx});
|
||||
eq_left_bias = std::make_shared<ov::op::v1::Add>(shape_ss, bias_const);
|
||||
}
|
||||
auto eq_left_reshape = getReshape(eq_left_bias, {1}, idces_et);
|
||||
auto eq_left_concat_const = ov::opset1::Constant::create(idces_et, {1}, {1});
|
||||
auto eq_left_concat = std::make_shared<ov::opset1::Concat>(ov::OutputVector{eq_left_reshape, eq_left_concat_const}, 0);
|
||||
auto eq_left_ss_begin = ov::opset1::Constant::create(idces_et, {2}, std::vector<size_t>{cur_idx, 0ul});
|
||||
auto eq_left_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {1});
|
||||
auto eq_left_concat =
|
||||
std::make_shared<ov::op::v0::Concat>(ov::OutputVector{eq_left_reshape, eq_left_concat_const}, 0);
|
||||
auto eq_left_ss_begin = ov::op::v0::Constant::create(idces_et, {2}, std::vector<size_t>{cur_idx, 0ul});
|
||||
auto eq_left_ss = getStridedSlice(idces_padded, eq_left_ss_begin, eq_left_concat, {0, 1});
|
||||
|
||||
std::shared_ptr<ov::Node> eq_right_bias = shape_ss;
|
||||
if (mid_idx != 0) {
|
||||
auto bias_const = ov::opset1::Constant::create(idces_et, {}, {mid_idx});
|
||||
eq_right_bias = std::make_shared<ov::opset1::Add>(shape_ss, bias_const);
|
||||
auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {mid_idx});
|
||||
eq_right_bias = std::make_shared<ov::op::v1::Add>(shape_ss, bias_const);
|
||||
}
|
||||
auto eq_right_reshape = getReshape(eq_right_bias, {1}, idces_et);
|
||||
auto eq_right_concat_const = ov::opset1::Constant::create(idces_et, {1}, {1});
|
||||
auto eq_right_concat = std::make_shared<ov::opset1::Concat>(ov::OutputVector{eq_right_reshape, eq_right_concat_const}, 0);
|
||||
auto eq_right_ss_begin = ov::opset1::Constant::create(idces_et, {2}, std::vector<size_t>{mid_idx, 0ul});
|
||||
auto eq_right_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {1});
|
||||
auto eq_right_concat =
|
||||
std::make_shared<ov::op::v0::Concat>(ov::OutputVector{eq_right_reshape, eq_right_concat_const}, 0);
|
||||
auto eq_right_ss_begin = ov::op::v0::Constant::create(idces_et, {2}, std::vector<size_t>{mid_idx, 0ul});
|
||||
auto eq_right_ss = getStridedSlice(idces_padded, eq_right_ss_begin, eq_right_concat, {0, 1});
|
||||
|
||||
auto equal = std::make_shared<ov::opset1::Equal>(eq_left_ss, eq_right_ss);
|
||||
auto equal = std::make_shared<ov::op::v1::Equal>(eq_left_ss, eq_right_ss);
|
||||
auto cond = getReshape(equal, {-1, 1}, idces_et);
|
||||
|
||||
std::shared_ptr<ov::Node> then_bias = shape_ss;
|
||||
if (cur_idx != 0) {
|
||||
auto bias_const = ov::opset1::Constant::create(idces_et, {}, {cur_idx});
|
||||
then_bias = std::make_shared<ov::opset1::Add>(shape_ss, bias_const);
|
||||
auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {cur_idx});
|
||||
then_bias = std::make_shared<ov::op::v1::Add>(shape_ss, bias_const);
|
||||
}
|
||||
auto then_reshape = getReshape(then_bias, {1}, idces_et);
|
||||
auto then_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {cur_idx});
|
||||
auto then_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {cur_idx});
|
||||
auto then = getStridedSlice(data_padded, then_ss_begin, then_reshape);
|
||||
|
||||
auto else_reshape = getReshape(shape_ss, {1}, idces_et);
|
||||
auto else_concat_const = ov::opset1::Constant::create(idces_et, {1}, {input_shapes[0][1].get_length()});
|
||||
auto else_concat = std::make_shared<ov::opset1::Concat>(ov::OutputVector{else_reshape, else_concat_const}, 0);
|
||||
auto else_bcast_const = ov::opset1::Constant::create(data_et, {}, {0});
|
||||
auto else_bcast = std::make_shared<ov::opset1::Broadcast>(else_bcast_const, else_concat);
|
||||
auto else_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {input_shapes[0][1].get_length()});
|
||||
auto else_concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{else_reshape, else_concat_const}, 0);
|
||||
auto else_bcast_const = ov::op::v0::Constant::create(data_et, {}, {0});
|
||||
auto else_bcast = std::make_shared<ov::op::v1::Broadcast>(else_bcast_const, else_concat);
|
||||
|
||||
auto select = std::make_shared<ov::opset1::Select>(cond, then, else_bcast);
|
||||
auto select = std::make_shared<ov::op::v1::Select>(cond, then, else_bcast);
|
||||
return select;
|
||||
};
|
||||
|
||||
@ -141,13 +134,15 @@ static std::shared_ptr<ov::Model> initNgram(std::vector<ov::PartialShape>& input
|
||||
concat_inputs[i] = getSelectBranch(i, mid_idx);
|
||||
}
|
||||
|
||||
auto final_concat = std::make_shared<ov::opset10::Concat>(concat_inputs, 1);
|
||||
auto final_concat = std::make_shared<ov::op::v0::Concat>(concat_inputs, 1);
|
||||
return std::make_shared<ov::Model>(final_concat, params, "ngram");
|
||||
}
|
||||
|
||||
class NgramCPUTest : public testing::WithParamInterface<NgramTestParams>, virtual public SubgraphBaseTest, public CPUTestsBase {
|
||||
class NgramCPUTest : public testing::WithParamInterface<NgramTestParams>,
|
||||
virtual public SubgraphBaseTest,
|
||||
public CPUTestsBase {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<NgramTestParams> &obj) {
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<NgramTestParams>& obj) {
|
||||
std::vector<InputShape> input_shapes;
|
||||
size_t k;
|
||||
ElementType data_et;
|
||||
@ -178,7 +173,6 @@ public:
|
||||
auto embeddings_tensor = ov::test::utils::create_and_fill_tensor_consistently(data_et, data_shape, 100, 1, 1);
|
||||
inputs.insert({model_inputs[0].get_node_shared_ptr(), embeddings_tensor});
|
||||
|
||||
|
||||
const auto& indices_et = model_inputs[1].get_element_type();
|
||||
const auto& indices_shape = targetInputStaticShapes[1];
|
||||
const size_t batch_size = data_shape[0];
|
||||
@ -207,9 +201,8 @@ protected:
|
||||
init_input_shapes(inputShapes);
|
||||
function = initNgram(inputDynamicShapes, data_et, idces_et, k);
|
||||
|
||||
if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) {
|
||||
configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE,
|
||||
InferenceEngine::PluginConfigInternalParams::DISABLE});
|
||||
if (!configuration.count("SNIPPETS_MODE")) {
|
||||
configuration.insert({"SNIPPETS_MODE", "DISABLE"});
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -222,28 +215,21 @@ TEST_P(NgramCPUTest, CompareWithRefs) {
|
||||
namespace {
|
||||
|
||||
std::vector<std::vector<InputShape>> inputShapes = {
|
||||
{
|
||||
InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}},
|
||||
InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}
|
||||
},
|
||||
{
|
||||
InputShape{{-1, 256}, {{12, 256}, {25, 256}}},
|
||||
InputShape{{-1, 2}, {{12, 2}, {25, 2}}}
|
||||
},
|
||||
{
|
||||
InputShape{{-1, 1}, {{12, 1}}},
|
||||
InputShape{{-1, 2}, {{12, 2}}}
|
||||
},
|
||||
{InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}, InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}},
|
||||
{InputShape{{-1, 256}, {{12, 256}, {25, 256}}}, InputShape{{-1, 2}, {{12, 2}, {25, 2}}}},
|
||||
{InputShape{{-1, 1}, {{12, 1}}}, InputShape{{-1, 2}, {{12, 2}}}},
|
||||
};
|
||||
|
||||
std::vector<size_t> k_values = {2, 3, 5, 7};
|
||||
std::vector<ElementType> idces_precisions = {ElementType::i32, ElementType::i64};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Ngram, NgramCPUTest,
|
||||
::testing::Combine(::testing::ValuesIn(inputShapes),
|
||||
::testing::Values(ElementType::f32),
|
||||
::testing::ValuesIn(idces_precisions),
|
||||
::testing::ValuesIn(k_values)),
|
||||
NgramCPUTest::getTestCaseName);
|
||||
} // namespace
|
||||
} // namespace CPUSubgraphTestsDefinitions
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Ngram,
|
||||
NgramCPUTest,
|
||||
::testing::Combine(::testing::ValuesIn(inputShapes),
|
||||
::testing::Values(ElementType::f32),
|
||||
::testing::ValuesIn(idces_precisions),
|
||||
::testing::ValuesIn(k_values)),
|
||||
NgramCPUTest::getTestCaseName);
|
||||
} // namespace
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
@ -6,10 +6,9 @@
|
||||
#include "shared_test_classes/subgraph/parameter_result.hpp"
|
||||
|
||||
using namespace SubgraphTestsDefinitions;
|
||||
using namespace ov::test;
|
||||
using namespace InferenceEngine;
|
||||
|
||||
namespace CPULayerTestsDefinitions {
|
||||
namespace ov {
|
||||
namespace test {
|
||||
|
||||
class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyApi {
|
||||
protected:
|
||||
@ -21,7 +20,7 @@ protected:
|
||||
auto inputBlob = inputs.front();
|
||||
const size_t elementsCount = inputBlob->size();
|
||||
for (size_t i = 0; i < inferIterations; ++i) {
|
||||
ov::test::utils::fill_data_random<Precision::FP32>(inputBlob, 10, 0, 1, i);
|
||||
ov::test::utils::fill_data_random<InferenceEngine::Precision::FP32>(inputBlob, 10, 0, 1, i);
|
||||
auto inputsInfo = cnnNetwork.getInputsInfo().begin()->second;
|
||||
std::string inputName = cnnNetwork.getInputsInfo().begin()->first;
|
||||
|
||||
@ -30,7 +29,7 @@ protected:
|
||||
std::copy(inpBlobData, inpBlobData + elementsCount, customInpData.begin());
|
||||
|
||||
auto& tensorDesc = inputsInfo->getTensorDesc();
|
||||
auto customBlob = make_shared_blob<float>(tensorDesc, customInpData.data(), elementsCount);
|
||||
auto customBlob = InferenceEngine::make_shared_blob<float>(tensorDesc, customInpData.data(), elementsCount);
|
||||
inferRequest.SetBlob(inputName, customBlob);
|
||||
|
||||
inferRequest.Infer();
|
||||
@ -46,8 +45,8 @@ protected:
|
||||
TEST_P(ParameterResultCustomBlobTest, CompareWithRefs) {
|
||||
// Just to show that it is not possible to set different precisions for inputs and outputs with the same name.
|
||||
// If it was possible, the input would have I8 precision and couldn't store data from the custom blob.
|
||||
inPrc = Precision::I8;
|
||||
outPrc = Precision::FP32;
|
||||
inPrc = InferenceEngine::Precision::I8;
|
||||
outPrc = InferenceEngine::Precision::FP32;
|
||||
|
||||
Run();
|
||||
}
|
||||
@ -84,4 +83,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_Check_Same_Blob,
|
||||
::testing::Values(ov::test::utils::DEVICE_CPU)),
|
||||
ParameterResultSubgraphTestBase::getTestCaseName);
|
||||
} // namespace
|
||||
} // namespace CPULayerTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
@ -2,24 +2,20 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "ov_models/builders.hpp"
|
||||
#include "ov_models/utils/ov_helpers.hpp"
|
||||
#include "shared_test_classes/base/layer_test_utils.hpp"
|
||||
#include "common_test_utils/node_builders/activation.hpp"
|
||||
#include "shared_test_classes/base/ov_subgraph.hpp"
|
||||
#include "test_utils/cpu_test_utils.hpp"
|
||||
#include "test_utils/fusing_test_utils.hpp"
|
||||
|
||||
using namespace ov::test;
|
||||
using namespace ngraph;
|
||||
using namespace CPUTestUtils;
|
||||
using namespace InferenceEngine;
|
||||
|
||||
namespace SubgraphTestsDefinitions {
|
||||
namespace ov {
|
||||
namespace test {
|
||||
using RemoveConvertCPUTestParams = std::tuple<ElementType, InputShape>;
|
||||
|
||||
class RemoveUselessBF16ConvertCPUTest : public testing::WithParamInterface<RemoveConvertCPUTestParams>,
|
||||
virtual public SubgraphBaseTest,
|
||||
public CPUTestsBase {
|
||||
virtual public SubgraphBaseTest,
|
||||
public CPUTestsBase {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<RemoveConvertCPUTestParams>& obj) {
|
||||
ElementType inType;
|
||||
@ -44,9 +40,9 @@ public:
|
||||
init_input_shapes({inputShape});
|
||||
auto input_params = std::make_shared<ov::op::v0::Parameter>(inType, inputShape.first);
|
||||
auto convert = std::make_shared<ov::op::v0::Convert>(input_params, element::f32);
|
||||
auto begin = builder::makeConstant(element::i64, ov::Shape{4}, std::vector<int64_t>{0, 0, 0, 0});
|
||||
auto end = builder::makeConstant(element::i64, ov::Shape{4}, std::vector<int64_t>{0, 0, 16, 0});
|
||||
auto stride = builder::makeConstant(element::i64, ov::Shape{4}, std::vector<int64_t>{1, 1, 1, 1});
|
||||
auto begin = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector<int64_t>{0, 0, 0, 0});
|
||||
auto end = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector<int64_t>{0, 0, 16, 0});
|
||||
auto stride = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector<int64_t>{1, 1, 1, 1});
|
||||
auto slice = std::make_shared<ov::op::v1::StridedSlice>(convert,
|
||||
begin,
|
||||
end,
|
||||
@ -84,17 +80,19 @@ public:
|
||||
init_input_shapes({inputShape});
|
||||
auto input_params = std::make_shared<ov::op::v0::Parameter>(inType, inputShape.first);
|
||||
|
||||
// Such complicated graph is necessary to cover the case when Convert has several children and connected to non zero output
|
||||
const auto split_axis = builder::makeConstant(element::i64, ov::Shape{}, std::vector<int64_t>{1});
|
||||
const auto split_lengths = builder::makeConstant(element::i64, ov::Shape{2}, std::vector<int64_t>{-1, 1});
|
||||
const auto split = std::make_shared<ov::opset10::VariadicSplit>(input_params, split_axis, split_lengths);
|
||||
// Such complicated graph is necessary to cover the case when Convert has several children and connected to non
|
||||
// zero output
|
||||
const auto split_axis = ngraph::builder::makeConstant(element::i64, ov::Shape{}, std::vector<int64_t>{1});
|
||||
const auto split_lengths =
|
||||
ngraph::builder::makeConstant(element::i64, ov::Shape{2}, std::vector<int64_t>{-1, 1});
|
||||
const auto split = std::make_shared<ov::op::v1::VariadicSplit>(input_params, split_axis, split_lengths);
|
||||
auto convert = std::make_shared<ov::op::v0::Convert>(split->output(1), inType);
|
||||
auto relu = builder::makeActivation(convert, inType, ::helpers::ActivationTypes::Relu);
|
||||
auto relu = ov::test::utils::make_activation(convert, inType, ov::test::utils::ActivationTypes::Relu);
|
||||
|
||||
ov::ResultVector results{
|
||||
std::make_shared<ov::opset10::Result>(split->output(0)),
|
||||
std::make_shared<ov::opset10::Result>(convert),
|
||||
std::make_shared<ov::opset10::Result>(relu),
|
||||
std::make_shared<ov::op::v0::Result>(split->output(0)),
|
||||
std::make_shared<ov::op::v0::Result>(convert),
|
||||
std::make_shared<ov::op::v0::Result>(relu),
|
||||
};
|
||||
|
||||
function = std::make_shared<ov::Model>(results, ov::ParameterVector{input_params}, "remove_convert");
|
||||
@ -131,4 +129,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_RemoveConvert,
|
||||
::testing::Combine(::testing::Values(ElementType::f32), ::testing::Values(inputShapes[0])),
|
||||
RemoveUselessConvertCPUTest::getTestCaseName);
|
||||
} // namespace
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
} // namespace test
|
||||
} // namespace ov
|
||||
|
Loading…
Reference in New Issue
Block a user