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

Dont mutate tensor stride in place in cudnn conv #126786

Closed
wants to merge 3 commits into from

Conversation

eellison
Copy link
Contributor

@eellison eellison commented May 21, 2024

Stack from ghstack (oldest at bottom):

Fix for #126241.

Within the cudnn convolution, we were in-place updating the strides of the tensor to disambiguate for size-1 dims and contiguous and channels last tensors. Instead of mutating the tensors stride, just use a temporary. Inside cudnn it is then copied: https://github.com/NVIDIA/cudnn-frontend/blob/d7ccb5b3c47b4de709604cce463ad66b775b7812/include/cudnn_frontend_Tensor.h#L201-L203.

@eellison eellison requested a review from eqy as a code owner May 21, 2024 15:59
Copy link

pytorch-bot bot commented May 21, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 0734941 with merge base 7e166e8 (image):
💚 Looks good so far! There are no failures yet. 💚

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

eellison added a commit that referenced this pull request May 21, 2024
ghstack-source-id: 5109bc89093fb2e0dca22675133c3ffbf9ee8633
Pull Request resolved: #126786
Copy link
Collaborator

@eqy eqy left a comment

Choose a reason for hiding this comment

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

Thanks!

Does this need to also be fixed for legacy API use-cases that are creating TensorDescriptors by passing Tensors directly and calling .stride() on them? e.g.,

void TensorDescriptor::set(const at::Tensor &t, at::MemoryFormat memory_format, size_t pad) {

@eellison
Copy link
Contributor Author

eellison commented May 21, 2024

What are the callsites of those apis ? Do they invoke fixSizeOneDimStride ?

@eellison
Copy link
Contributor Author

We don't compile RNNs in torch.compile - would prefer separate issue/fix for the other legacy callsites.

@eqy
Copy link
Collaborator

eqy commented May 21, 2024

@eellison Yes I think overloads of set() bottom out on the variant here

void set(cudnnDataType_t dataType, int dim, int* size, int* stride, bool nhwc) {
that calls fixSizeOneDimStride. The callsites are IIRC RNN, Conv v7, and maybe other legacy API places like batchnorm?

Fix for #126241. 

Within the cudnn convolution, we were in-place updating the strides of the tensor to disambiguate for size-1 dims and contiguous and channels last tensors. Instead of mutating the tensors stride, just use a temporary. Inside cudnn it is then copied: https://github.com/NVIDIA/cudnn-frontend/blob/d7ccb5b3c47b4de709604cce463ad66b775b7812/include/cudnn_frontend_Tensor.h#L201-L203.



[ghstack-poisoned]
eellison added a commit that referenced this pull request May 21, 2024
ghstack-source-id: 3de7eb31768a05fe2e9686b1b2c183fa8aee31c6
Pull Request resolved: #126786
@eellison eellison requested a review from eqy May 21, 2024 19:10
Fix for #126241. 

Within the cudnn convolution, we were in-place updating the strides of the tensor to disambiguate for size-1 dims and contiguous and channels last tensors. Instead of mutating the tensors stride, just use a temporary. Inside cudnn it is then copied: https://github.com/NVIDIA/cudnn-frontend/blob/d7ccb5b3c47b4de709604cce463ad66b775b7812/include/cudnn_frontend_Tensor.h#L201-L203.



[ghstack-poisoned]
eellison added a commit that referenced this pull request May 21, 2024
ghstack-source-id: bf7ad7fcf19506b9387511d895e4ce412903a385
Pull Request resolved: #126786
Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

This is fine as bandaid but better would be to refactor call sites

@eellison eellison added the topic: not user facing topic category label May 21, 2024
@eellison
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 21, 2024
@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

@github-actions github-actions bot deleted the gh/eellison/654/head branch June 22, 2024 05:30
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 topic: not user facing topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants