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

[Bugfix][TIR] Fix version conflict with typing for Python 3.8.0 #13744

Merged
merged 1 commit into from
Jan 18, 2023

Conversation

Ever-Kid
Copy link
Contributor

I came across this bug under python3.8.0 with error from typing.get_args() while trying to run testcases like tests/python/unittest/test_tir_schedule_set_axis_separator.py::test_set_axis_separator[transform_layout_named]

>           if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis:
E           IndexError: tuple index out of range

And the root cause here is a difference between python3.8.0 and later version:

        get_args(Callable[[], T][int]) == ([], int)
    """
-     if isinstance(tp, _GenericAlias):    // python3.8.0
+    if isinstance(tp, _GenericAlias) and not tp._special:    // python3.8.15
        res = tp.__args__
        if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis:
}

So I added it back to python/tvm/tir/schedule/_type_checker.py

@tvm-bot
Copy link
Collaborator

tvm-bot commented Jan 10, 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.

Generated by tvm-bot

@Ever-Kid
Copy link
Contributor Author

cc. @sunggg

@junrushao
Copy link
Member

@sunggg

Copy link
Contributor

@sunggg sunggg left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
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.

so I’m getting it in!

@junrushao
Copy link
Member

for some reason the CI is stuck on the new pipeline added today...let me try to retrigger

@junrushao
Copy link
Member

@tvm-bot rerun

@junrushao junrushao force-pushed the fix_typing_conflict branch from 00634b3 to 1bbfc02 Compare January 18, 2023 14:08
@junrushao
Copy link
Member

I rebased this branch to latest HEAD so that the CI could run properly

@junrushao junrushao merged commit 02e8bbf into apache:main Jan 18, 2023
@junrushao
Copy link
Member

It's merged! Thanks for the PR!

@Ever-Kid
Copy link
Contributor Author

Thanks you guys’ kindly help~

@Ever-Kid Ever-Kid deleted the fix_typing_conflict branch January 19, 2023 06:32
@vinx13
Copy link
Member

vinx13 commented Jan 20, 2023

I'm getting some error in Python 3.10

  File "/usr/lib/python3.10/typing.py", line 983, in __getattr__
    return getattr(self.__origin__, attr)
AttributeError: type object 'Callable' has no attribute '_special'

The attribute _special was actually removed since Python 3.9.0 (they introduced SpecialGenericAlias instead).

@junrushao
Copy link
Member

Oh no. would you mind having it fixed if it’s not super hard?

@sunggg
Copy link
Contributor

sunggg commented Jan 21, 2023

Darn, let me fix this. Shouldn't be hard.

Edit: until fix is merged, please remove ‘ty._special’ as a temporary solution.
PR is under review: #13820 (comment)

fzi-peccia pushed a commit to fzi-peccia/tvm that referenced this pull request Mar 27, 2023
…he#13744)

I came across this bug under python3.8.0 with error from `typing.get_args()` while trying to run testcases like `tests/python/unittest/test_tir_schedule_set_axis_separator.py::test_set_axis_separator[transform_layout_named]`
```
>           if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis:
E           IndexError: tuple index out of range
```
And the root cause here is a difference  between python3.8.0 and later version:
```diff
        get_args(Callable[[], T][int]) == ([], int)
    """
-     if isinstance(tp, _GenericAlias):    // python3.8.0
+    if isinstance(tp, _GenericAlias) and not tp._special:    // python3.8.15
        res = tp.__args__
        if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis:
}
```
So I added it back to `python/tvm/tir/schedule/_type_checker.py`
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