/usr/local/lib64/python3.6/site-packages/torch/fx/__pycache__
NameSizeModeActions
annotate.cpython-36.pyc7860644editdlrm
graph.cpython-36.pyc409320644editdlrm
graph_module.cpython-36.pyc209680644editdlrm
immutable_collections.cpython-36.pyc14320644editdlrm
interpreter.cpython-36.pyc176600644editdlrm
node.cpython-36.pyc221700644editdlrm
operator_schemas.cpython-36.pyc130440644editdlrm
proxy.cpython-36.pyc144270644editdlrm
subgraph_rewriter.cpython-36.pyc112570644editdlrm
tensor_type.cpython-36.pyc37390644editdlrm
_compatibility.cpython-36.pyc11460644editdlrm
_pytree.cpython-36.pyc26510644editdlrm
_symbolic_trace.cpython-36.pyc317270644editdlrm
__init__.cpython-36.pyc40180644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/fx/__pycache__/node.cpython-36.pyc (22170B)
3 Egae @sUddlmZmZmZmZmZmZmZmZm Z ddl m Z ddl m Z mZddlZddlZddlZddlmZmZmZerddlmZeeeeeejejejejfZ e j!Z"eedefefZ#eeeedfeeeeefe$d e fZ%ej&ej'j(j)ej'j(j*hZ+e e+edefed d d Z,d dZ-edefedddZ.edddZ/e ddGdd d Z0e dde%ee0ge%fe%dddZ1e dde%ee%ge%fe%dddZ2dS)) TYPE_CHECKINGUnionCallableAnyTupleListOptionalDictSet) compatibility)immutable_dictimmutable_listN)normalize_functionnormalize_moduleArgsKwargsPair)Graph.Node) orig_methodreturncCsV|j}|j}|dk r|Sx*ttjjgD]}t||d|kr&|jSq&Wtd|dS)Nzcannot find module for )__name__ __module__torchnnZ functionalgetattr RuntimeError)rnamemoduleguessr9/usr/local/lib64/python3.6/site-packages/torch/fx/node.py_find_module_of_method s r!cCs\t|tr6|jdkr6|jdkr$|jS|jd|jS|dkrBdSt|tjrT|jSt|S)a:Return the repr() of an object, special-casing types (internal helper). If obj is a type, we return a shorter version than the default type.__repr__, based on the module and qualified name, which is typically enough to uniquely identify a type. For everything else, we fall back on repr(obj). typingbuiltins..z...) isinstancetyper __qualname__types FunctionTyperrepr)objrrr _type_repr,s   r,)funcrcCs@tt|jd|kr|jS|j}t|}|jdd}|d|S)Nz torch._opsz torch.opsr$)rr#rr!replace)r-rrrrr _get_qualified_nameAs  r/)rcCst|tr*djdd|D}d|dSt|trldjdd|D}t|dkrXdnd }d ||d St|trdjd d|jD}d |dSt|trdt|St|SdS)Nz, css|]}t|VqdS)N) _format_arg).0arrr Lsz_format_arg..[]css|]}t|VqdS)N)r0)r1r2rrr r3Osr ,()css$|]\}}|dt|VqdS)z: N)r0)r1kvrrr r3Ss{}%) r%listjointuplelendictitemsrstr)argrDZ maybe_commaZ items_strrrr r0Js       r0T)is_backward_compatiblec @steZdZdZedddBdeededCeedfee dd d d Z e dd d dZ e dd ddZ edddddddZedddddddZddZe eedfd ddZejeedfdddZe eeefd ddZejeeefdddZe edd d d!Zeddeedd"d#d$Zeddeedd%d&d'Ze eed d(d)Zejeed*d+d)ZedDeedfd,d-d.Zed d/d0Zd1d2ZedddEeeeeeed3d4d5Zedddedd6d7d8Zed9dd:d;Z ed9ddFe!j"j#eee eeee fe$ee%d<d=d>Z&eddddd?d@dAZ'dS)Grao ``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`` has a function specified by its ``op`` property. The ``Node`` semantics for each value of ``op`` are as follows: - ``placeholder`` represents a function input. The ``name`` attribute specifies the name this value will take on. ``target`` is similarly the name of the argument. ``args`` holds either: 1) nothing, or 2) a single argument denoting the default parameter of the function input. ``kwargs`` is don't-care. Placeholders correspond to the function parameters (e.g. ``x``) in the graph printout. - ``get_attr`` retrieves a parameter from the module hierarchy. ``name`` is similarly the name the result of the fetch is assigned to. ``target`` is the fully-qualified name of the parameter's position in the module hierarchy. ``args`` and ``kwargs`` are don't-care - ``call_function`` applies a free function to some values. ``name`` is similarly the name of the value to assign to. ``target`` is the function to be applied. ``args`` and ``kwargs`` represent the arguments to the function, following the Python calling convention - ``call_module`` applies a module in the module hierarchy's ``forward()`` method to given arguments. ``name`` is as previous. ``target`` is the fully-qualified name of the module in the module hierarchy to call. ``args`` and ``kwargs`` represent the arguments to invoke the module on, *including the self argument*. - ``call_method`` calls a method on a value. ``name`` is as similar. ``target`` is the string name of the method to apply to the ``self`` argument. ``args`` and ``kwargs`` represent the arguments to invoke the module on, *including the self argument* - ``output`` contains the output of the traced function in its ``args[0]`` attribute. This corresponds to the "return" statement in the Graph printout. T)rGNrTargetArgument.)graphroptargetargskwargs return_typerc Cs||_||_|dkst||_|dkrXt|std|d |d |d tj|d n2t|t std|d |d |d tj|d ||_ i|_ |j t |ddt |ddi|_||_||_||_d|_d|_d|_i|_dS)a} 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 belong. name (str): The name to which the output of this ``Node`` should be assigned op (str): The opcode for this ``Node``. Can be one of 'placeholder', 'call_method', 'call_module', 'call_function', 'get_attr', 'output' target ('Target'): The target this op should call. See the broader ``Node`` docstring for more details. args (Tuple['Argument']): The args to be passed to ``target`` kwargs (Dict[str, 'Argument']): The kwargs to be passed to ``target`` return_type (Optional[Any]): The python type expression representing the type of the output of this node. This field can be used for annotation of values in the generated code or for other types of analyses. placeholder call_method call_module call_functionget_attroutputrootzNode [graph = z , name = 'z '] target z has type z but a Callable is expectedz but a str is expectedcSs|S)Nr)xrrr szNode.__init__..FN)rPrQrRrSrTrUrV)rJrAssertionErrorrKcallable ValueErrorrtypenamer%rErL _input_nodes_Node__update_args_kwargsmap_argusersr&_prev_nextZ_erased_repr_fn _stack_tracemeta)selfrJrrKrLrMrNrOrrr __init__xs( * (  z Node.__init__)rcCs|jS)z Returns the next ``Node`` in the linked list of Nodes. Returns: The next ``Node`` in the linked list of Nodes. )rb)rfrrr nexts z Node.nextcCs|jS)z Returns the previous ``Node`` in the linked list of Nodes. Returns: The previous ``Node`` in the linked list of Nodes. )ra)rfrrr prevs z Node.prev)rWrcCsB|j|jkstd|j|j}|||_|_|||_|_dS)aD Insert x before this node in the list of nodes in the graph. Example:: Before: p -> self bx -> x -> ax After: p -> x -> self bx -> ax Args: x (Node): The node to put before this node. Must be a member of the same graph. z0Attempting to move a Node into a different GraphN)rJrY_remove_from_listrarb)rfrWprrr prepends z Node.prependcCs|jj|dS)z Insert x after this node in the list of nodes in the graph. Equvalent to ``self.next.prepend(x)`` Args: x (Node): The node to put after this node. Must be a member of the same graph. N)rbrl)rfrWrrr appends z Node.appendcCs |j|j}}|||_|_dS)N)rarb)rfrknrrr rjszNode._remove_from_listcCs|jS)a@ The tuple of arguments to this ``Node``. The interpretation of arguments depends on the node's opcode. See the :class:`Node` docstring for more information. Assignment to this property is allowed. All accounting of uses and users is updated automatically on assignment. )_args)rfrrr rMs z Node.args)r2cCs|jt|dd|jdS)z Set the tuple of arguments to this Node. The interpretation of arguments depends on the node's opcode. See the ``fx.Graph`` docstring for more information. cSs|S)Nr)rWrrr rXszNode.args..N)r^r__kwargs)rfr2rrr rM s cCs|jS)aG The dict of keyword arguments to this ``Node``. The interpretation of arguments depends on the node's opcode. See the :class:`Node` docstring for more information. Assignment to this property is allowed. All accounting of uses and users is updated automatically on assignment. )rp)rfrrr rNs z Node.kwargs)r:cCs|j|jt|dddS)z Set the dict of kwargs to this Node. The interpretation of arguments depends on the node's opcode. See the ``fx.Graph`` docstring for more information. cSs|S)Nr)rWrrr rX,szNode.kwargs..N)r^ror_)rfr:rrr rN#s cCst|jjS)aE Return all Nodes that are inputs to this Node. This is equivalent to iterating over ``args`` and ``kwargs`` and only collecting the values that are Nodes. Returns: List of ``Nodes`` that appear in the ``args`` and ``kwargs`` of this ``Node``, in that order. )r?r]keys)rfrrr all_input_nodes.s zNode.all_input_nodes)idxrFrcCs t|j}|||<t||_dS)a3 Update an existing positional argument to contain the new value ``arg``. After calling, ``self.args[idx] == arg``. Args: idx (int): The index into ``self.args`` of the element to update arg (Argument): The new argument value to write into ``args`` N)r?rMrA)rfrsrFrMrrr update_arg<s zNode.update_arg)keyrFrcCst|j}|||<||_dS)a2 Update an existing keyword argument to contain the new value ``arg``. After calling, ``self.kwargs[key] == arg``. Args: key (str): The key in ``self.kwargs`` of the element to update arg (Argument): The new argument value to write into ``kwargs`` N)rCrN)rfrurFrNrrr update_kwargKs zNode.update_kwargcCs|jS)a# Return the Python stack trace that was recorded during tracing, if any. This property is usually populated by `Tracer.create_proxy`. To record stack traces during tracing for debug purposes, set `record_stack_traces = True` on the `Tracer` instance. )rd)rfrrr stack_traceZszNode.stack_trace)tracecCs ||_dS)N)rd)rfrxrrr rwds)new_args new_kwargscs~|_|_xjjD]}|jjqWi_tjfddtjfddxjjD]}|jjqfWdS)zB This API is internal. Do *not* call it directly. cs jj|S)N)r] setdefault)rn)rfrr rXssz+Node.__update_args_kwargs..cs jj|S)N)r]r{)rn)rfrr rXtsN)rorpr]rqr`popr_r{)rfryrzZold_useZnew_user)rfr Z__update_args_kwargshszNode.__update_args_kwargscCs|jr|j|S|jS)N)rcr)rfrrr __repr__ys z Node.__repr__cCs^t|tr|St|drVt|ds*t|S|jdkr@d|jS|jdkrVd|jSt|S)z Make target printouts more user-friendly. 1) builtins will be printed as `builtins.xyz` 2) operators will be printed as `operator.xyz` 3) other callables will be printed with qualfied name, e.g. torch.add rrr#z builtins. _operatorz operator.)r%rEhasattrr/rr)rfrLrrr _pretty_print_target~s       zNode._pretty_print_target)placeholder_namesmaybe_return_typenamercCs|jdkrt|jtst|j}||jr<|dt|jnd7}|rT|j|dS|jrjt|jdnd}|jrdt|jddnd}d |j d |d t |j d |jd |jd| S|jdkr"|jdk rt|jdnd}d |j d |d t |j d |jd |j |jd S|jdkr`|jrP|rPdt|j|d<d|jdS|jdk r|t|jdnd}d |j d |d t |j d |jd |j |jdt |jdt |jdSdS)a Return a descriptive string representation of ``self``. This method can be used with no arguments as a debugging utility. This function is also used internally in the ``__str__`` method of ``Graph``. Together, the strings in ``placeholder_names`` and ``maybe_return_typename`` make up the signature of the autogenerated ``forward`` function in this Graph's surrounding GraphModule. ``placeholder_names`` and ``maybe_return_typename`` should not be used otherwise. Args: placeholder_names: A list that will store formatted strings representing the placeholders in the generated ``forward`` function. Internal use only. maybe_return_typename: A single-element list that will store a formatted string representing the output of the generated ``forward`` function. Internal use only. Returns: str: If 1) we're using ``format_node`` as an internal helper in the ``__str__`` method of ``Graph``, and 2) ``self`` is a placeholder Node, return ``None``. Otherwise, return a descriptive string representation of the current Node. rPz: r7N z (default=rr9r>z : z[#users=z] = z[target=r5rTrUz -> zreturn z ](args = z , kwargs = )rKr%rLrErYr&r,rmrMrrBr`rr0rN)rfrrZarg_strZmaybe_typenameZ default_valrrr format_nodes& "  4 6  zNode.format_node) replace_withrcstj}xb|D]Z}ttdfdd }t|j|}t|j|}t|tsPtt|t s^t|j ||qWt jdkst|S)a  Replace all uses of ``self`` in the Graph with the Node ``replace_with``. Args: replace_with (Node): The node to replace all uses of ``self`` with. Returns: The list of Nodes on which this change was made. )rnrcs|kr S|SdS)Nr)rn)rrfrr maybe_replace_nodesz6Node.replace_all_uses_with..maybe_replace_noder) r?r`rr_rMrNr%rArYrCr^rB)rfrZ to_processZuse_noderryrzr)rrfr replace_all_uses_withs    zNode.replace_all_uses_withFcCsx|jd krdS|jdkr"|jtkS|jdkrt|jjdk s@td|jjj|j}|dk shtd|jt|d d Sd S) z Returns whether this op is impure, i.e. if its op is a placeholder or output, or if a call_function or call_module which is impure. Returns: bool: If the op is impure or not. rPrUTrSrRNz1self.graph.owning_module not set for purity checkz'Did not find expected submodule target Z _is_impureF>rPrU)rKrL_side_effectful_functionsrJZ owning_modulerYZ get_submoduler)rfZ target_modrrr is_impures      zNode.is_impure)rV arg_types kwarg_typesnormalize_to_only_use_kwargsrcCs`|jdkr.t|jstt|j|j|j||S|jdkr\t|jtsHtt ||j|j|jSdS)a Returns normalized arguments to Python targets. This means that `args/kwargs` will be matched up to the module/functional's signature and return exclusively kwargs in positional order if `normalize_to_only_use_kwargs` is true. Also populates default values. Does not support positional-only parameters or varargs parameters. Supports module calls. May require `arg_types` and `kwarg_types` in order to disambiguate overloads. Args: root (torch.nn.Module): Module upon which to resolve module targets. arg_types (Optional[Tuple[Any]]): Tuple of arg types for the args kwarg_types (Optional[Dict[str, Any]]): Dict of arg types for the kwargs normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs. Returns: Returns NamedTuple ArgsKwargsPair, or `None` if not successful. rSrRN) rKrZrLrYrrMrNr%rEr)rfrVrrrrrr normalized_argumentss  zNode.normalized_arguments) old_input new_inputcsZttdfdd }t|j|}t|j|}t|ts.maybe_replace_nodeN) rr_rMrNr%rArYrCr^)rfrrrryrzr)rrr replace_input_with,s   zNode.replace_input_with)N)rI.)rI.)NN)NNF)(rrr'__doc__r rErr rrrgpropertyrhrirlrmrjrIrMsetterrNrrrintrtrvrwr^r}rrrrrrModuleboolrrrrrrr r[sZ0M         "56 )r2fnrcs"tstdt|fddS)zi Apply fn to each Node appearing arg. arg may be a list, tuple, slice, or dict with string keys. z.torch.fx.map_arg(a, fn): fn must be a callablecst|tr|S|S)N)r%r)rW)rrr rXGszmap_arg..)rZrY map_aggregate)r2rr)rr r_Asr_cst|tr tfdd|DSt|tr@tfdd|DSt|trdtfdd|jDSt|trtt|j t|j t|j S|SdS)zi Apply fn to each Node appearing arg. arg may be a list, tuple, slice, or dict with string keys. c3s|]}t|VqdS)N)r)r1elem)rrr r3Osz map_aggregate..c3s|]}t|VqdS)N)r)r1r)rrr r3Qsc3s |]\}}|t|fVqdS)N)r)r1r:r;)rrr r3SsN) r%rAr?rrCr rDslicerstartstopstep)r2rr)rr rIs    $r)3r"rrrrrrrr r Z_compatibilityr Zimmutable_collectionsr rrr#r(Ztorch.fx.operator_schemasrrrrJrrErfloatrZdtypeZTensorZdeviceZ memory_formatZBaseArgumentTypes__args__Z base_typesrHrrIZ_assertopsZprofilerZ_record_function_enterZ_record_function_exitrr!r,r/r0rr_rrrrr sB,         i