Skip to content

Commit

Permalink
Tokenization helper cleanup and tests reenabling
Browse files Browse the repository at this point in the history
  • Loading branch information
v-Golubev committed Sep 28, 2024
1 parent 8f8344a commit c577fcd
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 94 deletions.
41 changes: 3 additions & 38 deletions src/common/snippets/src/utils/tokenization_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,44 +227,9 @@ bool tokenize_node(const std::shared_ptr<ov::Node>& node, const SnippetsTokeniza

// this is there stitching happens, get result of a copy of a body of currently processed input and put it to the new inputs
// internal output index == external output index
auto& input_body = clones[input_node];
size_t source_output_index = input_value.get_index();
auto source_result = input_body->get_results()[source_output_index];

// We cannot add new node, that is not Convert, after Convert (that is start node) to avoid arithmetic problems with conversion
// We can add any new node in Subgraph after Convert (bacause after Input)
// Parameter
// |
// Convert
//
// We cannot add new node, that isn't Convert, in Subgraph after existing Convert
// Parameter
// Relu
// Convert
//
// But we can add new Convert in Subgraph after existing Convert
// Parameter
// Relu
// Convert
// Convert
//
// Thus, We can grow subgraph only if Convert is the first node of subgraph and have to abort it's the last one and we want to add not Convert
// We have this limitation because at the moment we support only one execution precision inside body, so
// if there is Convert with input and output data types that aren't equal to supported exec type,
// we can get conversion math errors
const auto output_of_subgraph = source_result->get_input_node_shared_ptr(0);
if (!ov::is_type<ov::op::v0::Convert>(node) && ov::is_type<ov::op::v0::Convert>(output_of_subgraph)) {
// Also we can add new node after < Parameter -> Convert -> Convert -> Convert >
auto grandparent = output_of_subgraph->get_input_node_ptr(0);
while (ov::is_type<ov::op::v0::Convert>(grandparent)) {
grandparent = grandparent->get_input_node_ptr(0);
}

if (!ov::is_type<ov::op::v0::Parameter>(grandparent)) {
return abort("Convert supports only as Input and as Result of subgraph. Aborting");
}
}
// Result op has a single input
const auto& input_body = clones[input_node];
const size_t source_output_index = input_value.get_index();
const auto& source_result = input_body->get_results()[source_output_index];
internal_inputs.push_back(source_result->input_value(0));
} else {
// We need some non-scalar constants inside Subgraph in the following cases:
Expand Down
22 changes: 7 additions & 15 deletions src/common/snippets/tests/src/pass/collapse_subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,14 @@ void CollapseSubgraphTests::run() {
});
}

class SKIP_CollapseSubgraphTests : public CollapseSubgraphTests {
public:
void SetUp() override {
GTEST_SKIP();
}
void TearDown() override{};
};

