Remove legacy API from ov_cpu_unit_tests
(#21184)
* Remove `InferenceEngine` usage * Remove use of `ie_ngraph_utils.hpp` * Rename `ng_transormations` to `transformations` * Remove `ngraph` usage * Misprint
This commit is contained in:
parent
d9e04c3b9e
commit
b700040e29
@ -14,14 +14,14 @@ endif()
|
||||
|
||||
if(NOT (ARM OR AARCH64))
|
||||
list(APPEND EXCLUDED_SOURCE_PATHS_FOR_UNIT_TEST
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ngraph_transformations/arm)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/transformations/arm)
|
||||
endif()
|
||||
|
||||
if(NOT X86_64)
|
||||
list(APPEND EXCLUDED_SOURCE_PATHS_FOR_UNIT_TEST
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/jit_kernel_test.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/registers_pool.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ngraph_transformations/x64
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/transformations/x64
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/snippets_transformations
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/nodes/eltwise_node_test.cpp)
|
||||
endif()
|
||||
@ -93,7 +93,7 @@ if(ENABLE_FASTER_BUILD)
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES UNITY_BUILD ON UNITY_BUILD_MODE GROUP)
|
||||
group_source_file(unit_src_nodes ${CMAKE_CURRENT_SOURCE_DIR}/nodes)
|
||||
group_source_file(unit_src_snippets_transformations ${CMAKE_CURRENT_SOURCE_DIR}/snippets_transformations)
|
||||
group_source_file(unit_src_ngrah_transformation ${CMAKE_CURRENT_SOURCE_DIR}/ngraph_transformations)
|
||||
group_source_file(unit_src_transformations ${CMAKE_CURRENT_SOURCE_DIR}/transformations)
|
||||
group_source_file(unit_src_custom_shape_infer ${CMAKE_CURRENT_SOURCE_DIR}/shape_inference_test/custom_shape_infer)
|
||||
endif()
|
||||
|
||||
|
@ -17,10 +17,8 @@
|
||||
#include "cpu_tensor.h"
|
||||
#include "openvino/runtime/itensor.hpp"
|
||||
|
||||
#include "ie_ngraph_utils.hpp"
|
||||
|
||||
using namespace ov::intel_cpu;
|
||||
using namespace InferenceEngine;
|
||||
|
||||
using CPUTensorTest = ::testing::Test;
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "openvino/runtime/itensor.hpp"
|
||||
|
||||
using namespace ov::intel_cpu;
|
||||
using namespace InferenceEngine;
|
||||
|
||||
using CPUTensorExtTest = ::testing::Test;
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "memory_desc/dnnl_blocked_memory_desc.h"
|
||||
|
||||
using namespace ov::intel_cpu;
|
||||
using namespace InferenceEngine;
|
||||
using namespace testing;
|
||||
|
||||
TEST(MemDescTest, Conversion) {
|
||||
@ -46,7 +45,7 @@ TEST(MemDescTest, Conversion) {
|
||||
}
|
||||
|
||||
TEST(MemDescTest, UndefinedStateConversion) {
|
||||
ngraph::PartialShape ngraphUndefinedShape({{16}, {7, 15}, {-1, -1}, {3}});
|
||||
ov::PartialShape ngraphUndefinedShape({{16}, {7, 15}, {-1, -1}, {3}});
|
||||
Shape cpuShape(ngraphUndefinedShape);
|
||||
|
||||
const std::vector<dnnl::memory::format_tag> vecTags = {
|
||||
@ -220,7 +219,7 @@ TEST(MemDescTest, KeepOrder) {
|
||||
}
|
||||
|
||||
TEST(MemDescTest, UndefinedState) {
|
||||
ngraph::PartialShape ngraphShape({{16}, {-1, -1}, {20, 30}, {7}});
|
||||
ov::PartialShape ngraphShape({{16}, {-1, -1}, {20, 30}, {7}});
|
||||
ov::intel_cpu::Shape pluginShape(ngraphShape);
|
||||
DnnlBlockedMemoryDesc memDesc(pluginShape, dnnl::memory::data_type::f32, dnnl::memory::format_tag::nChw8c);
|
||||
|
||||
@ -261,7 +260,7 @@ TEST(MemDescTest, MemSize) {
|
||||
static const ov::element::Type iePrc = ov::element::f32;
|
||||
|
||||
|
||||
ngraph::PartialShape ngraphShapeUndef({{16}, {-1, -1}, {20, 30}, {7}});
|
||||
ov::PartialShape ngraphShapeUndef({{16}, {-1, -1}, {20, 30}, {7}});
|
||||
ov::intel_cpu::Shape pluginShapeUndef(ngraphShapeUndef);
|
||||
|
||||
auto creator = BlockedDescCreator::getCommonCreators().at(LayoutType::nspc);
|
||||
@ -275,7 +274,7 @@ TEST(MemDescTest, MemSize) {
|
||||
ASSERT_EQ(memDescUndef.getCurrentMemSize(), undefSize);
|
||||
ASSERT_EQ(memDescUndef.getMaxMemSize(), undefSize);
|
||||
|
||||
ngraph::PartialShape ngraphShapeDefUpperBound({{16}, {7, 14}, {20, 30}, {7}});
|
||||
ov::PartialShape ngraphShapeDefUpperBound({{16}, {7, 14}, {20, 30}, {7}});
|
||||
ov::intel_cpu::Shape pluginShapeDefUpperBound(ngraphShapeDefUpperBound);
|
||||
|
||||
auto blockedDescDefUpper = creator->createDesc(iePrc, pluginShapeDefUpperBound);
|
||||
@ -291,7 +290,7 @@ TEST(MemDescTest, MemSize) {
|
||||
ASSERT_EQ(memDescDefUpper.getCurrentMemSize(), undefSize);
|
||||
ASSERT_EQ(memDescDefUpper.getMaxMemSize(), maxElementsCount * DnnlExtensionUtils::sizeOfDataType(dnnlDataType));
|
||||
|
||||
ngraph::PartialShape ngraphShapeDefined({{16}, {16}, {10}, {7}});
|
||||
ov::PartialShape ngraphShapeDefined({{16}, {16}, {10}, {7}});
|
||||
ov::intel_cpu::Shape pluginShapeDefined(ngraphShapeDefined);
|
||||
|
||||
auto blockedDescDefined = creator->createDesc(iePrc, pluginShapeDefined);
|
||||
@ -317,10 +316,10 @@ TEST(MakeUndefinedDnnlDesc, checkRank) {
|
||||
const memory::data_type dataType = memory::data_type::u8;
|
||||
const memory::desc origin({10, 20, 15, 7}, dataType, memory::format_tag::nChw16c);
|
||||
|
||||
ov::intel_cpu::Shape pluginShapeWrongRank(ngraph::PartialShape{{-1, -1}, {-1, -1}, {-1, -1}});
|
||||
ov::intel_cpu::Shape pluginShapeWrongRank(ov::PartialShape{{-1, -1}, {-1, -1}, {-1, -1}});
|
||||
ASSERT_THROW(DnnlExtensionUtils::makeUndefinedDesc(origin, pluginShapeWrongRank), ov::Exception);
|
||||
|
||||
ov::intel_cpu::Shape pluginShapeRightRank(ngraph::PartialShape{{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
ov::intel_cpu::Shape pluginShapeRightRank(ov::PartialShape{{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
MemoryDescPtr memDesc;
|
||||
ASSERT_NO_THROW(memDesc = DnnlExtensionUtils::makeUndefinedDesc(origin, pluginShapeRightRank));
|
||||
ASSERT_FALSE(memDesc->isDefined());
|
||||
@ -331,7 +330,7 @@ TEST(MakeUndefinedDnnlDesc, checkDims) {
|
||||
const memory::data_type dataType = memory::data_type::u8;
|
||||
const memory::desc origin({10, 20, 15, 7}, dataType, memory::format_tag::nChw16c);
|
||||
|
||||
ngraph::PartialShape fullyUndef({{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
ov::PartialShape fullyUndef({{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
for (size_t i = 0; i < fullyUndef.size(); ++i) {
|
||||
auto partialShape = fullyUndef;
|
||||
partialShape[i] = {3}; // just a number which is not equal to any origin dims
|
||||
@ -362,7 +361,7 @@ TEST(MakeUndefinedDnnlDesc, checkLayout) {
|
||||
payloadArgs{ memory::format_tag::BAcd16a16b, {17, 2, 10, 7 }, "BAcd16a16b" }, // blocked and permuted outer dims
|
||||
};
|
||||
|
||||
ngraph::PartialShape fullyUndef({{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
ov::PartialShape fullyUndef({{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
|
||||
for (const auto& item : payload) {
|
||||
dnnl::memory::format_tag fmt;
|
||||
@ -396,7 +395,7 @@ TEST(MakeUndefinedDnnlDesc, extraData) {
|
||||
payloadArgs{ memory::format_tag::BAcd16a16b, {17, 2, 10, 7 } }, // blocked and permuted outer dims
|
||||
};
|
||||
|
||||
ngraph::PartialShape fullyUndef({{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
ov::PartialShape fullyUndef({{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}});
|
||||
|
||||
for (const auto& item : payload) {
|
||||
dnnl::memory::format_tag fmt;
|
||||
@ -435,7 +434,7 @@ TEST(isSameMethodTest, CheckTensorWithSameStrides) {
|
||||
}
|
||||
|
||||
TEST(makeDummyDesc, LowerBoundMoreThanDummyValue) {
|
||||
Shape shape(ngraph::PartialShape{1, 3, 85, {144, 1444}});
|
||||
Shape shape(ov::PartialShape{1, 3, 85, {144, 1444}});
|
||||
auto desc = std::make_shared<DnnlBlockedMemoryDesc>(shape, dnnl::memory::data_type::f32, dnnl::memory::format_tag::nchw);
|
||||
ASSERT_FALSE(desc->isDefined());
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <condition_variable>
|
||||
|
||||
using namespace ov::intel_cpu;
|
||||
using namespace InferenceEngine;
|
||||
|
||||
TEST(MemoryTest, SedDataCheck) {
|
||||
GTEST_SKIP();
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "memory_desc/dnnl_blocked_memory_desc.h"
|
||||
|
||||
using namespace ov::intel_cpu;
|
||||
using namespace InferenceEngine;
|
||||
using namespace testing;
|
||||
|
||||
/* ======================================= BASE ZERO DIM TEST ======================================= */
|
||||
@ -28,13 +27,13 @@ protected:
|
||||
{
|
||||
auto origShape = shape.toPartialShape();
|
||||
auto replaceShape = origShape;
|
||||
std::replace(replaceShape.begin(), replaceShape.end(), ngraph::Dimension(0), ngraph::Dimension(3));
|
||||
std::replace(replaceShape.begin(), replaceShape.end(), ov::Dimension(0), ov::Dimension(3));
|
||||
Shape dummyShape(replaceShape);
|
||||
DnnlBlockedMemoryDesc dummyDesc(dummyShape, DnnlExtensionUtils::ElementTypeToDataType(precision), fmt);
|
||||
expectedBlkDims = dummyDesc.getBlockDims();
|
||||
expectedOrder = dummyDesc.getOrder();
|
||||
for (size_t i = 0; i < dummyShape.getRank(); i++) {
|
||||
if (origShape[expectedOrder[i]] == ngraph::Dimension(0)) {
|
||||
if (origShape[expectedOrder[i]] == ov::Dimension(0)) {
|
||||
expectedBlkDims[i] = 0;
|
||||
}
|
||||
}
|
||||
@ -95,16 +94,16 @@ const std::vector<Shape> staticShapes = {
|
||||
};
|
||||
|
||||
const std::vector<Shape> dynamicShapes = {
|
||||
Shape(ngraph::PartialShape{0, -1, {0, 48}, -1}),
|
||||
Shape(ngraph::PartialShape{16, 0, -1, {0, 64}}),
|
||||
Shape(ngraph::PartialShape{-1, -1, 0, -1}),
|
||||
Shape(ngraph::PartialShape{{0, 16}, -1, {0, 48}, 0}),
|
||||
Shape(ngraph::PartialShape{-1, 32, 0, 0}),
|
||||
Shape(ngraph::PartialShape{0, 0, 48, -1}),
|
||||
Shape(ngraph::PartialShape{{0, 16}, 0, 0, 64}),
|
||||
Shape(ngraph::PartialShape{0, 0, 0, -1}),
|
||||
Shape(ngraph::PartialShape{{0, 16}, 0, 0, 0}),
|
||||
Shape(ngraph::PartialShape{0, 0, 0, 0})
|
||||
Shape(ov::PartialShape{0, -1, {0, 48}, -1}),
|
||||
Shape(ov::PartialShape{16, 0, -1, {0, 64}}),
|
||||
Shape(ov::PartialShape{-1, -1, 0, -1}),
|
||||
Shape(ov::PartialShape{{0, 16}, -1, {0, 48}, 0}),
|
||||
Shape(ov::PartialShape{-1, 32, 0, 0}),
|
||||
Shape(ov::PartialShape{0, 0, 48, -1}),
|
||||
Shape(ov::PartialShape{{0, 16}, 0, 0, 64}),
|
||||
Shape(ov::PartialShape{0, 0, 0, -1}),
|
||||
Shape(ov::PartialShape{{0, 16}, 0, 0, 0}),
|
||||
Shape(ov::PartialShape{0, 0, 0, 0})
|
||||
};
|
||||
|
||||
const std::vector<dnnl::memory::format_tag> fmts = {
|
||||
@ -229,8 +228,8 @@ TEST_P(MemDescWithZeroDimsCloneNewDimsTest, CloneWithNewDims) {
|
||||
}
|
||||
|
||||
const std::vector<Shape> srcDynShapes = {
|
||||
Shape(ngraph::PartialShape({-1, -1, -1, -1})),
|
||||
Shape(ngraph::PartialShape({{0, 16}, {0, 32}, {0, 48}, {0, 64}}))
|
||||
Shape(ov::PartialShape({-1, -1, -1, -1})),
|
||||
Shape(ov::PartialShape({{0, 16}, {0, 32}, {0, 48}, {0, 64}}))
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_MemDescWithZeroDimsCloneNewDimsTest, MemDescWithZeroDimsCloneNewDimsTest,
|
||||
|
@ -13,31 +13,21 @@
|
||||
#include <array>
|
||||
|
||||
#include <snippets/generator.hpp>
|
||||
|
||||
#include <ngraph/function.hpp>
|
||||
|
||||
#include <ngraph/opsets/opset1.hpp>
|
||||
#include <ngraph/opsets/opset2.hpp>
|
||||
|
||||
#include <ngraph/pass/constant_folding.hpp>
|
||||
#include <ngraph/pass/visualize_tree.hpp>
|
||||
|
||||
#include <snippets/op/subgraph.hpp>
|
||||
|
||||
#include <transformations/init_node_info.hpp>
|
||||
#include <transformations/utils/utils.hpp>
|
||||
#include <openvino/core/model.hpp>
|
||||
|
||||
#include <ov_models/utils/ov_helpers.hpp>
|
||||
|
||||
using namespace testing;
|
||||
|
||||
inline auto gen_inputs(const ngraph::Shape& shape, size_t n = 2) -> std::vector<std::vector<std::uint8_t>> {
|
||||
inline auto gen_inputs(const ov::Shape& shape, size_t n = 2) -> std::vector<std::vector<std::uint8_t>> {
|
||||
std::vector<std::vector<std::uint8_t>> referenceInputs(n);
|
||||
for (size_t k = 0; k < n; k++) {
|
||||
referenceInputs[k].resize(ngraph::shape_size(shape)*sizeof(float));
|
||||
referenceInputs[k].resize(ov::shape_size(shape)*sizeof(float));
|
||||
float* in0 = reinterpret_cast<float*>(&referenceInputs[k][0]);
|
||||
|
||||
for (size_t i = 0; i < ngraph::shape_size(shape); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shape); i++) {
|
||||
if (k % 3 == 0) {
|
||||
in0[i] = i / 2048.f;
|
||||
} else if (k % 3 == 1) {
|
||||
@ -50,7 +40,7 @@ inline auto gen_inputs(const ngraph::Shape& shape, size_t n = 2) -> std::vector<
|
||||
return referenceInputs;
|
||||
}
|
||||
|
||||
inline auto compare(std::shared_ptr<ngraph::Function>& s, std::shared_ptr<ngraph::Function>& f, std::vector<std::vector<std::uint8_t>>& in) -> bool{
|
||||
inline auto compare(std::shared_ptr<ov::Model>& s, std::shared_ptr<ov::Model>& f, std::vector<std::vector<std::uint8_t>>& in) -> bool{
|
||||
auto act = ngraph::helpers::interpreterFunction(s, in);
|
||||
auto exp = ngraph::helpers::interpreterFunction(f, in);
|
||||
|
||||
@ -58,7 +48,7 @@ inline auto compare(std::shared_ptr<ngraph::Function>& s, std::shared_ptr<ngraph
|
||||
const float* pact = reinterpret_cast<float*>(&act[0].second[0]);
|
||||
|
||||
bool isCorrect = true;
|
||||
for (size_t i = 0; i < ngraph::shape_size(f->get_result()->get_shape()); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(f->get_result()->get_shape()); i++) {
|
||||
if (std::abs(pexp[i]-pact[i]) > std::numeric_limits<float>::epsilon()
|
||||
|| std::isnan(pexp[i]) != std::isnan(pact[i])) {
|
||||
isCorrect = false;
|
||||
@ -68,20 +58,20 @@ inline auto compare(std::shared_ptr<ngraph::Function>& s, std::shared_ptr<ngraph
|
||||
return isCorrect;
|
||||
}
|
||||
|
||||
inline auto wrapAsSnippet(std::shared_ptr<ngraph::Function>& f,
|
||||
const ngraph::Shape& shape0,
|
||||
const ngraph::Shape& shape1) -> std::shared_ptr<ngraph::Function> {
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input0, input1}, ngraph::clone_function(*f.get()));
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input0, input1});
|
||||
inline auto wrapAsSnippet(std::shared_ptr<ov::Model>& f,
|
||||
const ov::Shape& shape0,
|
||||
const ov::Shape& shape1) -> std::shared_ptr<ov::Model> {
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input0, input1}, f->clone());
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input0, input1});
|
||||
}
|
||||
|
||||
inline auto wrapAsSnippet(std::shared_ptr<ngraph::Function>& f, const ngraph::Shape& shape0)
|
||||
-> std::shared_ptr<ngraph::Function> {
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape0);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input0}, ngraph::clone_function(*f.get()));
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input0});
|
||||
inline auto wrapAsSnippet(std::shared_ptr<ov::Model>& f, const ov::Shape& shape0)
|
||||
-> std::shared_ptr<ov::Model> {
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape0);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input0}, f->clone());
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input0});
|
||||
}
|
||||
|
||||
// Todo: Reimplement Snippets tests, so they won't require evaluate method for OP Subgraph
|
||||
@ -89,14 +79,14 @@ inline auto wrapAsSnippet(std::shared_ptr<ngraph::Function>& f, const ngraph::Sh
|
||||
// depend on the snippets lib in this (which is not allowed).
|
||||
TEST(SnippetsTests, GenerateAddParams) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto f = ([] (const ov::Shape& shape) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{add}, ngraph::ParameterVector{input0, input1});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{add}, ov::ParameterVector{input0, input1});
|
||||
})(shape);
|
||||
|
||||
auto s = wrapAsSnippet(f, shape, shape);
|
||||
@ -107,19 +97,19 @@ TEST(SnippetsTests, GenerateAddParams) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddConstant) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto f = ([] (const ov::Shape& shape) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
|
||||
std::vector<float> vals(ngraph::shape_size(shape));
|
||||
for (size_t i = 0; i < ngraph::shape_size(shape); i++) {
|
||||
std::vector<float> vals(ov::shape_size(shape));
|
||||
for (size_t i = 0; i < ov::shape_size(shape); i++) {
|
||||
vals[i] = 1-i/2048.f;
|
||||
}
|
||||
auto input1 = std::make_shared<ngraph::opset1::Constant>(ngraph::element::f32, shape, vals);
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto input1 = std::make_shared<ov::opset1::Constant>(ov::element::f32, shape, vals);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{add}, ngraph::ParameterVector{input0});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{add}, ov::ParameterVector{input0});
|
||||
})(shape);
|
||||
|
||||
auto s = wrapAsSnippet(f, shape);
|
||||
@ -130,14 +120,14 @@ TEST(SnippetsTests, GenerateAddConstant) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddConstantScalar) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Constant>(ngraph::element::f32, ngraph::Shape{1}, std::vector<float>({42.f}));
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto f = ([] (const ov::Shape& shape) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input1 = std::make_shared<ov::opset1::Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>({42.f}));
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{add}, ngraph::ParameterVector{input0});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{add}, ov::ParameterVector{input0});
|
||||
})(shape);
|
||||
|
||||
auto s = wrapAsSnippet(f, shape);
|
||||
@ -148,14 +138,14 @@ TEST(SnippetsTests, GenerateAddConstantScalar) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddConstantScalarEmptySize) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Constant>(ngraph::element::f32, ngraph::Shape(), std::vector<float>({42.f}));
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto f = ([] (const ov::Shape& shape) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input1 = std::make_shared<ov::opset1::Constant>(ov::element::f32, ov::Shape(), std::vector<float>({42.f}));
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{add}, ngraph::ParameterVector{input0});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{add}, ov::ParameterVector{input0});
|
||||
})(shape);
|
||||
|
||||
auto s = wrapAsSnippet(f, shape);
|
||||
@ -166,39 +156,39 @@ TEST(SnippetsTests, GenerateAddConstantScalarEmptySize) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddBroadcastX2Edges) {
|
||||
GTEST_SKIP();
|
||||
auto shape0 = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape1 = ngraph::Shape{1, 4, 16, 1};
|
||||
auto shape0 = ov::Shape{1, 4, 16, 31};
|
||||
auto shape1 = ov::Shape{1, 4, 16, 1};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape0, const ngraph::Shape& shape1) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto input2 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto f = ([] (const ov::Shape& shape0, const ov::Shape& shape1) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
auto input2 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto mul = std::make_shared<ngraph::opset1::Add>(input1, input2);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
auto mul = std::make_shared<ov::opset1::Add>(input1, input2);
|
||||
|
||||
auto sub = std::make_shared<ngraph::opset1::Add>(add, mul);
|
||||
auto sub = std::make_shared<ov::opset1::Add>(add, mul);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{sub}, ngraph::ParameterVector{input0, input1, input2});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{sub}, ov::ParameterVector{input0, input1, input2});
|
||||
})(shape0, shape1);
|
||||
|
||||
auto s = ([f] (const ngraph::Shape& shape0, const ngraph::Shape& shape1) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input2 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape0);
|
||||
auto input3 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto input4 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input2, input3, input4}, ngraph::clone_function(*f.get()));
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input2, input3, input4});
|
||||
auto s = ([f] (const ov::Shape& shape0, const ov::Shape& shape1) -> std::shared_ptr<ov::Model>{
|
||||
auto input2 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape0);
|
||||
auto input3 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
auto input4 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input2, input3, input4}, f->clone());
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input2, input3, input4});
|
||||
})(shape0, shape1);
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> referenceInputs(3);
|
||||
referenceInputs[0].resize(ngraph::shape_size(shape0)*sizeof(float));
|
||||
referenceInputs[1].resize(ngraph::shape_size(shape1)*sizeof(float));
|
||||
referenceInputs[2].resize(ngraph::shape_size(shape1)*sizeof(float));
|
||||
referenceInputs[0].resize(ov::shape_size(shape0)*sizeof(float));
|
||||
referenceInputs[1].resize(ov::shape_size(shape1)*sizeof(float));
|
||||
referenceInputs[2].resize(ov::shape_size(shape1)*sizeof(float));
|
||||
|
||||
float* in0 = reinterpret_cast<float*>(&referenceInputs[0][0]);
|
||||
float* in1 = reinterpret_cast<float*>(&referenceInputs[1][0]);
|
||||
float* in2 = reinterpret_cast<float*>(&referenceInputs[2][0]);
|
||||
for (size_t i = 0; i < ngraph::shape_size(shape0); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shape0); i++) {
|
||||
in0[i] = i/2048.f;
|
||||
}
|
||||
|
||||
@ -212,7 +202,7 @@ TEST(SnippetsTests, GenerateAddBroadcastX2Edges) {
|
||||
const float* pact = reinterpret_cast<float*>(&act[0].second[0]);
|
||||
|
||||
bool isCorrect = true;
|
||||
for (size_t i = 0; i < ngraph::shape_size(shape0); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shape0); i++) {
|
||||
if (pexp[i] != pact[i]) {
|
||||
isCorrect = false;
|
||||
std::cout << i << " expected " << pexp[i] << " actual " << pact[i] << std::endl;
|
||||
@ -224,29 +214,29 @@ TEST(SnippetsTests, GenerateAddBroadcastX2Edges) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddBroadcastY) {
|
||||
GTEST_SKIP();
|
||||
auto shape0 = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape1 = ngraph::Shape{1, 4, 1, 31};
|
||||
auto shape0 = ov::Shape{1, 4, 16, 31};
|
||||
auto shape1 = ov::Shape{1, 4, 1, 31};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape0, const ngraph::Shape& shape1) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto f = ([] (const ov::Shape& shape0, const ov::Shape& shape1) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{add}, ngraph::ParameterVector{input0, input1});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{add}, ov::ParameterVector{input0, input1});
|
||||
})(shape0, shape1);
|
||||
|
||||
auto s = wrapAsSnippet(f, shape0, shape1);
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> referenceInputs(2);
|
||||
referenceInputs[0].resize(ngraph::shape_size(shape0)*sizeof(float));
|
||||
referenceInputs[1].resize(ngraph::shape_size(shape1)*sizeof(float));
|
||||
referenceInputs[0].resize(ov::shape_size(shape0)*sizeof(float));
|
||||
referenceInputs[1].resize(ov::shape_size(shape1)*sizeof(float));
|
||||
|
||||
float* in0 = reinterpret_cast<float*>(&referenceInputs[0][0]);
|
||||
float* in1 = reinterpret_cast<float*>(&referenceInputs[1][0]);
|
||||
for (size_t i = 0; i < ngraph::shape_size(shape0); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shape0); i++) {
|
||||
in0[i] = i / 2048.f;
|
||||
}
|
||||
for (size_t i = 0; i < ngraph::shape_size(shape1); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shape1); i++) {
|
||||
in1[i] = 1 - i / 2048.f;
|
||||
}
|
||||
|
||||
@ -257,7 +247,7 @@ TEST(SnippetsTests, GenerateAddBroadcastY) {
|
||||
const float* pact = reinterpret_cast<float*>(&act[0].second[0]);
|
||||
|
||||
bool isCorrect = true;
|
||||
for (size_t i = 0; i < ngraph::shape_size(shape0); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shape0); i++) {
|
||||
if (pexp[i] != pact[i]) {
|
||||
isCorrect = false;
|
||||
std::cout << i << " expected " << pexp[i] << " actual " << pact[i] << std::endl;
|
||||
@ -269,22 +259,22 @@ TEST(SnippetsTests, GenerateAddBroadcastY) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddNegate) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto nagate = std::make_shared<ngraph::opset1::Negative>(add);
|
||||
auto f = ([] (const ov::Shape& shape) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
auto nagate = std::make_shared<ov::opset1::Negative>(add);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{nagate}, ngraph::ParameterVector{input0, input1});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{nagate}, ov::ParameterVector{input0, input1});
|
||||
})(shape);
|
||||
|
||||
auto s = ([f] (const ngraph::Shape& shape) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input2 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input3 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input2, input3}, ngraph::clone_function(*f.get()));
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input2, input3});
|
||||
auto s = ([f] (const ov::Shape& shape) -> std::shared_ptr<ov::Model>{
|
||||
auto input2 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input3 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input2, input3}, f->clone());
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input2, input3});
|
||||
})(shape);
|
||||
|
||||
auto referenceInputs = gen_inputs(shape, 2);
|
||||
@ -295,20 +285,20 @@ TEST(SnippetsTests, GenerateAddNegate) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddNegateAdd) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input2 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input1, input2);
|
||||
auto nagate = std::make_shared<ngraph::opset1::Negative>(add);
|
||||
auto input3 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto add2 = std::make_shared<ngraph::opset1::Add>(nagate, input3);
|
||||
std::shared_ptr<ngraph::Function> f = std::make_shared<ngraph::Function>(ngraph::NodeVector{add2}, ngraph::ParameterVector{input1, input2, input3});
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input2 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input1, input2);
|
||||
auto nagate = std::make_shared<ov::opset1::Negative>(add);
|
||||
auto input3 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto add2 = std::make_shared<ov::opset1::Add>(nagate, input3);
|
||||
std::shared_ptr<ov::Model> f = std::make_shared<ov::Model>(ov::NodeVector{add2}, ov::ParameterVector{input1, input2, input3});
|
||||
|
||||
auto input11 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input21 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input31 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input11, input21, input31}, ngraph::clone_function(*f.get()));
|
||||
std::shared_ptr<ngraph::Function> s = std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input11, input21, input31});
|
||||
auto input11 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input21 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input31 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input11, input21, input31}, f->clone());
|
||||
std::shared_ptr<ov::Model> s = std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input11, input21, input31});
|
||||
|
||||
auto referenceInputs = gen_inputs(shape, 3);
|
||||
bool isCorrect = compare(s, f, referenceInputs);
|
||||
@ -318,13 +308,13 @@ TEST(SnippetsTests, GenerateAddNegateAdd) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddNegateAddMultiEdge) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input2 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input1, input2);
|
||||
auto nagate = std::make_shared<ngraph::opset1::Negative>(add);
|
||||
auto add2 = std::make_shared<ngraph::opset1::Add>(nagate, input1);
|
||||
std::shared_ptr<ngraph::Function> f = std::make_shared<ngraph::Function>(ngraph::NodeVector{add2}, ngraph::ParameterVector{input1, input2});
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input2 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input1, input2);
|
||||
auto nagate = std::make_shared<ov::opset1::Negative>(add);
|
||||
auto add2 = std::make_shared<ov::opset1::Add>(nagate, input1);
|
||||
std::shared_ptr<ov::Model> f = std::make_shared<ov::Model>(ov::NodeVector{add2}, ov::ParameterVector{input1, input2});
|
||||
|
||||
auto s = wrapAsSnippet(f, shape, shape);
|
||||
auto referenceInputs = gen_inputs(shape, 2);
|
||||
@ -335,17 +325,17 @@ TEST(SnippetsTests, GenerateAddNegateAddMultiEdge) {
|
||||
|
||||
TEST(SnippetsTests, GenerateAddNegateAddMultiEdgeConst) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto input2 = ngraph::op::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.42});
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input1, input2);
|
||||
auto nagate = std::make_shared<ngraph::opset1::Negative>(add);
|
||||
auto add2 = std::make_shared<ngraph::opset1::Add>(nagate, input1);
|
||||
std::shared_ptr<ngraph::Function> f = std::make_shared<ngraph::Function>(ngraph::NodeVector{add2}, ngraph::ParameterVector{input1});
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto input2 = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{}, {0.42});
|
||||
auto add = std::make_shared<ov::opset1::Add>(input1, input2);
|
||||
auto nagate = std::make_shared<ov::opset1::Negative>(add);
|
||||
auto add2 = std::make_shared<ov::opset1::Add>(nagate, input1);
|
||||
std::shared_ptr<ov::Model> f = std::make_shared<ov::Model>(ov::NodeVector{add2}, ov::ParameterVector{input1});
|
||||
|
||||
auto input11 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input11}, ngraph::clone_function(*f.get()));
|
||||
std::shared_ptr<ngraph::Function> s = std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input11});
|
||||
auto input11 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input11}, f->clone());
|
||||
std::shared_ptr<ov::Model> s = std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input11});
|
||||
|
||||
auto referenceInputs = gen_inputs(shape, 1);
|
||||
bool isCorrect = compare(s, f, referenceInputs);
|
||||
@ -355,15 +345,15 @@ TEST(SnippetsTests, GenerateAddNegateAddMultiEdgeConst) {
|
||||
|
||||
TEST(SnippetsTests, GenerateErf) {
|
||||
GTEST_SKIP();
|
||||
auto shape = ngraph::Shape{1, 4, 16, 31};
|
||||
auto shape = ov::Shape{1, 4, 16, 31};
|
||||
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto gelu = std::make_shared<ngraph::opset1::Erf>(input1);
|
||||
std::shared_ptr<ngraph::Function> f = std::make_shared<ngraph::Function>(ngraph::NodeVector{gelu}, ngraph::ParameterVector{input1});
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto gelu = std::make_shared<ov::opset1::Erf>(input1);
|
||||
std::shared_ptr<ov::Model> f = std::make_shared<ov::Model>(ov::NodeVector{gelu}, ov::ParameterVector{input1});
|
||||
|
||||
auto input11 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input11}, ngraph::clone_function(*f.get()));
|
||||
std::shared_ptr<ngraph::Function> s = std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input11});
|
||||
auto input11 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input11}, f->clone());
|
||||
std::shared_ptr<ov::Model> s = std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input11});
|
||||
|
||||
auto referenceInputs = gen_inputs(shape, 1);
|
||||
bool isCorrect = compare(s, f, referenceInputs);
|
||||
@ -374,38 +364,38 @@ TEST(SnippetsTests, GenerateErf) {
|
||||
// ToDO: implement tile selection logic & broadcast emission to make it working. Broadcast substitution works
|
||||
TEST(SnippetsTests, GenerateAddBroadcastAutomatic) {
|
||||
GTEST_SKIP();
|
||||
std::array<ngraph::Shape, 3> shapes {
|
||||
ngraph::Shape{1, 4, 16, 31},
|
||||
ngraph::Shape{1, 4, 16, 1},
|
||||
ngraph::Shape{1, 4, 16, 1}
|
||||
std::array<ov::Shape, 3> shapes {
|
||||
ov::Shape{1, 4, 16, 31},
|
||||
ov::Shape{1, 4, 16, 1},
|
||||
ov::Shape{1, 4, 16, 1}
|
||||
};
|
||||
|
||||
auto f = ([] (const ngraph::Shape& shape0, const ngraph::Shape& shape1, const ngraph::Shape& shape2) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto input2 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape2);
|
||||
auto f = ([] (const ov::Shape& shape0, const ov::Shape& shape1, const ov::Shape& shape2) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
auto input2 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape2);
|
||||
|
||||
auto add = std::make_shared<ngraph::opset1::Add>(input0, input1);
|
||||
auto mul = std::make_shared<ngraph::opset1::Multiply>(input1, input2);
|
||||
auto sub = std::make_shared<ngraph::opset1::Subtract>(add, mul);
|
||||
auto add = std::make_shared<ov::opset1::Add>(input0, input1);
|
||||
auto mul = std::make_shared<ov::opset1::Multiply>(input1, input2);
|
||||
auto sub = std::make_shared<ov::opset1::Subtract>(add, mul);
|
||||
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{sub}, ngraph::ParameterVector{input0, input1, input2});
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{sub}, ov::ParameterVector{input0, input1, input2});
|
||||
})(shapes[0], shapes[1], shapes[2]);
|
||||
|
||||
auto s = ([f] (const ngraph::Shape& shape0, const ngraph::Shape& shape1, const ngraph::Shape& shape2) -> std::shared_ptr<ngraph::Function>{
|
||||
auto input0 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape1);
|
||||
auto input2 = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, shape2);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ngraph::OutputVector{input0, input1, input2}, ngraph::clone_function(*f.get()));
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector{snippet}, ngraph::ParameterVector{input0, input1, input2});
|
||||
auto s = ([f] (const ov::Shape& shape0, const ov::Shape& shape1, const ov::Shape& shape2) -> std::shared_ptr<ov::Model>{
|
||||
auto input0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape0);
|
||||
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape1);
|
||||
auto input2 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, shape2);
|
||||
auto snippet = std::make_shared<ov::snippets::op::Subgraph>(ov::OutputVector{input0, input1, input2}, f->clone());
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{snippet}, ov::ParameterVector{input0, input1, input2});
|
||||
})(shapes[0], shapes[1], shapes[2]);
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> referenceInputs(3);
|
||||
for (size_t k = 0; k < referenceInputs.size(); k++) {
|
||||
referenceInputs[k].resize(ngraph::shape_size(shapes[k]) * sizeof(float));
|
||||
referenceInputs[k].resize(ov::shape_size(shapes[k]) * sizeof(float));
|
||||
|
||||
auto in0 = reinterpret_cast<float*>(&referenceInputs[k][0]);
|
||||
for (size_t i = 0; i < ngraph::shape_size(shapes[k]); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shapes[k]); i++) {
|
||||
in0[i] = k == 0 ? i/2048.f : (k == 1 ? 1.f : 0.42f);
|
||||
}
|
||||
}
|
||||
@ -417,7 +407,7 @@ TEST(SnippetsTests, GenerateAddBroadcastAutomatic) {
|
||||
const float* pact = reinterpret_cast<float*>(&act[0].second[0]);
|
||||
|
||||
bool isCorrect = true;
|
||||
for (size_t i = 0; i < ngraph::shape_size(shapes[0]); i++) {
|
||||
for (size_t i = 0; i < ov::shape_size(shapes[0]); i++) {
|
||||
if (pexp[i] != pact[i]) {
|
||||
isCorrect = false;
|
||||
std::cout << i << " expected " << pexp[i] << " actual " << pact[i] << std::endl;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "graph.h"
|
||||
#include "edge.h"
|
||||
|
||||
#include "ie_ngraph_utils.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace intel_cpu {
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "dummy_node.hpp"
|
||||
|
||||
#include "ov_models/builders.hpp"
|
||||
#include "ie_ngraph_utils.hpp"
|
||||
#include "nodes/memory.hpp"
|
||||
#include "nodes/softmax.h"
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "nodes/transpose.h"
|
||||
|
||||
#include "ov_models/builders.hpp"
|
||||
#include "ie_ngraph_utils.hpp"
|
||||
|
||||
using namespace ov::intel_cpu;
|
||||
|
||||
@ -69,9 +68,9 @@ protected:
|
||||
// ov::Model with only a transpose node
|
||||
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(testPrec, ov::Shape(testShape))};
|
||||
auto order = std::vector<int32_t>{0, 3, 1, 2};
|
||||
auto constOrder = ngraph::builder::makeConstant(ngraph::element::i32, {order.size()}, order);
|
||||
auto transpose = std::make_shared<ngraph::opset5::Transpose>(params[0], constOrder);
|
||||
ov::ResultVector results{std::make_shared<ngraph::opset5::Result>(transpose)};
|
||||
auto constOrder = ngraph::builder::makeConstant(ov::element::i32, {order.size()}, order);
|
||||
auto transpose = std::make_shared<ov::op::v1::Transpose>(params[0], constOrder);
|
||||
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose)};
|
||||
|
||||
// Replicate
|
||||
auto replicate = [&](std::vector<NodePtr> &nodes, std::vector<EdgePtr> &edges) -> void {
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "ie_common.h"
|
||||
#include "nodes/eltwise.h"
|
||||
|
||||
using namespace InferenceEngine;
|
||||
using namespace ov::intel_cpu;
|
||||
|
||||
class EltwisePrecisionHelperTest : public testing::Test {};
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "cache/multi_cache.h"
|
||||
#include "nodes/input.h"
|
||||
|
||||
using namespace InferenceEngine;
|
||||
using namespace ov::intel_cpu;
|
||||
namespace ReorderCPUTest {
|
||||
inline void checkReorder(const ov::intel_cpu::IMemory& inputMemory,
|
||||
@ -96,7 +95,7 @@ struct ReorderCustomImplTestParamSet {
|
||||
};
|
||||
|
||||
struct ReorderCPUTestParamSet {
|
||||
ngraph::PartialShape inputPartialShape;
|
||||
ov::PartialShape inputPartialShape;
|
||||
// logical dimension vector of input
|
||||
std::vector<std::vector<size_t>> inputShapes;
|
||||
LayoutType srcLayout;
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "custom_shape_infer.hpp"
|
||||
#include "ie_ngraph_utils.hpp"
|
||||
#include "openvino/cc/factory.h"
|
||||
#include "openvino/core/partial_shape.hpp"
|
||||
#include "openvino/core/type.hpp"
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
const std::set<std::vector<element::Type>>& precisions2) : precisions1(precisions1), precisions2(precisions2) {
|
||||
}
|
||||
|
||||
std::set<std::vector<element::Type>> get_supported_precisions(const std::shared_ptr<ngraph::Node>& op) noexcept {
|
||||
std::set<std::vector<element::Type>> get_supported_precisions(const std::shared_ptr<ov::Node>& op) noexcept {
|
||||
if (ov::is_type<ov::test::snippets::DummyOperation1>(op)) {
|
||||
return precisions1;
|
||||
} else if (ov::is_type<ov::test::snippets::DummyOperation2>(op)) {
|
||||
@ -176,7 +176,7 @@ TEST_P(EnforcePrecisionTest, CompareFunctions) {
|
||||
|
||||
auto dummyPrecisionSelection = std::make_shared<DummyPrecisionSelection>(test_values.actual.precisions1, test_values.actual.precisions2);
|
||||
|
||||
auto get_supported_precisions = [dummyPrecisionSelection](const std::shared_ptr<ngraph::Node>& op) {
|
||||
auto get_supported_precisions = [dummyPrecisionSelection](const std::shared_ptr<ov::Node>& op) {
|
||||
return dummyPrecisionSelection->get_supported_precisions(op);;
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "cpu_streams_calculation.hpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace InferenceEngine;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "cpu_streams_calculation.hpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace InferenceEngine;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "cpu_streams_calculation.hpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace InferenceEngine;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "cpu_streams_calculation.hpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace InferenceEngine;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
|
@ -0,0 +1,452 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <openvino/core/model.hpp>
|
||||
#include <openvino/opsets/opset1.hpp>
|
||||
#include <openvino/opsets/opset3.hpp>
|
||||
#include <openvino/pass/manager.hpp>
|
||||
#include <ov_ops/type_relaxed.hpp>
|
||||
#include <transformations/cpu_opset/common/op/rope.hpp>
|
||||
#include <transformations/cpu_opset/common/pass/rope_fusion.hpp>
|
||||
|
||||
#include "common_test_utils/ov_test_utils.hpp"
|
||||
#include "utils/gen_pattern.hpp"
|
||||
#include "utils/print_model.hpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace ov::intel_cpu;
|
||||
using namespace ov::gen_pattern;
|
||||
|
||||
static ov::OutputVector makeCosSinCache(size_t max_position_embeddings, size_t rotary_ndims) {
|
||||
std::vector<float> lut_sin(max_position_embeddings * rotary_ndims, 0.0f);
|
||||
std::vector<float> lut_cos(max_position_embeddings * rotary_ndims, 0.0f);
|
||||
|
||||
// rotate_half style cos/sin table:
|
||||
// y1 = cos(m*xita_i) * x1 - sin(m*xita_i) * x2
|
||||
// y2 = cos(m*xita_i) * x2 + sin(m*xita_i) * x1
|
||||
//
|
||||
for (size_t i = 0, k = 0; i < rotary_ndims; i += 2, k++) {
|
||||
auto xita_i = 1.0 / std::pow(10000.0, static_cast<double>(i) / rotary_ndims);
|
||||
float* psin = lut_sin.data();
|
||||
float* pcos = lut_cos.data();
|
||||
for (size_t m = 0; m < max_position_embeddings; m++, psin += rotary_ndims, pcos += rotary_ndims) {
|
||||
auto vsin = std::sin(xita_i * m);
|
||||
auto vcos = std::cos(xita_i * m);
|
||||
pcos[k] = pcos[k + rotary_ndims / 2] = vcos;
|
||||
psin[k] = psin[k + rotary_ndims / 2] = vsin;
|
||||
}
|
||||
}
|
||||
auto Cos = makeConst(ov::element::f32, ov::Shape({1, 1, max_position_embeddings, rotary_ndims}), lut_cos);
|
||||
auto Sin = makeConst(ov::element::f32, ov::Shape({1, 1, max_position_embeddings, rotary_ndims}), lut_sin);
|
||||
|
||||
return {Cos, Sin};
|
||||
}
|
||||
|
||||
static std::shared_ptr<ov::Model> buildROPE_Llama2(const size_t batch,
|
||||
const size_t seq_length,
|
||||
const size_t max_position_embeddings,
|
||||
const size_t ndims,
|
||||
bool sin_cos_preprocessing) {
|
||||
auto input = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{batch, seq_length, 32, ndims});
|
||||
auto param_cos = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_length, ndims});
|
||||
auto param_sin = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_length, ndims});
|
||||
|
||||
auto seq_len = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1});
|
||||
auto gather_id = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1, seq_length});
|
||||
|
||||
auto gather_from_sin_cos = [&](const ov::Output<ov::Node>& const_tab) {
|
||||
auto ScatterUpdate_152236 = makeOP<ov::opset3::ScatterUpdate>({{0, 0, 0}, {2}, seq_len, {0}});
|
||||
auto slice_Slice = makeOP<ov::opset1::StridedSlice>({const_tab, {0, 0, 0}, ScatterUpdate_152236, {1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 0}},
|
||||
{"end_mask", {1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto squeeze_Squeeze_435 =
|
||||
makeOP<ov::opset1::Reshape>({slice_Slice, {-1, static_cast<int>(ndims)}}, {{"special_zero", false}});
|
||||
auto index_441_Gather = makeOP<ov::opset8::Gather>({squeeze_Squeeze_435, gather_id, {0}}, {{"batch_dims", 0}});
|
||||
return makeOP<ov::opset1::Reshape>({index_441_Gather, {1, 1, -1, static_cast<int>(ndims)}},
|
||||
{{"special_zero", false}});
|
||||
};
|
||||
|
||||
ov::OutputVector cos_sin(2);
|
||||
ov::ParameterVector parameters;
|
||||
if (sin_cos_preprocessing) {
|
||||
auto cos_sin_cache = makeCosSinCache(max_position_embeddings, ndims);
|
||||
cos_sin[0] = gather_from_sin_cos(cos_sin_cache[0]);
|
||||
cos_sin[1] = gather_from_sin_cos(cos_sin_cache[1]);
|
||||
parameters = ov::ParameterVector{input, seq_len, gather_id};
|
||||
} else {
|
||||
cos_sin[0] = param_cos;
|
||||
cos_sin[1] = param_sin;
|
||||
parameters = ov::ParameterVector{input, param_cos, param_sin};
|
||||
}
|
||||
|
||||
auto transpose_Transpose = makeOP<ov::opset1::Transpose>({input, {0, 2, 1, 3}});
|
||||
auto mul_Multiply = makeOP<ov::opset1::Multiply>({transpose_Transpose, cos_sin[0]}, {{"auto_broadcast", "numpy"}});
|
||||
auto slice_Slice_459 =
|
||||
makeOP<ov::opset1::StridedSlice>({transpose_Transpose, {0, 0, 0, 64}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto Constant_182988 = makeConst(ov::element::f32,
|
||||
ov::Shape({
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
}),
|
||||
{-1.000000f});
|
||||
auto neg_Multiply = makeOP<ov::opset1::Multiply>({slice_Slice_459, Constant_182988}, {{"auto_broadcast", "numpy"}});
|
||||
auto slice_Slice =
|
||||
makeOP<ov::opset1::StridedSlice>({transpose_Transpose, {0, 0, 0, 0}, {0, 0, 0, 64}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, slice_Slice}, {{"axis", -1}});
|
||||
auto mul_Multiply_463 = makeOP<ov::opset1::Multiply>({cat_Concat, cos_sin[1]}, {{"auto_broadcast", "numpy"}});
|
||||
auto add_Add = makeOP<ov::opset1::Add>({mul_Multiply, mul_Multiply_463}, {{"auto_broadcast", "numpy"}});
|
||||
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{add_Add}, parameters);
|
||||
}
|
||||
|
||||
TEST_F(TransformationTestsF, ConvertToROPE_LLama2_no_gather) {
|
||||
disable_rt_info_check();
|
||||
const int batch = 2;
|
||||
const int seq_length = 16;
|
||||
const size_t max_position_embeddings = 2048;
|
||||
const size_t ndims = 128;
|
||||
const size_t num_head = 32;
|
||||
|
||||
model = buildROPE_Llama2(batch, seq_length, max_position_embeddings, ndims, false);
|
||||
manager.register_pass<RoPEFusion>();
|
||||
|
||||
{
|
||||
auto hidden_states =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{batch, seq_length, num_head, ndims});
|
||||
auto param_cos = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_length, ndims});
|
||||
auto param_sin = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_length, ndims});
|
||||
auto add_Add = makeOP<RoPENode>({hidden_states, param_cos, param_sin},
|
||||
{{"config.slice_start", 0},
|
||||
{"config.slice_stop", 0},
|
||||
{"config.input_trans0213", true},
|
||||
{"config.is_interleaved", false},
|
||||
{"config.rotary_ndims", static_cast<int>(ndims)},
|
||||
{"config.gather_position_arg_id", 0}});
|
||||
|
||||
model_ref = std::make_shared<ov::Model>(ov::NodeVector{add_Add},
|
||||
ov::ParameterVector{hidden_states, param_cos, param_sin});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TransformationTestsF, ConvertToROPE_LLama2_with_gather) {
|
||||
disable_rt_info_check();
|
||||
const int batch = 2;
|
||||
const int seq_length = 16;
|
||||
const size_t max_position_embeddings = 2048;
|
||||
const size_t ndims = 128;
|
||||
const size_t num_head = 32;
|
||||
|
||||
model = buildROPE_Llama2(batch, seq_length, max_position_embeddings, ndims, true);
|
||||
manager.register_pass<RoPEFusion>();
|
||||
|
||||
{
|
||||
auto hidden_states =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{batch, seq_length, num_head, ndims});
|
||||
auto seq_len = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1});
|
||||
auto gather_id = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1, seq_length});
|
||||
auto cos_sin_cache = makeCosSinCache(max_position_embeddings, ndims);
|
||||
|
||||
auto add_Add = makeOP<RoPENode>({hidden_states, cos_sin_cache[0], cos_sin_cache[1], gather_id},
|
||||
{{"config.slice_start", 0},
|
||||
{"config.slice_stop", 0},
|
||||
{"config.input_trans0213", true},
|
||||
{"config.is_interleaved", false},
|
||||
{"config.rotary_ndims", static_cast<int>(ndims)},
|
||||
{"config.gather_position_arg_id", 3}});
|
||||
|
||||
model_ref = std::make_shared<ov::Model>(ov::NodeVector{add_Add},
|
||||
ov::ParameterVector{hidden_states, seq_len, gather_id});
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<ov::Model> buildROPE_GPTNEOX(const int batch,
|
||||
const int seq_length,
|
||||
const int max_position_embeddings,
|
||||
const int ndims,
|
||||
const int num_heads,
|
||||
const int rotary_ndims,
|
||||
bool sin_cos_preprocessing) {
|
||||
auto batch_s = static_cast<size_t>(batch);
|
||||
auto seq_length_s = static_cast<size_t>(seq_length);
|
||||
auto ndims_s = static_cast<size_t>(ndims);
|
||||
auto rotary_ndims_s = static_cast<size_t>(rotary_ndims);
|
||||
auto num_heads_s = static_cast<size_t>(num_heads);
|
||||
|
||||
auto input = std::make_shared<ov::opset1::Parameter>(ov::element::f32,
|
||||
ov::Shape{batch_s, seq_length_s, num_heads_s, ndims_s * 3});
|
||||
auto seq_len = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1});
|
||||
auto gather_idx =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1, 1, seq_length_s, rotary_ndims_s});
|
||||
auto batch_limit = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1});
|
||||
|
||||
ov::ParameterVector parameters;
|
||||
ov::OutputVector cos_sin(2);
|
||||
if (sin_cos_preprocessing) {
|
||||
auto cos_sin_lut = makeCosSinCache(max_position_embeddings, rotary_ndims);
|
||||
auto ro_slice_Slice = makeOP<ov::opset1::StridedSlice>({cos_sin_lut[0], {0}, batch_limit, {1}},
|
||||
{{"begin_mask", {0}},
|
||||
{"end_mask", {0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
cos_sin[0] = makeOP<ov::opset6::GatherElements>({ro_slice_Slice, gather_idx}, {{"axis", 2}});
|
||||
|
||||
auto ro_slice_Slice_385 = makeOP<ov::opset1::StridedSlice>({cos_sin_lut[1], {0}, batch_limit, {1}},
|
||||
{{"begin_mask", {0}},
|
||||
{"end_mask", {0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
cos_sin[1] = makeOP<ov::opset6::GatherElements>({ro_slice_Slice_385, gather_idx}, {{"axis", 2}});
|
||||
parameters = ov::ParameterVector{input, gather_idx, batch_limit};
|
||||
} else {
|
||||
auto param_cos =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_length_s, rotary_ndims_s});
|
||||
auto param_sin =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_length_s, rotary_ndims_s});
|
||||
parameters = ov::ParameterVector{input, param_cos, param_sin};
|
||||
cos_sin[0] = param_cos;
|
||||
cos_sin[1] = param_sin;
|
||||
}
|
||||
|
||||
auto slice_Slice = makeOP<ov::opset1::StridedSlice>({input, {0, 0, 0, 0}, {0, 0, 0, ndims}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto permute_Transpose = makeOP<ov::opset1::Transpose>({slice_Slice, {0, 2, 1, 3}});
|
||||
auto slice_Slice_351 =
|
||||
makeOP<ov::opset1::StridedSlice>({permute_Transpose, {0, 0, 0, 0}, {0, 0, 0, rotary_ndims}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto mul_Multiply = makeOP<ov::opset1::Multiply>({slice_Slice_351, cos_sin[0]}, {{"auto_broadcast", "numpy"}});
|
||||
auto slice_Slice_420 = makeOP<ov::opset1::StridedSlice>(
|
||||
{slice_Slice_351, {0, 0, 0, rotary_ndims / 2}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto Constant_396096 = makeConst(ov::element::f32,
|
||||
ov::Shape({
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
}),
|
||||
{-1.000000f});
|
||||
auto neg_Multiply = makeOP<ov::opset1::Multiply>({slice_Slice_420, Constant_396096}, {{"auto_broadcast", "numpy"}});
|
||||
auto slice_Slice_414 =
|
||||
makeOP<ov::opset1::StridedSlice>({slice_Slice_351, {0, 0, 0, 0}, {0, 0, 0, rotary_ndims / 2}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, slice_Slice_414}, {{"axis", -1}});
|
||||
auto mul_Multiply_424 = makeOP<ov::opset1::Multiply>({cat_Concat, cos_sin[1]}, {{"auto_broadcast", "numpy"}});
|
||||
auto add_Add = makeOP<ov::opset1::Add>({mul_Multiply, mul_Multiply_424}, {{"auto_broadcast", "numpy"}});
|
||||
auto slice_Slice_357 =
|
||||
makeOP<ov::opset1::StridedSlice>({permute_Transpose, {0, 0, 0, rotary_ndims}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto cat_Concat_458 = makeOP<ov::opset1::Concat>({add_Add, slice_Slice_357}, {{"axis", -1}});
|
||||
|
||||
return std::make_shared<ov::Model>(ov::NodeVector{cat_Concat_458}, parameters);
|
||||
}
|
||||
|
||||
TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_no_gather) {
|
||||
disable_rt_info_check();
|
||||
const int batch = 2;
|
||||
const int seq_len = 16;
|
||||
const int ndims = 80;
|
||||
const int num_heads = 32;
|
||||
const int rotary_ndims = 20;
|
||||
const int max_position_embeddings = 2048;
|
||||
|
||||
model = buildROPE_GPTNEOX(batch, seq_len, max_position_embeddings, ndims, num_heads, rotary_ndims, false);
|
||||
manager.register_pass<RoPEFusion>();
|
||||
{
|
||||
auto input =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{batch, seq_len, num_heads, ndims * 3});
|
||||
auto param_cos =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_len, rotary_ndims});
|
||||
auto param_sin =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, seq_len, rotary_ndims});
|
||||
auto rope = makeOP<RoPENode>({input, param_cos, param_sin},
|
||||
{{"config.slice_start", 0},
|
||||
{"config.slice_stop", ndims},
|
||||
{"config.input_trans0213", true},
|
||||
{"config.is_interleaved", false},
|
||||
{"config.rotary_ndims", rotary_ndims},
|
||||
{"config.gather_position_arg_id", 0}});
|
||||
model_ref = std::make_shared<ov::Model>(ov::NodeVector{rope}, ov::ParameterVector{input, param_cos, param_sin});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_with_gather) {
|
||||
disable_rt_info_check();
|
||||
const int batch = 2;
|
||||
const int seq_len = 16;
|
||||
const int ndims = 80;
|
||||
const int rotary_ndims = 20;
|
||||
const int num_heads = 32;
|
||||
const int max_position_embeddings = 2048;
|
||||
|
||||
model = buildROPE_GPTNEOX(batch, seq_len, max_position_embeddings, ndims, num_heads, rotary_ndims, true);
|
||||
manager.register_pass<RoPEFusion>();
|
||||
{
|
||||
auto cos_sin = makeCosSinCache(max_position_embeddings, rotary_ndims);
|
||||
auto input =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{batch, seq_len, num_heads, ndims * 3});
|
||||
auto gather_idx =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1, 1, seq_len, rotary_ndims});
|
||||
auto batch_limit = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{1});
|
||||
|
||||
auto rope = makeOP<RoPENode>({input, cos_sin[0], cos_sin[1], gather_idx},
|
||||
{{"config.slice_start", 0},
|
||||
{"config.slice_stop", ndims},
|
||||
{"config.input_trans0213", true},
|
||||
{"config.is_interleaved", false},
|
||||
{"config.rotary_ndims", rotary_ndims},
|
||||
{"config.gather_position_arg_id", 3}});
|
||||
model_ref =
|
||||
std::make_shared<ov::Model>(ov::NodeVector{rope}, ov::ParameterVector{input, gather_idx, batch_limit});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TransformationTestsF, ConvertToROPE_GPTJ) {
|
||||
disable_rt_info_check();
|
||||
const int batch = 2;
|
||||
const int seq_len = 7;
|
||||
const int num_heads = 16;
|
||||
const int ndims = 256;
|
||||
const int rotary_ndims = 64;
|
||||
{
|
||||
std::vector<int32_t> rpi_idx(rotary_ndims);
|
||||
for (int i = 0, index = 0; i < rotary_ndims; i += 2, index++) {
|
||||
rpi_idx[i] = index;
|
||||
rpi_idx[i + 1] = index;
|
||||
}
|
||||
auto repeat_interleave_index = makeConst(ov::element::i32, ov::Shape({rotary_ndims}), rpi_idx);
|
||||
|
||||
auto input =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{batch, seq_len, num_heads, ndims});
|
||||
auto gather_sin_cos =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, seq_len, rotary_ndims});
|
||||
|
||||
auto split = makeOP<ov::opset1::VariadicSplit>({gather_sin_cos, {-1}, {rotary_ndims / 2, -1}});
|
||||
auto sin_tab =
|
||||
makeOP<ov::opset1::Reshape>({split->output(0), {1, -1, 1, rotary_ndims / 2}}, {{"special_zero", false}});
|
||||
auto cos_tab =
|
||||
makeOP<ov::opset1::Reshape>({split->output(1), {1, -1, 1, rotary_ndims / 2}}, {{"special_zero", false}});
|
||||
|
||||
auto slice_Slice_576 =
|
||||
makeOP<ov::opset1::StridedSlice>({input, {0, 0, 0, 0}, {0, 0, 0, rotary_ndims}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto repeat_interleave_Cos =
|
||||
makeOP<ov::opset8::Gather>({cos_tab, repeat_interleave_index, {3}}, {{"batch_dims", 0}});
|
||||
auto mul_Multiply_757 =
|
||||
makeOP<ov::opset1::Multiply>({slice_Slice_576, repeat_interleave_Cos}, {{"auto_broadcast", "numpy"}});
|
||||
|
||||
auto slice_Slice_787 =
|
||||
makeOP<ov::opset1::StridedSlice>({slice_Slice_576, {0, 0, 0, 1}, {0, 0, 0, INT_MAX}, {1, 1, 1, 2}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto Constant_191672 = makeConst(ov::element::f32,
|
||||
ov::Shape({
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
}),
|
||||
{-1.000000f});
|
||||
auto neg_Multiply_790 =
|
||||
makeOP<ov::opset1::Multiply>({slice_Slice_787, Constant_191672}, {{"auto_broadcast", "numpy"}});
|
||||
auto Unsqueeze_61918 = makeOP<ov::opset1::Unsqueeze>({neg_Multiply_790, {-1}});
|
||||
auto slice_Slice_781 =
|
||||
makeOP<ov::opset1::StridedSlice>({slice_Slice_576, {0, 0, 0, 0}, {0, 0, 0, INT_MAX}, {1, 1, 1, 2}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto Unsqueeze_61919 = makeOP<ov::opset1::Unsqueeze>({slice_Slice_781, {-1}});
|
||||
auto stack_795 = makeOP<ov::opset1::Concat>({Unsqueeze_61918, Unsqueeze_61919}, {{"axis", -1}});
|
||||
auto ShapeOf_165368 = makeOP<ov::op::TypeRelaxed<ov::opset1::ShapeOf>>(
|
||||
{stack_795},
|
||||
{{"type_relax", true}, {"input_data_types", {}}, {"output_data_types", {ov::element::i32}}});
|
||||
auto flatten_Slice_811 = makeOP<ov::opset1::StridedSlice>({ShapeOf_165368, {0}, {3}, {1}},
|
||||
{{"begin_mask", {0}},
|
||||
{"end_mask", {0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto flatten_Concat_814 = makeOP<ov::opset1::Concat>({flatten_Slice_811, {-1}}, {{"axis", 0}});
|
||||
auto flatten_Reshape_815 =
|
||||
makeOP<ov::opset1::Reshape>({stack_795, flatten_Concat_814}, {{"special_zero", true}});
|
||||
auto repeat_interleave_Sin =
|
||||
makeOP<ov::opset8::Gather>({sin_tab, repeat_interleave_index, {3}}, {{"batch_dims", 0}});
|
||||
auto mul_Multiply_816 =
|
||||
makeOP<ov::opset1::Multiply>({flatten_Reshape_815, repeat_interleave_Sin}, {{"auto_broadcast", "numpy"}});
|
||||
auto add_Add_819 = makeOP<ov::opset1::Add>({mul_Multiply_757, mul_Multiply_816}, {{"auto_broadcast", "numpy"}});
|
||||
auto slice_Slice_582 =
|
||||
makeOP<ov::opset1::StridedSlice>({input, {0, 0, 0, rotary_ndims}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}},
|
||||
{{"begin_mask", {1, 1, 1, 0}},
|
||||
{"end_mask", {1, 1, 1, 0}},
|
||||
{"new_axis_mask", {}},
|
||||
{"shrink_axis_mask", {}},
|
||||
{"ellipsis_mask", {}}});
|
||||
auto cat_Concat_826 = makeOP<ov::opset1::Concat>({add_Add_819, slice_Slice_582}, {{"axis", -1}});
|
||||
auto permute_Transpose_828 = makeOP<ov::opset1::Transpose>({cat_Concat_826, {0, 2, 1, 3}});
|
||||
model = std::make_shared<ov::Model>(ov::NodeVector{permute_Transpose_828},
|
||||
ov::ParameterVector{input, gather_sin_cos});
|
||||
}
|
||||
manager.register_pass<RoPEFusion>();
|
||||
{
|
||||
auto input =
|
||||
std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{batch, seq_len, num_heads, ndims});
|
||||
auto cos_sin = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, seq_len, rotary_ndims});
|
||||
auto rope = makeOP<RoPENode>({input, cos_sin, cos_sin},
|
||||
{{"config.slice_start", 0},
|
||||
{"config.slice_stop", 0},
|
||||
{"config.input_trans0213", false},
|
||||
{"config.is_interleaved", true},
|
||||
{"config.rotary_ndims", rotary_ndims},
|
||||
{"config.gather_position_arg_id", 0}});
|
||||
model_ref = std::make_shared<ov::Model>(ov::NodeVector{rope}, ov::ParameterVector{input, cos_sin});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user