o
    ei                     @   sT  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m	Z	 d dl
mZmZ d dlmZmZ d dlmZmZmZ d dlZd dlm  mZ d dlmZ d dlmZ d dlmZ d d	lm Z  d d
l!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2 g dZ3e4e5Z6ee5dZ7de8de9fddZ:de;e8df de<e=e8f de8fddZ>e$ddG dd dZ?e$ddG d d! d!Z@g d"ZAe$d#dG d$d% d%ZBdFd'e=fd(d)ZCe$d#dG d*d+ d+eBZDe$ddd,d- ZEe$d#dG d.d/ d/eFZGe$d#dG d0d1 d1ZHe$ddG d2d3 d3eHZIe$d#dG d4d5 d5eHZJe$ddG d6d7 d7eHZKe'D ]ZLd8d9 ZMeMeL qKd:d; ZNe(D ]ZOeNeO q]d<d= ZPd>d? ZQd@dA g e.eRdeRdejSjTejSjUD ZVdBdC eVeH< dDdC eVe;< dEdC eVeW< eQeVe<< eVeW eVe+< eVe< eVe*< dS )G    N)OrderedDict)CallableIterator)fieldsis_dataclass)AnyOptionalTypeVar)_fx_map_arg)is_opaque_value_type)getArtifactLogger)	tree_map_)CapturedTraceback   )compatibility)Graphmagic_methodsreflectable_magic_methods)immutable_dictimmutable_list)Argument
base_typesNodeTarget)check_for_mutable_operation)	
TracerBaseGraphAppendingTracer
TraceErrorProxy	MetaProxy	AttributeParameterProxyScopeScopeContextManager
annotationobjreturnc                 C   s.   ddl }ddl}t| |j|j|j|j|jfS )z
    Returns True if obj is an arbitrary callable (function, lambda, method, etc.)
    that requires special tracing to handle. These cannot be symbolically traced
    using the standard Proxy mechanism.
    r   N)	functoolstypes
isinstanceFunctionType
MethodTypeBuiltinFunctionTypeBuiltinMethodTypepartial)r%   r'   r(    r/   X/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/fx/proxy.py_is_arbitrary_callable1   s   r1   args.kwargsc                    s:   d t d}d|d|f fdd}t||  t||  S )z
    Recursively searches args and kwargs for any arbitrary callable.
    Returns the first arbitrary callable found, or None if none exist.
    N_Tr%   r&   c                    s    d ur| S t | r|  | S N)r1   )r%   foundr/   r0   checkQ   s
   z'_find_arbitrary_callable.<locals>.check)r	   r   )r2   r3   r4   r8   r/   r6   r0   _find_arbitrary_callableF   s   

r9   Fis_backward_compatiblec                       s*   e Zd ZdZdedef fddZ  ZS )r"   a7  Scope object that records the module path and the module type
    of a module. Scope is used to track the information of the module
    that contains a Node in a Graph of GraphModule. For example::

        class Sub(torch.nn.Module):
            def forward(self, x):
                # This will be a call_method Node in GraphModule,
                # scope for this would be (module_path="sub", module_type=Sub)
                return x.transpose(1, 2)


        class M(torch.nn.Module):
            def __init__(self) -> None:
                self.sub = Sub()

            def forward(self, x):
                # This will be a call_method Node as well,
                # scope for this would be (module_path="", None)
                x = x.transpose(1, 2)
                x = self.sub(x)
                return x

    module_pathmodule_typec                    s   t    || _|| _d S r5   )super__init__r<   r=   )selfr<   r=   	__class__r/   r0   r?   x   s   

zScope.__init__)__name__
__module____qualname____doc__strr   r?   __classcell__r/   r/   rA   r0   r"   ^   s    r"   c                       s:   e Zd ZdZdedef fddZdd Zdd	 Z  ZS )
r#   zA context manager to track the Scope of Node during symbolic tracing.
    When entering a forward function of a Module, we'll update the scope information of
    the current module, and when we exit, we'll restore the previous scope information.
    scopecurrent_scopec                    s0   t    t|| _|j|_|j|_|| _d S r5   )r>   r?   copy_prev_scoper<   r=   _scope)r@   rI   rJ   rA   r/   r0   r?      s
   

