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.
Merge pull request openvinotoolkit#85 from eaidova/ea/selu
aten::selu
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/frontend/pytorch/node_context.hpp" | ||
#include "openvino/opsets/opset8.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace pytorch { | ||
namespace op { | ||
|
||
OutputVector translate_selu(NodeContext& context) { | ||
auto x = context.get_input(0); | ||
auto alpha = | ||
context.mark_node(opset8::Constant::create(element::f64, Shape{}, {1.6732632423543772848170429916717})); | ||
auto lambda = | ||
context.mark_node(opset8::Constant::create(element::f64, Shape{}, {1.0507009873554804934193349852946})); | ||
alpha = context.mark_node(std::make_shared<opset8::ConvertLike>(alpha, x)); | ||
lambda = context.mark_node(std::make_shared<opset8::ConvertLike>(lambda, x)); | ||
return {context.mark_node(std::make_shared<opset8::Selu>(x, alpha, lambda))}; | ||
}; | ||
|
||
} // namespace op | ||
} // namespace pytorch | ||
} // namespace frontend | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (C) 2018-2022 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from pytorch_layer_test_class import PytorchLayerTest | ||
|
||
|
||
class TestSilu(PytorchLayerTest): | ||
def _prepare_input(self): | ||
import numpy as np | ||
return (np.random.randn(1, 3, 224, 224).astype(np.float32),) | ||
|
||
def create_model(self, inplace=False): | ||
|
||
import torch | ||
import torch.nn.functional as F | ||
|
||
class aten_selu(torch.nn.Module): | ||
def __init__(self, inplace): | ||
super(aten_selu, self).__init__() | ||
self.inplace = inplace | ||
|
||
def forward(self, x): | ||
return x, F.selu(x, inplace=self.inplace) | ||
|
||
ref_net = None | ||
|
||
return aten_selu(inplace), ref_net, "aten::selu" if not inplace else "aten::selu_" | ||
|
||
@pytest.mark.nightly | ||
@pytest.mark.parametrize("inplace", [True, False]) | ||
def test_silu(self, inplace, ie_device, precision, ir_version): | ||
self._test(*self.create_model(inplace), ie_device, precision, ir_version) |