Skip to content

Commit

Permalink
Add dim_order compat support
Browse files Browse the repository at this point in the history
Differential Revision: D67542995
  • Loading branch information
digantdesai authored and facebook-github-bot committed Dec 20, 2024
1 parent a396b47 commit 9a5f9e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backends/apple/mps/mps_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
CompileSpec,
PreprocessResult,
)

from executorch.exir.passes.memory_format_ops_pass import DimOrderOpsRevertPass
from torch.export.exported_program import ExportedProgram

FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
Expand Down Expand Up @@ -83,6 +85,9 @@ def preprocess(
# FlatBuffer graph, process the `output` nodes and add their id to
# the `output_ids` array in the schema.

# TODO: Remove this once we have a better support for the dim-order ops.
edge_program = DimOrderOpsRevertPass()(edge_program)

mps_graph = MPSGraph(
version="0",
mps_nodes=[],
Expand Down
9 changes: 9 additions & 0 deletions backends/apple/mps/operators/constant_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def define_node(
)
)

@register_node_visitor
class ToDimOrderEmptyVisitor(NodeVisitor):
target = ["exir_ops.edge.dim_order_ops._to_dim_order_copy.default"]

def __init__(self, *args) -> None:
# We should never get here, because DimOrderOpsRevertPass replaces this with an aten.empty.memory_format op
# But if we do, we can't handle it ATM, so raise an exception
raise NotImplementedError("exir_ops.edge.dim_order_ops._to_dim_order_copy.default is not supported yet")


@register_node_visitor
class FullLikeVisitor(NodeVisitor):
Expand Down
9 changes: 9 additions & 0 deletions backends/apple/mps/operators/op_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ def define_node(
)
input_id = self.define_tensor(get_input_node(node, 0), mps_graph)
self.tensor_to_id[node] = input_id

@register_node_visitor
class ToDimOrderCopyVisitor(NodeVisitor):
target = ["exir_ops.edge.dim_order_ops._to_dim_order_copy.default"]

def __init__(self, *args) -> None:
# We should never get here, because DimOrderOpsRevertPass replaces this with an aten._to_copy op
# But if we do, we can't handle it ATM, so raise an exception
raise NotImplementedError("exir_ops.edge.dim_order_ops._to_dim_order_copy.default is not supported yet")

0 comments on commit 9a5f9e4

Please sign in to comment.