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

Implement hardsigmoid and hardswish | feat(torchlib) #1216

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions onnxscript/function_libs/torch_lib/ops/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,11 @@ def aten_glu_jvp(glu: TensorType, x: TensorType, dx: TensorType, dim: int) -> Te
raise NotImplementedError()


def aten_hardsigmoid(self: TensorType) -> TensorType:
@torch_op("aten::hardsigmoid")
def aten_hardsigmoid(self: TFloat) -> TFloat:
"""hardsigmoid(Tensor self) -> Tensor"""

raise NotImplementedError()
return op.HardSigmoid(self, alpha=1 / 6, beta=1 / 2)


def aten_hardsigmoid_backward(grad_output: TensorType, self: TensorType) -> TensorType:
Expand All @@ -608,10 +609,11 @@ def aten_hardsigmoid_backward(grad_output: TensorType, self: TensorType) -> Tens
raise NotImplementedError()


def aten_hardswish(self: TensorType) -> TensorType:
@torch_op("aten::hardswish")
def aten_hardswish(self: TFloat) -> TFloat:
"""hardswish(Tensor self) -> Tensor"""

raise NotImplementedError()
return op.HardSwish(self)


def aten_hardswish_backward(grad_output: TensorType, self: TensorType) -> TensorType:
Expand Down
2 changes: 2 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 @@ -1177,6 +1177,8 @@ def _where_input_wrangler(
core_ops.aten_embedding,
input_wrangler=_embedding_input_wrangler,
),
TorchLibOpInfo("nn.functional.hardsigmoid", nn_ops.aten_hardsigmoid),
TorchLibOpInfo("nn.functional.hardswish", nn_ops.aten_hardswish),
TorchLibOpInfo("nn.functional.hardtanh", nn_ops.aten_hardtanh),
TorchLibOpInfo("nn.functional.leaky_relu", nn_ops.aten_leaky_relu),
TorchLibOpInfo(
Expand Down
Loading