Skip to content

Conversation

ysiraichi
Copy link
Collaborator

This PR refactors the tensor_methods::full and tensor_methods::full_symint implementation by improving their error message, and returning a status type value.

Key Changes:

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

Example:

torch.full((2, -2, 2), 1.5, device="xla")

Before:

Traceback (most recent call last):
  File "examples.py", line 5, in <module>
    torch.full((2, -2, 2), 1.5, device="xla")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Check failed: std::all_of(size.begin(), size.end(), [](int64_t dim) { return dim >= 0; }): Dimensions cannot be negative numbers (at torch_xla/csrc/tensor_methods.cpp:208)

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

After:

Traceback (most recent call last):
  File "example.py", line 5, in <module>
    torch.full((2, -2, 2), 1.5, device="xla")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: full(): expected concrete sizes (i.e. non-symbolic) to be positive values, however found negative ones: [2, -2, 2]

Status Propagation Trace:
    From: CheckSizesArePositiveImpl at torch_xla/csrc/tensor_methods.cpp:427 (error: full(): expected concrete sizes (i.e. non-symbolic) to be positive values, however found negative ones: [2, -2, 2])
    From: full at torch_xla/csrc/tensor_methods.cpp:1818

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

Copy link
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 requested a review from zhanyong-wan August 19, 2025 13:34
@ysiraichi
Copy link
Collaborator Author

The CI failure is unrelated to this PR. I'm landing this.

@ysiraichi ysiraichi enabled auto-merge (squash) August 19, 2025 19:45
@ysiraichi ysiraichi disabled auto-merge August 19, 2025 19:45
@ysiraichi
Copy link
Collaborator Author

Couldn't merge this PR because of the failing CI.
Tried merging it using the command line, but that also didn't work, since the master branch is protected.
Waiting for the issue to be resolved.

@ysiraichi ysiraichi force-pushed the ysiraichi/better-error-full branch from e309dce to 9d02686 Compare August 23, 2025 13:46
@ysiraichi ysiraichi merged commit 147d2c2 into master Aug 23, 2025
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