MCPcopy Create free account
hub / github.com/pytorch/pytorch / erase_node

Method erase_node

torch/fx/graph.py:925–952  ·  view source on GitHub ↗

Erases a ``Node`` from the ``Graph``. Throws an exception if there are still users of that node in the ``Graph``. Args: to_erase (Node): The ``Node`` to erase from the ``Graph``.

(self, to_erase : Node)

Source from the content-addressed store, hash-verified

923
924 @compatibility(is_backward_compatible=True)
925 def erase_node(self, to_erase : Node) -> None:
926 """
927 Erases a ``Node`` from the ``Graph``. Throws an exception if
928 there are still users of that node in the ``Graph``.
929
930 Args:
931
932 to_erase (Node): The ``Node`` to erase from the ``Graph``.
933 """
934 if len(to_erase.users) > 0:
935 raise RuntimeError(f'Tried to erase Node {to_erase} but it still had {len(to_erase.users)} '
936 f'users in the graph: {to_erase.users}!')
937 if to_erase._erased:
938 warnings.warn(f"erase_node({to_erase}) on an already erased node")
939 return
940
941 to_erase._remove_from_list()
942 to_erase._erased = True # iterators may retain handles to erased nodes
943 self._len -= 1
944
945 # Null out this Node's argument nodes so that the Nodes referred to
946 # can update their ``users`` accordingly
947 new_args = map_arg(to_erase.args, lambda n: None)
948 assert isinstance(new_args, tuple)
949 to_erase.args = new_args
950 new_kwargs = map_arg(to_erase.kwargs, lambda n: None)
951 assert isinstance(new_kwargs, dict)
952 to_erase.kwargs = new_kwargs
953
954 @compatibility(is_backward_compatible=True)
955 def inserting_before(self, n: Optional[Node] = None):

Callers 15

eliminate_dead_codeMethod · 0.95
remove_suffixFunction · 0.95
test_remove_usesMethod · 0.95
_replace_patternFunction · 0.45
reinplaceFunction · 0.45
_run_and_compareMethod · 0.45
erase_nodesFunction · 0.45
merge_matmulFunction · 0.45
fuseFunction · 0.45
optimize_for_inferenceFunction · 0.45
split_const_subgraphsFunction · 0.45
remove_fx_nodeMethod · 0.45

Calls 4

isinstanceFunction · 0.85
warnMethod · 0.80
_remove_from_listMethod · 0.80
map_argFunction · 0.70

Tested by 5

test_remove_usesMethod · 0.76
test_replace_usesMethod · 0.36
test_erase_node_errorMethod · 0.36
convertMethod · 0.36