Skip to content

[NDArray] Allow arbitrary stride when the corresponding shape is 1#14797

Merged
vinx13 merged 2 commits intoapache:mainfrom
masahi:stride-check-shape-1
May 8, 2023
Merged

[NDArray] Allow arbitrary stride when the corresponding shape is 1#14797
vinx13 merged 2 commits intoapache:mainfrom
masahi:stride-check-shape-1

Conversation

@masahi
Copy link
Copy Markdown
Member

@masahi masahi commented May 7, 2023

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_dlpack when 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

@tvm-bot
Copy link
Copy Markdown
Collaborator

tvm-bot commented May 7, 2023

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.

  • No users to tag found in teams: ndarray See #10317 for details

Generated by tvm-bot

Copy link
Copy Markdown
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants