-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[PT FE] Support aten::take operation #29479
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
Open
vijaykr338
wants to merge
28
commits into
openvinotoolkit:master
Choose a base branch
from
vijaykr338:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−0
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0656890
added aten::take function in pytorch, but tests are not running
vijaykr338 98c1c61
implemented aten::str, aten::delete but unable to write their tests
vijaykr338 725c474
Merge branch 'master' into master
vijaykr338 d70f2f5
Merge branch 'master' into master
vijaykr338 d6adb61
Merge branch 'master' into master
vijaykr338 0393cde
fixed op_table.cpp
vijaykr338 cd831da
Merge branch 'master' into master
vijaykr338 3eea874
Merge branch 'master' into master
vijaykr338 3555b2e
fixed code style, added out of bounds check for take function, added …
vijaykr338 063f8e1
Merge branch 'openvinotoolkit:master' into master
vijaykr338 54aa9c9
Delete src/frontends/pytorch/src/op/str.cpp
vijaykr338 6648067
Delete src/frontends/pytorch/src/op/delete.cpp
vijaykr338 5b2eb21
Delete tests/layer_tests/pytorch_tests/test_delete.py
vijaykr338 0a72cd5
Update op_table.cpp
vijaykr338 6dbb55a
Merge branch 'master' into master
mvafin 30b4183
Merge branch 'master' into master
vijaykr338 be53f0b
added support for quantized relu6
vijaykr338 5e1e379
Delete tests/layer_tests/pytorch_tests/test_quantized_relu6.py
vijaykr338 e9caf31
Update op_table.cpp
vijaykr338 6e071df
Delete src/frontends/pytorch/src/op/quantized_relu6.cpp
vijaykr338 08c22c5
Merge branch 'master' into master
mvafin 5bd5bb8
Update tests/layer_tests/pytorch_tests/test_take.py
vijaykr338 31b6ece
Merge branch 'master' into master
mlukasze db60469
Merge branch 'master' into master
mlukasze 396f16c
Update src/frontends/pytorch/src/op/take.cpp
vijaykr338 055e355
Update src/frontends/pytorch/src/op/take.cpp
vijaykr338 ed3e61e
Update src/frontends/pytorch/src/op/take.cpp
vijaykr338 2535095
Update src/frontends/pytorch/src/op/take.cpp
vijaykr338 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 hidden or 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,43 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/core/validation_util.hpp" | ||
#include "openvino/frontend/pytorch/node_context.hpp" | ||
#include "openvino/op/constant.hpp" | ||
#include "openvino/op/gather.hpp" | ||
#include "openvino/op/reshape.hpp" | ||
#include "openvino/op/shape_of.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace pytorch { | ||
namespace op { | ||
|
||
using namespace ov::op; | ||
|
||
OutputVector translate_take_op(const NodeContext& context) { | ||
num_inputs_check(context, 2, 3); | ||
auto input = context.get_input(0); | ||
auto indices = context.get_input(1); | ||
auto input_shape = input.get_partial_shape(); | ||
if (input_shape.rank().is_static() && input_shape.rank().get_length() == 0) { | ||
FRONT_END_OP_CONVERSION_CHECK(false, "input tensor MUST be non-scalar"); | ||
} | ||
auto new_shape = context.mark_node(v0::Constant::create(element::i64, Shape{1}, {-1})); | ||
input = context.mark_node(std::make_shared<v1::Reshape>(input, new_shape, false)); | ||
indices = context.mark_node(std::make_shared<v0::Convert>(indices, element::i64)); | ||
auto axis_constant = context.mark_node(v0::Constant::create(element::i64, Shape{}, {0})); | ||
auto gather = context.mark_node(std::make_shared<v8::Gather>(input, indices, axis_constant)); | ||
vijaykr338 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!context.input_is_none(2)) { | ||
context.mutate_input(2, gather); | ||
} | ||
|
||
return {gather}; | ||
} | ||
|
||
} // namespace op | ||
} // namespace pytorch | ||
} // namespace frontend | ||
} // namespace ov |
This file contains hidden or 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 hidden or 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,35 @@ | ||
# Copyright (C) 2018-2025 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
import numpy as np | ||
import torch | ||
from pytorch_layer_test_class import PytorchLayerTest | ||
|
||
class TestTake(PytorchLayerTest): | ||
def _prepare_input(self, input_shape, indices_shape, max_val): | ||
input_tensor = np.random.randn(*input_shape).astype(np.float32) | ||
indices = np.random.randint(-max_val, max_val, indices_shape).astype(np.int64) | ||
return (input_tensor, indices) | ||
|
||
def create_model(self): | ||
class aten_take(torch.nn.Module): | ||
def forward(self, x, indices): | ||
return torch.take(x, indices) | ||
|
||
ref_net = None | ||
return aten_take(), ref_net, "aten::take" | ||
|
||
@pytest.mark.nightly | ||
@pytest.mark.precommit | ||
@pytest.mark.precommit_torch_export | ||
@pytest.mark.parametrize("input_shape", [(10,), (3, 4), (2, 3, 4)]) | ||
@pytest.mark.parametrize("indices_shape", [(5,), (2, 2), (3, 2)]) | ||
def test_take(self, input_shape, indices_shape, ie_device, precision, ir_version): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add test case for scenario with out. This would require few changes for whole class, you can refer to similar op: https://github.com/openvinotoolkit/openvino/blob/master/tests/layer_tests/pytorch_tests/test_take_along_dim.py#L51 |
||
max_val = np.prod(input_shape) | ||
self._test(*self.create_model(), ie_device, precision, ir_version, | ||
kwargs_to_prepare_input={ | ||
"input_shape": input_shape, | ||
"indices_shape": indices_shape, | ||
"max_val": max_val | ||
}) |
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.
Looking on how torch.take functions, scalar tensors should be allowed, for example:
torch.take(torch.tensor(5), torch.tensor(0)) -> tensor(5)
torch.take(torch.tensor(5), torch.tensor([0])) -> tensor([5])
Is there any reason for such check? I've modified test suite a bit and it seem that scalars should work correctly.