zScopeContextManager.__init__c                 C      | j S r5   )rM   r@   r/   r/   r0   	__enter__      zScopeContextManager.__enter__c                 G   s   | j j| j_| j j| j_d S r5   )rL   r<   rM   r=   )r@   r2   r/   r/   r0   __exit__   s   zScopeContextManager.__exit__)	rC   rD   rE   rF   r"   r?   rP   rR   rH   r/   r/   rA   r0   r#   ~   s    r#   )nn_module_stacktorch_fnsource_fn_stackoriginal_aten	recomputeac_graph_idhas_backward_hook	from_nodequantization_tag_numeric_debug_handlecustompartitioner_tagTc                   @   s  e Zd ZU eed< dZeed< dZeed< dZeed< dZ	eed< dZ
eed< dZeed	< eed
< eeeeef f ed< eeeeef f ed< edd		d0dededeedf deeef dee dee defddZdejdejfddZedddeddfdd Zedd			d1dededeedf deeef dee dee d!eegdf fd"d#Zd$d% Zeddd&edefd'd(Z eddd)ddefd*d+Z!eddd)dde"fd,d-Z#eddd)ddefd.d/Z$dS )2r   graphFrecord_stack_traces!_record_forward_stack_traces_onlycheck_mutable_operationstrace_assertsproxy_buffer_attributesforwardtraced_func_namerI   module_stacknode_name_to_scopeTr:   Nkindtargetr2   .r3   name	type_exprr&   c                 C   s  |dkr| j rt||| | j||||||}| jj| jjf| j|j< t	
 rt	 }|d}	|	r@|	|_t	j|	v r@d|jd< tD ]}
|
|v rRt||
 |j|
< qBt|j}|duritd||j ||jd< t	 }|durd|jd< d	|jv r|jd	|jd	< d|jv r|jd|_n| jrt| j|jd
< | jr|jst  }|r| |}|rd|  |_td| |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stack_traceTis_gradient_accNzAssigning new_seq_nr %s to %sseq_nris_functional_regeneratedr]   rS    zcreate_node %s) rb   r   r_   create_noderI   r<   r=   rh   rk   fx_tracebackhas_preserved_node_metaget_current_metagetrn   GRADIENT_ACC_SPECIAL_STACKmeta_COPY_META_FIELDSrK   _get_seq_nrannotation_logdebugget_current_replay_noderg   r`   r   extractsummary_filter_traceback_framesjoinformatstriplog)r@   ri   rj   r2   r3   rk   rl   nodecurrent_metarn   field
new_seq_nrreplay_nodeuser_stack_summaryr/   r/   r0   rs      sR   








zTracerBase.create_noder   c                    s   g }| j rdd |D }n d}t|D ]\}}|jdkr&||d  }|} nq|dkr-g }ddlm   fdd|D }tj|S )Nc                 S   s&   g | ]}|j d ks|jdr|qS )re   ztorch/__init__.py)rk   filenameendswith.0framer/   r/   r0   
<listcomp>  s    

z7TracerBase._filter_traceback_frames.<locals>.<listcomp>re   r   uninteresting_filesc                    s   g | ]
}|j   vr|qS r/   )r   r   r   r/   r0   r   4  s
    )ra   	enumeraterk   %torch.fx.experimental.symbolic_shapesr   	tracebackStackSummary	from_list)r@   r   user_framesfirst_forwardir   r/   r   r0   r     s&   	

z#TracerBase._filter_traceback_framesr   r   c                 C   s
   t || S r5   )r   )r@   r   r/   r/   r0   proxy<     
zTracerBase.proxyproxy_factory_fnc                 C   s~   |  |}|  |}	t|tstdt| t|	ts&tdt|	 | ||||	||}
|s9| |
}|S ||
}|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.
        z Expected args_ to be tuple, got z!Expected kwargs_ to be dict, got )
create_argr)   tupleAssertionErrortypedictrs   r   )r@   ri   rj   r2   r3   rk   rl   r   args_kwargs_r   r   r/   r/   r0   create_proxy@  s   




zTracerBase.create_proxyc                    sF   t   g d} r j  rt fdd|D rn s
 s!dS  S )zf
        Find the Python stack frame executing the user code during
        symbolic tracing.
        )
ztorch/fx/proxy.pyztorch/fx/_symbolic_trace.pyz%torch/fx/experimental/proxy_tensor.pyztorch/_ops.pyztorch/_tensor.pyztorch/utils/_python_dispatch.pyztorch/_prims_common/wrappers.pyztorch/_refs/__init__.pyz%torch/_refs/nn/functional/__init__.pyztorch/utils/_stats.pyc                 3   s     | ]} j j| V  qd S r5   )f_codeco_filenamer   )r   filer   r/   r0   	<genexpr>~  s    
z.TracerBase._find_user_frame.<locals>.<genexpr>N)inspectcurrentframef_backall)r@   pt_filesr/   r   r0   _find_user_framef  s   zTracerBase._find_user_frameac                    s  t t }|dur| S t tr jS t dr" S t trHt dr;fdd D }t | S t fdd D S t t	rVfdd D S t t
r`t S t trwt j j jS t trt j j jS t tjjtjjfr S tt r S t r fdd	t D }d
 jd|S t g ttjR sψ du sψ du rш S tdt  )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.
        N__fx_create_arg___fieldsc                       g | ]}  |qS r/   r   r   elemrO   r/   r0   r         z)TracerBase.create_arg.<locals>.<listcomp>c                    r   r/   r   r   rO   r/   r0   r     r   c                    r   r/   r   r   rO   r/   r0   r     r   c                    s"   i | ]}|j t |j qS r/   )rk   r   getattr)r   r   r   r@   r/   r0   
