-
Couldn't load subscription status.
- Fork 560
Set has_symbolic_sizes_strides on tensorImpl. #5164
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
base: master
Are you sure you want to change the base?
Conversation
| @JackCaoG , per our discussion, I tried your suggestion as in this PR but it didn't work: But I did find something strange. Before this change, neither |
torch_xla/csrc/tensor_impl.cpp Outdated
| tensor_(c10::make_intrusive<XLATensor>(std::move(tensor))) { | ||
| is_non_overlapping_and_dense_ = false; | ||
| const_cast<XLATensorImpl*>(this)->SetupSizeProperties(); | ||
| set_sizes_and_strides(c10::SymIntArrayRef(sym_sizes_.data(), sym_sizes_.size()), c10::fromIntArrayRefSlow(strides_default())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this call for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does has_symbolic_sizes_strides_ = true;:
https://github.com/pytorch/pytorch/blob/2c313e7b99b6070a3a7d640e4bc8bf2fe3acbcf1/c10/core/TensorImpl.cpp#L1152
And both pytorch and pt/xla check if has_symbolic_sizes_strides_ = false;(pytorch code) when doing tensor.size()
| hi @ezyang , can you please take a look at this PR and see if my change makes sense, along with the pytorch change? Also, in our meeting, you mentioned that we can check if the stride is contiguous. If so, we can ask Thanks! |
| FWIW, Not sure why Also, I summarized the problem in the pr description. |
| I figured out why With this PR, So should |
| hi @ezyang , in our meeting, you mentioned if the stride is contiguous, we can skip calling |
| Oh oops, I spoke too loosely. What you are hoping for is the call site calls empty directly, instead empty_strided with contiguous inputs. You usually have to fix the call site if it is messing this up, but the only place I really remember this being troublesome is pointwise TensorIterator ops |
Thanks @ezyang for the response. I did check the call site. The reason why the change in this PR starts calling On a side note, we found this PR #2682 which incorrectly set is_non_overlapping_and_dense_ to false for XLATensorImpl. If reverting the above PR is the correct thing to do, due to this logic, it seems With my hypothesis, do you think the call site is doing the right thing calling the empty_stride? |
| Interesting. It seems like we have never handled this correctly. A PyTorch change which does something like pytorch/pytorch#95003 should work. |
| Sorry I am a bit lost here. @ezyang the pr you pointed to was using the xla/torch_xla/csrc/tensor_impl.cpp Line 73 in b3f4c7b
My question is
@vanbasten23 also tried to undo the logic to overwrite |
| It is is a bit painful to give guidance here, because I only really understand how everything is supposed to work in a universe where XLATensor DOES support full strides (and you rely on functionalization to undo the strides before they get to XLA.) Then your problems resolve to an easier problem, which is whenever there is a direct call to empty_strided, is there a simpler call we can make that doesn't require performing compute on unbacked symints. In the case of empty_like, when the input is non-overlapping and dense, we can just directly paste the sizes/strides/contiguity fields from the input tensor, because we are guaranteed to preserve everything, and we don't have to worry about a contiguity recompute poking one of the fields wrong. But you're in some weird halfway state. I agree that it is probably a good idea to revert Ailing's change but I don't know how complicated it is to do so. To answer this question:
I think it needs to live upstream in empty_like.
If the XLA tensor is always contiguous, you can compute the default contiguous strides and then manually overwrite the contiguity fields with their expected values, similar to the PR I linked. This wouldn't need upstream change. |
This PR is a simplified version of #4998. This PR is intended to set has_symbolic_sizes_strides properly on XLATensorImpl. The ultimate goal is to make sure it throws an error when we call
tensor.sizes()on a tensor with dynamic dimension. This PR should work with the upstream pr to achieve that goal.Note that pytorch/xla has already checked
has_symbolic_sizes_strides_atXLATensorImpl::sizes_custom()(code). All remaining work is to sethas_symbolic_sizes_strides_properly.The problem right now is that
torch.fill_started to callXLANativeFunctions::empty_strided_symint. But before this PR and the pytorch pr pytorch/pytorch#101634, doingtorch.fill_did not callXLANativeFunctions::empty_strided_symint