openvinotoolkit / openvinotoolkit/openvino
[Bug]: [PyTorch Frontend] Incorrect translation for aten::slice when step is negative and start/end bounds are omitted
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.9k
- Forks
- 3.4k
- Avg merge
- 4d 4h
- Merged PRs (30d)
- 300
Description
OpenVINO Version
2026.5.0-23104-d903dc909e2 (master)
Operating System
Windows System
Device used for inference
CPU
Framework
None
Model used
No response
Issue description
While exploring src/frontends/pytorch/src/op/slice.cpp, I noticed a // TODO: support default start/end with negative step comment.
Currently, the OpenVINO PyTorch frontend hardcodes the default start bound to 0 and the end bound to INT_MAX for aten::slice when they are omitted (None). However, if the step is negative (e.g., x[::-1]), PyTorch semantics require the start to default to the end of the dimension and end to default to before the beginning of the dimension. Because the sign of step is ignored during translation, converting models that slice with negative steps and omitted bounds produces incorrect results (resulting in RuntimeError: slice step must be positive or empty tensors).
Step-by-step reproduction
Append the following test case to tests/layer_tests/pytorch_tests/test_slice.py:
`
class TestSliceNegativeStepDefaults(PytorchLayerTest):
def _prepare_input(self):
return (np.array(range(16), np.float32),)
def create_model(self, case):
if case == "both_default":
class aten_slice(torch.nn.Module):
def forward(self, x):
return x[::-1]
return aten_slice(), "aten::slice"
elif case == "start_default":
class aten_slice(torch.nn.Module):
def forward(self, x):
return x[:5:-1]
return aten_slice(), "aten::slice"
elif case == "end_default":
class aten_slice(torch.nn.Module):
def forward(self, x):
return x[10::-1]
return aten_slice(), "aten::slice"
@pytest.mark.parametrize("case", ["both_default", "start_default", "end_default"])
@pytest.mark.nightly
@pytest.mark.precommit
def test_slice_negative_step_defaults(self, ie_device, precision, ir_version, case):
self._test(*self.create_model(case), ie_device, precision, ir_version)
`
Run the newly added test via pytest:
pytest tests/layer_tests/pytorch_tests/test_slice.py::TestSliceNegativeStepDefaults -v
Relevant log output
DEBUG openvino.frontend.pytorch.ts_decoder:ts_decoder.py:114 Inlined graph:
graph(%self : __torch__.test_slice.___torch_mangle_44.aten_slice,
%x.1 : Tensor):
%2 : int = prim::Constant[value=10]()
%3 : int = prim::Constant[value=0]()
%4 : int = prim::Constant[value=-1]()
%5 : NoneType = prim::Constant()
%6 : Tensor = aten::slice(%x.1, %3, %2, %5, %4)
return (%6)
RuntimeError: slice step must be positive
=========================== short test summary info ===========================
FAILED tests\layer_tests\pytorch_tests\test_slice.py::TestSliceNegativeStepDefaults::test_slice_negative_step_defaults[ ie_device:CPU - precision:FP32 - case:both_default ]
FAILED tests\layer_tests\pytorch_tests\test_slice.py::TestSliceNegativeStepDefaults::test_slice_negative_step_defaults[ ie_device:CPU - precision:FP32 - case:start_default ]
FAILED tests\layer_tests\pytorch_tests\test_slice.py::TestSliceNegativeStepDefaults::test_slice_negative_step_defaults[ ie_device:CPU - precision:FP32 - case:end_default ]
FAILED tests\layer_tests\pytorch_tests\test_slice.py::TestSliceNegativeStepDefaults::test_slice_negative_step_defaults[ ie_device:GPU - precision:FP32 - case:both_default ]
FAILED tests\layer_tests\pytorch_tests\test_slice.py::TestSliceNegativeStepDefaults::test_slice_negative_step_defaults[ ie_device:GPU - precision:FP32 - case:start_default ]
...
======================= 12 failed, 36 warnings in 3.99s =======================
Issue submission checklist
- I'm reporting an issue. It's not a question.
- I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
- There is reproducer code and related data files such as images, videos, models, etc.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/frontends/pytorch/src/op/slice.cpp at the TODO for default start/end bounds with a negative step, then review the reproducer in tests/layer_tests/pytorch_tests/test_slice.py. Run pytest tests/layer_tests/pytorch_tests/test_slice.py::TestSliceNegativeStepDefaults -v; done means the three negative-step default cases pass without the reported runtime error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python, pytorch
- Domain
- machine-learning, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100