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
26 changes: 0 additions & 26 deletions backends/cadence/aot/replace_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,31 +283,6 @@ def call_operator(self, op, args, kwargs, meta):
return super().call_operator(op, args, kwargs, meta)


@register_cadence_pass(CadencePassAttribute(opt_level=0))
class ReplaceTCopyWithTransposePass(ExportPass):
"""
Replace t_copy with transpose_copy.int. If the input is 1D, the t_copy is
a nop. t_copy is not supported, so this is an opt_level=0 pass.
"""

def call_operator(self, op, args, kwargs, meta):
if get_edge_overload_packet(op) != exir_ops.edge.aten.t_copy:
return super().call_operator(op, args, kwargs, meta)

# Get the input tensor shape
in_tensor = args[0].to_tensor() if isinstance(args[0], ProxyValue) else args[0]

# If the input is a 1D tensor, this t_copy is a nop, so return the input
if in_tensor.dim() <= 1:
return args[0]

assert in_tensor.dim() == 2, "t_copy expects a tensor with <= 2 dimensions"
transpose_args = (args[0], 0, 1)
return super().call_operator(
exir_ops.edge.aten.transpose_copy.int, transpose_args, kwargs, meta
)


@register_cadence_pass(CadencePassAttribute(opt_level=0))
class ReplaceMMWithAddMMPass(ExportPass):
"""
Expand Down Expand Up @@ -2407,7 +2382,6 @@ class CadenceReplaceOpsInGraph:
passes = [
ReplaceEmptyTensorsWithFullPass,
ReplaceFunctionallyEquivalentOpTargets,
ReplaceTCopyWithTransposePass,
ReplacePermuteWithTransposePass,
ReplaceScalarWithTensorArgPass,
ReplaceConvolutionOptionalArgsWithConcreteArgsPass,
Expand Down
32 changes: 0 additions & 32 deletions backends/cadence/aot/tests/test_replace_ops_passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
ReplaceSingleElementTensorArgumentsFromFullOpWithScalarPass,
ReplaceSplitWithSlicePass,
ReplaceSqueezeAndUnsqueezeWithViewPass,
ReplaceTCopyWithTransposePass,
ReplaceTransposedConvWithLinearPass,
ReplaceTrivialConvWithLinear,
ReplaceWhereWithFullArgsWithWhereScalar,
Expand Down Expand Up @@ -368,37 +367,6 @@ def forward(self, x: torch.Tensor):
0,
)

@parameterized.expand(
[
[(16, 32)],
[(1, 240)],
[(4, 16)],
]
)
@torch.no_grad()
def test_replace_t_copy_with_transpose(self, shape: Tuple[int]):
class TCopy(torch.nn.Module):
def forward(self, x: torch.Tensor):
return exir_ops.edge.aten.t_copy(x)

w = torch.randn(shape)
inputs = (w,)
p1 = ReplaceTCopyWithTransposePass()
p2 = ReplacePermuteWithTransposePass()
model = TCopy()
graph_module = export_to_edge(model, inputs).exported_program().graph_module
graph_after_passes = cast(
PassResult, p2(cast(PassResult, p1(graph_module)).graph_module)
).graph_module
self.assertEqual(
count_node(graph_after_passes, exir_ops.edge.aten.transpose_copy.int),
1,
)
self.assertEqual(
count_node(graph_after_passes, exir_ops.edge.aten.t_copy),
0,
)

@parameterized.expand(
[
[(1, 8, 33), 8, 16, 3],
Expand Down
Loading