<dictcomp>  s    z)TracerBase.create_arg.<locals>.<dictcomp>rm   r/   .zargument of type: )_create_arg_bypassrw   r   r)   r   r   hasattrr   r   listr   _create_arg_dictslicer   startstopsteprangetorch_ops
OpOverloadHigherOrderOperatorr   r   r   rs   rB   r   enumEnumNotImplementedError)r@   r   handlerr2   r3   r/   r   r0   r     sP   
















&zTracerBase.create_argr%   c                 C      t d)aF  Called 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 flowr   r@   r%   r/   r/   r0   to_bool     zTracerBase.to_boolc                 C   r   )aA  Called 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.
        aH  Proxy 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 errorsr   r   r/   r/   r0   iter  r   zTracerBase.iterc                 C   s   t |d S )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r    r   r/   r/   r0   r     s   zTracerBase.keysNN)NNN)%rC   rD   rE   r   __annotations__r`   boolra   rb   rc   rd   rf   rG   r"   r   r   r   r   r   r   r   r   r   r   rs   r   r   r   r   r   r   r   r   r   r   r   r   r/   r/   r/   r0   r      s   
 

L
&

	%"J
r   rr   	node_namec                 C   s   t  }d}|dddkrtd|  |d d }ntjj r-td|  |d}ntj	
 d	 }tjj sRt  }|durRd|jv rRtd
|  |jd }|S )a:  
    Returns the seq_nr node meta for the current proxy node that we're creating.
    The seq_nr number in node meta is related to but not the same as the "sequence number"
    in autograd.
    We use the seq_nr to correlate forward and backward nodes in the traced FX graphs
    (e.g. in copy_fwd_metadata_to_bw_nodes).
    The corresponding forward and backward FX graph nodes should have the same seq_nr.

    The ordering of the seq_nr in the graph does not indicate when the node is executed.
    For example, the nodes in the invoke_subgraph HOP's subgraph may be called multiple
    times by different HOP nodes, but these nodes only have a single seq_nr, which may be
    smaller, the same, or larger than the calling HOP.

    `node_name` is the name of the node that we're creating. It is used for logging only.
    N
in_grad_fnr   z+%s: seq_nr from current_meta grad_fn_seq_nrgrad_fn_seq_nrr   z#%s: seq_nr from current_meta seq_nrrp   r   z%s: seq_nr from replay_node)rt   rv   rw   r|   r}   r   fxr   _is_preserving_node_seq_nrautograd_get_sequence_nrr~   ry   )r   r   r   r   r/   r/   r0   r{     s    

r{   c                       s"   e Zd Zdef fddZ  ZS )r   r_   c                    s0   t    || _tdd | _t | _i | _d S )Nrr   )	r>   r?   r_   r"   rI   collectionsr   rg   rh   )r@   r_   rA   r/   r0   r?   2  s
   


zGraphAppendingTracer.__init__)rC   rD   rE   r   r?   rH   r/   r/   rA   r0   r   0  s    r   c                 C   s   | st dd S )NzAssertion failed)r   xr/   r/   r0   	assert_fn:  s   r   c                   @   s   e Zd ZdS )r   N)rC   rD   rE   r/   r/   r/   r0   r   @  s    r   c                   @   s   e Zd ZdZeddd$deddfdd	Zd
efddZd%ddZ	d
e
fddZd
e
fddZdd Zd&ddZd
ed  fddZdd Zd
efddZedddd Zd d! Zed'd"d#ZdS )(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/README.md`
    Tr:   Nr   tracerOptional[TracerBase]c                 C   s"   |d u r	t |j}|| _|| _d S r5   )r   r_   r   r   )r@   r   r   r/   r/   r0   r?   c  s   

