-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Python 3.10 Union operator | support for JIT #109293
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
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/109293
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 5a8c408 with merge base 5ad1baf ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "module: typing" |
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.
okey dokey
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@ezyang This shouldn't be merged yet, first the failure of the Optional simplification should be clarified (as per review request). (whether to resolve it or to simply don't care about it) EDIT: I forget to make the review visible... |
|
@ezyang I couldn't quite figure out how to solve it. Either we find a solution or one can decide to not care about this error. Also if you haven't it would be good to check the C++ code as I am a novice with respect to C++ development. |
| expr.range(), | ||
| Var::create(expr.range(), Ident::create(expr.range(), "Union")), | ||
| List<Expr>::create(expr.range(), members)); | ||
| return std::move(synthesised_union); |
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.
nit: just return Subscript::create directly. There's a long thing about return on std::move impeding copy elision but iirc Exprs are cheap to move so it doesn't really matter.
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.
I added this after it was suggested in failed CI: https://github.com/pytorch/pytorch/actions/runs/6209430790/job/16857935849#step:10:13787
|
I'm willing to accept this with bugs. It will just mean some valid programs fail to typecheck, right? You can always figure it out later and send us a patch. We don't have dedicated TS cycles so I am mostly estimating that this feature is relatively low risk to add. I also am not sure how to solve your particular problem, but if this would be useful to you it's better to just get this in. |
It means some valid programs fail JIT-compilation, specifically, this test fails (in the duplicated tests from def test_union_optional_of_union_is_flattened(self):
@torch.jit.script
def fn(flag: int) -> str | int | None:
y: int | str | None = "foo"
if flag == 0:
x: Optional[int | str] = y
elif flag == 1:
x: Optional[int | str] = 1
else:
x: Optional[int | str] = None
return xwith the following error message upon attempting to It succeeds if |
|
Yeah, this is OK by me. Essentially, you are only strictly expanding the set of programs we accept, there are some programs we don't manage to get but they are easy to work around. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
@pytorchbot merge -f "spurious failure" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Fixes #101777
test/jit/test_union.pyintotest/jit/test_union_pep604.py, using PEP604 style Unionsget_argsandget_originwithtyping.get_argsandtyping.get_originwhich have the same functionality and became part of the standard library in 3.8pep604union_to_unionintree_views.hwhich converts aBinOP("|")node into the correspondingUnion. This function interceptsScriptTypeParser::parseTypeFromExprandScriptTypeParser::parseTypeFromExprImpland patches the expression.From what I could gather, the following fails:
In the section:
pytorch/torch/csrc/jit/frontend/script_type_parser.cpp
Lines 232 to 243 in 75b954b
When using regular
Union, theresolverpath is taken, whereas with the patch pep604 union,resolveTypedoesn't work.cc @ezyang @malfet @rgommers @xuzhao9 @gramster