Skip to content

Migrate runtime.xla_device in favor of core.xla_model.xla_device #9200

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ghpvnist
Copy link
Collaborator

@ghpvnist ghpvnist commented May 19, 2025

fixes #7831

Copy link
Collaborator

@yaoshiang yaoshiang left a comment

Choose a reason for hiding this comment

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

Is it possible to further harmonize our docs to the idiomatic torch.device("xla"), torch.device("xla:0"), and torch.device("xla", 1)?

@@ -15,14 +15,14 @@ import torch
import torch_xla
import torch_xla.core.xla_model as xm

t = torch.randn(2, 2, device=xm.xla_device())
t = torch.randn(2, 2, device=torch_xla.device())
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this be changed to device="xla"?

print(t.device)
print(t)
```

This code should look familiar. PyTorch/XLA uses the same interface as regular
PyTorch with a few additions. Importing `torch_xla` initializes PyTorch/XLA, and
`xm.xla_device()` returns the current XLA device. This may be a CPU or TPU
`torch_xla.device()` returns the current XLA device. This may be a CPU or TPU
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this be further simplified to simply describing that users get a devicea via torch.device("xla")?

t0 = torch.randn(2, 2, device=xm.xla_device())
t1 = torch.randn(2, 2, device=xm.xla_device())
t0 = torch.randn(2, 2, device=torch_xla.device())
t1 = torch.randn(2, 2, device=torch_xla.device())
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this be device="xla"?

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.

Confusion between xla_model.xla_device() and runtime.xla_device()
2 participants