[JIT] add type refinements for isinstance checks#26271
Closed
zdevito wants to merge 12 commits intogh/zdevito/111/basefrom
Closed
[JIT] add type refinements for isinstance checks#26271zdevito wants to merge 12 commits intogh/zdevito/111/basefrom
zdevito wants to merge 12 commits intogh/zdevito/111/basefrom
Conversation
This was referenced Sep 16, 2019
This was referenced Sep 24, 2019
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
suo
reviewed
Oct 2, 2019
test/test_jit.py
Outdated
| self.assertEqual(foo2(None, 4), 0) | ||
| self.assertEqual(foo2(4, None), 0) | ||
|
|
||
|
|
suo
approved these changes
Oct 2, 2019
| // isinstance appearing in an if expression | ||
| // causes type refinement to occur, we dont | ||
| // want to since it has already been handled | ||
| if (v->node()->kind() == prim::isinstance) |
| return false; | ||
|
|
||
| // isinstance appearing in an if expression | ||
| // causes type refinement to occur, we dont |
Member
There was a problem hiding this comment.
I find this comment hard to parse. "we dont want to" what? (I think the answer is we don't want to inline). "it has already been handled", what is "it" in this case? Maybe worth expanding this.
eellison
reviewed
Oct 2, 2019
Contributor
eellison
left a comment
There was a problem hiding this comment.
it would be good as a follow up to implement a peephole optimization for this op
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
[JIT] add type refinements for isinstance checks This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. gh-metadata: pytorch pytorch 26271 gh/zdevito/111/head
zdevito
added a commit
to zdevito/ATen
that referenced
this pull request
Oct 10, 2019
Summary: Pull Request resolved: pytorch/pytorch#26271 This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. Test Plan: Imported from OSS Differential Revision: D17412856 Pulled By: zdevito fbshipit-source-id: ded47eb086c4610998ad92bb1174225af00220f7
Contributor
thiagocrepaldi
pushed a commit
to thiagocrepaldi/pytorch
that referenced
this pull request
Feb 4, 2020
Summary: Pull Request resolved: pytorch#26271 This replaces unchecked_unwrap_optional with unchecked_cast. This enables the generalization of type refinement so that it works for isinstance checks as well. This also removes unchecked_unwrap_optional from code we generate, which is good because it is a hard op to serialize well since it doesn't directly encode the Optional[T] being unwrapped. In contrast, unchecked_cast always explicitly lists the type. Test Plan: Imported from OSS Differential Revision: D17412856 Pulled By: zdevito fbshipit-source-id: ded47eb086c4610998ad92bb1174225af00220f7
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.
Stack from ghstack:
This replaces unchecked_unwrap_optional with unchecked_cast. This
enables the generalization of type refinement so that it works for
isinstance checks as well. This also removes unchecked_unwrap_optional from
code we generate, which is good because it is a hard op to serialize well
since it doesn't directly encode the Optional[T] being unwrapped. In contrast,
unchecked_cast always explicitly lists the type.
Differential Revision: D17412856