Skip to content
Open
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
4 changes: 3 additions & 1 deletion backends/arm/_passes/remove_noop_pass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024-2025 Arm Limited and/or its affiliates.
# Copyright 2024-2026 Arm Limited and/or its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
Expand All @@ -25,7 +25,9 @@ def call_operator(self, op, args, kwargs, meta):
if op not in (
exir_ops.edge.dim_order_ops._clone_dim_order.default,
exir_ops.edge.dim_order_ops._to_dim_order_copy.default,
exir_ops.edge.aten.alias_copy.default,
exir_ops.edge.aten.copy.default,
exir_ops.edge.aten.detach_copy.default,
):
return super().call_operator(op, args, kwargs, meta)

Expand Down
1 change: 0 additions & 1 deletion backends/arm/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@
op_where,
op_while,
ops_binary,
ops_identity,
)
80 changes: 0 additions & 80 deletions backends/arm/operators/ops_identity.py

This file was deleted.

2 changes: 1 addition & 1 deletion backends/arm/test/ops/test_detach_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DetachCopy(torch.nn.Module):
exir_op = exir_op

def forward(self, x: torch.Tensor):
return torch.detach_copy(x)
return torch.detach_copy(x) + 1


@common.parametrize("test_data", test_data_suite)
Expand Down
62 changes: 11 additions & 51 deletions backends/arm/tosa/partitioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,68 +46,27 @@
logger = logging.getLogger(__name__)


def is_noop_clone(node: torch.fx.node.Node) -> bool:
"""Return True if the node is a no-op ``dim_order_ops._clone_dim_order``.

Args:
node (torch.fx.Node): FX node to inspect.

Returns:
bool: True if the node targets ``dim_order_ops._clone_dim_order.default``
in the Edge dialect; otherwise, False.

"""
def _is_noop_clone(node: torch.fx.node.Node) -> bool:
return node.target == exir_ops.edge.dim_order_ops._clone_dim_order.default


def is_noop_alias_copy(node: torch.fx.Node) -> bool:
"""Return True if the node is a no-op ``aten.alias_copy``.

Args:
node (torch.fx.Node): FX node to inspect.

Returns:
bool: True if the node targets ``aten.alias_copy.default``; otherwise,
False.

"""
def _is_noop_alias_copy(node: torch.fx.Node) -> bool:
return node.target == exir_ops.edge.aten.alias_copy.default


def is_noop_to_dim_order_copy(node: torch.fx.node.Node) -> bool:
"""Return True if node is a no-op ``dim_order_ops._to_dim_order_copy``.
def _is_noop_detach_copy(node: torch.fx.Node) -> bool:
return node.target == exir_ops.edge.aten.detach_copy.default

Consider the op a no-op when the output dtype equals the input's dtype.

Args:
node (torch.fx.Node): FX node to inspect.

Returns:
bool: True if it targets ``_to_dim_order_copy.default`` and preserves
dtype; otherwise, False.

"""
def _is_noop_to_dim_order_copy(node: torch.fx.node.Node) -> bool:
if node.target != exir_ops.edge.dim_order_ops._to_dim_order_copy.default:
return False
else:
input_node = ensure_type(torch.fx.Node, node.args[0])
return node.meta.get("dtype") == get_first_fake_tensor(input_node).dtype


def is_noop_expand(node: torch.fx.node.Node) -> bool:
"""Return True if the node is an ``expand_copy`` with all-ones multiples.

This corresponds to a semantic no-op, since expanding by 1 along every
dimension leaves the tensor unchanged.

Args:
node (torch.fx.Node): FX node to inspect.

Returns:
bool: True if the node targets ``aten.expand_copy.default`` and all
computed multiples are 1; otherwise, False.

"""
def _is_noop_expand(node: torch.fx.node.Node) -> bool:
if node.target != exir_ops.edge.aten.expand_copy.default:
return False
else:
Expand Down Expand Up @@ -291,10 +250,11 @@ def _tag_module( # noqa
)

is_noop_partition = all(
is_noop_clone(node)
or is_noop_alias_copy(node)
or is_noop_expand(node)
or is_noop_to_dim_order_copy(node)
_is_noop_clone(node)
or _is_noop_alias_copy(node)
or _is_noop_detach_copy(node)
or _is_noop_expand(node)
or _is_noop_to_dim_order_copy(node)
or node.target in Q_OPS
or node.target in DQ_OPS
for node in partition.nodes
Expand Down
Loading