Skip to content

[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
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

vijaykr338
Copy link
Contributor

@vijaykr338 vijaykr338 commented Mar 15, 2025

Details:

I was able to implement aten::take and aten::Delete function,

but aten::str posed really high difficult, i was only able to partially implement the it

currently, my implementation works for constant tensors, but for dynamic tensors, it currently stores shape and dtype for later use in debugging.

I have another question, how do you write tests for functions which are not implemented in Aten library yet?

I was able to write test cases for aten::take by following examples existing pytest files in the PyTorch layer tests folder.

but when I did the same for Delete and str, they consistently gave error

this is my first contribution to openVINO, I would greatly appreciate any guidance or assistance.

Tickets:

@vijaykr338 vijaykr338 requested a review from a team as a code owner March 15, 2025 05:15
@github-actions github-actions bot added the category: PyTorch FE OpenVINO PyTorch Frontend label Mar 15, 2025
@sys-openvino-ci sys-openvino-ci added the ExternalPR External contributor label Mar 15, 2025
@vijaykr338 vijaykr338 marked this pull request as draft March 15, 2025 10:47
@vijaykr338 vijaykr338 changed the title added aten::take function in pytorch FE, tests are not running [WIP] added aten::take, aten::str and aten::Delete, but unable to write their tests Mar 15, 2025
@vijaykr338 vijaykr338 marked this pull request as ready for review March 15, 2025 22:15
@mvafin
Copy link
Contributor

mvafin commented Mar 19, 2025

Please fix code style and add tests for aten::str and aten::Delete.

@vijaykr338
Copy link
Contributor Author

Please fix code style and add tests for aten::str and aten::Delete.

Sir @mvafin, I will fix the code style but

I am having issues writing tests for str

E       openvino._pyopenvino.OpConversionFailure: Check 'is_conversion_successful' failed at src/frontends/pytorch/src/frontend.cpp:174:
E       FrontEnd API failed with OpConversionFailure:
E       Model wasn't fully converted.
E       Summary:
E       -- No conversion rule found for operations: aten::str

I have added the aten::str in the op_table.cpp, along with the function name

@mvafin
Copy link
Contributor

mvafin commented Mar 21, 2025

Please fix code style and add tests for aten::str and aten::Delete.

Sir @mvafin, I will fix the code style but

I am having issues writing tests for str

E       openvino._pyopenvino.OpConversionFailure: Check 'is_conversion_successful' failed at src/frontends/pytorch/src/frontend.cpp:174:
E       FrontEnd API failed with OpConversionFailure:
E       Model wasn't fully converted.
E       Summary:
E       -- No conversion rule found for operations: aten::str

I have added the aten::str in the op_table.cpp, along with the function name

Did you build openvino? It seems you are testing the release version of openvino, not the one you built.

@vijaykr338
Copy link
Contributor Author

Please fix code style and add tests for aten::str and aten::Delete.

Sir @mvafin, I will fix the code style but
I am having issues writing tests for str

E       openvino._pyopenvino.OpConversionFailure: Check 'is_conversion_successful' failed at src/frontends/pytorch/src/frontend.cpp:174:
E       FrontEnd API failed with OpConversionFailure:
E       Model wasn't fully converted.
E       Summary:
E       -- No conversion rule found for operations: aten::str

I have added the aten::str in the op_table.cpp, along with the function name

Did you build openvino? It seems you are testing the release version of openvino, not the one you built.

I have recognized the issue
There was an issue with the registeration of aten::str in op_table.cpp, I am working on it now

@p-wysocki p-wysocki linked an issue Mar 24, 2025 that may be closed by this pull request
@vijaykr338
Copy link
Contributor Author

@mvafin I have updated the implementation and test file for aten::take and aten::delete
since there is no delete function in torch library, I assumed that it is meant to remove an element from input tensor, by slicing the portion before and after that element and then concatenating those slices

so my model looks like this for aten::delete

 def create_model(self):
        class aten_delete(torch.nn.Module):
            def forward(self, x, index):
                idx = int(index.item())
                # Delete along axis 0 by concatenating slices before and after idx.
                return torch.cat([x[:idx], x[idx+1:]], dim=0)
        ref_net = None
        return aten_delete(), ref_net, ["aten::slice", "aten::cat"]

please check

@vijaykr338
Copy link
Contributor Author

for aten::Str, I'd like to confirm it's intended function

should it mimic python's inbuilt str() function? the general function is to convert tensors into string representation

my current implementation does not work, as it gives errors

E       openvino._pyopenvino.OpConversionFailure: Check 'is_conversion_successful' failed at src/frontends/pytorch/src/frontend.cpp:174:
E       FrontEnd API failed with OpConversionFailure:
E       Model wasn't fully converted. Failed operations detailed log:
E       -- prim::Constant with a message:
E       String constant cannot be converted to OpenVINO opset and should be removed by consuming operation.
E       Summary:
E       -- Conversion is failed for: prim::Constant

according to docs, raw string constants aren’t directly supported in the OpenVINO opset - instead I found StringTensorUnpack - which can make break the string into three parts to make it usable for further operations

@vijaykr338
Copy link
Contributor Author

vijaykr338 commented Mar 29, 2025

@mvafin Please let me know your thoughts when you have a moment. Thank you.

@vijaykr338 vijaykr338 changed the title added aten::take, aten::str and aten::Delete, but unable to write their tests added aten::take, aten::str and aten::Delete Mar 31, 2025
@mvafin
Copy link
Contributor

mvafin commented Mar 31, 2025

@vijaykr338 Openvino support string tensors if created inside the model. However we cannot return or accept strings as model inputs/outputs. What model are you testing this on? I think it might be very hard or even impossible to make such a model that will be using aten::str inside.

As for delete, you are clearly not using aten::Delete inside the model code. I suspect that this operation is del that removes an element from dict. If so you wouldn't be able to implement since openvino doesn't support dictionaries, we decompose them.

@vijaykr338
Copy link
Contributor Author

vijaykr338 commented Apr 1, 2025

@vijaykr338 Openvino support string tensors if created inside the model. However we cannot return or accept strings as model inputs/outputs. What model are you testing this on? I think it might be very hard or even impossible to make such a model that will be using aten::str inside.

As for delete, you are clearly not using aten::Delete inside the model code. I suspect that this operation is del that removes an element from dict. If so you wouldn't be able to implement since openvino doesn't support dictionaries, we decompose them.

given such constraints, I think it would be wise to drop these 2 operations and focus on refining aten::Take instead

for aten::str, I thought about using an encoding-decoding pipeline to convert the string data to numerical data then back to it which is basically openVINO tokenizers, but that simply wont work.

similarly for aten::delete, I had another plan of making a 'mask' tensor with true and false values to filter out false indice elements from target tensor, but that wouldnt work either considering the constraints

I think it's better for me to refine just the aten::take function

@mvafin
Copy link
Contributor

mvafin commented Apr 7, 2025

@mvafin @rkazants the tests for pytorch ran fine on the other operating systems, I am not sure why Ubuntu 22.04 failed, even the logs didn't help

It failed by timeout. Tests either too long or we just have added too many new tests

@vijaykr338
Copy link
Contributor Author

vijaykr338 commented Apr 7, 2025

@mvafin @rkazants the tests for pytorch ran fine on the other operating systems, I am not sure why Ubuntu 22.04 failed, even the logs didn't help

It failed by timeout. Tests either too long or we just have added too many new tests

I see

I have reduced the amount of tests

@vijaykr338
Copy link
Contributor Author

@mvafin there seems to be some CI/CD issues, I checked the logs but they don't seem to be related to my implementation

@vijaykr338 vijaykr338 requested a review from mvafin April 10, 2025 04:50
@vijaykr338
Copy link
Contributor Author

@mvafin @rkazants Just checking in — is there anything else I should change or address in this PR? I noticed that the CI failures don’t seem related to my implementation.

I would really appreciate it if you could take a look whenever you get a chance

thanks

Copy link
Contributor

This PR will be closed in a week because of 2 weeks of no activity.

@github-actions github-actions bot added the Stale label May 18, 2025
@mlukasze mlukasze removed the request for review from slyalin May 21, 2025 09:43
@mlukasze
Copy link
Contributor

build_jenkins

@github-actions github-actions bot removed the Stale label May 22, 2025
@vijaykr338
Copy link
Contributor Author

@mlukasze the tests have completed, could you take a look?

@mlukasze
Copy link
Contributor

mlukasze commented Jun 3, 2025

build_jenkins

@vijaykr338
Copy link
Contributor Author

@mlukasze apologies for mentioning again, I believe that this PR can be merged now since all checks have passed successfully.

Comment on lines +24 to +27
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");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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");
}

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.

@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):
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

This PR will be closed in a week because of 2 weeks of no activity.

@github-actions github-actions bot added the Stale label Jun 27, 2025
@github-actions github-actions bot removed the Stale label Jul 1, 2025
Copy link
Contributor

This PR will be closed in a week because of 2 weeks of no activity.

@github-actions github-actions bot added the Stale label Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: PyTorch FE OpenVINO PyTorch Frontend ExternalPR External contributor Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Good First Issue]: Support aten::Delete aten::str aten::take
5 participants