zProxy.__init__r&   c                 C      d| j j dS )NzProxy()r   rk   rO   r/   r/   r0   __repr__k     zProxy.__repr__r    c                 C   s
   t | |S r5   r   )r@   kr/   r/   r0   __getattr__n  s   
zProxy.__getattr__c                 C   rN   r5   __dict__rO   r/   r/   r0   __getstate__s  rQ   zProxy.__getstate__c              	   C   s   dd l }i }| j D ](\}}z|||}W n ty.   td|| jj | |}Y nw |||< qd|vr<t	dd|vrDt	dt
|d |d }| D ]	\}}||j|< qQ|S )Nr   zVShallow copy %s of Proxy because it cannot be deepcopied. Proxy is created for node %sr   z.'node' not in new_dict during proxy unpicklingr   z0'tracer' not in new_dict during proxy unpickling)rK   r   itemsdeepcopy	Exceptionr   warningr   rk   r   r   )r@   memorK   new_dictr   vnew_obj	new_proxyr/   r/   r0   __deepcopy__v  s,   
zProxy.__deepcopy__c                 C   s
   || _ d S r5   r   )r@   dr/   r/   r0   __setstate__  r   zProxy.__setstate__c                 O   s   | j dd| f| |S )Ncall_method__call__)r   r   r@   r2   r3   r/   r/   r0   r     s   zProxy.__call__c                    s   t  }|d u rtd|j}|d u rtdtt|j}tj	dkr5ddl
m} |||jdd d}n|jd	 }|| }|jd
krO fddt|jD S  j S )N$inspect.currentframe() returned Noneframe.f_back is None      r   bisect_leftc                 S   rN   r5   offsetr   r/   r/   r0   <lambda>      z Proxy.__iter__.<locals>.<lambda>key   UNPACK_SEQUENCEc                 3   s    | ]} | V  qd S r5   r/   )r   r   rO   r/   r0   r     s    z!Proxy.__iter__.<locals>.<genexpr>)r   r   r   r   r   disget_instructionsr   sysversion_infobisectr  f_lastiopnamer   argvalr   r   )r@   r   calling_frame	inst_listr  inst_idxinstr/   rO   r0   __iter__  s"   


zProxy.__iter__c                 C   s   | j dtj| fi S Nrm   )r   r   operatorabsrO   r/   r/   r0   __abs__  s   zProxy.__abs__c           
      C   s  | j jrt }|d u rtd|j}|d u rtdtt|j	}t
jdkr9ddlm} |||jdd d}n|jd	 }|| }|jd
kr||d  }|jd u rVtd||jd	 d  }|jdkri|jdkpm|jdk}	|	r|jdkr| j dt| fi  dS | j | S )Nr   r  r  r   r  c                 S   rN   r5   r  r   r/   r/   r0   r	    r
  z Proxy.__bool__.<locals>.<lambda>r  r  POP_JUMP_IF_TRUEr   z%inst.arg is None for POP_JUMP_IF_TRUELOAD_GLOBALr   LOAD_ASSERTION_ERRORRAISE_VARARGSrm   T)r   rc   r   r   r   r   r   r  r  r   r  r  r  r  r  r  argr  r   r   r   )
