Add HSigmoidFusionWithClampDiv fusion and remove duplicated patterns … (#5665)
* Add HSigmoidFusionWithClampDiv fusion and remove duplicated patterns in HSwishFusion * use latest opset
This commit is contained in:
parent
520a6bd647
commit
a54b82323a
@ -17,14 +17,15 @@ class TRANSFORMATIONS_API HSigmoidFusion;
|
||||
class TRANSFORMATIONS_API HSigmoidFusionWithReluDiv;
|
||||
class TRANSFORMATIONS_API HSigmoidFusionWithReluMul;
|
||||
class TRANSFORMATIONS_API HSigmoidFusionWithoutRelu;
|
||||
class TRANSFORMATIONS_API HSigmoidFusionWithClamp;
|
||||
class TRANSFORMATIONS_API HSigmoidFusionWithClampMul;
|
||||
class TRANSFORMATIONS_API HSigmoidFusionWithClampDiv;
|
||||
|
||||
} // namespace pass
|
||||
} // namespace ngraph
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6))) / 6 with a HSigmoid op.
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph ((min(Relu(x + 3), 6)) / 6) with a HSigmoid op.
|
||||
*/
|
||||
class ngraph::pass::HSigmoidFusionWithReluDiv: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
@ -34,7 +35,7 @@ public:
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6)) * const(1/6) with a HSigmoid op.
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph ((min(Relu(x + 3), 6)) * const(1/6)) with a HSigmoid op.
|
||||
*/
|
||||
class ngraph::pass::HSigmoidFusionWithReluMul: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
@ -44,7 +45,7 @@ public:
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph x * (min(max(x + 3, 0), 6) / 6) with a HSigmoid op.
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph (min(max(x + 3, 0), 6) / 6) with a HSigmoid op.
|
||||
*/
|
||||
class ngraph::pass::HSigmoidFusionWithoutRelu: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
@ -54,12 +55,22 @@ public:
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph x * (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op.
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op.
|
||||
*/
|
||||
class ngraph::pass::HSigmoidFusionWithClamp: public ngraph::pass::MatcherPass {
|
||||
class ngraph::pass::HSigmoidFusionWithClampMul: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
HSigmoidFusionWithClamp();
|
||||
HSigmoidFusionWithClampMul();
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSigmoidFusion transformation replaces a sub-graph (Clamp(x + 3, 0, 6) * / 6) with a HSigmoid op.
|
||||
*/
|
||||
class ngraph::pass::HSigmoidFusionWithClampDiv: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
HSigmoidFusionWithClampDiv();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -73,6 +84,7 @@ public:
|
||||
add_matcher<ngraph::pass::HSigmoidFusionWithReluDiv>();
|
||||
add_matcher<ngraph::pass::HSigmoidFusionWithReluMul>();
|
||||
add_matcher<ngraph::pass::HSigmoidFusionWithoutRelu>();
|
||||
add_matcher<ngraph::pass::HSigmoidFusionWithClamp>();
|
||||
add_matcher<ngraph::pass::HSigmoidFusionWithClampMul>();
|
||||
add_matcher<ngraph::pass::HSigmoidFusionWithClampDiv>();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -16,15 +16,12 @@ namespace pass {
|
||||
class TRANSFORMATIONS_API HSwishFusion;
|
||||
class TRANSFORMATIONS_API HSwishFusionWithReluDiv;
|
||||
class TRANSFORMATIONS_API HSwishFusionWithReluMul;
|
||||
class TRANSFORMATIONS_API HSwishFusionWithoutRelu;
|
||||
class TRANSFORMATIONS_API HSwishFusionWithClampMul;
|
||||
class TRANSFORMATIONS_API HSwishFusionWithClampDiv;
|
||||
class TRANSFORMATIONS_API HSwishFusionWithHSigmoidMul;
|
||||
|
||||
class TRANSFORMATIONS_API HSwishFusionWithHSigmoid;
|
||||
|
||||
} // namespace pass
|
||||
} // namespace ngraph
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSwishFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6))) / 6 with a HSwish op.
|
||||
@ -45,44 +42,14 @@ public:
|
||||
HSwishFusionWithReluMul();
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSwishFusion transformation replaces a sub-graph x * (min(max(x + 3, 0), 6) / 6) with a HSwish op.
|
||||
*/
|
||||
class ngraph::pass::HSwishFusionWithoutRelu: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
HSwishFusionWithoutRelu();
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSwishFusion transformation replaces a sub-graph x * (Clamp(x + 3, 0, 6) * const(1/6)) with a HSwish op.
|
||||
*/
|
||||
class ngraph::pass::HSwishFusionWithClampMul: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
HSwishFusionWithClampMul();
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSwishFusion transformation replaces a sub-graph x * (Clamp(x + 3, 0, 6) / 6) with a HSwish op.
|
||||
*/
|
||||
class ngraph::pass::HSwishFusionWithClampDiv: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
HSwishFusionWithClampDiv();
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief HSwishFusion transformation replaces a sub-graph x * HSigmoid(x) with a HSwish op.
|
||||
*/
|
||||
class ngraph::pass::HSwishFusionWithHSigmoidMul: public ngraph::pass::MatcherPass {
|
||||
class ngraph::pass::HSwishFusionWithHSigmoid: public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
HSwishFusionWithHSigmoidMul();
|
||||
HSwishFusionWithHSigmoid();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -95,9 +62,6 @@ public:
|
||||
HSwishFusion() {
|
||||
add_matcher<ngraph::pass::HSwishFusionWithReluDiv>();
|
||||
add_matcher<ngraph::pass::HSwishFusionWithReluMul>();
|
||||
add_matcher<ngraph::pass::HSwishFusionWithoutRelu>();
|
||||
add_matcher<ngraph::pass::HSwishFusionWithClampMul>();
|
||||
add_matcher<ngraph::pass::HSwishFusionWithClampDiv>();
|
||||
add_matcher<ngraph::pass::HSwishFusionWithHSigmoidMul>();
|
||||
add_matcher<ngraph::pass::HSwishFusionWithHSigmoid>();
|
||||
}
|
||||
};
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <ngraph/opsets/opset5.hpp>
|
||||
#include <ngraph/opsets/opset7.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
|
||||
@ -20,21 +20,21 @@ ngraph::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() {
|
||||
MATCHER_SCOPE(HSigmoidFusionWithReluDiv);
|
||||
// Replaces a sub-graph ((min(Relu(x + 3), 6)) / 6 with a HSigmoid op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto add = ngraph::pattern::wrap_type<ngraph::opset7::Add>({input, add_constant});
|
||||
auto relu = ngraph::pattern::wrap_type<ngraph::opset7::Relu>({add});
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto min = ngraph::pattern::wrap_type<ngraph::opset7::Minimum>({relu, min_constant});
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto div = ngraph::pattern::wrap_type<ngraph::opset7::Divide>({min, div_constant});
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value<float>(add_const_value, 3.0)
|
||||
&& op::util::has_constant_value<float>(min_const_value, 6.0)
|
||||
@ -44,7 +44,7 @@ ngraph::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(x_output);
|
||||
auto hsigmoid = register_new_node<ngraph::opset7::HSigmoid>(x_output);
|
||||
|
||||
hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
@ -67,22 +67,21 @@ ngraph::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() {
|
||||
MATCHER_SCOPE(HSigmoidFusionWithReluMul);
|
||||
// Replaces a sub-graph ((min(Relu(x + 3), 6)) * const(1/6) with a HSigmoid op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
//auto mul_first = std::make_shared<ngraph::opset4::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto mul_second = std::make_shared<ngraph::opset4::Multiply>(min, mul_constant);
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto add = ngraph::pattern::wrap_type<ngraph::opset7::Add>({input, add_constant});
|
||||
auto relu = ngraph::pattern::wrap_type<ngraph::opset7::Relu>({add});
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto min = ngraph::pattern::wrap_type<ngraph::opset7::Minimum>({relu, min_constant});
|
||||
auto mul_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto mul_second = ngraph::pattern::wrap_type<ngraph::opset7::Multiply>({min, mul_constant});
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto mul_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto mul_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value<float>(add_const_value, 3.0f)
|
||||
&& op::util::has_constant_value<float>(min_const_value, 6.0f)
|
||||
@ -92,7 +91,7 @@ ngraph::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(x_output);
|
||||
auto hsigmoid = register_new_node<ngraph::opset7::HSigmoid>(x_output);
|
||||
|
||||
hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
@ -115,24 +114,24 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() {
|
||||
MATCHER_SCOPE(HSigmoidFusionWithoutRelu);
|
||||
// Replaces a sub-graph (min(max(x + 3, 0), 6) / 6) with a HSigmoid op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto max = std::make_shared<ngraph::opset4::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset4::Multiply>(input, div);
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto add = ngraph::pattern::wrap_type<ngraph::opset7::Add>({input, add_constant});
|
||||
auto max_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto max = ngraph::pattern::wrap_type<ngraph::opset7::Maximum>({add, max_constant});
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto min = ngraph::pattern::wrap_type<ngraph::opset7::Minimum>({max, min_constant});
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto div = ngraph::pattern::wrap_type<ngraph::opset7::Divide>({min, div_constant});
|
||||
auto mul = ngraph::pattern::wrap_type<ngraph::opset7::Multiply>({input, div});
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto max_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(max_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto max_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(max_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value<float>(add_const_value, 3.0f)
|
||||
&& op::util::has_constant_value<float>(max_const_value, 0.0f)
|
||||
@ -143,7 +142,7 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(x_output);
|
||||
auto hsigmoid = register_new_node<ngraph::opset7::HSigmoid>(x_output);
|
||||
|
||||
hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
@ -160,24 +159,24 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() {
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidFusionWithClamp, "HSigmoidFusionWithClamp", 0);
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidFusionWithClampMul, "HSigmoidFusionWithClampMul", 0);
|
||||
|
||||
ngraph::pass::HSigmoidFusionWithClamp::HSigmoidFusionWithClamp() {
|
||||
MATCHER_SCOPE(HSigmoidFusionWithClamp);
|
||||
ngraph::pass::HSigmoidFusionWithClampMul::HSigmoidFusionWithClampMul() {
|
||||
MATCHER_SCOPE(HSigmoidFusionWithClampMul);
|
||||
// Replaces a sub-graph (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::op::v0::Clamp>(add, 0.0f, 6.0f);
|
||||
auto mul_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto mul_first = std::make_shared<ngraph::opset4::Multiply>(clamp, mul_constant);
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto add = ngraph::pattern::wrap_type<ngraph::opset7::Add>({input, add_constant});
|
||||
auto clamp = ngraph::pattern::wrap_type<ngraph::op::v0::Clamp>({add});
|
||||
auto mul_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto mul_first = ngraph::pattern::wrap_type<ngraph::opset7::Multiply>({clamp, mul_constant});
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto mul_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto mul_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0)
|
||||
&& op::util::has_constant_value(mul_const_value, (1.0/6.0), 0.0001);
|
||||
@ -186,7 +185,11 @@ ngraph::pass::HSigmoidFusionWithClamp::HSigmoidFusionWithClamp() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(x_output);
|
||||
auto clamp_node = std::dynamic_pointer_cast<ngraph::opset7::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());
|
||||
if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6)
|
||||
return false;
|
||||
|
||||
auto hsigmoid = register_new_node<ngraph::opset7::HSigmoid>(x_output);
|
||||
|
||||
hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
@ -201,3 +204,49 @@ ngraph::pass::HSigmoidFusionWithClamp::HSigmoidFusionWithClamp() {
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(mul_first, matcher_name);
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidFusionWithClampDiv, "HSigmoidFusionWithClampDiv", 0);
|
||||
|
||||
ngraph::pass::HSigmoidFusionWithClampDiv::HSigmoidFusionWithClampDiv() {
|
||||
MATCHER_SCOPE(HSigmoidFusionWithClampDiv);
|
||||
// Replaces a sub-graph (Clamp(x + 3, 0, 6) / 6) with a HSigmoid op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto add = ngraph::pattern::wrap_type<ngraph::opset7::Add>({input, add_constant});
|
||||
auto clamp = ngraph::pattern::wrap_type<ngraph::op::v0::Clamp>({add});
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto div = ngraph::pattern::wrap_type<ngraph::opset7::Divide>({clamp, div_constant});
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0)
|
||||
&& op::util::has_constant_value(div_const_value, 6.0);
|
||||
|
||||
if (!valid_constant_values) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto clamp_node = std::dynamic_pointer_cast<ngraph::opset7::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());
|
||||
if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6)
|
||||
return false;
|
||||
|
||||
auto hsigmoid = register_new_node<ngraph::opset7::HSigmoid>(x_output);
|
||||
|
||||
hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
pattern_to_output.at(clamp).get_node_shared_ptr(),
|
||||
pattern_to_output.at(div).get_node_shared_ptr()
|
||||
},
|
||||
hsigmoid);
|
||||
ngraph::replace_node(m.get_match_root(), hsigmoid);
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(div, matcher_name);
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <ngraph/opsets/opset6.hpp>
|
||||
#include <ngraph/opsets/opset7.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
|
||||
@ -20,22 +20,22 @@ ngraph::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() {
|
||||
MATCHER_SCOPE(HSwishFusionWithReluDiv);
|
||||
// Replaces a sub-graph (x * (min(Relu(x + 3), 6)) / 6 with a HSwish op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(mul, div_constant);
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant);
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value<float>(add_const_value, 3.0)
|
||||
&& op::util::has_constant_value<float>(min_const_value, 6.0)
|
||||
@ -45,7 +45,7 @@ ngraph::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(x_output);
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(x_output);
|
||||
|
||||
hswish->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(),
|
||||
@ -72,22 +72,22 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() {
|
||||
MATCHER_SCOPE(HSwishFusionWithReluMul);
|
||||
// Replaces a sub-graph (x * (min(Relu(x + 3), 6)) * const(1/6) with a HSwish op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(mul_first, mul_constant);
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::pattern::wrap_type<ngraph::opset7::Constant>();
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(mul_first, mul_constant);
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto mul_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto mul_const_value = std::dynamic_pointer_cast<ngraph::opset7::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value<float>(add_const_value, 3.0f)
|
||||
&& op::util::has_constant_value<float>(min_const_value, 6.0f)
|
||||
@ -97,7 +97,7 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(x_output);
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(x_output);
|
||||
|
||||
hswish->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(),
|
||||
@ -118,166 +118,21 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() {
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithoutRelu, "HSwishFusionWithoutRelu", 0);
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithHSigmoid, "HSwishFusionWithHSigmoid", 0);
|
||||
|
||||
ngraph::pass::HSwishFusionWithoutRelu::HSwishFusionWithoutRelu() {
|
||||
MATCHER_SCOPE(HSwishFusionWithoutRelu);
|
||||
// Replaces a sub-graph x * (min(max(x + 3, 0), 6) / 6) with a HSwish op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto max = std::make_shared<ngraph::opset6::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, div);
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto max_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(max_constant).get_node_shared_ptr());
|
||||
auto min_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value<float>(add_const_value, 3.0f)
|
||||
&& op::util::has_constant_value<float>(max_const_value, 0.0f)
|
||||
&& op::util::has_constant_value<float>(min_const_value, 6.0f)
|
||||
&& op::util::has_constant_value<float>(div_const_value, 6.0f);
|
||||
|
||||
if (!valid_constant_values) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(x_output);
|
||||
|
||||
hswish->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(),
|
||||
pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
pattern_to_output.at(max_constant).get_node_shared_ptr(),
|
||||
pattern_to_output.at(max).get_node_shared_ptr(),
|
||||
pattern_to_output.at(min_constant).get_node_shared_ptr(),
|
||||
pattern_to_output.at(min).get_node_shared_ptr(),
|
||||
pattern_to_output.at(div_constant).get_node_shared_ptr(),
|
||||
pattern_to_output.at(div).get_node_shared_ptr(),
|
||||
pattern_to_output.at(mul).get_node_shared_ptr()
|
||||
},
|
||||
hswish);
|
||||
ngraph::replace_node(m.get_match_root(), hswish);
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(mul, matcher_name);
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithClampMul, "HSwishFusionWithClampMul", 0);
|
||||
|
||||
ngraph::pass::HSwishFusionWithClampMul::HSwishFusionWithClampMul() {
|
||||
MATCHER_SCOPE(HSwishFusionWithClampMul);
|
||||
// Replaces a sub-graph x * (Clamp(x + 3, 0, 6) * const(1/6)) with a HSwish op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset6::Clamp>(add, 0.0f, 6.0f);
|
||||
auto mul_constant = ngraph::pattern::wrap_type<ngraph::opset6::Constant>();
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(clamp, mul_constant);
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(input, mul_first);
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto mul_const_value = std::dynamic_pointer_cast<ngraph::opset6::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0)
|
||||
&& op::util::has_constant_value(mul_const_value, (1.0/6.0), 0.0001);
|
||||
|
||||
if (!valid_constant_values) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(x_output);
|
||||
|
||||
hswish->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(),
|
||||
pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
pattern_to_output.at(clamp).get_node_shared_ptr(),
|
||||
pattern_to_output.at(mul_constant).get_node_shared_ptr(),
|
||||
pattern_to_output.at(mul_first).get_node_shared_ptr(),
|
||||
pattern_to_output.at(mul_second).get_node_shared_ptr()
|
||||
},
|
||||
hswish);
|
||||
ngraph::replace_node(m.get_match_root(), hswish);
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(mul_second, matcher_name);
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithClampDiv, "HSwishFusionWithClampDiv", 0);
|
||||
|
||||
ngraph::pass::HSwishFusionWithClampDiv::HSwishFusionWithClampDiv() {
|
||||
MATCHER_SCOPE(HSwishFusionWithClampDiv);
|
||||
// Replaces a sub-graph x * (Clamp(x + 3, 0, 6) / 6) with a HSwish op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto add_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset4::Clamp>(add, 0.0f, 6.0f);
|
||||
auto div_constant = ngraph::pattern::wrap_type<ngraph::opset4::Constant>();
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(clamp, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset4::Multiply>(input, div);
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
auto &pattern_to_output = m.get_pattern_value_map();
|
||||
auto x_output = pattern_to_output.at(input);
|
||||
|
||||
auto add_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());
|
||||
auto div_const_value = std::dynamic_pointer_cast<ngraph::opset4::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());
|
||||
|
||||
bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0)
|
||||
&& op::util::has_constant_value(div_const_value, 6.0);
|
||||
if (!valid_constant_values) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hswish = std::make_shared<ngraph::opset4::HSwish>(x_output);
|
||||
|
||||
hswish->set_friendly_name(m.get_match_root()->get_friendly_name());
|
||||
ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(),
|
||||
pattern_to_output.at(clamp).get_node_shared_ptr(),
|
||||
pattern_to_output.at(div).get_node_shared_ptr(),
|
||||
pattern_to_output.at(mul).get_node_shared_ptr()
|
||||
},
|
||||
hswish);
|
||||
ngraph::replace_node(m.get_match_root(), hswish);
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(mul, matcher_name);
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithHSigmoidMul, "HSwishFusionWithHSigmoidMul", 0);
|
||||
|
||||
ngraph::pass::HSwishFusionWithHSigmoidMul::HSwishFusionWithHSigmoidMul() {
|
||||
MATCHER_SCOPE(HSwishFusionWithHSigmoidMul);
|
||||
ngraph::pass::HSwishFusionWithHSigmoid::HSwishFusionWithHSigmoid() {
|
||||
MATCHER_SCOPE(HSwishFusionWithHSigmoid);
|
||||
// Replaces a sub-graph x * HSigmoid(x) with a HSwish op.
|
||||
auto input = ngraph::pattern::any_input();
|
||||
auto hsigmoid_pattern = ngraph::pattern::wrap_type<ngraph::opset6::HSigmoid>({input}, ngraph::pattern::consumers_count(1));
|
||||
auto mul_pattern = ngraph::pattern::wrap_type<ngraph::opset6::Multiply>({input, hsigmoid_pattern});
|
||||
auto input = pattern::any_input();
|
||||
auto hsigmoid_pattern = pattern::wrap_type<ngraph::opset7::HSigmoid>({input}, pattern::consumers_count(1));
|
||||
auto mul_pattern = pattern::wrap_type<ngraph::opset7::Multiply>({input, hsigmoid_pattern});
|
||||
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
|
||||
const auto& pattern_to_output = m.get_pattern_value_map();
|
||||
auto hsigmoid = pattern_to_output.at(hsigmoid_pattern).get_node_shared_ptr();
|
||||
auto mul = pattern_to_output.at(mul_pattern).get_node_shared_ptr();
|
||||
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(pattern_to_output.at(input));
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(pattern_to_output.at(input));
|
||||
hswish->set_friendly_name(mul->get_friendly_name());
|
||||
ngraph::copy_runtime_info({hsigmoid, mul}, hswish);
|
||||
ngraph::replace_node(mul, hswish);
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include <ngraph/function.hpp>
|
||||
#include <ngraph/opsets/opset5.hpp>
|
||||
#include <ngraph/opsets/opset7.hpp>
|
||||
#include <ngraph/pass/manager.hpp>
|
||||
#include <transformations/common_optimizations/hsigmoid_fusion.hpp>
|
||||
#include <transformations/init_node_info.hpp>
|
||||
@ -21,14 +21,14 @@ using namespace testing;
|
||||
TEST(TransformationTests, HSigmoidFusionWithReluDivF16) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -40,8 +40,8 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF16) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -53,14 +53,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF16) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithReluDivF32) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -72,8 +72,8 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF32) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -85,14 +85,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF32) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithReluMul) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716});
|
||||
auto mul_second = std::make_shared<ngraph::opset4::Multiply>(min, mul_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716});
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(min, mul_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -104,8 +104,8 @@ TEST(TransformationTests, HSigmoidFusionWithReluMul) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -117,15 +117,15 @@ TEST(TransformationTests, HSigmoidFusionWithReluMul) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithoutRelu) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto max = std::make_shared<ngraph::opset4::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -137,8 +137,8 @@ TEST(TransformationTests, HSigmoidFusionWithoutRelu) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -147,15 +147,15 @@ TEST(TransformationTests, HSigmoidFusionWithoutRelu) {
|
||||
ASSERT_TRUE(res.first) << res.second;
|
||||
}
|
||||
|
||||
TEST(TransformationTests, HSigmoidFusionWithClamp) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithClampMul) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::op::v0::Clamp>(add, 0.0f, 6.0f);
|
||||
auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0});
|
||||
auto mul_first = std::make_shared<ngraph::opset4::Multiply>(clamp, mul_constant);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0});
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_first}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -167,8 +167,38 @@ TEST(TransformationTests, HSigmoidFusionWithClamp) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset5::HSigmoid>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input});
|
||||
}
|
||||
|
||||
auto res = compare_functions(f, f_ref);
|
||||
ASSERT_TRUE(res.first) << res.second;
|
||||
}
|
||||
|
||||
TEST(TransformationTests, HSigmoidFusionWithClampDiv) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset6::Clamp>(add, 0.0f, 6.0f);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(clamp, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSigmoidFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -180,14 +210,14 @@ TEST(TransformationTests, HSigmoidFusionWithClamp) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithReluMulWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset4::Multiply>(min, mul_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(min, mul_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -199,14 +229,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluMulWrongConstValue) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset4::Multiply>(min, mul_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(min, mul_constant);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -218,14 +248,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluMulWrongConstValue) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithReluDivWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -237,14 +267,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivWrongConstValue) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset4::Relu>(add);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -256,15 +286,15 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivWrongConstValue) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithoutReluWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset4::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -276,15 +306,15 @@ TEST(TransformationTests, HSigmoidFusionWithoutReluWrongConstValue) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset4::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset4::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset4::Divide>(min, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -296,12 +326,12 @@ TEST(TransformationTests, HSigmoidFusionWithoutReluWrongConstValue) {
|
||||
TEST(TransformationTests, HSigmoidFusionWithClampWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::op::v0::Clamp>(add, 0.11f, 6.02f);
|
||||
auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset4::Multiply>(clamp, mul_constant);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_first}, ngraph::ParameterVector{input});
|
||||
|
||||
@ -313,12 +343,12 @@ TEST(TransformationTests, HSigmoidFusionWithClampWrongConstValue) {
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset4::Add>(input, add_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::op::v0::Clamp>(add, 0.11f, 6.02f);
|
||||
auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset4::Multiply>(clamp, mul_constant);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_first}, ngraph::ParameterVector{input});
|
||||
}
|
||||
|
@ -8,8 +8,9 @@
|
||||
#include <memory>
|
||||
|
||||
#include <ngraph/function.hpp>
|
||||
#include <ngraph/opsets/opset6.hpp>
|
||||
#include <ngraph/opsets/opset7.hpp>
|
||||
#include <ngraph/pass/manager.hpp>
|
||||
#include "transformations/common_optimizations/hsigmoid_fusion.hpp"
|
||||
#include <transformations/common_optimizations/hswish_fusion.hpp>
|
||||
#include <transformations/init_node_info.hpp>
|
||||
#include <transformations/utils/utils.hpp>
|
||||
@ -21,28 +22,28 @@ using namespace testing;
|
||||
TEST(TransformationTests, HSwishFusionWithReluDivF16) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(mul, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithReluDiv>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -54,28 +55,28 @@ TEST(TransformationTests, HSwishFusionWithReluDivF16) {
|
||||
TEST(TransformationTests, HSwishFusionWithReluDivF32) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(mul, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithReluDiv>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -87,28 +88,28 @@ TEST(TransformationTests, HSwishFusionWithReluDivF32) {
|
||||
TEST(TransformationTests, HSwishFusionWithReluMul) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716});
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(mul_first, mul_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716});
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(mul_first, mul_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithReluMul>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -120,29 +121,31 @@ TEST(TransformationTests, HSwishFusionWithReluMul) {
|
||||
TEST(TransformationTests, HSwishFusionWithoutRelu) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto max = std::make_shared<ngraph::opset6::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, div);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithoutRelu>();
|
||||
auto gr = manager.register_pass<ngraph::pass::GraphRewrite>();
|
||||
gr->add_matcher<ngraph::pass::HSigmoidFusion>();
|
||||
gr->add_matcher<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -154,26 +157,28 @@ TEST(TransformationTests, HSwishFusionWithoutRelu) {
|
||||
TEST(TransformationTests, HSwishFusionWithClampMul) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset6::Clamp>(add, 0.0f, 6.0f);
|
||||
auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0});
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(clamp, mul_constant);
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(input, mul_first);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.0f, 6.0f);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0});
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant);
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(input, mul_first);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithClampMul>();
|
||||
auto gr = manager.register_pass<ngraph::pass::GraphRewrite>();
|
||||
gr->add_matcher<ngraph::pass::HSigmoidFusion>();
|
||||
gr->add_matcher<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -185,26 +190,28 @@ TEST(TransformationTests, HSwishFusionWithClampMul) {
|
||||
TEST(TransformationTests, HSwishFusionWithClampDiv) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset6::Clamp>(add, 0.0f, 6.0f);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(clamp, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, div);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.0f, 6.0f);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(clamp, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithClampDiv>();
|
||||
auto gr = manager.register_pass<ngraph::pass::GraphRewrite>();
|
||||
gr->add_matcher<ngraph::pass::HSigmoidFusion>();
|
||||
gr->add_matcher<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -216,35 +223,35 @@ TEST(TransformationTests, HSwishFusionWithClampDiv) {
|
||||
TEST(TransformationTests, HSwishFusionWithReluMulWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(mul_first, mul_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(mul_first, mul_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithReluMul>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(mul_first, mul_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167});
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(mul_first, mul_constant);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -256,35 +263,35 @@ TEST(TransformationTests, HSwishFusionWithReluMulWrongConstValue) {
|
||||
TEST(TransformationTests, HSwishFusionWithReluDivWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(mul, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithReluDiv>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset6::Relu>(add);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(mul, div_constant);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::Shape{});
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto relu = std::make_shared<ngraph::opset7::Relu>(add);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -296,37 +303,39 @@ TEST(TransformationTests, HSwishFusionWithReluDivWrongConstValue) {
|
||||
TEST(TransformationTests, HSwishFusionWithoutReluWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset6::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, div);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithoutRelu>();
|
||||
auto gr = manager.register_pass<ngraph::pass::GraphRewrite>();
|
||||
gr->add_matcher<ngraph::pass::HSigmoidFusion>();
|
||||
gr->add_matcher<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset6::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset6::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset6::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, div);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22});
|
||||
auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant);
|
||||
auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01});
|
||||
auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant);
|
||||
auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002});
|
||||
auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -338,31 +347,33 @@ TEST(TransformationTests, HSwishFusionWithoutReluWrongConstValue) {
|
||||
TEST(TransformationTests, HSwishFusionWithClampWrongConstValue) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset6::Clamp>(add, 0.11f, 6.02f);
|
||||
auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(clamp, mul_constant);
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(input, mul_first);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.11f, 6.02f);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant);
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(input, mul_first);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithoutRelu>();
|
||||
auto gr = manager.register_pass<ngraph::pass::GraphRewrite>();
|
||||
gr->add_matcher<ngraph::pass::HSigmoidFusion>();
|
||||
gr->add_matcher<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset6::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset6::Clamp>(add, 0.11f, 6.02f);
|
||||
auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset6::Multiply>(clamp, mul_constant);
|
||||
auto mul_second = std::make_shared<ngraph::opset6::Multiply>(input, mul_first);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11});
|
||||
auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant);
|
||||
auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.11f, 6.02f);
|
||||
auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15});
|
||||
auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant);
|
||||
auto mul_second = std::make_shared<ngraph::opset7::Multiply>(input, mul_first);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input});
|
||||
}
|
||||
@ -374,22 +385,22 @@ TEST(TransformationTests, HSwishFusionWithClampWrongConstValue) {
|
||||
TEST(TransformationTests, HSwishFusionWithHSigmoidMul) {
|
||||
std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset6::HSigmoid>(input);
|
||||
auto mul = std::make_shared<ngraph::opset6::Multiply>(input, hsigmoid);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input);
|
||||
auto mul = std::make_shared<ngraph::opset7::Multiply>(input, hsigmoid);
|
||||
|
||||
f = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input});
|
||||
|
||||
ngraph::pass::Manager manager;
|
||||
manager.register_pass<ngraph::pass::InitNodeInfo>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusionWithHSigmoidMul>();
|
||||
manager.register_pass<ngraph::pass::HSwishFusion>();
|
||||
manager.run_passes(f);
|
||||
ASSERT_NO_THROW(check_rt_info(f));
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset6::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset6::HSwish>(input);
|
||||
auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1));
|
||||
auto hswish = std::make_shared<ngraph::opset7::HSwish>(input);
|
||||
|
||||
f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user