TEST_F(SKIP_CollapseSubgraphTests /* CVS-114607 */, smoke_Snippets_Eltwise) {
TEST_F(CollapseSubgraphTests, smoke_Snippets_Eltwise) {
const auto& f = EltwiseFunction(std::vector<PartialShape> {{2, 3}, {1, 3}});
model = f.getOriginal();
model_ref = f.getReference();
run();
}

TEST_F(SKIP_CollapseSubgraphTests /* CVS-114607 */, smoke_Snippets_MatMulWithEltwise) {
TEST_F(CollapseSubgraphTests, smoke_Snippets_MatMulWithEltwise) {
const auto& f = MatMulEltwiseBranchesFunction(std::vector<PartialShape> {{1, 3, 4, 4}, {1, 3, 4, 4}});
model = f.getOriginal();
model_ref = f.getReference();
Expand All @@ -56,35 +48,35 @@ TEST_F(CollapseSubgraphTests, smoke_Snippets_AvoidLoopEltwise) {
run();
}

TEST_F(SKIP_CollapseSubgraphTests /* CVS-114607 */, smoke_Snippets_OneConvert) {
TEST_F(CollapseSubgraphTests, smoke_Snippets_OneConvert) {
const auto& f = ConvertFunction(std::vector<PartialShape>{{2, 5}});
model = f.getOriginal();
model_ref = f.getReference();
run();
}

TEST_F(SKIP_CollapseSubgraphTests /* CVS-114607 */, smoke_Snippets_ConvertInput) {
TEST_F(CollapseSubgraphTests, smoke_Snippets_ConvertInput) {
const auto& f = ConvertInputFunction(std::vector<PartialShape>{{2, 5}, {1, 5}});
model = f.getOriginal();
model_ref = f.getReference();
run();
}

TEST_F(SKIP_CollapseSubgraphTests /* CVS-114607 */, smoke_Snippets_ConvertOutput) {
TEST_F(CollapseSubgraphTests, smoke_Snippets_ConvertOutput) {
const auto& f = ConvertOutputFunction(std::vector<PartialShape>{{2, 5}, {1, 5}});
model = f.getOriginal();
model_ref = f.getReference();
run();
}

TEST_F(SKIP_CollapseSubgraphTests /* CVS-114607 */, smoke_Snippets_ConvertStub) {
TEST_F(CollapseSubgraphTests, smoke_Snippets_ConvertStub) {
const auto& f = ConvertStubFunction(std::vector<PartialShape>{{2, 5, 2}, {1, 5, 1}});
model = f.getOriginal();
model_ref = f.getReference();
run();
}

TEST_F(SKIP_CollapseSubgraphTests /* CVS-114607 */, smoke_Snippets_ConvertPartialInputsAndResults) {
TEST_F(CollapseSubgraphTests, smoke_Snippets_ConvertPartialInputsAndResults) {
const auto& f = ConvertPartialInputsAndResultsFunction(std::vector<PartialShape>{{2, 5, 1}, {1, 5, 1}, {2, 1, 10}},
std::vector<ov::element::Type>{ov::element::i8, ov::element::bf16, ov::element::f32},
std::vector<ov::element::Type>{ov::element::f32, ov::element::i8});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ConvertStub, ConvertStub,
::testing::Combine(
::testing::ValuesIn(inputShapes_ConvertInput),
::testing::ValuesIn(types_ConvertStub),
::testing::Values(2),
::testing::Values(2),
::testing::Values(1),
::testing::Values(1),
::testing::Values(ov::test::utils::DEVICE_CPU)),
Convert::getTestCaseName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ConvertStub, ConvertStub,
::testing::Combine(
::testing::ValuesIn(inputShapes_ConvertInput),
::testing::ValuesIn(types_ConvertInput),
::testing::Values(2),
::testing::Values(2),
::testing::Values(1),
::testing::Values(1),
::testing::Values(ov::test::utils::DEVICE_CPU)),
Convert::getTestCaseName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ class SnippetsMarkSkippedTests : public TransformationTestsF {
}
};

class SKIP_SnippetsMarkSkippedTests : public SnippetsMarkSkippedTests {
public:
void SetUp() override {
GTEST_SKIP();
}
void TearDown() override{};
};

TEST_F(SKIP_SnippetsMarkSkippedTests /* CVS-114336 */, smoke_Snippets_SkipAfterInputsMatMulEltwise) {
TEST_F(SnippetsMarkSkippedTests, smoke_Snippets_SkipAfterInputsMatMulEltwise) {
const auto &f = MatMulEltwiseBranchesFunction(std::vector<PartialShape> {{1, 3, 4, 4}, {1, 3, 4, 4}});
model = f.getOriginal();
// Fully tokenizable, since inputs are followed by MatMul
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_npu/thirdparty/level-zero
Submodule level-zero added at fd459f
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ class ConvertOutputFunction : public SnippetsFunctionBase {
};


/// There are 2 subgraphs: Add + Convert(Stub) and Relu
/// Tokenized simply by starting subgraph.
// in1 in2 in1 in2
// Add Subgraph
// Convert -> |
// Relu Subgraph
// Add |
// Convert -> Subgraph
// Relu |
// Result Result
class ConvertStubFunction : public SnippetsFunctionBase {
public:
Expand Down
29 changes: 10 additions & 19 deletions src/tests/ov_helpers/ov_snippets_models/src/subgraph_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::shared_ptr<ov::Model> ConvertFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inType, input_shapes[0]);
auto indata0 = std::make_shared<op::v0::Parameter>(inType, data0->get_shape());
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{std::make_shared<ov::snippets::op::ConvertTruncation>(indata0, outType)},
std::make_shared<ov::Model>(NodeVector{std::make_shared<op::v0::Convert>(indata0, outType)},
ParameterVector{indata0}));
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}
Expand All @@ -43,7 +43,7 @@ std::shared_ptr<ov::Model> ConvertInputFunction::initReference() const {
auto data1 = std::make_shared<op::v0::Parameter>(outType, input_shapes[1]);
auto indata0 = std::make_shared<op::v0::Parameter>(inType, data0->get_shape());
auto indata1 = std::make_shared<op::v0::Parameter>(outType, data1->get_shape());
auto convert = std::make_shared<ov::snippets::op::ConvertTruncation>(indata0, outType);
auto convert = std::make_shared<op::v0::Convert>(indata0, outType);
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1},
std::make_shared<ov::Model>(
NodeVector{std::make_shared<op::v1::Add>(convert, indata1)},
Expand All @@ -64,7 +64,7 @@ std::shared_ptr<ov::Model> ConvertOutputFunction::initReference() const {
auto indata0 = std::make_shared<op::v0::Parameter>(inType, data0->get_shape());
auto indata1 = std::make_shared<op::v0::Parameter>(inType, data1->get_shape());
auto add = std::make_shared<op::v1::Add>(indata0, indata1);
auto convert = std::make_shared<ov::snippets::op::ConvertTruncation>(add, outType);
auto convert = std::make_shared<op::v0::Convert>(add, outType);
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1},
std::make_shared<ov::Model>(
NodeVector{convert},
Expand All @@ -83,17 +83,8 @@ std::shared_ptr<ov::Model> ConvertStubFunction::initOriginal() const {
std::shared_ptr<ov::Model> ConvertStubFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inType, input_shapes[0]);
auto data1 = std::make_shared<op::v0::Parameter>(inType, input_shapes[1]);
auto indata0 = std::make_shared<op::v0::Parameter>(inType, data0->get_shape());
auto indata1 = std::make_shared<op::v0::Parameter>(inType, data1->get_shape());
auto add = std::make_shared<op::v1::Add>(indata0, indata1);
auto convert = std::make_shared<ov::snippets::op::ConvertTruncation>(add, outType);
auto subgraph0 = std::make_shared<ov::snippets::op::Subgraph>(
NodeVector{data0, data1}, std::make_shared<ov::Model>(NodeVector{convert}, ParameterVector{indata0, indata1}));
auto indata2 = std::make_shared<op::v0::Parameter>(convert->get_destination_type(), convert->get_shape());
auto relu = std::make_shared<op::v0::Relu>(indata2);
auto subgraph1 = std::make_shared<ov::snippets::op::Subgraph>(
NodeVector{subgraph0}, std::make_shared<ov::Model>(NodeVector{relu}, ParameterVector{indata2}));
return std::make_shared<ov::Model>(NodeVector{subgraph1}, ParameterVector{data0, data1});
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0, data1});
}

std::shared_ptr<ov::Model> ConvertPartialInputsAndResultsFunction::initOriginal() const {
Expand All @@ -116,12 +107,12 @@ std::shared_ptr<ov::Model> ConvertPartialInputsAndResultsFunction::initReference
auto indata0 = std::make_shared<op::v0::Parameter>(inTypes[0], data0->get_shape());
auto indata1 = std::make_shared<op::v0::Parameter>(inTypes[1], data1->get_shape());
auto indata2 = std::make_shared<op::v0::Parameter>(inTypes[2], data2->get_shape());
auto convert0 = std::make_shared<ov::snippets::op::ConvertTruncation>(indata0, outTypes[0]);
auto convert1 = std::make_shared<ov::snippets::op::ConvertTruncation>(indata1, outTypes[0]);
auto convert0 = std::make_shared<op::v0::Convert>(indata0, outTypes[0]);
auto convert1 = std::make_shared<op::v0::Convert>(indata1, outTypes[0]);
auto add = std::make_shared<op::v1::Add>(convert0, convert1);
auto relu = std::make_shared<op::v0::Relu>(add);
auto sub = std::make_shared<op::v1::Subtract>(relu, indata2);
auto convert2 = std::make_shared<ov::snippets::op::ConvertTruncation>(relu, outTypes[1]);
auto convert2 = std::make_shared<op::v0::Convert>(relu, outTypes[1]);
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(
NodeVector{data0, data1, data2}, std::make_shared<ov::Model>(NodeVector{sub, convert2}, ParameterVector{indata0, indata1, indata2}));
auto stub3 = createRollAsStub(subgraph);
Expand All @@ -144,7 +135,7 @@ std::shared_ptr<ov::Model> ConvertManyOnInputsFunction::initReference() const {
auto indata0 = std::make_shared<op::v0::Parameter>(types[0], data0->get_shape());
std::shared_ptr<ov::Node> out = indata0;
for (auto i = 1; i < types.size(); i++) {
auto convert = std::make_shared<ov::snippets::op::ConvertTruncation>(out, types[i]);
auto convert = std::make_shared<op::v0::Convert>(out, types[i]);
out = convert;
}
auto relu = std::make_shared<op::v0::Relu>(out);
Expand All @@ -169,7 +160,7 @@ std::shared_ptr<ov::Model> ConvertManyOnOutputsFunction::initReference() const {
auto relu = std::make_shared<op::v0::Relu>(indata0);
std::shared_ptr<ov::Node> out = relu;
for (auto i = 1; i < types.size(); i++) {
auto convert = std::make_shared<ov::snippets::op::ConvertTruncation>(out, types[i]);
auto convert = std::make_shared<op::v0::Convert>(out, types[i]);
out = convert;
}
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
Expand Down
10 changes: 5 additions & 5 deletions src/tests/ov_helpers/ov_snippets_models/src/subgraph_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::shared_ptr<ov::Model> EltwiseFunction::initReference() const {
auto indata1 = std::make_shared<op::v0::Parameter>(precision, data1->get_shape());
auto indata2 = std::make_shared<op::v0::Parameter>(precision, data1->get_shape());
auto add = std::make_shared<op::v1::Add>(indata0, indata1);
auto sub = std::make_shared<op::v1::Subtract>(add, const_data);
auto sub = std::make_shared<op::v1::Subtract>(add, indata2);
auto mul = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1, const_data},
std::make_shared<ov::Model>(NodeVector{std::make_shared<op::v1::Multiply>(add, sub)},
ParameterVector{indata0, indata1, indata2}));
Expand Down Expand Up @@ -151,10 +151,10 @@ std::shared_ptr<ov::Model> MatMulEltwiseBranchesFunction::initReference() const
const std::vector<float> const_values = ov::test::utils::generate_float_numbers(4, -10., 10.);
// snippet inputs
auto non_snippet_op = std::make_shared<op::v0::MatMul>(sinh_1, sinh_2);
auto mul_const_1 = std::make_shared<ov::snippets::op::Scalar>(precision, Shape{1}, const_values[0]);
auto add_const_1 = std::make_shared<ov::snippets::op::Scalar>(precision, Shape{1}, const_values[1]);
auto mul_const_2 = std::make_shared<ov::snippets::op::Scalar>(precision, Shape{1}, const_values[2]);
auto sub_const_2 = std::make_shared<ov::snippets::op::Scalar>(precision, Shape{1}, const_values[3]);
auto mul_const_1 = std::make_shared<op::v0::Constant>(precision, Shape{1}, const_values[0]);
auto add_const_1 = std::make_shared<op::v0::Constant>(precision, Shape{1}, const_values[1]);
auto mul_const_2 = std::make_shared<op::v0::Constant>(precision, Shape{1}, const_values[2]);
auto sub_const_2 = std::make_shared<op::v0::Constant>(precision, Shape{1}, const_values[3]);

// snippet function
Shape matMulOutShape = input_shapes[0].get_shape();
Expand Down

0 comments on commit c577fcd

Please sign in to comment.