r@   r   r  instsr  curr  firstlaststarts_with_assertr/   r/   r0   __bool__  s6   




zProxy.__bool__c                 C   s   | j | S r5   )r   r   rO   r/   r/   r0   r     s   z
Proxy.keysc                 C   r   )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RuntimeErrorrO   r/   r/   r0   __len__  s   zProxy.__len__c                    s  |r|nd}|r
|ni }i  fdd}t || t || tdkr3tdt  d| tt }t|tj	j
rQ|jf| }|d|j||S tj|r`|d|j||S t|tjjr|t||}|d ur|td|j d	| d
|jd||||j|jdS )Nr/   c                    s   t |  rd | j< d S d S r5   )r)   r   )r   clstracersr/   r0   find_tracer  s   
z-Proxy.__torch_function__.<locals>.find_tracerr   z!Found multiple different tracers z" while trying to trace operations r   z5Unable to symbolically trace the HigherOrderOperator z4 because it received an arbitrary callable argument z(. Use make_fx or dynamo tracing instead.rm   rk   )r   lenr,  r   r   nextr   r)   r   _CScriptMethodownerr   rk   	overridesis_tensor_method_or_propertyrC   r   r   r9   _namer_   _target_to_str)r/  orig_methodr(   r2   r3   r1  r   bad_callabler/   r.  r0   __torch_function__  sJ   



zProxy.__torch_function__r5   )r&   r    )r&   r   r   )rC   rD   rE   rF   r   r   r?   rG   r   r   r   r   r   r   r   r   r  r  r   r*  r   r-  classmethodr>  r/   r/   r/   r0   r   E  s$    

#
r   c                       sN   e Zd ZdZ	ddeddf fddZdefd	d
Zed fdd	Z	  Z
S )r   zW
    A Proxy subclass that propagates metadata (meta['val']) during graph tracing.
    Nr   r   r   c                    s   t  || || _d S r5   )r>   r?   	fake_mode)r@   r   r   r@  rA   r/   r0   r?     s   
zMetaProxy.__init__r&   c                 C   r   )Nz
MetaProxy(r   r   rO   r/   r/   r0   r     r   zMetaProxy.__repr__c                    s   |r|nd}|r
|ni }d }|D ]}t |tr|} nq|d u r$tdt ||||}|j |dd |D i ||jjd< W d    n1 sKw   Y  t|j|j|jS )Nr/   z5No MetaProxy found in arguments, but one is expected.c                 S   s&   g | ]}t |tr|jjd  n|qS )val)r)   r   r   ry   )r   r   r/   r/   r0   r   3  s   & z0MetaProxy.__torch_function__.<locals>.<listcomp>rA  )	r)   r   r   r>   r>  r@  r   ry   r   )r/  r<  r(   r2   r3   
meta_proxyr$  r   rA   r/   r0   r>     s*   
zMetaProxy.__torch_function__r   )rC   rD   rE   rF   r   r?   rG   r   r?  r>  rH   r/   r/   rA   r0   r     s    r   c                   @   s<   e Zd ZedddedefddZedd Zd	d
 Z	dS )r    Tr:   rootattrc                 C   s   || _ || _|j| _d | _d S r5   )rC  rD  r   _node)r@   rC  rD  r/   r/   r0   r?   ;  s   
zAttribute.__init__c                 C   s.   | j d u r| jdt| j| jfi j| _ | j S r  )rE  r   r   r   rC  rD  r   rO   r/   r/   r0   r   B  s   
zAttribute.nodec                 O   s   | j d| j| jf| |S )Nr   )r   r   rD  rC  r   r/   r/   r0   r   L  s   zAttribute.__call__N)
rC   rD   rE   r   r   rG   r?   propertyr   r   r/   r/   r/   r0   r    9  s    
	r    c                       sp   e Zd ZdZdedef fddZdefddZe	d	d
 Z
dd Zdd Ze	dd Zdd Zdd Z  ZS )r!   z
    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
    r   r   c                    s>   t  || t|tjjstdt| || _|| _	d S )NzExpected Parameter, got )
r>   r?   r)   r   nn	Parameterr   r   paramrk   )r@   r   r   rk   rI  rA   r/   r0   r?   Z  s
   
zParameterProxy.__init__r&   c                 C   s   d| j  dS )NzParameterProxy(r   r2  rO   r/   r/   r0   r   a  s   zParameterProxy.__repr__c                 C      | j jS r5   )rI  shaperO   r/   r/   r0   rK  d     zParameterProxy.shapec                 C   
   | j  S r5   )rI  sizerO   r/   r/   r0   rN  h     
zParameterProxy.sizec                 C   rM  r5   )rI  dimrO   r/   r/   r0   rP  k  rO  zParameterProxy.dimc                 C   rJ  r5   )rI  ndimrO   r/   r/   r0   rQ  n  rL  zParameterProxy.ndimc                 C   rM  r5   )rI  numelrO   r/   r/   r0   rR  r  rO  zParameterProxy.numelc                 C   rM  r5   )rI  nelementrO   r/   r/   r0   rS  u  rO  zParameterProxy.nelement)rC   rD   rE   rF   r   r   r?   rG   r   rF  rK  rN  rP  rQ  rR  rS  rH   r/   r/   rA   r0   r!   R  s    

r!   c                    s4    fdd} |_ d d d}tt|| d S )Nc                     s$   | d j }tt }|d|| |S )Nr   rm   )r   r   r  r   )r2   r3   r   rj   methodr/   r0   impl|  s   

z_scope.<locals>.impl___)rC   r   setattrr   )rU  rV  as_magicr/   rT  r0   rM   {  s   rM   c                    s:   d  d d} fdd}||_||_tt|| d S )N__rrX  rW  c                    s    t t }| jd||| fi S r  )r   r  r   r   )r@   rhsrj   orig_method_namer/   r0   rV    s   
z!_define_reflectable.<locals>.impl)r   rC   rE   rY  r   )r^  method_namerV  r/   r]  r0   _define_reflectable  s
   r`  c                 C   s   t d|  )NzJKeys for dictionaries used as an argument cannot contain a Node. Got key: r+  )r$  r/   r/   r0   _no_nodes_error  s
   ra  c                 C   sF   i }|  D ]\}}t|ts| |}t|t | |||< q|S r5   )r   r)   rG   r   map_argra  )r@   r   rr   r   r/   r/   r0   r     s   


