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

[vmap] symintify alias and squeeze #107577

Closed
wants to merge 4 commits into from

Conversation

kshitij12345
Copy link
Collaborator

@kshitij12345 kshitij12345 commented Aug 21, 2023

Following tests now pass (both ops call into alias on certain paths)

PYTORCH_TEST_WITH_DYNAMO=1 pytest test/functorch/test_vmap.py -k test_squeeze -v
PYTORCH_TEST_WITH_DYNAMO=1 pytest test/functorch/test_vmap.py -k test_conj -v

NOTE: Ideally, this symint version should work with non symint version as well but that would mean changes at multiple places. Wanted to get a review for this fix before-hand.

Other sites which use the IntArrayRef overload.

Tensor _reshape_alias(const Tensor& self, IntArrayRef sizes, IntArrayRef strides) {
// This is only used by `reshape` in cases where it would otherwise have dispatched
// to `view`. This removes the overhead of calling `view` which duplicates some of
// the work that's already been done (`infer_size_dv` and `computeStride`).
return alias_with_sizes_and_strides(self, sizes, strides);
}

view_impl is called from view and _unsafe_view.

inline Tensor view_impl(const Tensor& self, IntArrayRef size) {
at::DimVector inferred_size = at::infer_size_dv(size, self.numel());
auto stride = at::detail::computeStride(self.sizes(),
self.strides(),
inferred_size);
TORCH_CHECK(stride.has_value(), "view size is "
"not compatible with input tensor's size and stride (at least one dimension"
" spans across two contiguous subspaces). Use .reshape(...) instead.");
return alias_with_sizes_and_strides(self, inferred_size, *stride);
}

cc @ezyang

@pytorch-bot
Copy link

pytorch-bot bot commented Aug 21, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/107577

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 2abdba4 with merge base d0f8ee4 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@kshitij12345 kshitij12345 marked this pull request as ready for review August 21, 2023 14:52
if (self.is_quantized()) {
self_ = at::detail::make_tensor<QTensorImpl>(
c10::TensorImpl::VIEW, Storage(self.storage()), self.key_set(), self.dtype(), get_qtensorimpl(self)->quantizer());
self_.unsafeGetTensorImpl()->set_sizes_and_strides(sizes, strides, self.sym_storage_offset());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why we can't change the ArrayRef<int64_t> and SmallVector<int64_t> template above to use this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just forgot about that! Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, that won't work because there are two overloads for set_sizes_and_strides

  1. void set_sizes_and_strides(SymIntArrayRef sizes, SymIntArrayRef strides, optional<c10::SymInt> storage_offset)
  2. void set_sizes_and_strides(IntArrayRef new_size, IntArrayRef new_stride, optional<int64_t> storage_offset)

So, all inputs have to be symbolic or concrete, we can't pass self.sym_storage_offset() to second overload.

@cpuhrsch cpuhrsch added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 23, 2023
@kshitij12345
Copy link
Collaborator Author

Ping @zou3519

1 similar comment
@kshitij12345
Copy link
Collaborator Author

Ping @zou3519

@kshitij12345 kshitij12345 added release notes: functorch release notes category; Pertaining to torch.func or pytorch/functorch module: dynamic shapes labels Aug 31, 2023
@kshitij12345
Copy link
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 31, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamic shapes open source release notes: functorch release notes category; Pertaining to torch.func or pytorch/functorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants