Skip to content

Commit

Permalink
[Snippets] Tokenization helper cleanup and tokenization tests reenabl…
Browse files Browse the repository at this point in the history
…ing (#26843)

### Details:
- *Stub convert related logic is removed from tokenization helper, since
it is not actual anymore*
- *Skipped tokenization tests are reenabled, reference builders are
fixed*

### Tickets:
 - *CVS-142098*
 - *CVS-114607*
 - *CVS-114336*
  • Loading branch information
v-Golubev authored Oct 8, 2024
1 parent 0ebff04 commit 9c65ba2
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 208 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
20 changes: 4 additions & 16 deletions src/common/snippets/tests/src/pass/mha_tokenization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ namespace ov {
namespace test {
namespace snippets {

class SKIP_TokenizeMHASnippetsTests : public TokenizeMHASnippetsTests {
public:
void SetUp() override {
GTEST_SKIP();
}
void TearDown() override{};
};

void TokenizeMHASnippetsTests::run() {
ASSERT_TRUE(model);
manager.register_pass<ov::snippets::pass::ExtractReshapesFromMHA>();
Expand Down Expand Up @@ -103,8 +95,7 @@ TEST_F(TokenizeMHASnippetsTests, smoke_Snippets_MHA_with_MatMul0_Transpose) {
run();
}

TEST_F(SKIP_TokenizeMHASnippetsTests /* CVS-142098 */, smoke_Snippets_MHA_with_MatMul0_Transpose_Dynamic) {
GTEST_SKIP();
TEST_F(TokenizeMHASnippetsTests, smoke_Snippets_MHA_with_MatMul0_Transpose_Dynamic) {
const auto &f = MHAMatMul0TransposeFunction(std::vector<PartialShape>{{-1, -1, -1, -1}, {-1, -1, -1, -1}, {-1, -1, -1, -1}, {-1, -1, -1, -1}},
std::vector<ov::element::Type>({ov::element::f32, ov::element::f32, ov::element::f32, ov::element::f32}),
false);
Expand All @@ -113,8 +104,7 @@ TEST_F(SKIP_TokenizeMHASnippetsTests /* CVS-142098 */, smoke_Snippets_MHA_with_M
run();
}

TEST_F(SKIP_TokenizeMHASnippetsTests /* CVS-114607 */, smoke_Snippets_MHA_with_int_Matmuls) {
GTEST_SKIP();
TEST_F(TokenizeMHASnippetsTests, smoke_Snippets_MHA_with_int_Matmuls) {
const auto &f = MHAINT8MatMulTypeRelaxedFunction(std::vector<PartialShape>{{1, 128, 12, 64}, {1, 128, 12, 64}, {1, 12, 128, 128}, {1, 128, 12, 64}});
model = f.getOriginal();
model_ref = f.getReference();
Expand All @@ -128,8 +118,7 @@ TEST_F(TokenizeMHASnippetsTests, smoke_Snippets_MHA_Transpose_extraction) {
run();
}

TEST_F(SKIP_TokenizeMHASnippetsTests /* CVS-142098 */, smoke_Snippets_MHA_Dynamic_Transpose_extraction) {
GTEST_SKIP();
TEST_F(TokenizeMHASnippetsTests, smoke_Snippets_MHA_Dynamic_Transpose_extraction) {
const auto& f = MHATransposedInputFunction(std::vector<PartialShape>{{-1, -1, -1, -1}, {-1, -1, -1, -1}, {-1, -1, -1, -1}}, true);
model = f.getOriginal();
model_ref = f.getReference();
Expand All @@ -144,8 +133,7 @@ TEST_F(TokenizeMHASnippetsTests, smoke_Snippets_MHA_Transpose_extraction_and_uns
run();
}

TEST_F(SKIP_TokenizeMHASnippetsTests /* CVS-142098 */, smoke_Snippets_MHA_Dynamic_Transpose_extraction_and_unsupported_existing_transpose) {
GTEST_SKIP();
TEST_F(TokenizeMHASnippetsTests, smoke_Snippets_MHA_Dynamic_Transpose_extraction_and_unsupported_existing_transpose) {
const auto& f = MHATransposedInputFunction(std::vector<PartialShape>{{-1, -1, -1, -1}, {-1, -1, -1, -1}, {-1, -1, -1, -1}}, true,
std::vector<int64_t>{0, 3, 1, 2});
model = f.getOriginal();
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
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
76 changes: 11 additions & 65 deletions src/tests/ov_helpers/ov_snippets_models/src/subgraph_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ std::shared_ptr<ov::Model> ConvertFunction::initOriginal() const {
}
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)},
ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}

Expand All @@ -41,13 +38,7 @@ std::shared_ptr<ov::Model> ConvertInputFunction::initOriginal() const {
std::shared_ptr<ov::Model> ConvertInputFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inType, input_shapes[0]);
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 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)},
ParameterVector{indata0, indata1}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0, data1});
}

Expand All @@ -61,14 +52,7 @@ std::shared_ptr<ov::Model> ConvertOutputFunction::initOriginal() const {
std::shared_ptr<ov::Model> ConvertOutputFunction::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 subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1},
std::make_shared<ov::Model>(
NodeVector{convert},
ParameterVector{indata0, indata1}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0, data1});
}

Expand All @@ -83,17 +67,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 +91,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 @@ -141,15 +116,7 @@ std::shared_ptr<ov::Model> ConvertManyOnInputsFunction::initOriginal() const {
}
std::shared_ptr<ov::Model> ConvertManyOnInputsFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(types[0], input_shapes[0]);
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]);
out = convert;
}
auto relu = std::make_shared<op::v0::Relu>(out);
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{relu}, ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}

Expand All @@ -165,15 +132,7 @@ std::shared_ptr<ov::Model> ConvertManyOnOutputsFunction::initOriginal() const {
}
std::shared_ptr<ov::Model> ConvertManyOnOutputsFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(types[0], input_shapes[0]);
auto indata0 = std::make_shared<op::v0::Parameter>(types[0], data0->get_shape());
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]);
out = convert;
}
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{out}, ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}

Expand All @@ -194,20 +153,7 @@ std::shared_ptr<ov::Model> ConvertManyOnInputOutputFunction::initOriginal() cons
}
std::shared_ptr<ov::Model> ConvertManyOnInputOutputFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inTypes[0], input_shapes[0]);
auto indata0 = std::make_shared<op::v0::Parameter>(inTypes[0], data0->get_shape());
std::shared_ptr<ov::Node> out = indata0;
for (auto i = 1; i < inTypes.size(); i++) {
auto convert = std::make_shared<op::v0::Convert>(out, inTypes[i]);
out = convert;
}
auto relu = std::make_shared<op::v0::Relu>(data0);
out = relu;
for (auto i = 0; i < outTypes.size(); i++) {
auto convert = std::make_shared<op::v0::Convert>(out, outTypes[i]);
out = convert;
}
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{out}, ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}
} // namespace snippets
Expand Down
Loading

0 comments on commit 9c65ba2

Please sign in to comment.