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)
| 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): |