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

Mutation after tensor.expand returns wrong result. #5839

Open
ysiraichi opened this issue Nov 21, 2023 · 3 comments
Open

Mutation after tensor.expand returns wrong result. #5839

ysiraichi opened this issue Nov 21, 2023 · 3 comments

Comments

@ysiraichi
Copy link
Collaborator

🐛 Bug

The following code mutates the value of the expanded tensor.

import torch
import torch_xla.core.xla_model as xm

device = "cpu"
x = torch.arange(6, device=device)
y = x.expand(2, *x.shape)
y[0, 0] = 5

print(y)
# CPU
tensor([[5, 1, 2, 3, 4, 5],
        [5, 1, 2, 3, 4, 5]])

# XLA Eager
tensor([[ 5,  2,  4,  6,  8, 10],
        [ 5,  2,  4,  6,  8, 10]], device='xla:0')

Environment

  • PyTorch version: 63fc48257a02f8e28b79d13def7a7139589d4176 (Nov 2)
  • PyTorch/XLA version: d5d023063bfa8ecb4629f621f9b5890bc8396f58 (Nov 9)
@ysiraichi ysiraichi changed the title Weird behavior of mutation after tensor.expand. Mutation after tensor.expand returns wrong result. Nov 21, 2023
@JackCaoG
Copy link
Collaborator

yea... this is indeed incorrect. Hopefully if you dump the HLO it become obvious what happened

@ysiraichi
Copy link
Collaborator Author

I think this might be the same issue as the non-XLA version: pytorch/pytorch#114302

@JackCaoG
Copy link
Collaborator

oh nice!

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

No branches or pull requests

2 participants