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

Cache results of is_torch_tpu_available() #18777

Merged
merged 3 commits into from
Sep 1, 2022
Merged

Conversation

comaniac
Copy link
Contributor

What does this PR do?

xm.xla_device() (called by is_torch_tpu_available()) hangs when calling multiple times but no XLA devices are available, and this results in Trainer hanging. Since currently torch_xla will be used as long as it is installed in the current active Python environment, I encountered this issue even when I only want to run the Trainer with PyTorch on GPU.

The detail reason behind torch_xla is still under investigation (see pytorch/xla#3939).

To workaround this issue, this PR adds lru_cache to is_torch_tpu_available(), so that xm.xla_device() is guaranteed to be called only once when no XLA device is available.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@muellerzr @sgugger

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 26, 2022

The documentation is not available anymore as the PR was closed or merged.

@comaniac
Copy link
Contributor Author

Not sure the reason of CI failure. It seems not relevant to this PR.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

This sounds fair to me, but I'll let @sgugger, mastermind of the Trainer, review when he's back from leave at the end of the week!

@comaniac
Copy link
Contributor Author

@LysandreJik thanks for the review and sure we could wait for @sgugger.
Meanwhile, do I need to do anything to fix the CI failure?

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your PR! Tests failures seem unrelated, I have tried re-runing them. Could you you rebase on main if the failure persist?

@sgugger
Copy link
Collaborator

sgugger commented Sep 1, 2022

Thanks for bearing with us. The test failures are spurious and unrelated, so we can merge this.

@sgugger sgugger merged commit 1c381f3 into huggingface:main Sep 1, 2022
@comaniac comaniac deleted the patch-1 branch September 1, 2022 15:45
oneraghavan pushed a commit to oneraghavan/transformers that referenced this pull request Sep 26, 2022
* Cache results of is_torch_tpu_available()

* Update src/transformers/utils/import_utils.py

* Update src/transformers/utils/import_utils.py
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.

4 participants