microsoft / microsoft/onnxruntime

Slice behavior wrong with negative step and end = INT_MAX

Open
#11,107 14 comments 0 reactions 1 assignee View on GitHub

@hariharans29 is already working on this.

Since Apr 5, 2022.

core runtime
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 8h
Merged PRs (30d)
179

Description

Describe the bug
ORT's Slice tests assert that Slice(x, starts = [-1], ends = [INT_MAX], steps = [-1]) == Reverse(x).

ONNX spec says:

For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX when slicing forward and INT_MIN when slicing backward.

I haven't yet tested to see if the behavior is correct with INT_MIN, but that should be checked as well.

Urgency
None.

To Reproduce
Build ORT and run onnxruntime_test_all --gtest_filter='SliceTest.Slice1D_ReverseAllAxes_1'.
Currently the test triggers a shape inference failure which results in a warning being logged.

Expected behavior
Slice(x, starts = [-1], ends = [INT_MAX], steps = [-1]) == <empty tensor>
Slice(x, starts = [-1], ends = [INT_MIN], steps = [-1]) == Reverse(x)

Both cases should be tested in ORT and not result in shape inference failures.

Additional context
Add any other context about the problem here. If the issue is about a particular model, please share the model details as well to facilitate debugging.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.