Skip to content

[PyTorch FE] Support aten::ravel operation#34006

Open
Nishant-ZFYII wants to merge 4 commits intoopenvinotoolkit:masterfrom
Nishant-ZFYII:gfi-28902-aten-ravel
Open

[PyTorch FE] Support aten::ravel operation#34006
Nishant-ZFYII wants to merge 4 commits intoopenvinotoolkit:masterfrom
Nishant-ZFYII:gfi-28902-aten-ravel

Conversation

@Nishant-ZFYII
Copy link
Contributor

Fixes #28902

What / Why

torch.ravel(input) returns a contiguous flattened 1-D tensor. It is semantically
equivalent to torch.reshape(input, (-1,)). The PyTorch frontend was missing a
translator for aten::ravel, so any model using torch.ravel() would fail
conversion with an "unsupported op" error.

This adds a minimal translator that maps aten::ravel to the OpenVINO Reshape
op with a constant pattern of [-1], which produces a 1-D output whose length
equals the total number of elements in the input tensor.

No new OpenVINO ops are introduced — this is purely a frontend mapping.

References

Checks

  • cmake --build build --target openvino_pytorch_frontend — compiles cleanly
  • clang-format-18 --dry-run -Werror on ravel.cpp and op_table.cpp — 0 issues
  • pytest tests/layer_tests/pytorch_tests/test_ravel.py -k CPU60/60 passed
    (GPU tests require GPU plugin not available locally; CI will cover GPU)

CC: @openvinotoolkit/openvino-pytorch-fe-maintainers

Adds a translator for aten::ravel that reshapes the input tensor
to a 1-D tensor using Reshape with shape [-1].

Closes openvinotoolkit#28902
@Nishant-ZFYII Nishant-ZFYII requested a review from a team as a code owner February 7, 2026 18:43
@github-actions github-actions bot added the category: PyTorch FE OpenVINO PyTorch Frontend label Feb 7, 2026
@sys-openvino-ci sys-openvino-ci added the ExternalPR External contributor label Feb 7, 2026
@Nishant-ZFYII
Copy link
Contributor Author

@openvinotoolkit/openvino-pytorch-fe-maintainers

Good Day,

Can you please look into the PR and review it.

Please let me know if further changes are required. Happy to help :)

Thanks and Regards.

@mlukasze mlukasze requested a review from Copilot February 25, 2026 08:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the PyTorch aten::ravel operation to the OpenVINO PyTorch frontend. The torch.ravel() function flattens a tensor into a contiguous 1-D array, which is semantically equivalent to torch.reshape(input, (-1,)).

Changes:

  • Added a translator that maps aten::ravel to OpenVINO's Reshape op with a constant pattern of [-1]
  • Registered the new translator in the operation table
  • Added comprehensive test coverage for various input shapes and data types

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/frontends/pytorch/src/op/ravel.cpp Implements the translate_ravel function that converts aten::ravel to OpenVINO Reshape op
src/frontends/pytorch/src/op_table.cpp Registers the translate_ravel converter and adds aten::ravel to the supported operations map
tests/layer_tests/pytorch_tests/test_ravel.py Adds test cases covering various tensor shapes and data types for the ravel operation

…kit#28902)

PytorchLayerTest._test expects (model, kind), not (model, ref_net, kind).
Returning 3 values caused ie_device to receive 'aten::ravel' as device.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


class TestRavel(PytorchLayerTest):
def _prepare_input(self, shape, dtype="float32"):
return (np.random.randn(*shape).astype(dtype),)
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

[MEDIUM] _prepare_input uses np.random.randn, which bypasses the PytorchLayerTest RNG (self.random) used across the suite for deterministic, reproducible inputs (e.g., test_trilu.py, test_reshape.py). Consider switching to self.random.randn(..., dtype=dtype) (or equivalent) so the test is stable and consistent with other PyTorch layer tests.

Suggested change
return (np.random.randn(*shape).astype(dtype),)
return (self.random.randn(*shape).astype(dtype),)

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,28 @@
// Copyright (C) 2018-2025 Intel Corporation
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

[LOW] New files use a 2018-2025 copyright header, while most nearby PyTorch FE sources use 2018-2026 (e.g., op_table.cpp, range_length.cpp). Please align the year range in this new source file with the repository’s current convention.

Suggested change
// Copyright (C) 2018-2025 Intel Corporation
// Copyright (C) 2018-2026 Intel Corporation

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue]: Support aten::ravel operation

4 participants