Skip to content
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

guard against None in pytorch get_xla_supported_devices #9572

Merged
merged 4 commits into from
Oct 12, 2021

Conversation

ckchow
Copy link
Contributor

@ckchow ckchow commented Sep 16, 2021

What does this PR do?

Guard against None when checking if TPU's are available. This happens (e.g.) if you use google's standard deep learning containers on CPU only machines.

Fixes #9552

Does your PR introduce any breaking changes? If yes, please list them.

None

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@ckchow
Copy link
Contributor Author

ckchow commented Sep 16, 2021

I'm actually not sure how to write a proper test for this. Seems like it would have to pull an XLA container.

@kaushikb11
Copy link
Contributor

I'm actually not sure how to write a proper test for this. Seems like it would have to pull an XLA container.

We have TPU CI tests in place, But for this, we would require to pull an XLA container with no TPUs attached. Could you please add a comment for this in the code?

Do you think "the guard against None and return an empty list" should be added to the XLA's API itself? cc: @JackCaoG

@awaelchli awaelchli added accelerator: tpu Tensor Processing Unit feature Is an improvement or enhancement labels Sep 17, 2021
@awaelchli awaelchli added this to the v1.5 milestone Sep 17, 2021
@awaelchli awaelchli added bug Something isn't working and removed feature Is an improvement or enhancement labels Sep 17, 2021
@awaelchli awaelchli modified the milestones: v1.5, v1.4.x Sep 17, 2021
Copy link
Contributor

@SeanNaren SeanNaren 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 this! At the least I think add a todo saying that this needs to be tested in a XLA supported container without TPUs!

@mergify mergify bot added ready PRs ready to be merged has conflicts labels Sep 17, 2021
Copy link
Contributor

@kaushikb11 kaushikb11 left a comment

Choose a reason for hiding this comment

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

Blocking this merge for now. I have asked the XLA team if this change could instead be introduced on the pt/xla's side

@mergify mergify bot removed the ready PRs ready to be merged label Sep 17, 2021
@JackCaoG
Copy link

@kaushikb11 so get_xla_supported_devices will never return a empty list, so maybe we can just check if get_xla_supported_devices('TPU') != None

@ckchow
Copy link
Contributor Author

ckchow commented Sep 17, 2021

I feel like somebody might change get_xla_supported_devices to return empty lists in the future (i.e. if I were a contributor to that codebase I would feel tempted to do so), so I think checking for None and len() > 0 explicitly is safer. I guess it's also correct to check tpus != None and tpus, but I always forget that empty lists are false in python so that feels a little unexpected.

@JackCaoG
Copy link

I could try to change the pt/xla code to return an empty list, but

  1. That will also require me to change a couple other places in pt/xla
  2. This is BC breaking, if there are users/frameworks that explicitly checking for !=None that will also have to change.

so I will prefer to leave the return None if no device found logic

@tchaton tchaton requested a review from rohitgr7 as a code owner October 12, 2021 11:10
@mergify mergify bot removed the has conflicts label Oct 12, 2021
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

LGTM !

@tchaton tchaton enabled auto-merge (squash) October 12, 2021 11:17
@mergify mergify bot added the ready PRs ready to be merged label Oct 12, 2021
@kaushikb11
Copy link
Contributor

Thanks @ckchow for the contribution! We always look forward to improving our compatibility with TPUs! :)

@codecov
Copy link

codecov bot commented Oct 12, 2021

Codecov Report

Merging #9572 (a3e9139) into master (b530b7a) will decrease coverage by 4%.
The diff coverage is 0%.

@@           Coverage Diff           @@
##           master   #9572    +/-   ##
=======================================
- Coverage      93%     89%    -4%     
=======================================
  Files         178     178            
  Lines       15652   15650     -2     
=======================================
- Hits        14508   13899   -609     
- Misses       1144    1751   +607     

@tchaton tchaton merged commit f14a47a into Lightning-AI:master Oct 12, 2021
rohitgr7 pushed a commit to Tshimanga/pytorch-lightning that referenced this pull request Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accelerator: tpu Tensor Processing Unit bug Something isn't working ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XLA error on CPU
8 participants