-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PT FE] Added support for aten::__lshift__ and aten::__rshift__ and aten::bitwise_left_shift and aten::bitwise_right_shift #28939
Closed
Mohamed-Ashraf273
wants to merge
22
commits into
openvinotoolkit:master
from
Mohamed-Ashraf273:shiftOperations
Closed
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cb108c3
Added support for aten::__lshift__, aten::__rshift__, aten::bitwise_l…
Mohamed-Ashraf273 78be01f
Merge branch 'master' of https://github.com/Mohamed-Ashraf273/openvin…
Mohamed-Ashraf273 1035cbb
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 250bab8
Merge branch 'master' of https://github.com/Mohamed-Ashraf273/openvin…
Mohamed-Ashraf273 eb0e0fa
Merge branch 'shiftOperations' of https://github.com/Mohamed-Ashraf27…
Mohamed-Ashraf273 c912906
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 31c86b4
Merge branch 'shiftOperations' of https://github.com/Mohamed-Ashraf27…
Mohamed-Ashraf273 1ca9736
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 ee4f6fa
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 17fc133
aten shift operations are tested successfully
Mohamed-Ashraf273 3172a5d
Merge branch 'master' into shiftOperations
Mohamed-Ashraf273 c327640
removing unnecessary includes
Mohamed-Ashraf273 1aa2c3d
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 e8c0147
resolving separate source problem
Mohamed-Ashraf273 a77069c
shift operations tested
Mohamed-Ashraf273 8613a87
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 7d3eff1
Merge branch 'master' into shiftOperations
Mohamed-Ashraf273 4fbc673
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 f34f53c
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 80ff052
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 8cbdd91
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 d111388
Merge branch 'openvinotoolkit:master' into shiftOperations
Mohamed-Ashraf273 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,29 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/op/bitwise_left_shift.hpp" | ||
#include "openvino/frontend/pytorch/node_context.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace pytorch { | ||
namespace op { | ||
|
||
using namespace ov::op; | ||
|
||
OutputVector translate_lshift(const NodeContext& context) { | ||
num_inputs_check(context, 2, 2); | ||
|
||
auto [input_tensor, shift_amount] = get_inputs_with_promoted_types(context, 0, 1); | ||
|
||
auto lshift_node = context.mark_node(std::make_shared<v15::BitwiseLeftShift>(input_tensor, shift_amount)); | ||
|
||
return {lshift_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/frontend/pytorch/node_context.hpp" | ||
#include "openvino/op/bitwise_right_shift.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace pytorch { | ||
namespace op { | ||
|
||
using namespace ov::op; | ||
|
||
OutputVector translate_rshift(const NodeContext& context) { | ||
num_inputs_check(context, 2, 2); | ||
|
||
auto [input_tensor, shift_amount] = get_inputs_with_promoted_types(context, 0, 1); | ||
|
||
auto rshift_node = context.mark_node(std::make_shared<v15::BitwiseRightShift>(input_tensor, shift_amount)); | ||
|
||
return {rshift_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
108 changes: 108 additions & 0 deletions
108
tests/layer_tests/pytorch_tests/test_shift_operations.py
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,108 @@ | ||
# Copyright (C) 2018-2025 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import numpy as np | ||
import pytest | ||
import torch | ||
from pytorch_layer_test_class import PytorchLayerTest, skip_if_export | ||
|
||
|
||
class TestShiftOperators(PytorchLayerTest): | ||
def _prepare_input(self, lhs_dtype, rhs_dtype, lhs_shape, rhs_shape): | ||
choices = np.array([1, 2, 4, 8, 16, 32]) | ||
shifts = np.array([0, 1, 2, 3, 4, 5]) | ||
|
||
x = np.random.choice(choices, lhs_shape).astype(lhs_dtype) | ||
y = np.random.choice(shifts, rhs_shape).astype(rhs_dtype) | ||
return x, y | ||
|
||
def create_model(self): | ||
class aten_shift(torch.nn.Module): | ||
def forward(self, lhs, rhs): | ||
return lhs << rhs, lhs >> rhs | ||
|
||
ref_net = None | ||
return aten_shift(), ref_net, ("aten::__lshift__", "aten::__rshift__") | ||
|
||
@pytest.mark.nightly | ||
@pytest.mark.precommit | ||
@pytest.mark.precommit_torch_export | ||
@pytest.mark.precommit_fx_backend | ||
@pytest.mark.parametrize("lhs_dtype", ["int32", "int64"]) | ||
@pytest.mark.parametrize("rhs_dtype", ["int32", "int64"]) | ||
@pytest.mark.parametrize( | ||
("lhs_shape", "rhs_shape"), | ||
[ | ||
([2, 3], [2, 3]), | ||
([2, 3], []), | ||
([], [2, 3]), | ||
([], []), | ||
], | ||
) | ||
def test_shift_operators(self, lhs_dtype, rhs_dtype, lhs_shape, rhs_shape, ie_device, precision, ir_version): | ||
self._test( | ||
*self.create_model(), | ||
ie_device, | ||
precision, | ||
ir_version, | ||
kwargs_to_prepare_input={ | ||
"lhs_dtype": lhs_dtype, | ||
"rhs_dtype": rhs_dtype, | ||
"lhs_shape": lhs_shape, | ||
"rhs_shape": rhs_shape, | ||
}, | ||
trace_model=True, | ||
freeze_model=False, | ||
) | ||
|
||
|
||
class TestBitwiseShiftFunctions(PytorchLayerTest): | ||
def _prepare_input(self, lhs_dtype, rhs_dtype, lhs_shape, rhs_shape): | ||
choices = np.array([1, 2, 4, 8, 16, 32]) | ||
shifts = np.array([0, 1, 2, 3, 4, 5]) | ||
|
||
x = np.random.choice(choices, lhs_shape).astype(lhs_dtype) | ||
y = np.random.choice(shifts, rhs_shape).astype(rhs_dtype) | ||
return x, y | ||
|
||
def create_model(self): | ||
class aten_bitwise_shift(torch.nn.Module): | ||
def forward(self, lhs, rhs): | ||
return ( | ||
torch.bitwise_left_shift(lhs, rhs), | ||
torch.bitwise_right_shift(lhs, rhs) | ||
) | ||
|
||
ref_net = None | ||
return aten_bitwise_shift(), ref_net, ("aten::bitwise_left_shift", "aten::bitwise_right_shift") | ||
|
||
@pytest.mark.nightly | ||
@pytest.mark.precommit | ||
@pytest.mark.precommit_torch_export | ||
@pytest.mark.precommit_fx_backend | ||
@pytest.mark.parametrize("lhs_dtype", ["int32", "int64"]) | ||
@pytest.mark.parametrize("rhs_dtype", ["int32", "int64"]) | ||
@pytest.mark.parametrize( | ||
("lhs_shape", "rhs_shape"), | ||
[ | ||
([2, 3], [2, 3]), | ||
([2, 3], []), | ||
([], [2, 3]), | ||
([], []), | ||
], | ||
) | ||
def test_bitwise_shift_functions(self, lhs_dtype, rhs_dtype, lhs_shape, rhs_shape, ie_device, precision, ir_version): | ||
self._test( | ||
*self.create_model(), | ||
ie_device, | ||
precision, | ||
ir_version, | ||
kwargs_to_prepare_input={ | ||
"lhs_dtype": lhs_dtype, | ||
"rhs_dtype": rhs_dtype, | ||
"lhs_shape": lhs_shape, | ||
"rhs_shape": rhs_shape, | ||
}, | ||
trace_model=True, | ||
freeze_model=False, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two operations are sort of binary operations for which we do not create separate source files and translator. Please check how other binary operations are supported and support yours in the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for your review,
I've started working on resolving the problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkazants I've resolved the problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @rkazants ,
can you review my changes in this PR