Skip to content
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
7 changes: 4 additions & 3 deletions backends/arm/_passes/convert_expand_copy_to_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


def calculate_multiples(args):
"""Returns expand args converted to repeat args, and whether the expand changes the rank"""
input_node_or_tensor = args[0]

if isinstance(input_node_or_tensor, torch.fx.node.Node):
Expand All @@ -45,7 +46,7 @@ def calculate_multiples(args):
multiples[i] if multiples[i] != -1 and extended_shape[i] == 1 else 1
for i in range(expanded_rank)
]
return multiples
return multiples, expanded_rank != len(input_shape)


class ConvertExpandCopyToRepeatPass(ArmPass):
Expand All @@ -62,9 +63,9 @@ def call_operator(self, op, args, kwargs, meta):
if op != self.expand_copy:
return super().call_operator(op, args, kwargs, meta)

multiples = calculate_multiples(args)
multiples, changes_rank = calculate_multiples(args)

if all((x == 1 for x in multiples)):
if all((x == 1 for x in multiples)) and not changes_rank:
# All dimensions/repetitions occur only once. Remove node
# altogether since it's in practice just a copy.
logger.warning("Found redundant expand node (no-op). Removing it.")
Expand Down
4 changes: 2 additions & 2 deletions backends/arm/tosa/partitioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def is_noop_expand(node: torch.fx.node.Node) -> bool:
if node.target != exir_ops.edge.aten.expand_copy.default:
return False
else:
multiples = calculate_multiples(node.args)
return all(m == 1 for m in multiples)
multiples, changes_rank = calculate_multiples(node.args)
return all(m == 1 for m in multiples) and not changes_rank


def is_partitioned(
Expand Down
Loading