Skip to content

[torchax] jax_tensor.copy_(cpu_tensor) fails #8980

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
tengyifei opened this issue Apr 15, 2025 · 0 comments · May be fixed by #9211
Open

[torchax] jax_tensor.copy_(cpu_tensor) fails #8980

tengyifei opened this issue Apr 15, 2025 · 0 comments · May be fixed by #9211
Assignees
Labels
bug Something isn't working torchxla2

Comments

@tengyifei
Copy link
Collaborator

Reproducer:

import torch
import torchax
torchax.enable_globally()

cpu_tensor = torch.tensor([1.0, 2.0])
jax_tensor = torch.tensor([2.0, 3.0], device='jax')
jax_tensor.copy_(cpu_tensor)


ERROR:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/google/home/yifeit/torchprime/.venv/lib/python3.11/site-packages/torchax/tensor.py", line 257, in __torch_function__
    return func(*args, **(kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/yifeit/torchprime/.venv/lib/python3.11/site-packages/torchax/tensor.py", line 275, in __torch_dispatch__
    return self.env.dispatch(func, types, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/yifeit/torchprime/.venv/lib/python3.11/site-packages/torchax/tensor.py", line 489, in dispatch
    res = op.func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/yifeit/torchprime/.venv/lib/python3.11/site-packages/torchax/ops/jaten.py", line 132, in _aten_copy
    x._elem = y._elem.astype(x._elem.dtype)
              ^^^^^^^
AttributeError: 'Tensor' object has no attribute '_elem'

Per PyTorch docs (https://pytorch.org/docs/stable/generated/torch.Tensor.copy_.html), copying between tensors on different devices should be supported.

cc @qihqi

@qihqi qihqi self-assigned this Apr 16, 2025
@ysiraichi ysiraichi added bug Something isn't working torchxla2 labels Apr 17, 2025
@qihqi qihqi linked a pull request May 20, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working torchxla2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants