Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PT FE] Fix Bitwise translators with 3 inputs (#26930)

Roman Kazantsev9027e1d6d116
diff --git a/src/frontends/pytorch/src/op/bitwise.cpp b/src/frontends/pytorch/src/op/bitwise.cpp
index ba602c86b7b..ef66e15c5bc 100644
--- a/src/frontends/pytorch/src/op/bitwise.cpp
+++ b/src/frontends/pytorch/src/op/bitwise.cpp
@@ -7,6 +7,7 @@
#include "openvino/op/bitwise_not.hpp"
#include "openvino/op/bitwise_or.hpp"
#include "openvino/op/bitwise_xor.hpp"
+#include "openvino/op/convert_like.hpp"
#include "utils.hpp"
namespace ov {
@@ -29,8 +30,12 @@ OutputVector translate_bitwise_and(const NodeContext& context) {
Output<Node> x;
Output<Node> y;
std::tie(x, y) = get_inputs_with_promoted_types(context, 0, 1);
- auto and_x = context.mark_node(std::make_shared<ov::op::v13::BitwiseAnd>(x, y));
+ auto and_x = context.mark_node(std::make_shared<ov::op::v13::BitwiseAnd>(x, y))->output(0);
if (!context.input_is_none(2)) {
+ auto out = context.get_input(2);
+ if (out.get_element_type().is_dynamic() || and_x.get_element_type() != out.get_element_type()) {
+ and_x = context.mark_node(std::make_shared<ov::op::v1::ConvertLike>(and_x, out));
+ }
context.mutate_input(2, and_x);
}
return {and_x};
@@ -41,8 +46,12 @@ OutputVector translate_bitwise_or(const NodeContext& context) {
Output<Node> x;
Output<Node> y;
std::tie(x, y) = get_inputs_with_promoted_types(context, 0, 1);
- auto or_x = context.mark_node(std::make_shared<ov::op::v13::BitwiseOr>(x, y));
+ auto or_x = context.mark_node(std::make_shared<ov::op::v13::BitwiseOr>(x, y))->output(0);
if (!context.input_is_none(2)) {
+ auto out = context.get_input(2);
+ if (out.get_element_type().is_dynamic() || or_x.get_element_type() != out.get_element_type()) {
+ or_x = context.mark_node(std::make_shared<ov::op::v1::ConvertLike>(or_x, out));
+ }
context.mutate_input(2, or_x);
}
return {or_x};
@@ -53,8 +62,12 @@ OutputVector translate_bitwise_xor(const NodeContext& context) {
Output<Node> x;
Output<Node> y;
std::tie(x, y) = get_inputs_with_promoted_types(context, 0, 1);
- auto xor_x = context.mark_node(std::make_shared<ov::op::v13::BitwiseXor>(x, y));
+ auto xor_x = context.mark_node(std::make_shared<ov::op::v13::BitwiseXor>(x, y))->output(0);
if (!context.input_is_none(2)) {
+ auto out = context.get_input(2);
+ if (out.get_element_type().is_dynamic() || xor_x.get_element_type() != out.get_element_type()) {
+ xor_x = context.mark_node(std::make_shared<ov::op::v1::ConvertLike>(xor_x, out));
+ }
context.mutate_input(2, xor_x);
}
return {xor_x};
diff --git a/tests/layer_tests/pytorch_tests/test_bitwise_ops.py b/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
index e55a86f279d..a400f6dcd76 100644
--- a/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
+++ b/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
@@ -75,8 +75,6 @@ class TestBitwiseOp(PytorchLayerTest):
):
if ie_device == "GPU" and (lhs_dtype != "bool" or rhs_dtype != "bool"):
pytest.xfail(reason="bitwise ops are not supported on GPU")
- if out and version.parse(np.__version__) >= version.parse("2.0.0"):
- pytest.xfail(reason="CVS-154082: incorrect handling out type")
self._test(
*self.create_model(op_type, out),
ie_device,