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

Method graph_copy

torch/fx/graph.py:821–845  ·  view source on GitHub ↗

Copy all nodes from a given graph into ``self``. Args: g (Graph): The source graph from which to copy Nodes. val_map (Dict[Node, Node]): a dictionary that will be populated with a mapping from nodes in ``g`` to nodes in ``self``. Note that

(self, g : 'Graph', val_map : Dict[Node, Node], return_output_node=False)

Source from the content-addressed store, hash-verified

819
820 @compatibility(is_backward_compatible=True)
821 def graph_copy(self, g : 'Graph', val_map : Dict[Node, Node], return_output_node=False) -> 'Optional[Argument]':
822 """
823 Copy all nodes from a given graph into ``self``.
824
825 Args:
826
827 g (Graph): The source graph from which to copy Nodes.
828
829 val_map (Dict[Node, Node]): a dictionary that will be populated with a mapping
830 from nodes in ``g`` to nodes in ``self``. Note that ``val_map`` can be passed
831 in with values in it already to override copying of certain values.
832
833 Returns:
834
835 The value in ``self`` that is now equivalent to the output value in ``g``,
836 if ``g`` had an ``output`` node. ``None`` otherwise.
837 """
838 for node in g.nodes:
839 if node in val_map:
840 continue
841 if node.op == 'output':
842 rv = map_arg(node.args[0], lambda n: val_map[n])
843 return rv if not return_output_node else (rv, node)
844 val_map[node] = self.node_copy(node, lambda n : val_map[n])
845 return None
846
847 def __deepcopy__(self, memo=None) -> 'Graph':
848 """

Callers 10

__deepcopy__Method · 0.95
transformMethod · 0.95
test_inline_graphMethod · 0.95
__init__Method · 0.80
partitionerFunction · 0.80
_insert_reshard_gmFunction · 0.80
_replace_patternFunction · 0.80

Calls 2

node_copyMethod · 0.95
map_argFunction · 0.70

Tested by 5

transformMethod · 0.76
test_inline_graphMethod · 0.76