
    קgg                        d dl Z d dlmZ d dlmZmZmZmZm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  e j        d          d             Z e j        d          d             Z G d de	j        j                  ZdS )	    N)nullcontext)AnyCallableDictOptionalSequence)torch_function_passthroughc            	      	   t           t           j        ft           j        t           j        j        ft           j        j        t           j        j        j        ft           j        t           j        j        ft           j        t           j        j        ft           j        t           j        j        fg} i t           j        j        t           j        j	        t           j        j
        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j         t           j        j         t           j        j!        t           j        j!        t           j        j"        t           j        j"        t           j        j#        t           j        j#        t           j        j$        t           j        j$        t           j        j%        t           j        j%        t           j        j&        t           j'        j(        t           j        j)        t           j'        j)        i}| D ]D\  }}|j*        D ]7}|j+        ,                    |          ||j+        ,                    |          <   8Et[          t           j                  D ]T}|t           j        j*        v r?t           j        j+        ,                    |          |t]          t           j        |          <   Ut           j        j/        j*        D ]^}t]          t           j        |d          pt]          t           |          }t           j        j/        j+        ,                    |          ||<   _|S )z}
    Mapping of torch API functions to torch._refs functions.
    E.g. torch_to_refs_map()[torch.add] == torch._refs.add
    N)0torch_refsnn
functionalspecialfftlinalgTensor
__invert__bitwise_not__xor__bitwise_xor__and__bitwise_and__or__
bitwise_or__eq__eq__rsub__rsub__rtruediv__rtruediv__floordiv__floor_divide__rfloordiv__	rfloordiv__pow__pow__rpow__rpow	new_emptynew_full	new_zerosnew_onesfill_zero_tosum_to_sizecopy__primscopy_toresize__all____dict__getdirgetattr_conversions)modulesr	mod_torchmod_refsstensor_attrs         P/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/_prims/context.pytorch_to_refs_maprB      s;    
	5;>"		ekn78	+,	EKO$	u{)*G!8ek5 	ek5 	U[3	
 	U[^ 	u{/ 	!5;#7 	!5;#; 	"EK$9 	eko 	u{/ 	 5 	u{3 	 5 	u{3  	EK-!" 	EK-#$ 	 %+"9EL0U\0- A0  ' D D	8! 	D 	DA+3+<+@+@+C+CAi $$Q''((	D  F F###*/+*>*B*B1*E*EAgelA&&' [%- B BelAt44Iq8I8I1:>>qAA+H    c                  8    d t           j        j        D             S )zJ
    Set of all prim functions, e.g., torch._prims.add in all_prims()
    c                 V    h | ]&}t           j        j                            |          'S  )r   r2   r6   r7   ).0r?   s     rA   	<setcomp>zall_prims.<locals>.<setcomp>M   s+    GGGQEL!%%a((GGGrC   )r   r2   r5   rF   rC   rA   	all_primsrI   H   s    
 HG%,2FGGGGrC   c            
       X    e Zd ZdZdd efdZ	 	 ddeded	ee         d
e	e
         fdZdS )TorchRefsModeaB  
    Switches the interpretation of torch.* functions and Tensor methods to
    use PrimTorch refs in torch._refs.  (Direct calls to _refs are unaffected.)

    >>> # xdoctest: +SKIP
    >>> with TorchRefsMode():
    ...     torch.add(x, y)  # calls torch._refs.add(x, y)

    By default, this context manager will fall back on the torch.* if the
    ref does not exist; set strict=True to error if this occurs.
    If the ref exists we still would like to fall back on the torch.* sometimes,
    this behavior can be customized by passing a function to should_fallback_fn.
    Fc                      dS )NFrF   )_s    rA   <lambda>zTorchRefsMode.<lambda>b   s    e rC   c                 0    || _         || _        || _        d S )N)strictshould_fallback_fnprims_mode_cls)selfrP   rQ   rR   s       rA   __init__zTorchRefsMode.__init___   s!     "4,rC   rF   N	orig_functypesargskwargsc                 2   |i }|t           v s|t                      v r4|                                 5   ||i |cd d d            S # 1 swxY w Y   t                      }|                    |d           }|Et          |t          j        j                  r&t          j	        j
                            |d           }nY|Wt          |t          j        j                  r8t          |dd           }|%t          j	        j
                            |d           }|C|                     | ||||          r ||i |S | 5   ||i |cd d d            S # 1 swxY w Y   | j        r/t          dt          j                            |                      ||i |S )Ndefaultzno _refs support for )r	   rI   rR   rB   r7   
isinstancer   _ops
OpOverload_decompdecomposition_tableOpOverloadPacketr9   rQ   rP   RuntimeError	overridesresolve_name)rS   rU   rV   rW   rX   mappingfuncrZ   s           rA   __torch_function__z TorchRefsMode.__torch_function__i   s>    >F 222i9;;6N6N$$&& 2 2 y$1&112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2#%%{{9d++ <Jy%*2GHH<=488DIIDD\jEJ4OPP\iD99G"}8<<WdKK&&tYdFKK 2 y$1&111 - -tT,V,,- - - - - - - - - - - - - - - -; 	Q(D(DY(O(OQQ   y$)&)))s#   AAA;EEE)rF   N)__name__
__module____qualname____doc__r   rT   r   r   r   r   r   rf   rF   rC   rA   rK   rK   P   s           ++"	- - - - !!%)* )*)* )* sm	)*
 )* )* )* )* )* )*rC   rK   )	functools
contextlibr   typingr   r   r   r   r   r   torch._decomptorch._primstorch._refstorch._refs.nntorch._refs.nn.functionaltorch._refs.specialtorch.overridestorch._prims_commonr	   	lru_cacherB   rI   rb   TorchFunctionModerK   rF   rC   rA   <module>rx      sU       " " " " " " : : : : : : : : : : : : : :                                  : : : : : : T3 3 3l TH H HB* B* B* B* B*EO5 B* B* B* B* B*rC   