``Node`` is the data structure that represents individual operations within a ``Graph``. For the most part, Nodes represent callsites to various entities, such as operators, methods, and Modules (some exceptions include nodes that specify function inputs and outputs). Each ``Node``
| 126 | |
| 127 | @compatibility(is_backward_compatible=True) |
| 128 | class Node: |
| 129 | """ |
| 130 | ``Node`` is the data structure that represents individual operations within |
| 131 | a ``Graph``. For the most part, Nodes represent callsites to various entities, |
| 132 | such as operators, methods, and Modules (some exceptions include nodes that |
| 133 | specify function inputs and outputs). Each ``Node`` has a function specified |
| 134 | by its ``op`` property. The ``Node`` semantics for each value of ``op`` are as follows: |
| 135 | |
| 136 | - ``placeholder`` represents a function input. The ``name`` attribute specifies the name this value will take on. |
| 137 | ``target`` is similarly the name of the argument. ``args`` holds either: 1) nothing, or 2) a single argument |
| 138 | denoting the default parameter of the function input. ``kwargs`` is don't-care. Placeholders correspond to |
| 139 | the function parameters (e.g. ``x``) in the graph printout. |
| 140 | - ``get_attr`` retrieves a parameter from the module hierarchy. ``name`` is similarly the name the result of the |
| 141 | fetch is assigned to. ``target`` is the fully-qualified name of the parameter's position in the module hierarchy. |
| 142 | ``args`` and ``kwargs`` are don't-care |
| 143 | - ``call_function`` applies a free function to some values. ``name`` is similarly the name of the value to assign |
| 144 | to. ``target`` is the function to be applied. ``args`` and ``kwargs`` represent the arguments to the function, |
| 145 | following the Python calling convention |
| 146 | - ``call_module`` applies a module in the module hierarchy's ``forward()`` method to given arguments. ``name`` is |
| 147 | as previous. ``target`` is the fully-qualified name of the module in the module hierarchy to call. |
| 148 | ``args`` and ``kwargs`` represent the arguments to invoke the module on, *excluding the self argument*. |
| 149 | - ``call_method`` calls a method on a value. ``name`` is as similar. ``target`` is the string name of the method |
| 150 | to apply to the ``self`` argument. ``args`` and ``kwargs`` represent the arguments to invoke the module on, |
| 151 | *including the self argument* |
| 152 | - ``output`` contains the output of the traced function in its ``args[0]`` attribute. This corresponds to the "return" statement |
| 153 | in the Graph printout. |
| 154 | """ |
| 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 | """ |
no outgoing calls
no test coverage detected
searching dependent graphs…