-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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
Support runtime assertion for inline constraints #100763
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/100763
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 17be12d: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
test/dynamo/test_export.py
Outdated
capture_scalar_outputs=True, | ||
) | ||
def test_export_preserve_constraints_as_metadata_tensor(self): | ||
from torch._export.constraints import constrain_as_value |
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 move it at the top of file? We recently ran into circular import issue, so i wanted to make sure it doesn't happen again?
test/export/test_passes.py
Outdated
self.assertEqual(num_assert, 3) | ||
self.assertEqual(num_scalar_tensor, 3) | ||
|
||
with self.assertRaisesRegex(RuntimeError, r"^_local_scalar_dense_default.*\[2, 5\].$"): |
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.
This error message is bit hard to understand from user's perspective, how about we just dump the stacktrace from user code instead?
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.
sure!
new_inp = torch.tensor([1, 1, 1, 1]) | ||
self.assertEqual(mod(new_inp), new_gm(new_inp)) | ||
|
||
# FIXME: support control flow operators for the pass |
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.
should be fixed after #100836
if upper < math.inf: | ||
self._inser_assert_async(operator.le, proxy, upper, assert_msg) | ||
|
||
def _inser_assert_async(self, operator, l, r, assert_msg): |
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: _insert_assert_async
if "val" in meta: | ||
val = meta["val"] | ||
|
||
def add_assertions(val): |
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 leave a comment on explaining the high level approach? Especially the part why we need to accumulate messages.
cbs, msgs = add_assertions(sym) | ||
for cb, msg in zip(cbs, msgs): | ||
def sym_size_cb(proxy, assert_msg, dim): | ||
dim_proxy = super(AddRuntimeAssertionsForConstraintsPass, self).call_operator( |
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.
Why can't it be just super().call_operator()?
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'm not sure.. Seems related to some weird name resolution issue.
@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 |
This pr does the following:
previously, inline constraints is not properly set for tensor output data-dependent ops such as a.nonzero because of its return value is not symint. This pr just uses all the unbacked symbols i.e.those start with "i"/"f" in create_unbacked_sym* functions. Note that these symbols are guaranteed to be a super set of inline user constraints.
add inline assertions support by checking.
Currently, it only deal with tensor, SymInt, SymFloat, SymBool output data-dependent ops and ignore the rest. It's good enough for now as we only have a limited number of data-dependent ops (.item and .nonzero are explicitly tested).
The examples for graph that is added assertions is shown below:
cc @soumith @voznesenskym @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @desertfire