-
Notifications
You must be signed in to change notification settings - Fork 21.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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Exceptions in Pytorch Export #123499
Comments
We actually support python asserts today. As a workaround, you could try changing them into asserts. |
Thanks a lot, @tugsbayasgalan, for your reply! I wasn't aware that an assert statement could be used. With assertion, I can catch thrown assertions of an exported program like so:
However, The ticket could be closed, if you want. |
@FabianSchuetze TorchDynamo (and thus export) supports try .. except handling, bit it does not support raising the exceptions. If you have code like
This should work today. But in your example, we can just raise the assertion, which is hard to fix w/o graph breaks. |
馃殌 The feature, motivation and pitch
Exceptions are currently not supported in pytorch export. Consider the following example documenting this:
However, exception are an idiomatic way to report errors and bail-out early. For example, I count 278 uses of exceptions in diffusers models folder. Furthermore, exceptions are supported in torch.jit.
Is there any way exception can be supported in torch.compile? What would it take to implement this feature?
Alternatives
Alternatives are splitting the function into subfunctions, branching with
torch.cond
and then return empty tensors as status message if a predicate is not satisfied. That generates much nested code, but is also not uncommon in embedded c programs which forbid using exceptions.Additional context
No response
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4
The text was updated successfully, but these errors were encountered: