-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[JIT] Don't throw when type is used in TorchScript #28053
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
Conversation
3e49c15 to
3a2500b
Compare
| def fn(x): | ||
| return type(x) | ||
|
|
||
| with self.assertRaisesRegex(RuntimeError, "value of type type"): |
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.
Can you put quotes around the output here so it doesn't look like a typo?
e.g.
value of type 'type'
torch/_jit_internal.py
Outdated
| # with an abstract method, in either case we cannot compile it as a class | ||
| if '__abstractmethods__' in names: | ||
| return False | ||
| fns = [getattr(cls, name) for name in names if inspect.isroutine(getattr(cls, name))] |
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.
You can avoid special casing type here by changing the getattr to getattr(cls, name, None)
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.
Or better yet change this whole thing to this which doesn't have the problem of accessing the attribute at all:
members = inspect.getmembers(cls)
members = map(lambda x: x[1], members)
fns = filter(inspect.isroutine, members)|
Just checking in here—any blockers? |
|
@pytorchbot rebase this please |
1 similar comment
|
@pytorchbot rebase this please |
facebook-github-bot
left a comment
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.
@eellison is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Type objects in python have an attribute
__abstractmethods__that throws when it is accessed, so we were failing with an AttributeError whenever a type was used in TorchScript.This pr prevents that error from happening. We can't just throw when a type is used because it could be used to access a static method: #27163