Skip to content
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

[ONNX] Export logical_not #96315

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/onnx/test_pytorch_onnx_onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4905,6 +4905,24 @@ def forward(self, x, y):
y = torch.randint(10, (2, 3, 5), dtype=torch.long)
self.run_test(XorModel(), input_args=(x, y))

@skipIfUnsupportedMinOpsetVersion(9)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Enable a opinfo test? I am finishing up #92087 which also fixes the test file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, very robust this time.

def test_logical_not(self):
class NotModel(torch.nn.Module):
def forward(self, x):
return torch.logical_not(x)

x = torch.randint(0, 2, (5, 5), dtype=torch.bool)
self.run_test(NotModel(), input_args=(x,))

x = torch.randint(10, (5, 5), dtype=torch.int32)
self.run_test(NotModel(), input_args=(x,))

x = torch.randint(10, (5, 5), dtype=torch.double)
self.run_test(NotModel(), input_args=(x,))

x = torch.randint(10, (2, 3, 5), dtype=torch.float32)
self.run_test(NotModel(), input_args=(x,))

@skipIfUnsupportedMinOpsetVersion(11) # float equal added after opset 11
def test_eq(self):
class EqualModel(torch.nn.Module):
Expand Down
7 changes: 7 additions & 0 deletions torch/onnx/symbolic_opset9.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"log1p",
"log2",
"logical_and",
"logical_not",
"logical_or",
"logical_xor",
"logsumexp",
Expand Down Expand Up @@ -2295,6 +2296,12 @@ def logical_xor(g: jit_utils.GraphContext, input, other):
return g.op("Xor", input, other)


@_onnx_symbolic("aten::logical_not")
@_beartype.beartype
def logical_not(g: jit_utils.GraphContext, input):
return g.op("Not", g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.BOOL))


@_onnx_symbolic("aten::__rshift_")
@_beartype.beartype
def __rshift_(g: jit_utils.GraphContext, self, other):
Expand Down