Skip to content

ErrorHandling: make GetComputationClient() return StatusOr<T> type. #9384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 24, 2025

Conversation

ysiraichi
Copy link
Collaborator

@ysiraichi ysiraichi commented Jun 18, 2025

Ref: #9339

This PR creates a new version of GetComputationClient() that returns a StatusOr<T> type for better error handling. Since this function is frequently used in the codebase, its old version remains, but annotated with ABSL_DEPRECATED() (following #9381 example) and renamed to GetComputationClientOrDie(). The new version is created with the old name. Summarizing:

  • Old GetComputationClient() is renamed to GetComputationClientOrDie()
  • New torch_xla::runtime::status::GetComputationClient() function that returns StatusOr<T> type
  • The old version remains, and calls the new function. It uses XLA_CHECK() for throwing an error on non-ok status, maintaining its old behavior
  • New ConsumeAndMaybeThrow() function for throwing errors if non-ok status reach the Python API boundary

Copy link
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.

Thanks for the change, added a few comments.

@ysiraichi ysiraichi force-pushed the ysiraichi/status-for-getcomputationclient branch from 391d353 to 3344bb0 Compare June 18, 2025 19:25
@ysiraichi
Copy link
Collaborator Author

Incorporated the changes suggested by @zhanyong-wan comment.

Copy link
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.

Can you create a unit test for the new API? runtime_test.cpp in the same directory could work.

@ysiraichi
Copy link
Collaborator Author

@ghpvnist What kind of tests did you have in mind?
I think C++ tests usually go inside test/cpp directory.

@ghpvnist
Copy link
Collaborator

I think C++ tests usually go inside test/cpp directory.

This directory has precedent of tests within the same directory. I prefer to have tests close where the files are stored that way, future refactoring changes would be easier. Wdyt? @zhanyong-wan

What kind of tests did you have in mind?

I was thinking the typical unit tests for test coverage purposes. Something along the lines of:

  • Check that calls to GetComputationClient return a valid client.
  • GetComputationClientIfInitialized should return nullptr vs a valid client.
  • etc.

@ysiraichi ysiraichi force-pushed the ysiraichi/status-for-getcomputationclient branch from a351a69 to 7e0da02 Compare June 19, 2025 16:34
@zhanyong-wan
Copy link
Collaborator

I think C++ tests usually go inside test/cpp directory.

This directory has precedent of tests within the same directory. I prefer to have tests close where the files are stored that way, future refactoring changes would be easier. Wdyt? @zhanyong-wan

While I prefer to have tests in the same directory as the code too, pytorch uses the test/cpp/test_foo.cpp convention. I think we should align with that to ease upstreaming.

@ysiraichi
Copy link
Collaborator Author

@zhanyong-wan @ghpvnist Let me know if there's anything else you'd like to see in this PR.

@zhanyong-wan
Copy link
Collaborator

Hi @ysiraichi , I'll take a look soon. In the future, when the PR is ready for another review, could you click on the spinning-arrows icon next to the reviewer name? That'll let us know that you are done with editing and it's our turn. Thanks!

@ysiraichi
Copy link
Collaborator Author

Ah, ok. Got it. I don't think I ever noticed that feature. Thanks for the tip.

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 ghpvnist June 24, 2025 13:05
@ysiraichi ysiraichi merged commit 10ed554 into master Jun 24, 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