Skip to content

Large ending index in Slice operator when exporting to ONNX model #24251

@lsy323

Description

@lsy323

When exporting a PyTorch model to ONNX, if the model has the range indices selection operator (e.g. x[2:]) and didn't specify the ending index, the "end" attribute in the exported Slice operator will be an extremely large number. This happens with PyTorch 1.0 1.1 and 1.2. However, in 0.4, there isn't such a case. I wonder if this behavior is intended?

e.g. the model is like this:

class testMod(nn.Module):
    def forward(self, x):
        return x[2:]

model = testMod()
x = torch.rand(10)
torch.onnx.export(model, x, "slice.onnx", verbose=True, input_names=["input"], output_names=["output"], opset_version = 10)

The exported Slice op is:
%output : Float(8) = onnx::Slice[axes=[0], ends=[**9223372036854775807**], starts=[2]](%input), scope: testMod

If using v0.4 to export, the ending index could be inferred:
%output : Float(8) = onnx::Slice[axes=[0], ends=[**10**], starts=[2]](%input), scope: testMod

Many Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions