Instantiate an instance of ``Node``. Note: most often, you want to use the Graph APIs, i.e. ``Graph.call_module``, ``Graph.call_method``, etc. rather than instantiating a ``Node`` directly. Args: graph (Graph): The ``Graph`` to which this ``Node`` should
(self, graph: 'Graph', name: str, op: str, target: 'Target',
args: Tuple['Argument', ...], kwargs: Dict[str, 'Argument'],
return_type : Optional[Any] = None)
| 155 | |
| 156 | @compatibility(is_backward_compatible=True) |
| 157 | def __init__(self, graph: 'Graph', name: str, op: str, target: 'Target', |
| 158 | args: Tuple['Argument', ...], kwargs: Dict[str, 'Argument'], |
| 159 | return_type : Optional[Any] = None) -> None: |
| 160 | """ |
| 161 | Instantiate an instance of ``Node``. Note: most often, you want to use the |
| 162 | Graph APIs, i.e. ``Graph.call_module``, ``Graph.call_method``, etc. rather |
| 163 | than instantiating a ``Node`` directly. |
| 164 | |
| 165 | Args: |
| 166 | graph (Graph): The ``Graph`` to which this ``Node`` should belong. |
| 167 | |
| 168 | name (str): The name to which the output of this ``Node`` should be assigned |
| 169 | |
| 170 | op (str): The opcode for this ``Node``. Can be one of 'placeholder', |
| 171 | 'call_method', 'call_module', 'call_function', 'get_attr', |
| 172 | 'output' |
| 173 | |
| 174 | target ('Target'): The target this op should call. See the broader |
| 175 | ``Node`` docstring for more details. |
| 176 | |
| 177 | args (Tuple['Argument']): The args to be passed to ``target`` |
| 178 | |
| 179 | kwargs (Dict[str, 'Argument']): The kwargs to be passed to ``target`` |
| 180 | |
| 181 | return_type (Optional[Any]): The python type expression representing the |
| 182 | type of the output of this node. This field can be used for |
| 183 | annotation of values in the generated code or for other types |
| 184 | of analyses. |
| 185 | """ |
| 186 | self.graph = graph |
| 187 | self.name = name # unique name of value being created |
| 188 | assert op in ['placeholder', 'call_method', 'call_module', 'call_function', 'get_attr', 'output', 'root'] |
| 189 | self.op = op # the kind of operation = placeholder|call_method|call_module|call_function|get_attr |
| 190 | if op == 'call_function': |
| 191 | if not callable(target): |
| 192 | raise ValueError(f'Node [graph = {graph}, name = \'{name}\'] target {target} has type {torch.typename(target)} ' |
| 193 | 'but a Callable is expected') |
| 194 | else: |
| 195 | if not isinstance(target, str): |
| 196 | raise ValueError(f'Node [graph = {graph}, name = \'{name}\'] target {target} has type {torch.typename(target)} ' |
| 197 | 'but a str is expected') |
| 198 | self.target = target # for method/module/function, the name of the method/module/function/attr |
| 199 | # being invoked, e.g add, layer1, or torch.add |
| 200 | |
| 201 | # All `Node`-valued inputs. Key is the Node, value is don't-care. |
| 202 | # The public API for this is `all_input_nodes`, this private attribute |
| 203 | # should not be accessed directly. |
| 204 | self._input_nodes : Dict[Node, None] = {} |
| 205 | self.__update_args_kwargs(map_arg(args, lambda x: x), map_arg(kwargs, lambda x: x)) # type: ignore[arg-type] |
| 206 | |
| 207 | # All of the nodes that use the value produced by this Node |
| 208 | # Note one user may correspond to several uses, e.g. the node fo ``x + x`` |
| 209 | # would appear once here, but represents two uses. |
| 210 | # |
| 211 | # Is a dict to act as an "ordered set". Keys are significant, value dont-care |
| 212 | self.users : Dict[Node, None] = {} |
| 213 | # Type expression representing the output value of this node. |
| 214 | # This should contain the same class of Type objects that would appear |
nothing calls this directly
no test coverage detected