[jit] Resolve NamedTuple types in Python#26443
Closed
Conversation
eellison
approved these changes
Sep 19, 2019
Contributor
eellison
left a comment
There was a problem hiding this comment.
Cool! Thanks for doing this.
lgtm if tests pass. as a follow up we can try this with generic UDT besides NamedTuples - seems like the logic would work as well.
| elif hasattr(ann, "__torch_script_class__"): | ||
| return ClassType(_qualified_name(ann)) | ||
| elif lookup is not None: | ||
| # Maybe resolve a NamedTuple to a Tuple Type |
Contributor
There was a problem hiding this comment.
It's okay if this is limited to NamedTuple types for now, however I think the logic extends to any custom type...
torch/jit/annotations.py
Outdated
|
|
||
|
|
||
| def ann_to_type(ann): | ||
| def ann_to_type(ann, lookup=None): |
Contributor
There was a problem hiding this comment.
Maybe more descriptive name than lookup ? or add comment that it's an (rcb, sourcerange) tuple
Contributor
|
i think tests didn't run, rebase ? |
Contributor
mingbowan
pushed a commit
to mingbowan/pytorch
that referenced
this pull request
Sep 23, 2019
Summary: When used as annotations on Python functions, `NamedTuple`s go through our Python annotation -> type mapping which previously had no way of lookup up `NamedTuple`s (which are created lazily by checking if the type has certain properties, so the lookup is creating the `TupleType` from scratch). This PR threads through the necessary data to make them work. Fixes pytorch#26437 Pull Request resolved: pytorch#26443 Pulled By: driazati Differential Revision: D17486441 fbshipit-source-id: a6bbb543ff05a5abe61f1a7f68db9ecdb652b358
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.
When used as annotations on Python functions,
NamedTuples go through our Python annotation -> type mapping which previously had no way of lookup upNamedTuples (which are created lazily by checking if the type has certain properties, so the lookup is creating theTupleTypefrom scratch). This PR threads through the necessary data to make them work.Fixes #26437
Differential Revision: D17486441