Skip to content

Improve error message of functions related to GetXlaTensor().#9520

Merged
ysiraichi merged 5 commits intomasterfrom
ysiraichi/better-get-xla-tensor-messages
Aug 7, 2025
Merged

Improve error message of functions related to GetXlaTensor().#9520
ysiraichi merged 5 commits intomasterfrom
ysiraichi/better-get-xla-tensor-messages

Conversation

@ysiraichi
Copy link
Copy Markdown
Collaborator

@ysiraichi ysiraichi commented Jul 30, 2025

This PR refactors functions related to GetXlaTensor(), improving error message, and propagating status. These changes should make errors more actionable from users perspective. Additionally, this PR also allows Python API bound functions to returns status values.

Key Changes:

  • Add GetValueOrThrow(Status) overload, so that we can call GetValueOrThrow for both Status ans StatusOr<T> return values
  • Properly handle status return types when binding Python functions, i.e. allow calls likescope.def(..., [](...) -> absl::Status { ... })
    • Calls GetValueOrThrow() in the resulting status, returning void
    • Lambda source information correctly appear in the status propagation trace
  • Modify error messages of:
    • GetXlaTensorImpl(): assumes less context, with a more detailed error message
    • GetXlaTensor(): more meaningful, and higher level message
    • GetXlaTensors(): more information, such as the index of the non-XLA tensor
    • ReplaceXlaTensor(): reworded
  • Create GetInputXlaTensor() for returning errors with more context
    • This should be used instead of calling GetXlaTensor(), specifically for inputs that directly come from the user
  • Refactor 2 Python API implementation, as example:
    • _xla_dot_general: calling GetInputXlaTensor() on its tensor inputs
    • _get_graph_hash: calling GetXlaTensors() instead of an explicit loop with the same semantic

Update (Aug 4):

  • Created BuildStatusErrorMessage(const absl::Status&), in order to get the error message, and status propagation trace when crashing on a ABSL_CHECK() call.
    • Leaving the C++ stacktrace for future work
  • Removed test for _get_graph_hash, since it crashes, now
  • Added better error messages for ReplaceTensor functions

@ysiraichi ysiraichi force-pushed the ysiraichi/better-get-xla-tensor-messages branch from c47cb27 to d51f82a Compare July 30, 2025 18:00
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!

Comment thread test/dynamo/test_dynamo_integrations_util.py Outdated
Comment thread test/quantized_ops/test_dot_general.py Outdated
Comment thread torch_xla/csrc/aten_xla_bridge.h Outdated
Comment thread torch_xla/csrc/aten_xla_bridge.h Outdated
Comment thread torch_xla/csrc/aten_xla_bridge.cpp
Comment thread test/dynamo/test_dynamo_integrations_util.py Outdated
Comment thread test/quantized_ops/test_dot_general.py Outdated
Comment thread torch_xla/csrc/aten_xla_bridge.cpp Outdated
Comment thread torch_xla/csrc/aten_xla_bridge.cpp Outdated
Comment thread torch_xla/csrc/init_python_bindings.cpp Outdated
Comment thread test/dynamo/test_dynamo_integrations_util.py Outdated
Comment thread test/dynamo/test_dynamo_integrations_util.py Outdated
Comment thread torch_xla/csrc/init_python_bindings.cpp Outdated
Comment thread torch_xla/csrc/init_python_bindings.cpp Outdated
@ysiraichi
Copy link
Copy Markdown
Collaborator Author

Besides the changes requested in the review, other relevant changes are:

  • Created BuildStatusErrorMessage(const absl::Status&), in order to get the error message, and status propagation trace when crashing on a ABSL_CHECK() call.
    • Leaving the C++ stacktrace for future work
  • Removed test for _get_graph_hash, since it crashes, now
  • Added better error messages for ReplaceTensor functions

@ysiraichi ysiraichi requested a review from zhanyong-wan August 5, 2025 14:45
Comment thread torch_xla/csrc/status.h
Copy link
Copy Markdown
Collaborator

@ghpvnist ghpvnist left a comment

Choose a reason for hiding this comment

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

LGTM pending @zhanyong-wan's approval.

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-get-xla-tensor-messages branch from 99ed2b8 to ba1f008 Compare August 7, 2025 12:21
@ysiraichi ysiraichi merged commit 6050927 into master Aug 7, 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.

3 participants