Skip to content

flip: improve error handling and error messages. #9550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ysiraichi
Copy link
Collaborator

This PR refactors the tensor_methods::flip implementation by improving its error message, and returning a status type value.

Key Changes:

  • Make tensor_methods::flip return StatusOr<absl_nonnull XLATensorPtr>
  • Improve error message on incompatible tensor shapes

Example:

dims = [0, 0, 0, 1, 2, 3, -1]
a = torch.rand(2, 2, 2, 2, device="xla")
print(torch.flip(a, dims=dims))

Before:

Traceback (most recent call last):
  File "scratch.py", line 8, in <module>
    print(torch.flip(a, dims=dims))
          ^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Check failed: unique_dims.size() == dimensions.size() (4 vs. 7) (at torch_xla/csrc/tensor_methods.cpp:1675)

Exception raised from operator& at torch_xla/csrc/runtime/tf_logging.cpp:26 (most recent call first):

After:

Traceback (most recent call last):
  File "scratch.py", line 8, in <module>
    print(torch.flip(a, dims=dims))
          ^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: flip(): expected each dimension to appear at most once. Found dimensions: 0 (3 times), 3 (2 times). Consider changing dims from [0, 0, 0, 1, 2, 3, -1] to [0, 1, 2, 3].

Status Propagation Trace:
    From: flip at torch_xla/csrc/tensor_methods.cpp:1704 (error: flip(): expected each dimension to appear at most once. Found dimensions: 0 (3 times), 3 (2 times). Consider changing dims from [0, 0, 0, 1, 2, 3, -1] to [0, 1, 2, 3].)

Exception raised from MaybeThrow at torch_xla/csrc/status.cpp:128 (most recent call first):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant