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

Method create_node

torch/fx/graph.py:866–910  ·  view source on GitHub ↗

Create a ``Node`` and add it to the ``Graph`` at the current insert-point. Note that the current insert-point can be set via :meth:`Graph.inserting_before` and :meth:`Graph.inserting_after`. Args: op (str): the opcode for this Node. One of 'call_function

(self, op: str, target: 'Target',
                    args: Optional[Tuple['Argument', ...]] = None,
                    kwargs: Optional[Dict[str, 'Argument']] = None,
                    name: Optional[str] = None,
                    type_expr: Optional[Any] = None)

Source from the content-addressed store, hash-verified

864
865 @compatibility(is_backward_compatible=True)
866 def create_node(self, op: str, target: 'Target',
867 args: Optional[Tuple['Argument', ...]] = None,
868 kwargs: Optional[Dict[str, 'Argument']] = None,
869 name: Optional[str] = None,
870 type_expr: Optional[Any] = None) -> Node:
871 """
872 Create a ``Node`` and add it to the ``Graph`` at the current insert-point.
873 Note that the current insert-point can be set via :meth:`Graph.inserting_before`
874 and :meth:`Graph.inserting_after`.
875
876 Args:
877 op (str): the opcode for this Node. One of 'call_function', 'call_method', 'get_attr',
878 'call_module', 'placeholder', or 'output'. The semantics of these opcodes are
879 described in the ``Graph`` docstring.
880
881 args (Optional[Tuple[Argument, ...]]): is a tuple of arguments to this node.
882
883 kwargs (Optional[Dict[str, Argument]]): the kwargs of this Node
884
885 name (Optional[str]): an optional string name for the ``Node``.
886 This will influence the name of the value assigned to in the
887 Python generated code.
888
889 type_expr (Optional[Any]): an optional type annotation representing the
890 Python type the output of this node will have.
891
892 Returns:
893
894 The newly-created and inserted node.
895 """
896 assert op in ('call_function', 'call_method', 'get_attr', 'call_module', 'placeholder', 'output')
897 args = () if args is None else args
898 kwargs = {} if kwargs is None else kwargs
899 assert isinstance(args, tuple), "args must be a tuple"
900 assert isinstance(kwargs, dict), "kwargs must be a dict"
901
902 candidate = name if name is not None else self._target_to_str(target)
903 name = self._graph_namespace.create_name(candidate, None)
904 n = Node(self, name, op, target, args, kwargs, type_expr)
905
906 self._graph_namespace.associate_name_with_obj(name, n)
907
908 self._insert(n)
909 self._len += 1
910 return n
911
912 @compatibility(is_backward_compatible=False)
913 def process_inputs(self, *args):

Callers 15

placeholderMethod · 0.95
get_attrMethod · 0.95
call_moduleMethod · 0.95
call_methodMethod · 0.95
call_functionMethod · 0.95
node_copyMethod · 0.95
outputMethod · 0.95
fold_weightFunction · 0.95
transformMethod · 0.95

Calls 5

_target_to_strMethod · 0.95
isinstanceFunction · 0.85
create_nameMethod · 0.80
NodeClass · 0.70

Tested by 15

transformMethod · 0.76
test_wrong_topoMethod · 0.76
test_typename_printMethod · 0.76
test_inf_nan_kwdsMethod · 0.76
test_replace_inputMethod · 0.76
test_insertion_pointMethod · 0.76
test_update_args_apiMethod · 0.76
test_move_beforeMethod · 0.76