Skip to content

Commit b313ace

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
turn on dim order in cadence test (#7756)
Summary: This diff turns on dim order in cadence test. Also we get around `to_copy` operator in verifier to keep the verifier check enable. Differential Revision: D68246404
1 parent 1f1a96f commit b313ace

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

backends/cadence/aot/compiler.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
ExecutorchProgramManager,
3434
to_edge,
3535
)
36+
from executorch.exir.dialects._ops import ops as exir_ops
3637
from executorch.exir.pass_base import PassResult
3738
from executorch.exir.passes import ToOutVarPass
3839
from executorch.exir.passes.sym_shape_eval_pass import HintBasedSymShapeEvalPass
@@ -185,14 +186,17 @@ def export_to_edge(
185186
edge_prog_manager = to_edge(
186187
expo_program,
187188
compile_config=EdgeCompileConfig(
188-
_skip_dim_order=True,
189189
# Allow specific non-core aten ops in the IR.
190190
_core_aten_ops_exception_list=[
191191
torch.ops.aten._native_batch_norm_legit_functional.default,
192192
torch.ops.aten.linear.default,
193193
torch.ops.aten.linalg_vector_norm.default,
194194
torch.ops.aten.unfold.default,
195195
torch.ops.aten.angle.default,
196+
# cadence replaced to_dim_order_copy with _to_copy for performance
197+
# skip _to_copy op to get around of dim order check
198+
# We should remove this op once cadence can support dim order
199+
exir_ops.edge.aten._to_copy.default,
196200
],
197201
),
198202
)

backends/cadence/aot/replace_ops.py

+32
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,37 @@ def call_operator(
17991799
)
18001800

18011801

1802+
@register_cadence_pass(CadencePassAttribute(opt_level=0))
1803+
class ReplaceToDimOrderCopyWithToCopyPass(ExportPass):
1804+
"""
1805+
dim_order_ops::to_dim_order_copy is not supported, so this is an opt_level=0 pass.
1806+
If the dim order is sequential, we don't need the extra work with strides and
1807+
can just use to_copy.
1808+
"""
1809+
1810+
def call_operator(
1811+
self,
1812+
op,
1813+
args: Tuple[Argument, ...],
1814+
kwargs: Dict[str, Argument],
1815+
meta: NodeMetadata,
1816+
) -> ProxyValue:
1817+
if op != exir_ops.edge.dim_order_ops._to_dim_order_copy.default:
1818+
return super().call_operator(op, args, kwargs, meta)
1819+
1820+
# pyre-ignore[16]: `None` has no attribute `to_tensor`.
1821+
assert (args[0] == range(args[0].to_tensor().dim()), "Only sequential dims supported")
1822+
1823+
return super().call_operator(
1824+
exir_ops.edge.aten._to_copy.default,
1825+
(
1826+
args[0],
1827+
),
1828+
{},
1829+
meta,
1830+
)
1831+
1832+
18021833
@register_cadence_pass(CadencePassAttribute(opt_level=0))
18031834
class ReplaceFullLikeWithFullPass(ExportPass):
18041835
"""
@@ -2108,4 +2139,5 @@ class CadenceReplaceOpsInGraph:
21082139
ReplaceSingleElementTensorArgumentsFromFullOpWithScalarPass,
21092140
ReplaceAtenAvgPoolWithJarvisAvgPoolPass,
21102141
ReplaceAtenLinalgVectorNormWithCadenceLinalgVectorNormPass,
2142+
ReplaceToDimOrderCopyWithToCopyPass,
21112143
]

0 commit comments

Comments
 (0)