forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add type_prop and backend tests for gelu op * add visitor test for gelu op * add additional type_prop and backend tests and remove gelu from manifest * resolve conflicts * fix indentation and remove unecessary includes * remove gelu from manifests
- Loading branch information
Showing
6 changed files
with
190 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (C) 2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "gtest/gtest.h" | ||
#include "ngraph/ngraph.hpp" | ||
#include "util/type_prop.hpp" | ||
|
||
using namespace std; | ||
using namespace ngraph; | ||
|
||
TEST(type_prop, gelu_default_mode_inference_f32) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::f32, Shape{1, 32, 32}); | ||
auto gelu = make_shared<op::v7::Gelu>(param); | ||
|
||
ASSERT_EQ(gelu->get_element_type(), element::f32); | ||
ASSERT_EQ(gelu->get_shape(), (Shape{1, 32, 32})); | ||
ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::ERF); | ||
} | ||
|
||
TEST(type_prop, gelu_default_mode_inference_f16) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::f16, Shape{1, 32, 32}); | ||
auto gelu = make_shared<op::v7::Gelu>(param); | ||
|
||
ASSERT_EQ(gelu->get_element_type(), element::f16); | ||
ASSERT_EQ(gelu->get_shape(), (Shape{1, 32, 32})); | ||
ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::ERF); | ||
} | ||
|
||
TEST(type_prop, gelu_tanh_mode_inference_f32) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::f32, Shape{1, 32, 32}); | ||
auto gelu = make_shared<op::v7::Gelu>(param, op::GeluApproximationMode::TANH); | ||
|
||
ASSERT_EQ(gelu->get_element_type(), element::f32); | ||
ASSERT_EQ(gelu->get_shape(), (Shape{1, 32, 32})); | ||
ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::TANH); | ||
} | ||
|
||
TEST(type_prop, gelu_tanh_mode_inference_f16) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::f16, Shape{1, 32, 32}); | ||
auto gelu = make_shared<op::v7::Gelu>(param, op::GeluApproximationMode::TANH); | ||
|
||
ASSERT_EQ(gelu->get_element_type(), element::f16); | ||
ASSERT_EQ(gelu->get_shape(), (Shape{1, 32, 32})); | ||
ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::TANH); | ||
} | ||
|
||
TEST(type_prop, gelu_incompatible_input_type_boolean) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::boolean, Shape{1, 32, 32}); | ||
ASSERT_THROW(std::make_shared<op::v7::Gelu>(param), ngraph::NodeValidationFailure); | ||
} | ||
|
||
TEST(type_prop, gelu_incompatible_input_type_u16) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::u16, Shape{1, 32, 32}); | ||
ASSERT_THROW(std::make_shared<op::v7::Gelu>(param), ngraph::NodeValidationFailure); | ||
} | ||
|
||
TEST(type_prop, gelu_incompatible_input_type_i32) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::i32, Shape{1, 32, 32}); | ||
ASSERT_THROW(std::make_shared<op::v7::Gelu>(param), ngraph::NodeValidationFailure); | ||
} | ||
|
||
TEST(type_prop, gelu_incompatible_input_type_i16) | ||
{ | ||
auto param = make_shared<op::Parameter>(element::i16, Shape{1, 32, 32}); | ||
ASSERT_THROW(std::make_shared<op::v7::Gelu>(param), ngraph::NodeValidationFailure); | ||
} | ||
|
||
TEST(type_prop, gelu_dynamic_rank_input_shape_2D) | ||
{ | ||
const PartialShape param_shape{Dimension::dynamic(), 10}; | ||
const auto param = std::make_shared<op::Parameter>(element::f32, param_shape); | ||
const auto op = std::make_shared<op::v7::Gelu>(param); | ||
ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape{Dimension(), 10})); | ||
} | ||
|
||
TEST(type_prop, gelu_dynamic_rank_input_shape_3D) | ||
{ | ||
const PartialShape param_shape{100, Dimension::dynamic(), 58}; | ||
const auto param = std::make_shared<op::Parameter>(element::f32, param_shape); | ||
const auto op = std::make_shared<op::v7::Gelu>(param); | ||
ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape{100, Dimension(), 58})); | ||
} | ||
|
||
TEST(type_prop, gelu_dynamic_rank_input_shape_full) | ||
{ | ||
const auto param = std::make_shared<op::Parameter>(element::f32, PartialShape::dynamic()); | ||
const auto op = std::make_shared<op::v7::Gelu>(param); | ||
ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include "ngraph/ngraph.hpp" | ||
#include "ngraph/op/util/attr_types.hpp" | ||
#include "ngraph/opsets/opset7.hpp" | ||
|
||
#include "util/visitor.hpp" | ||
|
||
using namespace std; | ||
using namespace ngraph; | ||
using ngraph::test::NodeBuilder; | ||
|
||
TEST(attributes, gelu_op) | ||
{ | ||
NodeBuilder::get_ops().register_factory<opset7::Gelu>(); | ||
const auto data_input = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3}); | ||
const auto approximation_mode = op::GeluApproximationMode::ERF; | ||
const auto gelu = make_shared<opset7::Gelu>(data_input, approximation_mode); | ||
NodeBuilder builder(gelu); | ||
auto g_gelu = as_type_ptr<opset7::Gelu>(builder.create()); | ||
|
||
EXPECT_EQ(g_gelu->get_approximation_mode(), gelu->get_approximation_mode()); | ||
} |