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

Improve device auto-detection #7787

Merged
merged 13 commits into from
Aug 1, 2024
Merged

Improve device auto-detection #7787

merged 13 commits into from
Aug 1, 2024

Conversation

zpcore
Copy link
Collaborator

@zpcore zpcore commented Jul 31, 2024

Resolves #7730.

Now device are automatically detected when we import torch_xla:

$ python
Python 3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:36:39) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch_xla
WARNING:root:libtpu.so and TPU device found. Setting PJRT_DEVICE=TPU.
>>> torch_xla.real_devices()
['TPU:0', 'TPU:1', 'TPU:2', 'TPU:3']
>>> torch_xla.device()
device(type='xla', index=0)

@zpcore zpcore marked this pull request as ready for review July 31, 2024 20:05
@zpcore zpcore requested review from will-cromar and JackCaoG July 31, 2024 20:05
@zpcore
Copy link
Collaborator Author

zpcore commented Jul 31, 2024

RFC: Is there a plan to hard code PJRT_DEVICE in the python script to replace the PJRT_DEVICE environment variable? @miladm

Copy link
Collaborator

@will-cromar will-cromar 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 clean up!

@JackCaoG do you see any problem selecting $PJRT_DEVICE when we import torch_xla?

@zpcore zpcore added usability Bugs/features related to improving the usability of PyTorch/XLA tpuci labels Jul 31, 2024
@JackCaoG
Copy link
Collaborator

Thanks for the clean up!

@JackCaoG do you see any problem selecting $PJRT_DEVICE when we import torch_xla?

seems fine to me as long as we don't init the runtime yet.

@zpcore zpcore requested a review from will-cromar August 1, 2024 18:01
@zpcore zpcore merged commit 2ba4e05 into master Aug 1, 2024
23 checks passed
@zpcore zpcore deleted the piz/pjrt branch September 3, 2024 17:29
byi8220 added a commit to byi8220/pytorch-lightning that referenced this pull request Nov 23, 2024
Fixes Lightning-AI#20419

`torch_xla.runtime.using_pjrt()` is removed in pytorch/xla#7787

This PR replaces references to that function with a check to [`device_type()`](https://github.com/pytorch/xla/blob/master/torch_xla/runtime.py#L83) to recreate the behavior of that function, minus the manual initialization
lantiga pushed a commit to Lightning-AI/pytorch-lightning that referenced this pull request Nov 25, 2024
…py for `torch-xla>=2.5` (#20442)

* Replace `using_pjrt()` xla runtime `device_type()` check with in xla.py

Fixes #20419

`torch_xla.runtime.using_pjrt()` is removed in pytorch/xla#7787

This PR replaces references to that function with a check to [`device_type()`](https://github.com/pytorch/xla/blob/master/torch_xla/runtime.py#L83) to recreate the behavior of that function, minus the manual initialization

* Added tests/refactored for version compat

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* precommit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Bugs/features related to improving the usability of PyTorch/XLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve device auto-detection
3 participants