Skip to content

Commit

Permalink
Eliminate nop Convert at the beginning of the MOC pipeline (#26872)
Browse files Browse the repository at this point in the history
### Details:
Added NopElimination at the beginning of the MOC
After pytorch conversion, we can see useless Convert (fp32 to fp32) in
the graph
```
Constant (fp32) -> Node1
                -> Convert( to fp32) -> Node2
```
So after ConstantFolding, we will get
```
Constant (fp32) -> Node1
Constant (fp32) -> Node2
```
Deletion of the convert above fixes the duplication of the constant
                          
### Tickets:
 - *CVS-151490*
  • Loading branch information
itikhono authored Oct 3, 2024
1 parent 890f2e1 commit 505b59f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ bool ov::pass::MOCTransformations::run_on_model(const std::shared_ptr<ov::Model>
// In particular, if zero dim tensor is consumed in body of MultiSubGraphOp
// RemoveConcatZeroDimInput and RemoveMultiSubGraphOpDanglingParamsResults should be called together.
using namespace ov::pass;
REGISTER_PASS(manager, EliminateConvert)
REGISTER_PASS(manager, EliminateScatterUpdate)
REGISTER_PASS(manager, RemoveConcatZeroDimInput)
REGISTER_PASS(manager, EliminateLoopInputsOutputs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ TEST(TransformationTests, TestModelTensorsConsistencyUseShapesTrue) {
EXPECT_TRUE(model->outputs()[0].get_names() == new_tensors);
}

TEST(TransformationTests, MOCConvertElimination) {
auto input = std::make_shared<opset12::Parameter>(element::f32, Shape{1});
auto const_val = opset12::Constant::create(element::f32, Shape{1}, {2});

auto add1 = std::make_shared<opset12::Add>(input, const_val);
auto convert_fp32 = std::make_shared<opset12::Convert>(const_val, element::f32);
auto mul = std::make_shared<opset12::MatMul>(add1, convert_fp32);

auto model = std::make_shared<Model>(NodeVector{mul}, ParameterVector{input});
ov::pass::Manager m;
m.register_pass<ov::pass::MOCTransformations>(false);
m.run_passes(model);

EXPECT_EQ(count_ops_of_type<opset12::Constant>(model), 1);
}

TEST(TransformationTests, TestModelTensorsConsistencyUseShapesFalse) {
auto input = std::make_shared<opset12::Parameter>(element::f32, Shape{1});
auto const1 = opset12::Constant::create(element::f32, Shape{1}, {1});
Expand Down

0 comments on commit 505b59f

Please sign in to comment.