forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PT FE] Support non boolean inputs for __or__ and __and__ operations (o…
…penvinotoolkit#19268) * [PT FE] Support non boolean inputs for __or__ and __and__ operations * Add test for __or__
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 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,42 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/frontend/pytorch/node_context.hpp" | ||
#include "openvino/op/logical_and.hpp" | ||
#include "openvino/op/logical_or.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace pytorch { | ||
namespace op { | ||
|
||
using namespace ov::op; | ||
|
||
OutputVector translate_or(const NodeContext& context) { | ||
num_inputs_check(context, 2, 2); | ||
auto x = context.get_input(0); | ||
auto y = context.get_input(1); | ||
x = context.mark_node(std::make_shared<v0::Convert>(x, element::boolean)); | ||
y = context.mark_node(std::make_shared<v0::Convert>(y, element::boolean)); | ||
// TODO: use bitwise op here when will be supported by openvino | ||
auto or_node = context.mark_node(std::make_shared<v1::LogicalOr>(x, y)); | ||
return {or_node}; | ||
}; | ||
|
||
OutputVector translate_and(const NodeContext& context) { | ||
num_inputs_check(context, 2, 2); | ||
auto x = context.get_input(0); | ||
auto y = context.get_input(1); | ||
x = context.mark_node(std::make_shared<v0::Convert>(x, element::boolean)); | ||
y = context.mark_node(std::make_shared<v0::Convert>(y, element::boolean)); | ||
// TODO: use bitwise op here when will be supported by openvino | ||
auto or_node = context.mark_node(std::make_shared<v1::LogicalAnd>(x, y)); | ||
return {or_node}; | ||
}; | ||
|
||
} // 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,28 @@ | ||
# Copyright (C) 2018-2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from pytorch_layer_test_class import PytorchLayerTest | ||
|
||
|
||
class TestLog(PytorchLayerTest): | ||
def _prepare_input(self): | ||
import numpy as np | ||
return (np.random.randint(0, 255, (20, 30, 40, 50)),) | ||
|
||
def create_model(self): | ||
import torch | ||
|
||
class aten_or(torch.nn.Module): | ||
def forward(self, x): | ||
res = torch.ByteTensor(x.size()).zero_() | ||
res[:, :, :, 1:] = res[:, :, :, 1:] | (x[:, :, :, 1:] != x[:, :, :, :-1]) | ||
res[:, :, :, :-1] = res[:, :, :, :-1] | (x[:, :, :, 1:] != x[:, :, :, :-1]) | ||
return res.float() | ||
|
||
return aten_or(), None, "aten::__or__" | ||
|
||
@pytest.mark.nightly | ||
@pytest.mark.precommit | ||
def test_or(self, ie_device, precision, ir_version): | ||
self._test(*self.create_model(), ie_device, precision, ir_version, dynamic_shapes=False, trace_model=True) |