1# 2# Copyright (c) 2023 Apple Inc. All rights reserved. 3# Provided subject to the LICENSE file in the top level directory. 4# 5 6import torch 7from executorch.backends.apple.mps.operators.node_visitor import ( 8 NodeVisitor, 9 register_node_visitor, 10) 11from executorch.backends.apple.mps.serialization.mps_graph_schema import MPSGraph 12from executorch.backends.apple.mps.utils.mps_utils import get_input_node 13from executorch.exir.dialects._ops import ops as exir_ops 14 15 16@register_node_visitor 17class CloneVisitor(NodeVisitor): 18 target = ["aten.clone.default", "aten._to_copy.default"] 19 20 def __init__(self, *args) -> None: 21 super().__init__(*args) 22 23 def define_node( 24 self, 25 node: torch.fx.Node, 26 mps_graph: MPSGraph, 27 ) -> None: 28 if node.target == exir_ops.edge.aten._to_copy.default: 29 # TODO 30 if len(node.args) > 1: 31 raise RuntimeError( 32 "aten._to_copy not supported with more than one argument currently" 33 ) 34 input_id = self.define_tensor(get_input_node(node, 0), mps_graph) 35 self.tensor_to_id[node] = input_id 36