-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Transformations] Add Squeeze-15 downgrade transformation #27286
Merged
mlukasze
merged 5 commits into
openvinotoolkit:master
from
mmikolajcz:mateuszm/squeeze15/downgrade
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c6140dd
[Transformations] Add Squeeze-15 downgrade transformation
mmikolajcz 8190601
Merge branch 'master' into mateuszm/squeeze15/downgrade
mlukasze 46ac6db
Add check to compare transform pshape
mmikolajcz 125b727
Merge branch 'mateuszm/squeeze15/downgrade' of https://github.com/mmi…
mmikolajcz fa8e730
Merge branch 'master' into mateuszm/squeeze15/downgrade
mmikolajcz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...on/transformations/include/transformations/op_conversions/convert_squeeze15_downgrade.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "openvino/pass/matcher_pass.hpp" | ||
#include "transformations_visibility.hpp" | ||
|
||
namespace ov { | ||
namespace pass { | ||
/** | ||
* @ingroup ov_transformation_common_api | ||
* @brief Converts Squeeze v15 to Squeeze v0. | ||
*/ | ||
class TRANSFORMATIONS_API ConvertSqueeze15ToSqueeze0 : public MatcherPass { | ||
public: | ||
OPENVINO_RTTI("ConvertSqueeze15ToSqueeze0", "0"); | ||
ConvertSqueeze15ToSqueeze0(); | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...common/transformations/src/transformations/op_conversions/convert_squeeze15_downgrade.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "transformations/op_conversions/convert_squeeze15_downgrade.hpp" | ||
|
||
#include "itt.hpp" | ||
#include "openvino/core/rt_info.hpp" | ||
#include "openvino/op/squeeze.hpp" | ||
#include "openvino/pass/pattern/op/wrap_type.hpp" | ||
#include "transformations/utils/utils.hpp" | ||
|
||
ov::pass::ConvertSqueeze15ToSqueeze0::ConvertSqueeze15ToSqueeze0() { | ||
MATCHER_SCOPE(ConvertSqueeze15ToSqueeze0); | ||
|
||
const auto& squeeze_v15_pattern = pattern::wrap_type<ov::op::v15::Squeeze>(); | ||
|
||
const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) { | ||
const auto& squeeze_v15 = ov::as_type_ptr<ov::op::v15::Squeeze>(m.get_match_root()); | ||
if (!squeeze_v15 || transformation_callback(squeeze_v15)) { | ||
return false; | ||
} | ||
std::shared_ptr<op::v0::Squeeze> squeeze_v0; | ||
if (squeeze_v15->get_input_size() == 1) { | ||
squeeze_v0 = std::make_shared<op::v0::Squeeze>(squeeze_v15->input_value(0)); | ||
} else if (squeeze_v15->get_input_size() == 2 && !squeeze_v15->get_allow_axis_skip()) { | ||
squeeze_v0 = std::make_shared<op::v0::Squeeze>(squeeze_v15->input_value(0), squeeze_v15->input_value(1)); | ||
} else { | ||
return false; | ||
} | ||
squeeze_v0->set_friendly_name(squeeze_v15->get_friendly_name()); | ||
copy_runtime_info(squeeze_v15, squeeze_v0); | ||
replace_node(squeeze_v15, squeeze_v0); | ||
|
||
return true; | ||
}; | ||
|
||
auto m = std::make_shared<pattern::Matcher>(squeeze_v15_pattern, matcher_name); | ||
register_matcher(m, callback); | ||
} |
112 changes: 112 additions & 0 deletions
112
src/common/transformations/tests/op_conversions/convert_squeeze15_downgrade_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "transformations/op_conversions/convert_squeeze15_downgrade.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <memory> | ||
|
||
#include "common_test_utils/ov_test_utils.hpp" | ||
#include "openvino/opsets/opset1.hpp" | ||
#include "openvino/opsets/opset15.hpp" | ||
#include "openvino/pass/manager.hpp" | ||
#include "transformations/utils/utils.hpp" | ||
using namespace ov; | ||
using namespace testing; | ||
|
||
namespace { | ||
|
||
enum class IndicesMode { NONE, CONST, PARAM }; | ||
|
||
std::shared_ptr<ov::Model> create_v15_model(const IndicesMode indices_mode, | ||
const std::vector<int> indices_const_val, | ||
const bool allow_axis_skip) { | ||
const PartialShape data_shape{-1, {2, 5}, 1, {1, 5}, 4}; | ||
const auto& data = std::make_shared<ov::opset15::Parameter>(ov::element::f32, data_shape); | ||
ov::ParameterVector params = {data}; | ||
std::shared_ptr<op::v15::Squeeze> squeeze; | ||
if (indices_mode == IndicesMode::NONE) { | ||
squeeze = std::make_shared<ov::opset15::Squeeze>(data, allow_axis_skip); | ||
} else if (indices_mode == IndicesMode::PARAM) { | ||
const auto& indices = | ||
std::make_shared<ov::opset15::Parameter>(ov::element::i32, PartialShape({data_shape.rank()})); | ||
params.push_back(indices); | ||
squeeze = std::make_shared<ov::opset15::Squeeze>(data, indices, allow_axis_skip); | ||
} else if (indices_mode == IndicesMode::CONST) { | ||
const auto& indices = | ||
ov::opset15::Constant::create(ov::element::i32, Shape({indices_const_val.size()}), indices_const_val); | ||
squeeze = std::make_shared<ov::opset15::Squeeze>(data, indices, allow_axis_skip); | ||
} | ||
squeeze->set_friendly_name("squeeze15"); | ||
return std::make_shared<ov::Model>(squeeze->outputs(), params); | ||
} | ||
|
||
std::shared_ptr<ov::Model> create_v1_model(const IndicesMode indices_mode, const std::vector<int> indices_const_val) { | ||
const PartialShape data_shape{-1, {2, 5}, 1, {1, 5}, 4}; | ||
const auto& data = std::make_shared<ov::opset1::Parameter>(ov::element::f32, data_shape); | ||
ov::ParameterVector params = {data}; | ||
std::shared_ptr<op::v0::Squeeze> squeeze; | ||
if (indices_mode == IndicesMode::NONE) { | ||
squeeze = std::make_shared<ov::opset1::Squeeze>(data); | ||
} else if (indices_mode == IndicesMode::PARAM) { | ||
const auto& indices = | ||
std::make_shared<ov::opset1::Parameter>(ov::element::i32, PartialShape({data_shape.rank()})); | ||
params.push_back(indices); | ||
squeeze = std::make_shared<ov::opset1::Squeeze>(data, indices); | ||
} else if (indices_mode == IndicesMode::CONST) { | ||
const auto& indices = | ||
ov::opset1::Constant::create(ov::element::i32, Shape({indices_const_val.size()}), indices_const_val); | ||
squeeze = std::make_shared<ov::opset1::Squeeze>(data, indices); | ||
} | ||
squeeze->set_friendly_name("squeeze15"); | ||
return std::make_shared<ov::Model>(squeeze->outputs(), params); | ||
} | ||
|
||
} // namespace | ||
|
||
TEST_F(TransformationTestsF, ConvertSqueeze15ToSqueeze1_no_indices_no_skip) { | ||
manager.register_pass<ov::pass::ConvertSqueeze15ToSqueeze0>(); | ||
model = create_v15_model(IndicesMode::NONE, {}, false); | ||
model_ref = create_v1_model(IndicesMode::NONE, {}); | ||
EXPECT_EQ(model->output(0).get_partial_shape(), model_ref->output(0).get_partial_shape()); | ||
comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); | ||
comparator.enable(FunctionsComparator::CmpValues::ATTRIBUTES); | ||
comparator.enable(FunctionsComparator::CmpValues::NAMES); | ||
} | ||
|
||
TEST_F(TransformationTestsF, ConvertSqueeze15ToSqueeze1_no_indices_skip) { | ||
manager.register_pass<ov::pass::ConvertSqueeze15ToSqueeze0>(); | ||
model = create_v15_model(IndicesMode::NONE, {}, true); | ||
model_ref = create_v1_model(IndicesMode::NONE, {}); | ||
EXPECT_EQ(model->output(0).get_partial_shape(), model_ref->output(0).get_partial_shape()); | ||
comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); | ||
comparator.enable(FunctionsComparator::CmpValues::ATTRIBUTES); | ||
comparator.enable(FunctionsComparator::CmpValues::NAMES); | ||
} | ||
|
||
TEST_F(TransformationTestsF, ConvertSqueeze15ToSqueeze1_const_indices_no_skip) { | ||
manager.register_pass<ov::pass::ConvertSqueeze15ToSqueeze0>(); | ||
model = create_v15_model(IndicesMode::CONST, {0, -4, 3}, false); | ||
model_ref = create_v1_model(IndicesMode::CONST, {0, -4, 3}); | ||
EXPECT_EQ(model->output(0).get_partial_shape(), model_ref->output(0).get_partial_shape()); | ||
comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); | ||
comparator.enable(FunctionsComparator::CmpValues::ATTRIBUTES); | ||
comparator.enable(FunctionsComparator::CmpValues::NAMES); | ||
} | ||
|
||
TEST_F(TransformationTestsF, ConvertSqueeze15ToSqueeze1_dynamic_indices_no_skip) { | ||
manager.register_pass<ov::pass::ConvertSqueeze15ToSqueeze0>(); | ||
model = create_v15_model(IndicesMode::PARAM, {}, false); | ||
model_ref = create_v1_model(IndicesMode::PARAM, {}); | ||
EXPECT_EQ(model->output(0).get_partial_shape(), model_ref->output(0).get_partial_shape()); | ||
comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); | ||
comparator.enable(FunctionsComparator::CmpValues::ATTRIBUTES); | ||
comparator.enable(FunctionsComparator::CmpValues::NAMES); | ||
} | ||
|
||
TEST_F(TransformationTestsF, ConvertSqueeze15ToSqueeze1_unsupported_skip) { | ||
manager.register_pass<ov::pass::ConvertSqueeze15ToSqueeze0>(); | ||
model = create_v15_model(IndicesMode::PARAM, {}, true); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v15::Squeeze single input constructor has been extended with
allow_axis_skip
so thefalse
value should be a common conditionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or the behavior is the same when axes are not provided?
@barnasm1 Could you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result for empty axes is the same (
PartialShape::dynamic()
) for both attributes values.