Skip to content

Commit

Permalink
[Transformations] MatMulMultiplyFusion: added a check on consumers count
Browse files Browse the repository at this point in the history
  • Loading branch information
v-Golubev committed Sep 10, 2024
1 parent 090da7b commit 0f23578
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pass::MatMulMultiplyFusion::MatMulMultiplyFusion() {
auto input_pattern = pattern::any_input();
auto weights_pattern = pattern::any_input(pattern::has_static_rank());
auto mul_const_pattern = pattern::wrap_type<ov::op::v0::Constant>();
auto matmul_pattern = pattern::wrap_type<ov::op::v0::MatMul>({input_pattern, weights_pattern});
auto matmul_pattern = pattern::wrap_type<ov::op::v0::MatMul>({input_pattern, weights_pattern}, pattern::consumers_count(1));
auto mul_pattern = pattern::wrap_type<ov::op::v1::Multiply>({matmul_pattern, mul_const_pattern});

matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ TEST_F(TransformationTestsF, MatMulMultiplyFusionNonConstantTransposedWeightsNon
comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
}

TEST_F(TransformationTestsF, MatMulMultiplyFusionNonSingleConsumer) {
auto data = std::make_shared<opset8::Parameter>(element::f32, Shape{2, 3});
auto weights = opset8::Constant::create(element::f32, Shape{2, 3}, {2, 6, 6, 12, 10, 18});
auto matmul = std::make_shared<opset8::MatMul>(data, weights, false, true);
auto mul_const = opset8::Constant::create(element::f32, Shape{1, 2}, {4, 5});
auto mul = std::make_shared<opset8::Multiply>(matmul, mul_const);
auto add = std::make_shared<opset8::Add>(matmul, mul);
model = std::make_shared<Model>(NodeVector{add}, ParameterVector{data});

manager.register_pass<ov::pass::MatMulMultiplyFusion>();
comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
}

using MatMulMultiplyFusionParams = std::tuple<PartialShape, Shape, bool, Shape, Shape, bool>;

class MatMulMultiplyFusionDynamicShapes : public testing::WithParamInterface<MatMulMultiplyFusionParams>,
Expand Down

0 comments on commit 0f23578

Please sign in to comment.