Zero inputs Concat fix and Scatter Update ops fix (#14284)
This commit is contained in:
1 parent
57082859ef
commit
9478062e79
6 files changed
+75
-1
No files matched your search
+12
@@ -14,6 +14,7 @@ class TRANSFORMATIONS_API EliminateConcat;
|
||||
class TRANSFORMATIONS_API EliminateConvert;
|
||||
class TRANSFORMATIONS_API EliminateConvertNonZero;
|
||||
class TRANSFORMATIONS_API EliminateEltwise;
|
||||
class TRANSFORMATIONS_API EliminateScatterUpdate;
|
||||
class TRANSFORMATIONS_API EliminatePad;
|
||||
class TRANSFORMATIONS_API EliminateSplit;
|
||||
class TRANSFORMATIONS_API EliminateSplitConcat;
|
||||
@@ -104,6 +105,16 @@ public:
|
||||
EliminateEltwise();
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief EliminateScatterUpdate eliminates scatter ops that do nothing (updates/indices are empty)
|
||||
*/
|
||||
class ov::pass::EliminateScatterUpdate : public ov::pass::MatcherPass {
|
||||
public:
|
||||
OPENVINO_RTTI("EliminateScatterUpdate", "0");
|
||||
EliminateScatterUpdate();
|
||||
};
|
||||
|
||||
class ov::pass::NopElimination : public GraphRewrite {
|
||||
public:
|
||||
OPENVINO_RTTI("NopElimination", "0");
|
||||
@@ -127,6 +138,7 @@ using ov::pass::EliminateConvert;
|
||||
using ov::pass::EliminateConvertNonZero;
|
||||
using ov::pass::EliminateEltwise;
|
||||
using ov::pass::EliminatePad;
|
||||
using ov::pass::EliminateScatterUpdate;
|
||||
using ov::pass::EliminateSplit;
|
||||
using ov::pass::EliminateSplitConcat;
|
||||
using ov::pass::EliminateSqueeze;
|
||||
|
||||
+1
@@ -109,6 +109,7 @@ bool ov::pass::MOCTransformations::run_on_model(const std::shared_ptr<ngraph::Fu
|
||||
// In particular, if zero dim tensor is consumed in body of MultiSubGraphOp
|
||||
// RemoveConcatZeroDimInput and RemoveMultiSubGraphOpDanglingParams should be called together.
|
||||
using namespace ov::pass;
|
||||
REGISTER_PASS(manager, EliminateScatterUpdate)
|
||||
REGISTER_PASS(manager, RemoveConcatZeroDimInput)
|
||||
REGISTER_PASS(manager, Validate)
|
||||
// todo: ticket 96960
|
||||
|
||||
+26
@@ -16,6 +16,7 @@
|
||||
#include <transformations/common_optimizations/nop_elimination.hpp>
|
||||
#include <transformations/utils/utils.hpp>
|
||||
|
||||
#include "compare.hpp"
|
||||
#include "itt.hpp"
|
||||
|
||||
using namespace std;
|
||||
@@ -718,6 +719,30 @@ pass::EliminateEltwise::EliminateEltwise() {
|
||||
this->register_matcher(m, callback);
|
||||
}
|
||||
|
||||
pass::EliminateScatterUpdate::EliminateScatterUpdate() {
|
||||
MATCHER_SCOPE(EliminateScatterUpdate);
|
||||
auto scatter_pattern =
|
||||
pattern::wrap_type<opset8::ScatterUpdate, opset8::ScatterNDUpdate, opset8::ScatterElementsUpdate>();
|
||||
|
||||
matcher_pass_callback callback = [=](pattern::Matcher& m) {
|
||||
auto scatter = m.get_match_root();
|
||||
const auto& indices_pshape = scatter->get_input_partial_shape(1);
|
||||
const auto& updates_pshape = scatter->get_input_partial_shape(2);
|
||||
|
||||
auto has_zero = [](const ov::PartialShape& shape) -> bool {
|
||||
return std::any_of(shape.cbegin(), shape.cend(), ov::cmp::Equal<ov::Dimension>(0));
|
||||
};
|
||||
if (has_zero(indices_pshape) || has_zero(updates_pshape)) {
|
||||
return replace_output_update_name(scatter->output(0), scatter->input_value(0));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
auto m = make_shared<pattern::Matcher>(scatter_pattern, matcher_name);
|
||||
this->register_matcher(m, callback);
|
||||
}
|
||||
|
||||
ngraph::pass::NopElimination::NopElimination(bool use_shape_for_elimination) {
|
||||
// shape-agnostic transformations
|
||||
ADD_MATCHER_FOR_THIS(EliminatePad)
|
||||
@@ -732,6 +757,7 @@ ngraph::pass::NopElimination::NopElimination(bool use_shape_for_elimination) {
|
||||
|
||||
// shape-dependent transformations
|
||||
if (use_shape_for_elimination) {
|
||||
ADD_MATCHER_FOR_THIS(EliminateScatterUpdate)
|
||||
ADD_MATCHER_FOR_THIS(EliminateReshape)
|
||||
ADD_MATCHER_FOR_THIS(EliminateSqueeze)
|
||||
ADD_MATCHER_FOR_THIS(EliminateUnsqueeze)
|
||||
|
||||
+13
-1
@@ -45,7 +45,19 @@ ov::pass::RemoveConcatZeroDimInput::RemoveConcatZeroDimInput() {
|
||||
|
||||
bool inputs_removed = concat->get_input_size() > concat_inputs.size();
|
||||
if (inputs_removed) {
|
||||
concat->set_arguments(concat_inputs);
|
||||
if (concat_inputs.empty()) {
|
||||
if (concat->get_output_element_type(0).is_dynamic())
|
||||
return false;
|
||||
if (concat->get_output_partial_shape(0).is_dynamic())
|
||||
return false;
|
||||
const auto& empty_constant = opset8::Constant::create(concat->get_output_element_type(0),
|
||||
concat->get_output_partial_shape(0).to_shape(),
|
||||
{});
|
||||
concat->output(0).replace(empty_constant);
|
||||
empty_constant->set_friendly_name(concat->get_friendly_name());
|
||||
} else {
|
||||
concat->set_arguments(concat_inputs);
|
||||
}
|
||||
}
|
||||
return inputs_removed;
|
||||
};
|
||||
|
||||
+21
@@ -178,3 +178,24 @@ TEST_F(TransformationTestsF, RemoveConcatZeroDimTwoInputs) {
|
||||
function_ref = std::make_shared<ov::Model>(ov::NodeVector{concat}, ov::ParameterVector{input1});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TransformationTestsF, RemoveConcatZeroDimAllInputsEmpty) {
|
||||
{
|
||||
auto input1 = std::make_shared<ov::opset8::Parameter>(ov::element::f32,
|
||||
ov::PartialShape{1, 0, 1});
|
||||
auto input2 = std::make_shared<ov::opset8::Parameter>(ov::element::f32,
|
||||
ov::PartialShape{1, 0, 1});
|
||||
|
||||
int64_t axis = -1;
|
||||
auto concat = std::make_shared<ov::opset8::Concat>(ov::OutputVector{input1, input2}, axis);
|
||||
|
||||
function = std::make_shared<ov::Model>(ov::NodeVector{concat}, ov::ParameterVector{input1, input2});
|
||||
|
||||
manager.register_pass<ov::pass::RemoveConcatZeroDimInput>();
|
||||
}
|
||||
|
||||
{
|
||||
auto concat = std::make_shared<ov::opset8::Constant>(ov::element::f32, ov::Shape{1, 0, 2}, std::vector<float>{});
|
||||
function_ref = std::make_shared<ov::Model>(ov::NodeVector{concat}, ov::ParameterVector{});
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <openvino/cc/pass/itt.hpp>
|
||||
#include <transformations/common_optimizations/dimension_tracking.hpp>
|
||||
#include <transformations/common_optimizations/fold_subgraph_empty_inputs.hpp>
|
||||
#include <transformations/common_optimizations/nop_elimination.hpp>
|
||||
#include <transformations/common_optimizations/remove_concat_zero_dim_input.hpp>
|
||||
#include <transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.hpp>
|
||||
#include <transformations/disable_decompression_convert_constant_folding.hpp>
|
||||
@@ -150,6 +151,7 @@ CNNNetworkNGraphImpl::CNNNetworkNGraphImpl(const std::shared_ptr<Function>& nGra
|
||||
using namespace ngraph::pass;
|
||||
REGISTER_PASS(m, FixRtInfo)
|
||||
using namespace ov::pass;
|
||||
REGISTER_PASS(m, EliminateScatterUpdate)
|
||||
REGISTER_PASS(m, RemoveConcatZeroDimInput)
|
||||
REGISTER_PASS(m, RemoveMultiSubGraphOpDanglingParams)
|
||||
REGISTER_PASS(m, FoldSubgraphEmptyInputs)
|
||||
|
||||
Reference in new issue
Block a user