Skip to content

Commit e6bfff6

Browse files
whiteking64facebook-github-bot
authored andcommitted
[ONNX] Add hardsigmoid symbolic in opset 9 pytorch#49649 (pytorch#54193)
Summary: Fixes pytorch#49649 Adds support for torch.nn.Hardsigmoid operator in torch.onnx.export Pull Request resolved: pytorch#54193 Reviewed By: anjali411 Differential Revision: D27522969 Pulled By: SplitInfinity fbshipit-source-id: 33abcec578f4bc3cf5c3ee1c1bed7d94816bee96
1 parent 2dd7daf commit e6bfff6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/source/onnx.rst

+1
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ The following operators are supported:
617617
* glu
618618
* group_norm
619619
* gt
620+
* hardsigmoid
620621
* hardswish
621622
* hardtanh
622623
* im2col

test/onnx/test_pytorch_onnx_onnxruntime.py

+12
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,18 @@ def forward(self, x):
972972
x = torch.rand(3, 3).to(dtype=torch.float32)
973973
self.run_test(MyModel(), x)
974974

975+
def test_hardsigmoid(self):
976+
model = torch.nn.Hardsigmoid()
977+
978+
x = torch.rand(3, 3).to(dtype=torch.float32)
979+
self.run_test(model, x)
980+
981+
# corner cases
982+
x = torch.tensor(3).to(dtype=torch.float32)
983+
self.run_test(model, x)
984+
x = torch.tensor(-3).to(dtype=torch.float32)
985+
self.run_test(model, x)
986+
975987
def test_clamp(self):
976988
class ClampModel(torch.nn.Module):
977989
def forward(self, x):

torch/onnx/symbolic_opset9.py

+6
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,12 @@ def hardswish(g, self):
18661866
hardtanh_ = g.op("Div", hardtanh_, g.op('Constant', value_t=torch.tensor(6, dtype=torch.float)))
18671867
return g.op("Mul", self, hardtanh_)
18681868

1869+
1870+
@parse_args('v')
1871+
def hardsigmoid(g, self):
1872+
return g.op('HardSigmoid', self, alpha_f=1 / 6)
1873+
1874+
18691875
def alias(g, self):
18701876
return self
18711877

0 commit comments

Comments
 (0)