r   c                 C   s   i | ]}|d d qS )c                 S   s   |S r5   r/   r@   r   r/   r/   r0   r	    s    z<dictcomp>.<lambda>r/   )r   tr/   r/   r0   r     s    r   c                 C   s   |j S r5   )r   rd  r/   r/   r0   r	    r
  r	  c                    s   t  fdd|D S )Nc                 3   s    | ]}  |V  qd S r5   r   r   rO   r/   r0   r     s    z<lambda>.<locals>.<genexpr>)r   rd  r/   rO   r0   r	    r   c                    s    fdd|D S )Nc                    r   r/   r   r   rO   r/   r0   r     r   z<lambda>.<locals>.<listcomp>r/   rd  r/   rO   r0   r	    s    )rr   )Xr   rK   r  r   r   loggingr  r  r   r   collections.abcr   r   dataclassesr   r   typingr   r   r	   r   torch.fx.tracebackr   rt   torch._Cr
   rb  torch._library.opaque_objectr   torch._loggingr   torch.utils._pytreer   torch.utils._tracebackr   _compatibilityr   r_   r   r   r   immutable_collectionsr   r   r   r   r   r   r   operator_schemasr   __all__	getLoggerrC   r   r|   objectr   r1   r   r   rG   r9   r"   r#   rz   r   r{   r   r   
ValueErrorr   r   r   r    r!   rU  rM   r`  r^  ra  r   r   r   r   r   r   r   r/   r/   r/   r0   <module>   s   




  N7	
 L'&

