From 93e23eac2bfe613ed87aa06db75bacc9c8ecf6d9 Mon Sep 17 00:00:00 2001 From: Zonglin Peng Date: Mon, 14 Apr 2025 19:28:54 -0700 Subject: [PATCH] port hardtanh and add hardtanh test (#9914) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/9914 titled Reviewed By: skrtskrtfb Differential Revision: D72405686 --- backends/cadence/fusion_g3/operators/targets.bzl | 1 + backends/cadence/utils/facto_util.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/backends/cadence/fusion_g3/operators/targets.bzl b/backends/cadence/fusion_g3/operators/targets.bzl index fffeee0d7b3..b878226fcb1 100644 --- a/backends/cadence/fusion_g3/operators/targets.bzl +++ b/backends/cadence/fusion_g3/operators/targets.bzl @@ -40,6 +40,7 @@ OPERATORS = [ "rsqrt", "sigmoid", "sqrt", + "hardtanh", "tanh", "transpose_copy", "where", diff --git a/backends/cadence/utils/facto_util.py b/backends/cadence/utils/facto_util.py index 52b64dc1581..f38c1cc4154 100644 --- a/backends/cadence/utils/facto_util.py +++ b/backends/cadence/utils/facto_util.py @@ -99,6 +99,7 @@ def apply_scalar_contraints(op_name: str) -> list[ScalarDtype]: match op_name: case "add.Scalar" | "sub.Scalar" | "mul.Scalar" | "div.Scalar": return [ScalarDtype.int] + case _: return [ScalarDtype.float, ScalarDtype.int] @@ -122,6 +123,11 @@ def facto_testcase_gen(op_name: str) -> List[Tuple[List[str], OrderedDict[str, s cp.Size.Le(lambda deps, r, d: 2**2), ] ) + if in_spec.name == "max_val": # hardtanh + spec.inspec[index].deps = [0, 1] + spec.inspec[index].constraints.extend( + [cp.Value.Ge(lambda deps, _: deps[1])] + ) else: spec.inspec[index].constraints.extend( [