(
node_left: Iterable[torch.fx.Node],
node_right: Iterable[torch.fx.Node],
)
| 36 | # NB: Set this to None to handle validation from MobileBert |
| 37 | @lru_cache(maxsize=None) |
| 38 | def 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 | |
| 66 | def is_identical_graph( |
no outgoing calls
no test coverage detected