Skip to content

Error Handling: refactor GetXlaTensor and related functions to use status types.#9510

Merged
ysiraichi merged 4 commits intomasterfrom
ysiraichi/status-for-get-xla-tensor
Jul 29, 2025
Merged

Error Handling: refactor GetXlaTensor and related functions to use status types.#9510
ysiraichi merged 4 commits intomasterfrom
ysiraichi/status-for-get-xla-tensor

Conversation

@ysiraichi
Copy link
Copy Markdown
Collaborator

@ysiraichi ysiraichi commented Jul 25, 2025

This PR refactors error handling for GetXlaTensor() and related functions (e.g. TryGetXlaTensor(), TryGetXlaTensors(), and ReplaceXlaTensor()), by incorporating status types. At this moment, these changes do not translate into better UX for the user. However, this PR lays the groundwork for improving that.

Key Changes

  • GetXlaTensor() returns a StatusOr<XLATensorPtr>
  • Deprecate TryGetXlaTensor() in favor of GetXlaTensor()
    • Removing it would be difficult, since the current codegen depends on it and there's no clear replacement
    • Replaced other call-sites with appropriate usage of GetXlaTensor()
  • Remove TryGetXlaTensors() (note the plural)
    • There was only one usage
    • Easily replaceable by GetXlaTensor()
  • Refactor ReplaceXlaTensor(), returning absl::Status
  • Replace all GetXlaTensor() calls with GetValueOrThrow(GetXlaTensor()) (same for GetXlaTensors() -- plural)
  • Replace all ReplaceXlaTensor() calls with MaybeThrow(ReplaceXlaTensor())

Comment thread torch_xla/csrc/init_python_bindings.cpp
@ysiraichi ysiraichi marked this pull request as ready for review July 25, 2025 19:15
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.

Nice!

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.h
Comment thread torch_xla/csrc/aten_xla_bridge.h Outdated
@ysiraichi ysiraichi merged commit cd3bd91 into master Jul 29, 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