/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__/proxy.cpython-36.pyc (14427B)
3 Eg9@spddlZddlZddlZddlZddlZddlmZmZmZddl m Z m Z m Z m Z mZmZmZddlmZmZmZmZmZddlmZddlmZedd Gd d d Zedd Gd d d eZedd GdddeZedd GdddZedd GdddeZ edd GdddeZ!xeD]Z"ddZ#e#e"q2WddZ$xeD]Z%e$e%qZWdS)N) magic_methodsreflectable_magic_methodsGraph)TupleDictOptionalIterableAnyIteratorCallable)TargetNodeArgument base_types map_aggregate) compatibility)check_for_mutable_operationT)is_backward_compatiblec @s2eZdZUedZedZeeddde e e e dfe e e fee eeedddZedded d d d Zeddde e e edfe e efee eeeegd fd ddZddZeddee dddZeddd edddZeddd edddZeddd edddZdS) TracerBaseFT)rN.)kindtargetargskwargsname type_exprreturncCs0|dkr|jrt||||jj||||||S)a' Inserts a graph node given target, args, kwargs, and name. This method can be overridden to do extra checking, validation, or modification of values used in node creation. For example, one might want to disallow in-place operations from being recorded. call_function)check_mutable_operationsrgraph create_node)selfrrrrrrr":/usr/local/lib64/python3.6/site-packages/torch/fx/proxy.pyr s  zTracerBase.create_nodeProxy)nodercCs t||S)N)r$)r!r%r"r"r#proxy%szTracerBase.proxy)rrrrrrproxy_factory_fncCs|j|}|j|} t|ts"tt| ts0t|j|||| ||} |sT|j| } n|| } |jr|j} | rt j | } t j j | }|j }dj|| j_| S)ao Create a Node from the given arguments, then return the Node wrapped in a Proxy object. If kind = 'placeholder', then we're creating a Node that represents the parameter of a function. If we need to encode a default parameter, we use the ``args`` tuple. ``args`` is otherwise empty for ``placeholder`` Nodes. ) create_arg isinstancetupleAssertionErrordictr r&record_stack_traces_find_user_frame traceback walk_stack StackSummaryextractformatjoinr%Z stack_trace)r!rrrrrrr'args_kwargs_r%r&Z user_frameZwalk_stack_gensummaryZtb_linesr"r"r# create_proxy)s      zTracerBase.create_proxycsHtjddg}x*r:jrtfdd|DrPqWsDdSS)zf Find the Python stack frame executing the user code during symbolic tracing. ztorch/fx/proxy.pyztorch/fx/symbolic_trace.pyc3s|]}jjj| VqdS)N)f_code co_filenameendswith).0file)framer"r# [sz.TracerBase._find_user_frame..N)inspect currentframef_backall)r!Zfx_filesr")r?r#r/NszTracerBase._find_user_frame)arcsLt|t r t|dr |jSt|trVt|drVtfdd|D}t||St|ttfr~t|fdd|DSt|tri}x>|jD]2\}}j |}dd}t ||j |||<qW|St|t rt j |j j |j j |jSt|tr|jSt|ts2|dks2|d kr6|Std t|dS) z A method that lowers the objects seen as arguments during symbolic evaluation into Argument types that can be stored in IR. Can be override to support more trace-specific types. __fx_create_arg___fieldsc3s|]}j|VqdS)N)r))r=elem)r!r"r#r@rsz(TracerBase.create_arg..c3s|]}j|VqdS)N)r))r=rH)r!r"r#r@uscSst|trtddS)NzMKeys for dictionaries used as an argument cannot contain a Node. Got key: {k})r*r RuntimeError)argr"r"r#no_node~s z&TracerBase.create_arg..no_nodeN.zargument of type: )r*r$hasattrrFr+typelistr-itemsr)rslicestartstopstepr%rNotImplementedError)r!rErrkvrKr")r!r#r)cs,      $  zTracerBase.create_arg)objrcCs tddS)aFCalled when a proxy object is being converted to a boolean, such as when used in control flow. Normally we don't know what to do because we don't know the value of the proxy, but a custom tracer can attach more information to the graph node using create_node and can choose to return a value. zFsymbolically traced variables cannot be used as inputs to control flowN) TraceError)r!rXr"r"r#to_boolszTracerBase.to_boolcCs tddS)aACalled when a proxy object is being iterated over, such as when used in control flow. Normally we don't know what to do because we don't know the value of the proxy, but a custom tracer can attach more information to the graph node using create_node and can choose to return an iterator. aHProxy object cannot be iterated. This can be attempted when the Proxy is used in a loop or as a *args or **kwargs function argument. See the torch.fx docs on pytorch.org for a more detailed explanation of what types of control flow can be traced, and check out the Proxy docstring for help troubleshooting Proxy iteration errorsN)rY)r!rXr"r"r#iterszTracerBase.itercCs t|dS)zCalled when a proxy object is has the keys() method called. This is what happens when ** is called on a proxy. This should return an iterator it ** is suppose to work in your custom tracer. keys) Attribute)r!rXr"r"r#r\szTracerBase.keys)NN)NNN)__name__ __module__ __qualname__rrr.boolrrstrr rrrrr rr r&r r9r/r)rZr r[r\r"r"r"r#r s( 6 @"-rcs"eZdZedfdd ZZS)GraphAppendingTracer)rcstj||_dS)N)super__init__r)r!r) __class__r"r#res zGraphAppendingTracer.__init__)r^r_r`rre __classcell__r"r")rfr#rcsrcc@s eZdZdS)rYN)r^r_r`r"r"r"r#rYsrYc@seZdZdZedddeddddZed d d Zd d d dZ dd ddZ e dd ddZ e d ddZeddddZddZedddZdS)r$a ``Proxy`` objects are ``Node`` wrappers that flow through the program during symbolic tracing and record all the operations (``torch`` function calls, method calls, operators) that they touch into the growing FX Graph. If you're doing graph transforms, you can wrap your own ``Proxy`` method around a raw ``Node`` so that you can use the overloaded operators to add additional things to a ``Graph``. ``Proxy`` objects cannot be iterated. In other words, the symbolic tracer will throw an error if a ``Proxy`` is used in a loop or as an ``*args``/``**kwargs`` function argument. There are two main ways around this: 1. Factor out the untraceable logic into a top-level function and use ``fx.wrap`` on it. 2. If the control flow is static (i.e. the loop trip count is based on some hyperparameter), the code can be kept in its original position and refactored into something like:: for i in range(self.some_hyperparameter): indexed_item = proxied_value[i] For a more detailed description into the Proxy internals, check out the "Proxy" section in `torch/fx/OVERVIEW.md` T)rNzOptional[TracerBase])r%tracercCs"|dkrt|j}||_||_dS)N)rcrrhr%)r!r%rhr"r"r#res zProxy.__init__)rcCsd|jjdS)NzProxy())r%r)r!r"r"r#__repr__szProxy.__repr__r]cCs t||S)N)r])r!rVr"r"r# __getattr__szProxy.__getattr__cOs|jjdd|f||S)N call_method__call__)rhr9)r!rrr"r"r#rmszProxy.__call__csntj}|dk st|j}|dk s&tttj|j|jd}|j dkrbfddt |j DSj j S)NUNPACK_SEQUENCEc3s|]}|VqdS)Nr")r=i)r!r"r#r@sz!Proxy.__iter__..)rArBr,rCrNdisget_instructionsr:f_lastiopnamerangeargvalrhr[)r!r?Z calling_frameinstr")r!r#__iter__s   zProxy.__iter__cCs |jj|S)N)rhrZ)r!r"r"r#__bool__szProxy.__bool__cCs |jj|S)N)rhr\)r!r"r"r#r\sz Proxy.keyscCs tddS)Nz'len' is not supported in symbolic tracing by default. If you want this call to be recorded, please call torch.fx.wrap('len') at module scope)rI)r!r"r"r#__len__sz Proxy.__len__cs|r|nf}|r|ni}ifdd}tjjj||tjjj||tdkrrtdtjd|tt j}t |tj j r|j f|}|jd|j||Stjj|r|jd|j||S|jd||||jj|jdSdS) Ncst|rd|j<dS)N)r*rh)rE)clstracersr"r# find_tracer s z-Proxy.__torch_function__..find_tracerrz!Found multiple different tracers z" while trying to trace operations rlr)r)torchZfxr%rlenrIrNr\nextr[r*_CZ ScriptMethodownerr9rZ overridesZis_tensor_method_or_propertyr^rZ_target_to_str)r{Z orig_methodtypesrrr}rhr")r{r|r#__torch_function__s       zProxy.__torch_function__)N)NN)r^r_r`__doc__rrrerbrjrkrmr rxraryr\rz classmethodrr"r"r"r#r$s r$c@s:eZdZeddeedddZeddZdd Z d S) r]T)r)rootattrcCs||_||_|j|_d|_dS)N)rrrh_node)r!rrr"r"r#re#szAttribute.__init__cCs.|jdkr(|jjdt|j|jfij|_|jS)Nr)rrhr9getattrrrr%)r!r"r"r#r%*s zAttribute.nodecOs|jjd|j|jf||S)Nrl)rhr9rr)r!rrr"r"r#rm2szAttribute.__call__N) r^r_r`rr$rbrepropertyr%rmr"r"r"r#r]!s r]FcsneZdZdZeedfdd ZedddZe dd Z d d Z d d Z e ddZ ddZddZZS)ParameterProxyz A special proxy which lets "shape", "size", "dim", and a few other attribute accesses pass through to the underlying module parameter object, so that conditional tests on these attributes will not throw exception during tracing )rhr%cs0tj||t|tjjs t||_||_dS)N) rdrer*r~nn Parameterr,paramr)r!rhr%rr)rfr"r#re=szParameterProxy.__init__)rcCsd|jdS)NzParameterProxy(ri)r)r!r"r"r#rjCszParameterProxy.__repr__cCs|jjS)N)rshape)r!r"r"r#rFszParameterProxy.shapecCs |jjS)N)rsize)r!r"r"r#rJszParameterProxy.sizecCs |jjS)N)rdim)r!r"r"r#rMszParameterProxy.dimcCs|jjS)N)rndim)r!r"r"r#rPszParameterProxy.ndimcCs |jjS)N)rnumel)r!r"r"r#rTszParameterProxy.numelcCs |jjS)N)rnelement)r!r"r"r#rWszParameterProxy.nelement)r^r_r`rrrrerbrjrrrrrrrrgr"r")rfr#r6s  rcs4fdd}|_djdd}tt||dS)Ncs$|dj}tt}|jd|||S)Nrr)rhroperatorr9)rrrhr)methodr"r#impl]s  z_scope..impl___)r^stripsetattrr$)rrZas_magicr")rr#_scope\s rcs:djdd}fdd}||_||_tt||dS)NZ__rrrcs tt}|jjd|||fiS)Nr)rrrhr9)r!rhsr)orig_method_namer"r#ris z!_define_reflectable..impl)rr^r`rr$)r method_namerr")rr#_define_reflectablefs  r)&rqr~rArr0rrrrtypingrrrr r r r r%r rrrrZ_compatibilityrZoperator_schemasrrrc ValueErrorrYr$r]rrrrrr"r"r"r#s4$  (c$