[NDArray] Allow arbitrary stride when the corresponding shape is 1#14797
Merged
vinx13 merged 2 commits intoapache:mainfrom May 8, 2023
Merged
[NDArray] Allow arbitrary stride when the corresponding shape is 1#14797vinx13 merged 2 commits intoapache:mainfrom
vinx13 merged 2 commits intoapache:mainfrom
Conversation
Collaborator
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
tqchen
approved these changes
May 7, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As discussed in pytorch/pytorch#99803, as of PT 1.13, PT started to fill in a stride with 1 whenever the corresponding shape axis has size 1 during PT tensor to DLPack conversion. This breaks
tvm.runtime.ndarray.from_dlpackwhen the shape is like(1, 77)(clip for SD) or whenever the batch size is 1 in vision models. So this is going to be a common problem that people would encounter in practice (see https://discuss.tvm.apache.org/t/a-pytorch-and-tvm-version-incompatibility-problem-while-using-from-dlpack-and-to-dlpack/14771).This PR fixes this issue by relaxing the runtime stride check. An alternative is to modify the strides during
from_dlpack, but since PT introduced this change for a good reason, I felt that trying to calculate the "correct" strides on our side again is not a good idea.@tqchen @junrushao