Skip to content

Conversation

ysiraichi
Copy link
Collaborator

This PR refactors the uniform_ operation implementation by improving its error message, and returning a status type value.

Key Changes:

  • Make tensor_methods::uniform_ return Status
  • Improve error messages and error handling
    • Add CheckUniformRangeIsValid function

Example

a = torch.empty( 2, 2, device="xla")
a.uniform_(5, 2)

Before:

Traceback (most recent call last):
  File "examples/uniform.py", line 6, in <module>
    a.uniform_(5, 2)
RuntimeError: Check failed: from <= to (5 vs. 2) (at torch_xla/csrc/tensor_methods.cpp:3673)

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

After:

Traceback (most recent call last):
  File "examples/uniform.py", line 6, in <module>
    a.uniform_(5, 2)
RuntimeError: uniform_(): expected `from` (5) to be smaller or equal `to` (2).

Status Propagation Trace:
    From: CheckUniformRangeIsValid at torch_xla/csrc/tensor_methods.cpp:3659 (error: uniform_(): expected argument `from` (5) to be smaller or equal argument `to` (2).)
    From: uniform_ at torch_xla/csrc/tensor_methods.cpp:3667
    From: uniform_ at torch_xla/csrc/aten_xla_type.cpp:3910

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

@ysiraichi ysiraichi force-pushed the ysiraichi/better-error-uniform_ branch from 3441991 to b66ef5f Compare September 12, 2025 19:24
@ysiraichi

This comment was marked as outdated.

@ysiraichi ysiraichi force-pushed the ysiraichi/better-error-uniform_ branch from b66ef5f to d1e8007 Compare September 19, 2025 10:47
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