Skip to content

Commit

Permalink
Implement softplus | feat(torchlib) (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinchuby authored Nov 16, 2023
1 parent 24d77d9 commit 577f51a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions onnxscript/function_libs/torch_lib/ops/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2038,10 +2038,13 @@ def aten_soft_margin_loss_backward(
raise NotImplementedError()


def aten_softplus(self: TensorType, beta: float = 1.0, threshold: float = 20.0) -> TensorType:
@torch_op("aten::softplus")
def aten_softplus(self: TFloat, beta: float = 1.0, threshold: float = 20.0) -> TFloat:
"""softplus(Tensor self, Scalar beta=1, Scalar threshold=20) -> Tensor"""

raise NotImplementedError()
self_scaled = self * beta
softplus = op.Softplus(self_scaled) / beta
return op.Where(self_scaled > threshold, self, softplus)


def aten_softplus_backward(
Expand Down
5 changes: 5 additions & 0 deletions onnxscript/tests/function_libs/torch_lib/ops_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,11 @@ def _where_input_wrangler(
reason="fixme: ORT failed. https://github.com/microsoft/onnxruntime/issues/16438",
test_class_name="TestOutputConsistencyFullGraph",
),
TorchLibOpInfo("nn.functional.softplus", nn_ops.aten_softplus).xfail(
dtypes=(torch.float16,),
reason="fixme: ORT failed. https://github.com/microsoft/onnxruntime/issues/16449",
test_class_name="TestOutputConsistencyEager",
),
TorchLibOpInfo(
"split_with_sizes",
core_ops.aten_split_with_sizes,
Expand Down

0 comments on commit 577f51a

Please sign in to comment.