diff --git a/backends/xnnpack/operators/__init__.py b/backends/xnnpack/operators/__init__.py index 7eafe91eaea..f2a2cd3facc 100644 --- a/backends/xnnpack/operators/__init__.py +++ b/backends/xnnpack/operators/__init__.py @@ -51,6 +51,5 @@ op_static_constant_pad, op_static_resize_bilinear_2d, op_sub, - op_tanh, op_to_copy, ) diff --git a/backends/xnnpack/operators/op_tanh.py b/backends/xnnpack/operators/op_tanh.py deleted file mode 100644 index 6031839eceb..00000000000 --- a/backends/xnnpack/operators/op_tanh.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -from typing import Dict - -import torch -from executorch.backends.xnnpack.operators.node_visitor import ( - NodeVisitor, - register_node_visitor, -) -from executorch.backends.xnnpack.serialization.xnnpack_graph_schema import ( - XNNGraph, - XNNTanh, - XNode, -) -from executorch.backends.xnnpack.utils.utils import get_input_node - - -@register_node_visitor -class TanhVisitor(NodeVisitor): - target = "aten.tanh.default" - - def __init__(self, *args) -> None: - super().__init__(*args) - - def define_node( - self, - node: torch.fx.Node, - xnn_graph: XNNGraph, - vals_to_ids: Dict[torch.fx.Node, int], - debug_handle: int, - ) -> None: - self.define_nodes_tensor_inputs_outputs(node, xnn_graph, vals_to_ids) - - # input - input_id = vals_to_ids[get_input_node(node, 0)] - - # output - output_id = vals_to_ids[node] - - ser_node = XNode( - xnode_union=XNNTanh( - input_id=input_id, - output_id=output_id, - flags=0, - ), - debug_handle=debug_handle, - ) - xnn_graph.xnodes.append(ser_node) diff --git a/backends/xnnpack/partition/config/__init__.py b/backends/xnnpack/partition/config/__init__.py index 3c45788cb7d..27c2f76b97d 100644 --- a/backends/xnnpack/partition/config/__init__.py +++ b/backends/xnnpack/partition/config/__init__.py @@ -50,7 +50,6 @@ SoftmaxConfig, SquareRootConfig, SubConfig, - TanhConfig, UpsampleBilinear2dConfig, ) from executorch.backends.xnnpack.partition.config.node_configs import ( @@ -102,7 +101,6 @@ PreluConfig, ReciprocalSquareRootConfig, ReLUConfig, - TanhConfig, # SDPAConfig, TODO: D60553559: preserving SDPA for fairseq fails SigmoidConfig, SliceCopyConfig, diff --git a/backends/xnnpack/partition/config/generic_node_configs.py b/backends/xnnpack/partition/config/generic_node_configs.py index b1b53256039..12d2557369b 100644 --- a/backends/xnnpack/partition/config/generic_node_configs.py +++ b/backends/xnnpack/partition/config/generic_node_configs.py @@ -378,13 +378,6 @@ def supported_precision_types(self) -> List[ConfigPrecisionType]: return [ConfigPrecisionType.FP32] -class TanhConfig(GenericNodePartitionerConfig): - target_name = "tanh.default" - - def supported_precision_types(self) -> List[ConfigPrecisionType]: - return [ConfigPrecisionType.FP32] - - class MeanDimConfig(GenericNodePartitionerConfig): target_name = "mean.dim" diff --git a/backends/xnnpack/partition/configs.py b/backends/xnnpack/partition/configs.py index defdbe172a9..36ae882b23e 100644 --- a/backends/xnnpack/partition/configs.py +++ b/backends/xnnpack/partition/configs.py @@ -67,7 +67,6 @@ exir_ops.edge.aten.rsqrt.default, exir_ops.edge.aten.log.default, exir_ops.edge.aten.gelu.default, - exir_ops.edge.aten.tanh.default, ] SUPPORTED_MODULES = [ diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index b4373593649..3559cd77781 100644 --- a/backends/xnnpack/runtime/XNNCompiler.cpp +++ b/backends/xnnpack/runtime/XNNCompiler.cpp @@ -1521,36 +1521,6 @@ Error defineGeluNode( return Error::Ok; } -/* -Define serialized tanh node into the subgraph, using the remapped ids -to map the serialized ids, to the new ids generated when defining the -tensor value -*/ -Error defineTanhNode( - xnn_subgraph_t subgraph_ptr, - const std::unordered_map& remapped_ids, - const NodePtr node, - const fb_xnnpack::XNNGraph* graph) noexcept { - MAYBE_UNUSED(graph); - - auto graph_node = node->xnode_union_as_XNNTanh(); - - xnn_status status = xnn_define_tanh( - subgraph_ptr, - remapped_ids.at(graph_node->input_id()), - remapped_ids.at(graph_node->output_id()), - graph_node->flags()); - - ET_CHECK_OR_RETURN_ERROR( - status == xnn_status_success, - Internal, - "Failed to create tanh node %i with code: %s", - node->debug_handle(), - xnn_status_to_string(status)); - - return Error::Ok; -} - /* Define serialized ceiling node into the subgraph, using the remapped ids to map the serialized ids, to the new ids generated when defining the @@ -2146,7 +2116,6 @@ DefineNodeFunc getDefineNodeFunc(fb_xnnpack::XNodeUnion nodeType) { _DEFINE(Hardswish) _DEFINE(LeakyReLU) _DEFINE(Log) - _DEFINE(Tanh) _DEFINE(Maximum) _DEFINE(Negate) _DEFINE(Square) diff --git a/backends/xnnpack/serialization/runtime_schema.fbs b/backends/xnnpack/serialization/runtime_schema.fbs index 766989cb3e6..ecd29c0c904 100644 --- a/backends/xnnpack/serialization/runtime_schema.fbs +++ b/backends/xnnpack/serialization/runtime_schema.fbs @@ -155,7 +155,6 @@ union XNodeUnion { XNNReciprocalSquareRoot: _XNNNode1x1, XNNLog: _XNNNode1x1, XNNGelu: _XNNNode1x1, - XNNTanh: _XNNNode1x1, } union XValueUnion { diff --git a/backends/xnnpack/serialization/schema.fbs b/backends/xnnpack/serialization/schema.fbs index 7abce60cd54..0d23d84f9d8 100644 --- a/backends/xnnpack/serialization/schema.fbs +++ b/backends/xnnpack/serialization/schema.fbs @@ -151,7 +151,6 @@ union XNodeUnion { XNNReciprocalSquareRoot: _XNNNode1x1, XNNLog: _XNNNode1x1, XNNGelu: _XNNNode1x1, - XNNTanh: _XNNNode1x1, } union XValueUnion { diff --git a/backends/xnnpack/serialization/xnnpack_graph_schema.py b/backends/xnnpack/serialization/xnnpack_graph_schema.py index 99b64708f86..9489a1dfb81 100644 --- a/backends/xnnpack/serialization/xnnpack_graph_schema.py +++ b/backends/xnnpack/serialization/xnnpack_graph_schema.py @@ -324,11 +324,6 @@ class XNNLog(XNNNode1x1): pass -@dataclass -class XNNTanh(XNNNode1x1): - pass - - @dataclass class XNNMaximum(XNNNode2x1): pass @@ -401,7 +396,6 @@ class XNNScaledDotProductAttention: XNNReciprocalSquareRoot, XNNLog, XNNGelu, - XNNTanh, ] diff --git a/backends/xnnpack/test/ops/test_tanh.py b/backends/xnnpack/test/ops/test_tanh.py deleted file mode 100644 index e7bac4541c9..00000000000 --- a/backends/xnnpack/test/ops/test_tanh.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -import unittest - -import torch -from executorch.backends.xnnpack.test.tester import Tester - - -class TestTanh(unittest.TestCase): - def setUp(self): - torch._dynamo.reset() - - class Tanh(torch.nn.Module): - def __init__(self): - super().__init__() - - def forward(self, x): - return torch.tanh(x) - - def run_tanh_test(self, inputs): - ( - Tester(self.Tanh(), inputs) - .export() - .check_count({"torch.ops.aten.tanh.default": 1}) - .to_edge_transform_and_lower() - .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) - .check_not(["executorch_exir_dialects_edge__ops_aten_tanh_default"]) - .to_executorch() - .serialize() - .run_method_and_compare_outputs() - ) - - def test_fp16_tanh(self): - inputs = (torch.randn(20).to(torch.float16),) - self.run_tanh_test(inputs) - - def test_fp32_tanh(self): - inputs = (torch.randn(20),) - self.run_tanh_test(inputs)