Skip to content

div: improve error handling and error messages.#9549

Merged
ysiraichi merged 3 commits intomasterfrom
ysiraichi/better-error-div
Aug 11, 2025
Merged

div: improve error handling and error messages.#9549
ysiraichi merged 3 commits intomasterfrom
ysiraichi/better-error-div

Conversation

@ysiraichi
Copy link
Copy Markdown
Collaborator

@ysiraichi ysiraichi commented Aug 8, 2025

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

Key Changes:

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

Before:

Traceback (most recent call last):
  File "scratch.py", line 8, in <module>
    print(torch.div(x, y, rounding_mode="bad"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Check failed: false: rounding_mode must be one of None, 'trunc', or 'floor' (at torch_xla/csrc/tensor_methods.cpp:1439)

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.div(x, y, rounding_mode="bad"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: div(): invalid rounding mode `bad`. Expected it to be either 'trunc', 'floor', or be left unspecified.

Status Propagation Trace:
    From: div at torch_xla/csrc/tensor_methods.cpp:1440 (error: div(): invalid rounding mode `bad`. Expected it to be either 'trunc', 'floor', or be left unspecified.)

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

Copy link
Copy Markdown
Collaborator

@zhanyong-wan zhanyong-wan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ysiraichi ysiraichi force-pushed the ysiraichi/better-error-div branch from ec62418 to 9b9ecf2 Compare August 11, 2025 16:18
@ysiraichi ysiraichi merged commit 23158fd into master Aug 11, 2025
23 of 24 checks passed
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.

2 participants