[PyTorch FE] Support aten::ravel operation#34006
[PyTorch FE] Support aten::ravel operation#34006Nishant-ZFYII wants to merge 4 commits intoopenvinotoolkit:masterfrom
Conversation
Adds a translator for aten::ravel that reshapes the input tensor to a 1-D tensor using Reshape with shape [-1]. Closes openvinotoolkit#28902
|
@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. |
There was a problem hiding this comment.
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::ravelto OpenVINO'sReshapeop 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.
|
|
||
| class TestRavel(PytorchLayerTest): | ||
| def _prepare_input(self, shape, dtype="float32"): | ||
| return (np.random.randn(*shape).astype(dtype),) |
There was a problem hiding this comment.
[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.
| return (np.random.randn(*shape).astype(dtype),) | |
| return (self.random.randn(*shape).astype(dtype),) |
| @@ -0,0 +1,28 @@ | |||
| // Copyright (C) 2018-2025 Intel Corporation | |||
There was a problem hiding this comment.
[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.
| // Copyright (C) 2018-2025 Intel Corporation | |
| // Copyright (C) 2018-2026 Intel Corporation |
Fixes #28902
What / Why
torch.ravel(input)returns a contiguous flattened 1-D tensor. It is semanticallyequivalent to
torch.reshape(input, (-1,)). The PyTorch frontend was missing atranslator for
aten::ravel, so any model usingtorch.ravel()would failconversion with an "unsupported op" error.
This adds a minimal translator that maps
aten::ravelto the OpenVINOReshapeop with a constant pattern of
[-1], which produces a 1-D output whose lengthequals the total number of elements in the input tensor.
No new OpenVINO ops are introduced — this is purely a frontend mapping.
References
torch.raveldocs: https://pytorch.org/docs/stable/generated/torch.ravel.htmlTensor.raveldocs: https://pytorch.org/docs/stable/generated/torch.Tensor.ravel.htmlReshapeop spec: https://docs.openvino.ai/2024/documentation/openvino-ir-format/operation-sets/operation-specs/shape/reshape-1.htmlsrc/frontends/pytorch/README.mdChecks
cmake --build build --target openvino_pytorch_frontend— compiles cleanlyclang-format-18 --dry-run -Werroronravel.cppandop_table.cpp— 0 issuespytest tests/layer_tests/pytorch_tests/test_ravel.py -k CPU— 60/60 passed(GPU tests require GPU plugin not available locally; CI will cover GPU)
CC: @openvinotoolkit/openvino-pytorch-fe-maintainers