[SoftSign-9] Shell, reference impl and decomposition for SoftSign-9 (#11546)
This commit is contained in:
1 parent
7851020cd3
commit
62d17a070a
25 files changed
+544
-10
No files matched your search
@@ -77,6 +77,7 @@
|
||||
#include <ngraph/runtime/reference/sequences.hpp>
|
||||
#include <ngraph/runtime/reference/sigmoid.hpp>
|
||||
#include <ngraph/runtime/reference/sign.hpp>
|
||||
#include <ngraph/runtime/reference/softsign.hpp>
|
||||
#include <ngraph/runtime/reference/squared_difference.hpp>
|
||||
#include <ngraph/runtime/reference/tanh.hpp>
|
||||
#include <ngraph/runtime/reference/tensor_iterator.hpp>
|
||||
@@ -3729,6 +3730,36 @@ bool evaluate(const shared_ptr<op::v0::Interpolate>& op,
|
||||
return true;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const shared_ptr<op::v9::SoftSign>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) {
|
||||
element::Type input_et = op->get_input_element_type(0);
|
||||
switch (input_et) {
|
||||
case element::Type_t::f64:
|
||||
runtime::reference::softsign<double>(inputs[0]->get_data_ptr<double>(),
|
||||
outputs[0]->get_data_ptr<double>(),
|
||||
shape_size(inputs[0]->get_shape()));
|
||||
break;
|
||||
case element::Type_t::f32:
|
||||
runtime::reference::softsign<float>(inputs[0]->get_data_ptr<float>(),
|
||||
outputs[0]->get_data_ptr<float>(),
|
||||
shape_size(inputs[0]->get_shape()));
|
||||
break;
|
||||
case element::Type_t::f16:
|
||||
runtime::reference::softsign<float16>(inputs[0]->get_data_ptr<float16>(),
|
||||
outputs[0]->get_data_ptr<float16>(),
|
||||
shape_size(inputs[0]->get_shape()));
|
||||
break;
|
||||
case element::Type_t::bf16:
|
||||
runtime::reference::softsign<bfloat16>(inputs[0]->get_data_ptr<bfloat16>(),
|
||||
outputs[0]->get_data_ptr<bfloat16>(),
|
||||
shape_size(inputs[0]->get_shape()));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool evaluate_node(std::shared_ptr<Node> node, const HostTensorVector& outputs, const HostTensorVector& inputs) {
|
||||
auto element_type = node->get_output_element_type(0);
|
||||
|
||||
@@ -133,3 +133,4 @@ NGRAPH_OP(PRelu, op::v0)
|
||||
|
||||
NGRAPH_OP(RDFT, op::v9)
|
||||
NGRAPH_OP(ROIAlign, op::v9)
|
||||
NGRAPH_OP(SoftSign, op::v9)
|
||||
@@ -0,0 +1,90 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/softsign.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct SoftSignParams {
|
||||
template <class IT>
|
||||
SoftSignParams(const ov::PartialShape& shape, const ov::element::Type& iType, const std::vector<IT>& iValues, const std::vector<IT>& oValues)
|
||||
: pshape(shape),
|
||||
inType(iType),
|
||||
outType(iType),
|
||||
inputData(CreateTensor(iType, iValues)),
|
||||
refData(CreateTensor(iType, oValues)) {}
|
||||
|
||||
ov::PartialShape pshape;
|
||||
ov::element::Type inType;
|
||||
ov::element::Type outType;
|
||||
ov::Tensor inputData;
|
||||
ov::Tensor refData;
|
||||
};
|
||||
|
||||
class ReferenceSoftSignLayerTest : public testing::TestWithParam<SoftSignParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.pshape, params.inType, params.outType);
|
||||
inputData = {params.inputData};
|
||||
refOutData = {params.refData};
|
||||
}
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<SoftSignParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "shape=" << param.pshape << "_";
|
||||
result << "iType=" << param.inType << "_";
|
||||
result << "oType=" << param.outType;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Model> CreateFunction(const PartialShape& input_shape, const element::Type& input_type,
|
||||
const element::Type& SoftSign_output_type) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
const auto SoftSign = std::make_shared<op::v9::SoftSign>(in);
|
||||
return std::make_shared<ov::Model>(NodeVector {SoftSign}, ParameterVector {in});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceSoftSignLayerTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t IN_ET>
|
||||
std::vector<SoftSignParams> generateSoftSignFloatParams() {
|
||||
using T = typename element_type_traits<IN_ET>::value_type;
|
||||
|
||||
std::vector<SoftSignParams> ParamsVector {
|
||||
SoftSignParams(ov::PartialShape {4},
|
||||
IN_ET,
|
||||
std::vector<T>{-1.0, 0.0, 1.0, 15.0},
|
||||
std::vector<T>{-0.5, 0.0, 0.5, 0.9375})
|
||||
};
|
||||
return ParamsVector;
|
||||
}
|
||||
|
||||
std::vector<SoftSignParams> generateSoftSignCombinedParams() {
|
||||
const std::vector<std::vector<SoftSignParams>> SoftSignTypeParams {
|
||||
generateSoftSignFloatParams<element::Type_t::f32>(),
|
||||
generateSoftSignFloatParams<element::Type_t::f16>(),
|
||||
generateSoftSignFloatParams<element::Type_t::bf16>()
|
||||
};
|
||||
std::vector<SoftSignParams> combinedParams;
|
||||
|
||||
for (const auto& params : SoftSignTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_SoftSign_With_Hardcoded_Refs, ReferenceSoftSignLayerTest,
|
||||
testing::ValuesIn(generateSoftSignCombinedParams()), ReferenceSoftSignLayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <ngraph/pass/graph_rewrite.hpp>
|
||||
#include <transformations_visibility.hpp>
|
||||
|
||||
namespace ngraph {
|
||||
namespace pass {
|
||||
|
||||
class TRANSFORMATIONS_API SoftSignDecomposition;
|
||||
|
||||
} // namespace pass
|
||||
} // namespace ngraph
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief SoftSignDecomposition transformation replaces SoftSign with the following graph
|
||||
*
|
||||
* Input ---> Abs
|
||||
* | |
|
||||
* | |
|
||||
* | |
|
||||
* | V
|
||||
* | Add <--- 1
|
||||
* | |
|
||||
* | |
|
||||
* V |
|
||||
* Divide <----|
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* V
|
||||
* Output
|
||||
*/
|
||||
|
||||
class ngraph::pass::SoftSignDecomposition : public ngraph::pass::MatcherPass {
|
||||
public:
|
||||
OPENVINO_RTTI("SoftSignDecomposition", "0");
|
||||
SoftSignDecomposition();
|
||||
};
|
||||
+2
@@ -14,6 +14,7 @@
|
||||
#include <transformations/control_flow/unroll_if.hpp>
|
||||
#include <transformations/op_conversions/normalize_l2_decomposition.hpp>
|
||||
#include <transformations/op_conversions/softmax_decomposition.hpp>
|
||||
#include <transformations/op_conversions/softsign_decomposition.hpp>
|
||||
|
||||
#include "itt.hpp"
|
||||
#include "transformations/common_optimizations/add_fake_quantize_fusion.hpp"
|
||||
@@ -162,6 +163,7 @@ bool ngraph::pass::CommonOptimizations::run_on_model(const std::shared_ptr<ngrap
|
||||
decomp->add_matcher<ngraph::pass::SimplifyCTCGreedyDecoderSeqLen>();
|
||||
decomp->add_matcher<ngraph::pass::EinsumDecomposition>();
|
||||
decomp->add_matcher<ngraph::pass::SoftmaxDecomposition, false>();
|
||||
decomp->add_matcher<ngraph::pass::SoftSignDecomposition>();
|
||||
decomp->add_matcher<ngraph::pass::GatherNegativeConstIndicesNormalize>();
|
||||
decomp->add_matcher<ngraph::pass::DropoutWithRandomUniformReplacer>();
|
||||
decomp->add_matcher<ngraph::pass::TransposeReshapeEliminationForMatmul>();
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <memory>
|
||||
#include <ngraph/opsets/opset9.hpp>
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
#include <transformations/op_conversions/softsign_decomposition.hpp>
|
||||
|
||||
#include "itt.hpp"
|
||||
|
||||
ngraph::pass::SoftSignDecomposition::SoftSignDecomposition() {
|
||||
MATCHER_SCOPE(SoftSignDecomposition);
|
||||
auto softsign = pattern::wrap_type<ngraph::opset9::SoftSign>();
|
||||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) {
|
||||
auto m_softsign = m.get_match_root();
|
||||
|
||||
if (transformation_callback(m_softsign)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto input = m_softsign->input_value(0);
|
||||
const auto& data_type = m_softsign->get_input_element_type(0);
|
||||
auto abs = std::make_shared<ngraph::opset9::Abs>(input);
|
||||
auto constant = ngraph::opset9::Constant::create(data_type, ngraph::Shape{1}, {1});
|
||||
auto add = std::make_shared<ngraph::opset9::Add>(abs, constant);
|
||||
auto div = std::make_shared<ngraph::opset9::Divide>(input, add);
|
||||
|
||||
replace_node(m_softsign, div);
|
||||
copy_runtime_info(m_softsign, {abs, add, div});
|
||||
div->set_friendly_name(m_softsign->get_friendly_name());
|
||||
|
||||
return true;
|
||||
};
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(softsign, matcher_name);
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openvino/op/softsign.hpp"
|
||||
|
||||
namespace ngraph {
|
||||
namespace op {
|
||||
namespace v9 {
|
||||
using ov::op::v9::SoftSign;
|
||||
} // namespace v9
|
||||
} // namespace op
|
||||
} // namespace ngraph
|
||||
@@ -157,6 +157,7 @@
|
||||
#include "ngraph/op/slice.hpp"
|
||||
#include "ngraph/op/softmax.hpp"
|
||||
#include "ngraph/op/softplus.hpp"
|
||||
#include "ngraph/op/softsign.hpp"
|
||||
#include "ngraph/op/space_to_batch.hpp"
|
||||
#include "ngraph/op/space_to_depth.hpp"
|
||||
#include "ngraph/op/split.hpp"
|
||||
|
||||
@@ -158,6 +158,7 @@
|
||||
#include "openvino/op/slice.hpp"
|
||||
#include "openvino/op/softmax.hpp"
|
||||
#include "openvino/op/softplus.hpp"
|
||||
#include "openvino/op/softsign.hpp"
|
||||
#include "openvino/op/space_to_batch.hpp"
|
||||
#include "openvino/op/space_to_depth.hpp"
|
||||
#include "openvino/op/split.hpp"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openvino/op/util/unary_elementwise_arithmetic.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace op {
|
||||
namespace v9 {
|
||||
class OPENVINO_API SoftSign : public util::UnaryElementwiseArithmetic {
|
||||
public:
|
||||
OPENVINO_OP("SoftSign", "opset9");
|
||||
BWDCMP_RTTI_DECLARATION;
|
||||
|
||||
SoftSign() = default;
|
||||
/// \brief Constructs a SoftSign operation.
|
||||
///
|
||||
/// \param arg Node that produces the input tensor.<br>
|
||||
/// `[d0, ...]`
|
||||
/// Output `[d0, ...]`
|
||||
///
|
||||
SoftSign(const Output<Node>& arg);
|
||||
|
||||
bool visit_attributes(AttributeVisitor& visitor) override;
|
||||
|
||||
void validate_and_infer_types() override;
|
||||
|
||||
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
|
||||
bool evaluate(ov::TensorVector& outputs,
|
||||
const ov::TensorVector& inputs,
|
||||
const ov::EvaluationContext& evaluation_context) const override;
|
||||
bool has_evaluate() const override;
|
||||
};
|
||||
} // namespace v9
|
||||
} // namespace op
|
||||
} // namespace ov
|
||||
@@ -193,3 +193,4 @@ _OPENVINO_OP_REG(IRDFT, ov::op::v9)
|
||||
_OPENVINO_OP_REG(RDFT, ov::op::v9)
|
||||
_OPENVINO_OP_REG(Eye, ov::op::v9)
|
||||
_OPENVINO_OP_REG(ROIAlign, ov::op::v9)
|
||||
_OPENVINO_OP_REG(SoftSign, ov::op::v9)
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
namespace ngraph {
|
||||
namespace runtime {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
void softsign(const T* arg, T* out, size_t count) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
out[i] = arg[i] / (1 + std::abs(arg[i]));
|
||||
}
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace runtime
|
||||
} // namespace ngraph
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include "ngraph/runtime/reference/softsign.hpp"
|
||||
|
||||
#include <openvino/core/validation_util.hpp>
|
||||
|
||||
#include "itt.hpp"
|
||||
#include "openvino/core/attribute_visitor.hpp"
|
||||
#include "openvino/op/softsign.hpp"
|
||||
#include "openvino/runtime/tensor.hpp"
|
||||
|
||||
namespace {
|
||||
template <ov::element::Type_t ET>
|
||||
inline bool evaluate(const ov::Tensor& arg, const ov::Tensor& out, const size_t count) {
|
||||
using T = typename ov::element_type_traits<ET>::value_type;
|
||||
ngraph::runtime::reference::softsign<T>(arg.data<T>(), out.data<T>(), count);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool evaluate_softsign(const ov::Tensor& arg, const ov::Tensor& out) {
|
||||
bool rc = true;
|
||||
size_t count = arg.get_size();
|
||||
|
||||
switch (arg.get_element_type()) {
|
||||
NGRAPH_TYPE_CASE(evaluate_softsign, bf16, arg, out, count);
|
||||
NGRAPH_TYPE_CASE(evaluate_softsign, f16, arg, out, count);
|
||||
NGRAPH_TYPE_CASE(evaluate_softsign, f32, arg, out, count);
|
||||
NGRAPH_TYPE_CASE(evaluate_softsign, f64, arg, out, count);
|
||||
default:
|
||||
rc = false;
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BWDCMP_RTTI_DEFINITION(ov::op::v9::SoftSign);
|
||||
|
||||
ov::op::v9::SoftSign::SoftSign(const Output<Node>& arg) : UnaryElementwiseArithmetic(arg) {
|
||||
constructor_validate_and_infer_types();
|
||||
}
|
||||
|
||||
void ov::op::v9::SoftSign::validate_and_infer_types() {
|
||||
NGRAPH_OP_SCOPE(v9_SoftSign_validate_and_infer_types);
|
||||
const element::Type& input_et = get_input_element_type(0);
|
||||
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
input_et.is_dynamic() || input_et.is_real(),
|
||||
"Input element type must be float, instead got: ",
|
||||
input_et);
|
||||
|
||||
UnaryElementwiseArithmetic::validate_and_infer_types();
|
||||
}
|
||||
|
||||
bool ov::op::v9::SoftSign::visit_attributes(AttributeVisitor& visitor) {
|
||||
NGRAPH_OP_SCOPE(v9_SoftSign_visit_attributes);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<ov::Node> ov::op::v9::SoftSign::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
NGRAPH_OP_SCOPE(v9_SoftSign_clone_with_new_inputs);
|
||||
check_new_args_count(this, new_args);
|
||||
return std::make_shared<ov::op::v9::SoftSign>(new_args.at(0));
|
||||
}
|
||||
|
||||
bool ov::op::v9::SoftSign::has_evaluate() const {
|
||||
NGRAPH_OP_SCOPE(v9_SoftSign_has_evaluate);
|
||||
switch (get_input_element_type(0)) {
|
||||
case ov::element::bf16:
|
||||
case ov::element::f16:
|
||||
case ov::element::f32:
|
||||
case ov::element::f64:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ov::op::v9::SoftSign::evaluate(ov::TensorVector& outputs,
|
||||
const ov::TensorVector& inputs,
|
||||
const ov::EvaluationContext& evaluation_context) const {
|
||||
NGRAPH_OP_SCOPE(v9_SoftSign_evaluate);
|
||||
|
||||
OPENVINO_ASSERT(outputs.size() == 1 && inputs.size() == 1,
|
||||
"SoftSign evaluate needs exactly 1 input and 1 output, instead got:",
|
||||
inputs.size(),
|
||||
" input(s) and ",
|
||||
outputs.size(),
|
||||
" output(s).");
|
||||
|
||||
const auto& in = inputs[0];
|
||||
auto& out = outputs[0];
|
||||
out.set_shape(in.get_shape());
|
||||
return evaluate_softsign(in, out);
|
||||
}
|
||||
@@ -230,6 +230,7 @@ set(SRC
|
||||
type_prop/slice.cpp
|
||||
type_prop/softmax.cpp
|
||||
type_prop/softplus.cpp
|
||||
type_prop/softsign.cpp
|
||||
type_prop/space_to_batch.cpp
|
||||
type_prop/space_to_depth.cpp
|
||||
type_prop/split.cpp
|
||||
@@ -395,6 +396,7 @@ set(SRC
|
||||
visitors/op/slice.cpp
|
||||
visitors/op/softmax.cpp
|
||||
visitors/op/softplus.cpp
|
||||
visitors/op/softsign.cpp
|
||||
visitors/op/space_to_batch.cpp
|
||||
visitors/op/space_to_depth.cpp
|
||||
visitors/op/split.cpp
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "ngraph/op/sin.hpp"
|
||||
#include "ngraph/op/sinh.hpp"
|
||||
#include "ngraph/op/softmax.hpp"
|
||||
#include "ngraph/op/softsign.hpp"
|
||||
#include "ngraph/op/sqrt.hpp"
|
||||
#include "ngraph/op/squeeze.hpp"
|
||||
#include "ngraph/op/tan.hpp"
|
||||
@@ -1795,3 +1796,21 @@ TEST(eval, evaluate_softmax_8) {
|
||||
vector<float> out{0.5, 0.5};
|
||||
ASSERT_EQ(val, out);
|
||||
}
|
||||
|
||||
TEST(eval, evaluate_softsign_9) {
|
||||
auto arg = std::make_shared<ngraph::op::Parameter>(element::f32, PartialShape::dynamic());
|
||||
auto softsign = std::make_shared<ngraph::op::v9::SoftSign>(arg);
|
||||
auto fun = std::make_shared<Function>(OutputVector{softsign}, ParameterVector{arg});
|
||||
ov::TensorVector result_tensor(1);
|
||||
float input_vector[] = {1, -1, 2.5, -3.5};
|
||||
ov::Tensor input{ov::element::f32, ov::Shape{4}, input_vector};
|
||||
|
||||
ASSERT_TRUE(fun->evaluate(result_tensor, ov::TensorVector{input}));
|
||||
EXPECT_EQ(result_tensor[0].get_element_type(), ov::element::f32);
|
||||
EXPECT_EQ(result_tensor[0].get_shape(), ov::Shape{4});
|
||||
|
||||
vector<float> out{0.5, -0.5, 0.714285, -0.777777};
|
||||
auto result_data = result_tensor[0].data<float>();
|
||||
for (size_t i = 0; i < result_tensor[0].get_size(); ++i)
|
||||
EXPECT_NEAR(result_data[i], out[i], 1e-6F);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "openvino/opsets/opset9.hpp"
|
||||
#include "util/type_prop.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
|
||||
TEST(type_prop, softsign_incorrect_type) {
|
||||
const auto input_type = element::i32;
|
||||
const auto input_shape = Shape{1, 3, 6};
|
||||
auto data = make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
try {
|
||||
auto softsign_func = make_shared<op::v9::SoftSign>(data);
|
||||
// Should have thrown, so fail if it didn't
|
||||
FAIL() << "Incorrect begin type exception not thrown.";
|
||||
} catch (const NodeValidationFailure& error) {
|
||||
EXPECT_HAS_SUBSTRING(error.what(), std::string("Input element type must be float, instead got"));
|
||||
} catch (...) {
|
||||
FAIL() << "Deduced type check failed for unexpected reason.";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(type_prop, softsign_f32) {
|
||||
const auto input_type = element::f32;
|
||||
const auto input_shape = Shape{1, 3, 6};
|
||||
auto data = make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
auto softsign_func = make_shared<op::v9::SoftSign>(data);
|
||||
EXPECT_EQ(softsign_func->get_element_type(), input_type);
|
||||
EXPECT_EQ(softsign_func->get_shape(), input_shape);
|
||||
}
|
||||
|
||||
TEST(type_prop, softsign_f32_partial) {
|
||||
const auto input_type = element::f32;
|
||||
const auto input_shape = PartialShape{1, Dimension::dynamic(), 6};
|
||||
auto data = make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
auto softsign_func = make_shared<op::v9::SoftSign>(data);
|
||||
EXPECT_EQ(softsign_func->get_element_type(), input_type);
|
||||
ASSERT_TRUE(softsign_func->get_output_partial_shape(0).same_scheme(input_shape));
|
||||
ASSERT_TRUE(softsign_func->get_output_partial_shape(0).rank().is_static());
|
||||
|
||||
// rank unknown
|
||||
auto softsign_partial =
|
||||
make_shared<op::v9::SoftSign>(make_shared<op::v0::Parameter>(input_type, PartialShape::dynamic()));
|
||||
ASSERT_TRUE(softsign_partial->get_output_partial_shape(0).same_scheme(PartialShape::dynamic()));
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "unary_ops.hpp"
|
||||
|
||||
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v9::SoftSign, ngraph::element::f32>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(visitor_without_atrribute, UnaryOperatorVisitor, Types, UnaryOperatorTypeName);
|
||||
@@ -57,6 +57,7 @@
|
||||
#include <transformations/common_optimizations/transpose_sinking.hpp>
|
||||
#include "transformations/common_optimizations/convert_compression_only_to_legacy.hpp"
|
||||
#include "transformations/disable_decompression_convert_constant_folding.hpp"
|
||||
#include "transformations/op_conversions/softsign_decomposition.hpp"
|
||||
#include <transformations/utils/utils.hpp>
|
||||
|
||||
#include "transformations/pwl_approximation.hpp"
|
||||
@@ -733,6 +734,7 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) {
|
||||
pass_config->disable<ngraph::pass::TransposeReduction>();
|
||||
// Operations Max and Min aren't supported
|
||||
pass_config->disable<ngraph::pass::ConcatReduceFusion>();
|
||||
// pass_config->disable<ngraph::pass::SoftSignDecomposition>();
|
||||
manager.run_passes(graph);
|
||||
convertedNetwork = InferenceEngine::details::convertFunctionToICNNNetwork(graph, clonedNetwork);
|
||||
isNgraphPassesUsed = true;
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <ngraph/function.hpp>
|
||||
#include <ngraph/opsets/opset9.hpp>
|
||||
#include <transformations/op_conversions/softsign_decomposition.hpp>
|
||||
#include <transformations/init_node_info.hpp>
|
||||
|
||||
#include "common_test_utils/ngraph_test_utils.hpp"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
TEST_F(TransformationTestsF, SoftSignDecomposition) {
|
||||
{
|
||||
auto data = std::make_shared<ngraph::opset9::Parameter>(ngraph::element::f32, ngraph::Shape{3, 1, 2});
|
||||
auto softsign = std::make_shared<ngraph::opset9::SoftSign>(data);
|
||||
|
||||
function = std::make_shared<ngraph::Function>(ngraph::NodeVector{softsign}, ngraph::ParameterVector{data});
|
||||
|
||||
manager.register_pass<ngraph::pass::SoftSignDecomposition>();
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset9::Parameter>(ngraph::element::f32, ngraph::Shape{3, 1, 2});
|
||||
auto abs = std::make_shared<ngraph::opset9::Abs>(input);
|
||||
auto add = std::make_shared<ngraph::opset9::Add>(abs, ngraph::opset9::Constant::create(ngraph::element::f32,
|
||||
ngraph::Shape{1},
|
||||
{1}));
|
||||
auto div = std::make_shared<ngraph::opset9::Divide>(input, add);
|
||||
|
||||
function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TransformationTestsF, SoftSignDecompositionFP16) {
|
||||
{
|
||||
auto data = std::make_shared<ngraph::opset9::Parameter>(ngraph::element::f16, ngraph::Shape{3, 1, 2});
|
||||
auto softsign = std::make_shared<ngraph::opset9::SoftSign>(data);
|
||||
|
||||
function = std::make_shared<ngraph::Function>(ngraph::NodeVector{softsign}, ngraph::ParameterVector{data});
|
||||
|
||||
manager.register_pass<ngraph::pass::SoftSignDecomposition>();
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::make_shared<ngraph::opset9::Parameter>(ngraph::element::f16, ngraph::Shape{3, 1, 2});
|
||||
auto abs = std::make_shared<ngraph::opset9::Abs>(input);
|
||||
auto add = std::make_shared<ngraph::opset9::Add>(abs, ngraph::opset9::Constant::create(ngraph::element::f16,
|
||||
ngraph::Shape{1},
|
||||
{1}));
|
||||
auto div = std::make_shared<ngraph::opset9::Divide>(input, add);
|
||||
|
||||
function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input});
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,8 @@ const std::map<ActivationTypes, std::vector<std::vector<float>>> activationTypes
|
||||
{Mish, {{}}},
|
||||
{PReLu, {{-0.01f}}},
|
||||
{GeluErf, {{}}},
|
||||
{GeluTanh, {{}}}
|
||||
{GeluTanh, {{}}},
|
||||
{SoftSign, {{}}}
|
||||
};
|
||||
|
||||
std::vector<Precision> netPrc = {
|
||||
|
||||
+8
-8
@@ -89,14 +89,14 @@ const std::vector<InferenceEngine::Precision> preluNetPrecisions = {
|
||||
};
|
||||
|
||||
const std::map<ActivationTypes, std::vector<std::vector<float>>> activationTypes = {
|
||||
{Sigmoid, {}},
|
||||
{Tanh, {}},
|
||||
{Relu, {}},
|
||||
{Exp, {}},
|
||||
{Log, {}},
|
||||
{Sign, {}},
|
||||
{Abs, {}},
|
||||
{Clamp, {{-5, 5}}}
|
||||
{Sigmoid, {}},
|
||||
{Tanh, {}},
|
||||
{Relu, {}},
|
||||
{Exp, {}},
|
||||
{Log, {}},
|
||||
{Sign, {}},
|
||||
{Abs, {}},
|
||||
{Clamp, {{-5, 5}}}
|
||||
};
|
||||
|
||||
const std::map<ActivationTypes, std::vector<std::vector<float>>> preluActivationTypes = {
|
||||
|
||||
+7
@@ -1005,6 +1005,13 @@ std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v4::SoftPlus>
|
||||
return std::make_shared<ov::Model>(results, params, "SoftPlusGraph");
|
||||
}
|
||||
|
||||
std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v9::SoftSign> &node) {
|
||||
const auto params = ngraph::builder::makeDynamicParams(ov::element::f16, {{4, 4}});
|
||||
auto Node = std::make_shared<ov::op::v9::SoftSign>(params.at(0));
|
||||
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(Node)};
|
||||
return std::make_shared<ov::Model>(results, params, "SoftSignGraph");
|
||||
}
|
||||
|
||||
std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v1::Softmax> &node) {
|
||||
const auto params = ngraph::builder::makeDynamicParams(ov::element::f16, {{2, 2, 3}});
|
||||
auto Node = std::make_shared<ov::op::v1::Softmax>(params.at(0), 0);
|
||||
|
||||
+1
@@ -75,6 +75,7 @@ static std::map<ngraph::helpers::ActivationTypes, std::string> activationNames =
|
||||
{ngraph::helpers::ActivationTypes::RoundHalfAwayFromZero, "RoundHalfAwayFromZero"},
|
||||
{ngraph::helpers::ActivationTypes::GeluErf, "GeluErf"},
|
||||
{ngraph::helpers::ActivationTypes::GeluTanh, "GeluTanh"},
|
||||
{ngraph::helpers::ActivationTypes::SoftSign, "SoftSign"},
|
||||
};
|
||||
|
||||
typedef std::tuple<
|
||||
|
||||
+2
-1
@@ -123,7 +123,8 @@ enum ActivationTypes {
|
||||
RoundHalfToEven,
|
||||
RoundHalfAwayFromZero,
|
||||
GeluErf,
|
||||
GeluTanh
|
||||
GeluTanh,
|
||||
SoftSign
|
||||
};
|
||||
|
||||
enum EltwiseTypes {
|
||||
|
||||
@@ -117,6 +117,8 @@ std::shared_ptr<ngraph::Node> makeActivation(const ngraph::Output<Node> &in,
|
||||
return std::make_shared<ngraph::op::v7::Gelu>(in, ngraph::op::GeluApproximationMode::ERF);
|
||||
case ngraph::helpers::ActivationTypes::GeluTanh:
|
||||
return std::make_shared<ngraph::op::v7::Gelu>(in, ngraph::op::GeluApproximationMode::TANH);
|
||||
case ngraph::helpers::ActivationTypes::SoftSign:
|
||||
return std::make_shared<ngraph::op::v9::SoftSign>(in);
|
||||
default:
|
||||
throw std::runtime_error("Can't create layer for this activation type");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user