-
Notifications
You must be signed in to change notification settings - Fork 486
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
Lowering as_strided
errors for input tensors smaller than size-stride specs.
#5719
Comments
@JackCaoG any thoughts? |
Right, I took a look at the logic at xla/torch_xla/csrc/ops/as_strided.cpp Line 26 in e7af313
We should be able to check this in the higher level. Can we check where does this xla/torch_xla/csrc/aten_xla_type.cpp Lines 699 to 716 in e7af313
Maybe we just need to expand |
It's exactly there! |
ok let's make |
I mean: it does surface the error to the graph building phase (instead of lowering). But the code still doesn't work because of the reason mentioned above. Do you still think this solution should be merged? |
That's weird.. I thought during fallback we move all XLA tensors to CPU, perform the operation on CPU and then move the result back to the XLA, is that not the case? |
As far as I understand, if we execute # x is created with capacity for 20 elements
x = torch.randn(20, device=xm.xla_device())
# y has shape (10,), but its storage is the same as x
y = x[10:]
# y is moved to CPU
# y has shape (10,), so a CPU tensor of shape (10,) will be created
# - i.e. the CPU tensor will have a storage capacity for 10 elements
# - can't reshape it to (20,), since the storage doesn't have this capacity
z = y.as_strided((20,), (1,), 0) |
oh ok I see the problem... I guess it is one of those cases that's very hard to implement correctly. @bdhirsh Given that now functionization lives upstream, in the case of the
can we just expand the y form [10] to [20]? I am a bit confuse what's the expected behavior of this |
In your example, you are explicitly asking for an offset of 0 when creating A good way to think about Since Now, this is the sort of thing that will surely have plenty of edge cases when we mix a few views with a few in-place ops... Surely @bdhirsh will have a better understanding of all these. |
For how to do all this, you can take as reference |
I feel like this is a more complex version of falling back the whole computation of |
Nevermind. I think I finally understood what you were saying. That said, I don't think we even need to move things to the CPU. We only need to apply the operation on the base tensor. |
We have a tentative PoR to get AOTAutograd to stop emitting as_strided() in all cases (that I'm hoping to get around to early next year). There isn't a detailed design doc yet (I'll have one before working on it) but high level idea written down here with Ed: https://docs.google.com/document/d/1DlfFq8TKbuAn2zyJxLfoW-X1qkkm5PLdHFtySo03QAk/edit |
🐛 Bug
The following usage of
as_strided
errors when lowering.This error shows up when trying to execute
hf_Reformer
from Torchbench, usingopenxla
as backend. As far as I understand, the problem is that AOTAutograd is callingas_strided
-- not entirely sure why. This problem seems to be related to the limitations of reshape functions in XLA, as suggested in #2964.Expected behavior
I would expect it to break earlier, say, when
XLANativeFunctions::as_strided
is being executed, instead of when it gets to the lowering part. Or, maybe better than that, we could fallback to CPU while issueing a warning that "as_strided
is creating a copy, which may not be optimal...".Environment
PyTorch/XLA: c9a1324 (Oct 3)
The text was updated successfully, but these errors were encountered: