-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Script] Be more careful when generating ast.ExtSlice for Subscript #15483
Conversation
The ast.ExtSlice expects a non-empty list, otherwise evaluation fails with "error: empty dims on ExtSlice". Also, each element in "dims" list of ExtSlice must be either Slice or Index. In python3.8 an expression A[()] is parsed (by ast) as Subscript with slice being Index(value=Tuple(elts=[])). When we translate a subscript from doc.AST to ast, we unconditionally convert every tuple to ast.ExtSlice, which in this case is incorrect. The fix is to map empty tuple back to the Index(Tuple[])) instead of ExtSlice. In other cases, ensure that members of ExtSlice are of correct types.
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 |
2 similar comments
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 |
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 |
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.
Thank you for the fix, and LGTM! It looks like this is specifically for python 3.8 and earlier, as the ast.Index
and ast.ExtSlice
classes were deprecated in python 3.9.
I'm rather surprised on how this test was able to pass, as the CI runs on python3.8.16, and this test case also uses length-zero tuples as an index. Does the bug only trigger when the object is passed to an external macro?
This happens when we evaluate and expression containing |
Interesting findings! When initiating TVMScript, we tested bunch of cases in certain python versions, but not all - which might be the source of such issues |
The ast.ExtSlice expects a non-empty list, otherwise evaluation fails with
error: empty dims on ExtSlice
. Also, each element in "dims" list of ExtSlice must be either Slice or Index.In python3.8 an expression
A[()]
is parsed (by ast) as Subscript with slice beingIndex(value=Tuple(elts=[]))
. When we translate a subscript from doc.AST to ast, we unconditionally convert every tuple to ast.ExtSlice, which in this case is incorrect.The fix is to map empty tuple back to the
Index(Tuple[]))
instead of ExtSlice. In other cases, ensure that members of ExtSlice are of correct types.