Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixing ONNX export of logical ops to have correct output datatype#15185

Closed
spandantiwari wants to merge 4 commits into
pytorch:masterfrom
spandantiwari:spandantiwari/onnx_logical_ops
Closed

Fixing ONNX export of logical ops to have correct output datatype#15185
spandantiwari wants to merge 4 commits into
pytorch:masterfrom
spandantiwari:spandantiwari/onnx_logical_ops

Conversation

@spandantiwari
Copy link
Copy Markdown

Currently PyTorch ONNX exporter exports the logical ops (lt, gt, le, ge, eq) with output type in corresponding ONNX ops as type tensor(uint8). But ONNX spec allows for only tensor(bool), which is why models that have these ops fail to load properly.

This issue is captured in #11339. Part of this issue, relating to the allowed input types, has been fixed in ONNX spec by @houseroad. This PR fixes the other part pertaining to output type.

@spandantiwari
Copy link
Copy Markdown
Author

The failed check seems to be unrelated (test run timed out).

@spandantiwari
Copy link
Copy Markdown
Author

Seeing the same issue again. There's a timeout reported. Also, an assert in blob_test is coming up, but I am not sure if that's the failing test and it seems unrelated. Could someone please take a look and advise?

@houseroad
Copy link
Copy Markdown
Member

@spandantiwari no worries, I triggered the rebuild manually.

@spandantiwari
Copy link
Copy Markdown
Author

@houseroad - thanks a lot!

@spandantiwari
Copy link
Copy Markdown
Author

@houseroad - this one failed quite quickly. Looks like some network issue.

@houseroad
Copy link
Copy Markdown
Member

Yeah, seems some problem with the docker image. No worries, I think we can ignore it.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Dec 20, 2018

Hi @houseroad, is this PR ok to merge?

@houseroad
Copy link
Copy Markdown
Member

@ezyang it may break some internal pipeline, let me double check. Will send you the feedback soon.

Copy link
Copy Markdown
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank.

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Dec 20, 2018

Looks like this broke a test:

Dec 20 21:25:25 =================================== FAILURES ===================================
Dec 20 21:25:25 ____________________________ TestOperators.test_ne _____________________________
Dec 20 21:25:25 
Dec 20 21:25:25 self = <test_operators.TestOperators testMethod=test_ne>
Dec 20 21:25:25 
Dec 20 21:25:25     def test_ne(self):
Dec 20 21:25:25         x = torch.randn(1, 2, 3, 1, requires_grad=False).int()
Dec 20 21:25:25         y = torch.randn(1, 4, requires_grad=False).int()
Dec 20 21:25:25 >       self.assertONNX(lambda x, y: torch.ne(x, y), (x, y))
Dec 20 21:25:25 
Dec 20 21:25:25 /var/lib/jenkins/workspace/test/onnx/test_operators.py:497: 
Dec 20 21:25:25 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
Dec 20 21:25:25 /var/lib/jenkins/workspace/test/onnx/test_operators.py:69: in assertONNX
Dec 20 21:25:25     self.assertExpected(onnx_model_pbtxt, subname)
Dec 20 21:25:25 /var/lib/jenkins/workspace/test/common_utils.py:593: in assertExpected
Dec 20 21:25:25     self.assertMultiLineEqual(expected, s)
Dec 20 21:25:25 E   AssertionError: 'ir_version: 3\nproducer_name: "pytorch"\nproducer_version: "0.4"\ngraph {\n  no [truncated]... != u'ir_version: 3\nproducer_name: "pytorch"\nproducer_version: "0.4"\ngraph {\n  n [truncated]...
Dec 20 21:25:25 E     ir_version: 3
Dec 20 21:25:25 E     producer_name: "pytorch"
Dec 20 21:25:25 E     producer_version: "0.4"
Dec 20 21:25:25 E     graph {
Dec 20 21:25:25 E       node {
Dec 20 21:25:25 E         input: "0"
Dec 20 21:25:25 E         input: "1"
Dec 20 21:25:25 E         output: "2"
Dec 20 21:25:25 E         op_type: "Equal"
Dec 20 21:25:25 E       }
Dec 20 21:25:25 E       node {
Dec 20 21:25:25 E         input: "2"
Dec 20 21:25:25 E         output: "3"
Dec 20 21:25:25 E   +     op_type: "Cast"
Dec 20 21:25:25 E   +     attribute {
Dec 20 21:25:25 E   +       name: "to"
Dec 20 21:25:25 E   +       i: 2
Dec 20 21:25:25 E   +       type: INT
Dec 20 21:25:25 E   +     }
Dec 20 21:25:25 E   +   }
Dec 20 21:25:25 E   +   node {
Dec 20 21:25:25 E   +     input: "3"
Dec 20 21:25:25 E   +     output: "4"
Dec 20 21:25:25 E         op_type: "Not"
Dec 20 21:25:25 E       }
Dec 20 21:25:25 E       name: "torch-jit-export"
Dec 20 21:25:25 E       input {
Dec 20 21:25:25 E         name: "0"
Dec 20 21:25:25 E         type {
Dec 20 21:25:25 E           tensor_type {
Dec 20 21:25:25 E             elem_type: 6
Dec 20 21:25:25 E             shape {
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 1
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 2
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 3
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 1
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E             }
Dec 20 21:25:25 E           }
Dec 20 21:25:25 E         }
Dec 20 21:25:25 E       }
Dec 20 21:25:25 E       input {
Dec 20 21:25:25 E         name: "1"
Dec 20 21:25:25 E         type {
Dec 20 21:25:25 E           tensor_type {
Dec 20 21:25:25 E             elem_type: 6
Dec 20 21:25:25 E             shape {
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 1
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 4
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E             }
Dec 20 21:25:25 E           }
Dec 20 21:25:25 E         }
Dec 20 21:25:25 E       }
Dec 20 21:25:25 E       output {
Dec 20 21:25:25 E   -     name: "3"
Dec 20 21:25:25 E   ?            ^
Dec 20 21:25:25 E   +     name: "4"
Dec 20 21:25:25 E   ?            ^
Dec 20 21:25:25 E         type {
Dec 20 21:25:25 E           tensor_type {
Dec 20 21:25:25 E             elem_type: 2
Dec 20 21:25:25 E             shape {
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 1
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 2
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 3
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E               dim {
Dec 20 21:25:25 E                 dim_value: 4
Dec 20 21:25:25 E               }
Dec 20 21:25:25 E             }
Dec 20 21:25:25 E           }
Dec 20 21:25:25 E         }
Dec 20 21:25:25 E       }
Dec 20 21:25:25 E     }
Dec 20 21:25:25 E     opset_import {
Dec 20 21:25:25 E       version: 9
Dec 20 21:25:25 E     }

@houseroad

@houseroad
Copy link
Copy Markdown
Member

@ezyang interesting, the ci didn't catch it. @spandantiwari do you mind to update the expect file and resubmit the PR? Thanks.

@spandantiwari
Copy link
Copy Markdown
Author

@ houseroad - yes, I can do that. I think the CI did not catch it because torch.ne support went in another PR very recently. So this branch might be stale. I can update it.
BTW, this PR is showing up as closed. Should I make changes in a new PR, or send an update for the same PR/branch?

@houseroad
Copy link
Copy Markdown
Member

No worries, feel free to open a new pr. Thanks

@spandantiwari
Copy link
Copy Markdown
Author

OK will do.

@spandantiwari
Copy link
Copy Markdown
Author

@houseroad - I have a new PR #15677 that updates the export of torch.ne and fixes the above test failure. Please take a look when you get a chance.

facebook-github-bot pushed a commit that referenced this pull request Jan 3, 2019
…utput datatype (#15677)

Summary:
This is the an updated version of the earlier PR #15185, since that one was closed.

Currently PyTorch ONNX exporter exports the logical ops (lt, gt, le, ge, eq, ne) with output type in corresponding ONNX ops as type tensor(uint8). But ONNX spec allows for only tensor(bool), which is why models that have these ops fail to load properly.

This issue is captured in #11339. Part of this issue, relating to the allowed input types, has been fixed in ONNX spec by houseroad. This PR fixes the other part pertaining to output type.
Pull Request resolved: #15677

Reviewed By: dzhulgakov

Differential Revision: D13568450

Pulled By: houseroad

fbshipit-source-id: a6afbea1afdb4edad8f8b1bc492f50b14e5f2fce
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…torch#15185)

Summary:
Currently PyTorch ONNX exporter exports the logical ops (`lt`, `gt`, `le`, `ge`, `eq`) with output type in corresponding ONNX ops as type `tensor(uint8)`. But ONNX spec allows for only `tensor(bool)`, which is why models that have these ops fail to load properly.

This issue is captured in pytorch#11339. Part of this issue, relating to the allowed input types, has been fixed in ONNX spec by houseroad. This PR fixes the other part pertaining to output type.
Pull Request resolved: pytorch#15185

Differential Revision: D13494873

Pulled By: houseroad

fbshipit-source-id: 069d2f956a5ae9bf0ac2540a32594a31b01adef8
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…utput datatype (pytorch#15677)

Summary:
This is the an updated version of the earlier PR pytorch#15185, since that one was closed.

Currently PyTorch ONNX exporter exports the logical ops (lt, gt, le, ge, eq, ne) with output type in corresponding ONNX ops as type tensor(uint8). But ONNX spec allows for only tensor(bool), which is why models that have these ops fail to load properly.

This issue is captured in pytorch#11339. Part of this issue, relating to the allowed input types, has been fixed in ONNX spec by houseroad. This PR fixes the other part pertaining to output type.
Pull Request resolved: pytorch#15677

Reviewed By: dzhulgakov

Differential Revision: D13568450

Pulled By: houseroad

fbshipit-source-id: a6afbea1afdb4edad8f8b1bc492f50b14e5f2fce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants