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

Method replace_input_with

torch/fx/node.py:645–662  ·  view source on GitHub ↗

Loop through input nodes of ``self``, and replace all instances of ``old_input`` with ``new_input``. Args: old_input (Node): The old input node to be replaced. new_input (Node): The new input node to replace ``old_input``.

(self, old_input: 'Node', new_input: 'Node')

Source from the content-addressed store, hash-verified

643
644 @compatibility(is_backward_compatible=True)
645 def replace_input_with(self, old_input: 'Node', new_input: 'Node'):
646 """
647 Loop through input nodes of ``self``, and replace all instances of
648 ``old_input`` with ``new_input``.
649
650 Args:
651
652 old_input (Node): The old input node to be replaced.
653 new_input (Node): The new input node to replace ``old_input``.
654 """
655 def maybe_replace_node(n : Node) -> Node:
656 return new_input if n == old_input else n
657
658 new_args = map_arg(self.args, maybe_replace_node)
659 new_kwargs = map_arg(self.kwargs, maybe_replace_node)
660 assert isinstance(new_args, tuple)
661 assert isinstance(new_kwargs, dict)
662 self.__update_args_kwargs(new_args, new_kwargs)
663
664 def _rename(self, candidate: str):
665 if candidate == self.name:

Calls 3

__update_args_kwargsMethod · 0.95
isinstanceFunction · 0.85
map_argFunction · 0.70

Tested by 1

test_replace_inputMethod · 0.64