-
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 downgrade transformation for AvgPool-14
and MaxPool-14
#23381
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ba6df14
Add downgrade transformation
p-wysocki 1b10463
Merge remote-tracking branch 'upstream/master' into pool_downgrade
p-wysocki 51ef54f
Minor change
p-wysocki 48d6342
Merge branch 'master' into pool_downgrade
p-wysocki 95551d9
Disable transformations for template plugin
p-wysocki 40db892
Refactor into single file for NPU plugin
p-wysocki 6467d88
Merge branch 'master' into pool_downgrade
p-wysocki c08ce1d
Merge branch 'master' into pool_downgrade
mlukasze 818f710
WIP
p-wysocki be530bc
Merge branch 'pool_downgrade' of https://github.com/p-wysocki/openvin…
p-wysocki acb24a3
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
p-wysocki 32248fe
WIP
p-wysocki 021e124
Merge remote-tracking branch 'upstream/master' into pool_downgrade
p-wysocki 367d6d1
Added workaround subgraph
p-wysocki ecd4c5f
Merge remote-tracking branch 'upstream/master' into pool_downgrade
p-wysocki d9caaae
Fix segfault in test
p-wysocki 425eb6f
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
p-wysocki 00a0f4f
Apply CR
p-wysocki c4d332d
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
p-wysocki 9c98562
Apply CR
p-wysocki bdcf948
Fix code style
p-wysocki 65b96f9
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
p-wysocki 7c84245
Minor change
p-wysocki b12dce2
Apply CR
p-wysocki f44d1a4
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
p-wysocki 32cbea8
Apply CR
p-wysocki 05f817c
Clang format
p-wysocki 726e59f
Merge branch 'master' into pool_downgrade
mlukasze c5c63c4
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
p-wysocki 3cd7778
Fix include errors
p-wysocki 35daa3a
Minor change
p-wysocki 4604156
Minor change
p-wysocki 070c111
Fix linter
p-wysocki c4d93eb
Merge branch 'master' into pool_downgrade
p-wysocki dd43c61
Merge branch 'master' into pool_downgrade
p-wysocki 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
22 changes: 22 additions & 0 deletions
22
...mmon/transformations/include/transformations/op_conversions/convert_avgpool_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,22 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "openvino/pass/graph_rewrite.hpp" | ||
#include "transformations_visibility.hpp" | ||
|
||
namespace ov { | ||
namespace pass { | ||
/** | ||
* @ingroup ie_transformation_common_api | ||
* @brief Converts AvgPool v14 to AvgPool v1 | ||
*/ | ||
class TRANSFORMATIONS_API ConvertAvgPool14ToAvgPool1 : public MatcherPass { | ||
public: | ||
OPENVINO_RTTI("ConvertAvgPool14ToAvgPool1", "0"); | ||
ConvertAvgPool14ToAvgPool1(); | ||
}; | ||
} // 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
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
96 changes: 96 additions & 0 deletions
96
src/common/transformations/src/transformations/op_conversions/convert_avgpool_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,96 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "transformations/op_conversions/convert_avgpool_downgrade.hpp" | ||
|
||
#include "itt.hpp" | ||
#include "openvino/core/rt_info.hpp" | ||
#include "openvino/op/avg_pool.hpp" | ||
#include "openvino/op/broadcast.hpp" | ||
#include "openvino/op/concat.hpp" | ||
#include "openvino/op/convert_like.hpp" | ||
#include "openvino/op/gather.hpp" | ||
#include "openvino/op/pad.hpp" | ||
#include "openvino/op/range.hpp" | ||
#include "openvino/op/select.hpp" | ||
#include "openvino/op/shape_of.hpp" | ||
#include "openvino/op/subtract.hpp" | ||
#include "openvino/pass/pattern/op/wrap_type.hpp" | ||
#include "transformations/utils/utils.hpp" | ||
|
||
ov::pass::ConvertAvgPool14ToAvgPool1::ConvertAvgPool14ToAvgPool1() { | ||
MATCHER_SCOPE(ConvertAvgPool14ToAvgPool1); | ||
|
||
const auto avg_pool_v14_pattern = pattern::wrap_type<ov::op::v14::AvgPool>(); | ||
|
||
const matcher_pass_callback callback = [](pattern::Matcher& m) { | ||
const auto avg_pool_v14 = std::dynamic_pointer_cast<ov::op::v14::AvgPool>(m.get_match_root()); | ||
const auto rounding_type_v14 = avg_pool_v14->get_rounding_type(); | ||
const auto rounding_type_v1 = | ||
mlukasze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rounding_type_v14 == ov::op::RoundingType::CEIL_TORCH ? ov::op::RoundingType::CEIL : rounding_type_v14; | ||
|
||
const auto exclude_pad = avg_pool_v14->get_exclude_pad(); | ||
const auto input = avg_pool_v14->input_value(0); | ||
NodeRegistry node_registry; | ||
ov::Shape pads_begin; | ||
ov::Shape pads_end; | ||
ov::Output<ov::Node> new_input; | ||
|
||
using ov::op::v0::Constant; | ||
using ov::op::v0::Concat; | ||
using ov::op::v1::Pad; | ||
using ov::op::v1::Subtract; | ||
using ov::op::v1::ConvertLike; | ||
using ov::op::v3::Broadcast; | ||
using ov::op::v3::ShapeOf; | ||
using ov::op::v4::Range; | ||
|
||
if (!exclude_pad && rounding_type_v14 == ov::op::RoundingType::CEIL_TORCH) { | ||
const auto zero = node_registry.make<Constant>(element::f32, Shape{}, 0); | ||
const auto zero_node = node_registry.make<ConvertLike>(zero, input); | ||
const auto zero_i64 = node_registry.make<Constant>(element::i64, Shape{}, 0); | ||
const auto shape = node_registry.make<ShapeOf>(input, element::i64); | ||
const auto rank = node_registry.make<ShapeOf>(shape, element::i64); | ||
const auto pads_begin_v14 = avg_pool_v14->get_pads_begin(); | ||
const auto pads_begin_node = | ||
node_registry.make<Constant>(element::i64, Shape{pads_begin_v14.size()}, pads_begin_v14); | ||
const auto pads_end_v14 = avg_pool_v14->get_pads_end(); | ||
const auto pads_end_node = | ||
node_registry.make<Constant>(element::i64, Shape{pads_end_v14.size()}, pads_end_v14); | ||
const auto pads_len = node_registry.make<Constant>(element::i64, Shape{}, pads_begin_v14.size()); | ||
const auto pads_diff = node_registry.make<Subtract>(rank, pads_len); | ||
const auto pads_remaining = node_registry.make<Broadcast>(zero_i64, pads_diff); | ||
const auto pads_begin_v1 = node_registry.make<ov::op::v0::Concat>( | ||
OutputVector{std::move(pads_remaining), std::move(pads_begin_node)}, | ||
0); | ||
const auto pads_end_v1 = node_registry.make<ov::op::v0::Concat>( | ||
OutputVector{std::move(pads_remaining), std::move(pads_begin_node)}, | ||
0); | ||
const auto pad_node = | ||
node_registry.make<Pad>(input, pads_begin_v1, pads_end_v1, zero_node, ov::op::PadMode::CONSTANT); | ||
pads_begin = Shape(pads_begin_v14.size(), 0); | ||
pads_end = Shape(pads_begin_v14.size(), 0); | ||
new_input = pad_node; | ||
} else { | ||
pads_begin = avg_pool_v14->get_pads_begin(); | ||
pads_end = avg_pool_v14->get_pads_end(); | ||
new_input = input; | ||
} | ||
const auto avg_pool_v1 = node_registry.make<ov::op::v1::AvgPool>(new_input, | ||
avg_pool_v14->get_strides(), | ||
pads_begin, | ||
pads_end, | ||
avg_pool_v14->get_kernel(), | ||
exclude_pad, | ||
rounding_type_v1, | ||
avg_pool_v14->get_auto_pad()); | ||
avg_pool_v1->set_friendly_name(avg_pool_v14->get_friendly_name()); | ||
copy_runtime_info(avg_pool_v14, node_registry.get()); | ||
replace_node(avg_pool_v14, avg_pool_v1); | ||
return true; | ||
}; | ||
|
||
auto m = std::make_shared<pattern::Matcher>(avg_pool_v14_pattern, matcher_name); | ||
register_matcher(m, callback); | ||
} |
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
Oops, something went wrong.
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.
from the code, it looks like we always can donwgrade avg_pool v14 to v1.
Are there any cases where we can't downgrade?
should we "return false" for these cases to prevent this downgrade?
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.
I'm not aware of such cases since
AvgPoolV14
differs only in additionalov::op::RoundingType::CEIL_TORCH
which is getting converted toov::op::RoundingType::CEIL
. The only significant thing happening in the transformation is the workaround subgraph for pooling in padding area mentioned in #23381 (comment).