Skip to content

Commit 8b78cc1

Browse files
authored
Fix 50% perf reduction in model
Differential Revision: D90145865 Pull Request resolved: pytorch#16483
1 parent 6f57750 commit 8b78cc1

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎backends/cadence/aot/memory_constraints.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,6 @@ def is_removable_cat_op(
484484
# If any of the tensors to be concatenated is slice_nop or cat_nop, bail
485485
if any(self.is_slice_view(arg) for arg in cat_tensors):
486486
return False
487-
488-
# If any of the tensors already has a relative placement constraint,
489-
# we cannot add a new constraint for this cat without conflicting.
490-
# This can happen when a tensor is used in multiple cat operations.
491-
if any(self.has_relative_placement_constraint(arg) for arg in cat_tensors):
492-
return False
493-
494487
# If the same tensor appears multiple times in the cat inputs,
495488
# we cannot place it at multiple different offsets relative to the output.
496489
if len(cat_tensors) != len(set(cat_tensors)):

‎backends/cadence/aot/replace_ops.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,8 +1678,15 @@ class ReplaceLinearWithFullyConnectedOpPass(RemoveOrReplacePassInterface):
16781678
"""
16791679

16801680
linear_to_fc_op: Dict[EdgeOpOverload, EdgeOpOverload] = {
1681+
# Default variants
16811682
exir_ops.edge.aten.linear.default: exir_ops.edge.cadence.fully_connected.default,
16821683
exir_ops.edge.cadence.quantized_linear.default: exir_ops.edge.cadence.quantized_fully_connected.default,
1684+
# Per-tensor variants
1685+
exir_ops.edge.cadence.quantized_linear.per_tensor: exir_ops.edge.cadence.quantized_fully_connected.per_tensor,
1686+
# Type-specialized variants (int8)
1687+
exir_ops.edge.cadence.quantized_linear_asym8sxasym8s_asym8s.per_tensor: exir_ops.edge.cadence.quantized_fully_connected_asym8sxasym8s_asym8s.per_tensor,
1688+
# Type-specialized variants (uint8)
1689+
exir_ops.edge.cadence.quantized_linear_asym8uxasym8u_asym8u.per_tensor: exir_ops.edge.cadence.quantized_fully_connected_asym8uxasym8u_asym8u.per_tensor,
16831690
}
16841691

16851692
@property
@@ -1915,7 +1922,10 @@ class ReplaceIm2RowWithViewPass(RemoveOrReplacePassInterface):
19151922

19161923
@property
19171924
def targets(self) -> list[EdgeOpOverload]:
1918-
return [exir_ops.edge.cadence.im2row.default]
1925+
return [
1926+
exir_ops.edge.cadence.im2row.default,
1927+
exir_ops.edge.cadence.im2row.per_tensor,
1928+
]
19191929

19201930
def maybe_remove_or_replace(self, node: torch.fx.Node) -> bool:
19211931
# Check if im2row applies padding. If yes, we cannot replace it with view.

0 commit comments

Comments
 (0)