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

Method inserting_before

torch/fx/graph.py:955–976  ·  view source on GitHub ↗

Set the point at which create_node and companion methods will insert into the graph. When used within a 'with' statement, this will temporary set the insert point and then restore it when the with statement exits:: with g.inserting_before(n): ... # insert

(self, n: Optional[Node] = None)

Source from the content-addressed store, hash-verified

953
954 @compatibility(is_backward_compatible=True)
955 def inserting_before(self, n: Optional[Node] = None):
956 """Set the point at which create_node and companion methods will insert into the graph.
957 When used within a 'with' statement, this will temporary set the insert point and
958 then restore it when the with statement exits::
959
960 with g.inserting_before(n):
961 ... # inserting before node n
962 ... # insert point restored to what it was previously
963 g.inserting_before(n) # set the insert point permanently
964
965 Args:
966
967 n (Optional[Node]): The node before which to insert. If None this will insert before
968 the beginning of the entire graph.
969
970 Returns:
971 A resource manager that will restore the insert point on ``__exit__``.
972 """
973 if n is None:
974 return self.inserting_after(self._root)
975 assert n.graph == self, "Node to insert before is not in graph."
976 return _InsertPoint(self, n.prepend)
977
978 @compatibility(is_backward_compatible=True)
979 def inserting_after(self, n: Optional[Node] = None):

Callers 15

inserting_afterMethod · 0.95
create_fx_from_snodesFunction · 0.95
test_insertion_pointMethod · 0.95
_replace_patternFunction · 0.45
reinplaceFunction · 0.45
optimize_for_inferenceFunction · 0.45
_inline_moduleFunction · 0.45
split_const_subgraphsFunction · 0.45
_initMethod · 0.45
__init__Method · 0.45
add_placeholderMethod · 0.45

Calls 2

inserting_afterMethod · 0.95
_InsertPointClass · 0.70

Tested by 11

test_insertion_pointMethod · 0.76
test_replace_usesMethod · 0.36
test_insert_argMethod · 0.36
merge_mm_shared_rhsMethod · 0.36
convertMethod · 0.36
transformMethod · 0.36
test_custom_classMethod · 0.36