MCPcopy Create free account
hub / github.com/pytorch/executorch / is_same_node

Function is_same_node

exir/backend/utils.py:38–63  ·  view source on GitHub ↗
(
    node_left: Iterable[torch.fx.Node],
    node_right: Iterable[torch.fx.Node],
)

Source from the content-addressed store, hash-verified

36# NB: Set this to None to handle validation from MobileBert
37@lru_cache(maxsize=None)
38def is_same_node(
39 node_left: Iterable[torch.fx.Node],
40 node_right: Iterable[torch.fx.Node],
41) -> bool:
42 # two nodes are the same if they have the same target and op
43 # same for their args
44 if isinstance(node_left, torch.fx.Node) and isinstance(node_right, torch.fx.Node):
45 if not (
46 (node_left.target == node_right.target)
47 and (node_left.op == node_right.op)
48 and (len(node_left.all_input_nodes) == len(node_right.all_input_nodes))
49 and all(
50 is_same_node(arg_left, arg_right)
51 for arg_left, arg_right in zip(
52 node_left.all_input_nodes, node_right.all_input_nodes
53 )
54 )
55 ):
56 return False
57 else:
58 if len(list(node_left)) != len(list(node_right)):
59 return False
60 for n_left, n_right in zip(node_left, node_right):
61 if not is_same_node(n_left, n_right):
62 return False
63 return True
64
65
66def is_identical_graph(

Callers 1

is_identical_graphFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected