Skip to content

[torchax] Make copy_ works on different device. #9211

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qihqi
Copy link
Collaborator

@qihqi qihqi commented May 20, 2025

Fixes #8980

@qihqi qihqi requested a review from yaoshiang May 20, 2025 04:13
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.

approved with optional suggestion for test clarity

cpu_tensor = torch.tensor([1, 2, 3])

with self.env:
xla_tensor = torch.tensor([0, 0, 0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the intent here that create a tensor within torchax.tensor.Environment sets a new default device (presumably jax")?

with self.env:
xla_tensor = torch.tensor([0, 0, 0])
xla_tensor.copy_(cpu_tensor)

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you assert that the xla_tensor now has the expected value? Something like

assert cpu_tensor.to_list() == xla_tensor.to_list()
assert xla_tensor.device == <expected device - e.g. the copy_ didn't mess up the device of xla_tensor>

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.

[torchax] jax_tensor.copy_(cpu_tensor) fails
2 participants