[Bug]: [PyTorch Frontend] aten::narrow with a negative start returns an empty tensor
OpenVINO Version
2026.4.0-22959-99c81491cc3-releases/2026/4 (pip wheel); src/frontends/pytorch/src/op/narrow.cpp is unchanged on master (checked 2026-09-18).
Operating System
Windows System
Device used for inference
CPU
Framework
PyTorch
Model used
Minimal module, see reproducer.
Issue description
torch.narrow(input, dim, start, length) documents that start "can be negative, which means indexing from the end of dim". The PyTorch frontend computes the slice stop as start + length without normalizing a negative start, so narrow(x, 1, -2, 2) becomes Slice(start=-2, stop=0), i.e. an empty tensor, instead of the last two elements along dim. A negative start whose window stops before the end of the axis happens to work because Slice accepts a negative stop (narrow(x, 1, -3, 2) → Slice(-3, -1)), so the failure is specific to windows that reach the end of the axis (start + length == 0), which is the common x.narrow(d, -k, k) idiom.
The existing layer test tests/layer_tests/pytorch_tests/test_narrow.py only covers start in {0, 1}.
Step-by-step reproduction
import torch, numpy as np, openvino as ov
class M(torch.nn.Module):
def forward(self, x):
return x.narrow(1, -2, 2)
x = torch.arange(60, dtype=torch.float32).reshape(5, 3, 4)
ref = M()(x)
m = ov.convert_model(torch.jit.script(M()), example_input=(x,))
out = ov.Core().compile_model(m, "CPU")([x.numpy()])[0]
print("torch:", ref.shape, "openvino:", out.shape)Output:
torch: torch.Size([5, 2, 4]) openvino: (5, 0, 4)Expected: identical shapes and values (the last two elements along dim 1).
Relevant log output
(no error; the result is silently wrong)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.
Source: openvinotoolkit/openvino