
    sgg                        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y)	    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                  j0                  t         j                  j2                  t         j                  j4                  t         j                  j6                  t         j                  j8                  t         j                  j:                  t         j                  j<                  t         j                  j<                  t         j                  j>                  t         j                  j>                  t         j                  j@                  t         j                  j@                  t         j                  jB                  t         j                  jB                  t         j                  jD                  t         j                  jD                  t         j                  jF                  t         j                  jF                  t         j                  jH                  t         j                  jH                  t         j                  jJ                  t         j                  jJ                  t         j                  jL                  t         jN                  jP                  t         j                  jR                  t         jN                  jR                  i}| D ]M  \  }}|jT                  D ]9  }|jV                  jY                  |      ||jV                  jY                  |      <   ; O t[        t         j                        D ]c  }|t         j                  jT                  v s t         j                  jV                  jY                  |      |t]        t         j                  |      <   e t         j                  j^                  jT                  D ]e  }t]        t         j                  |d      xs t]        t         |      }t         j                  j^                  jV                  jY                  |      ||<   g |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         G/var/www/html/venv/lib/python3.12/site-packages/torch/_prims/context.pytorch_to_refs_maprB      s0    
	5;;>>"			ekknn778	++,	EKKOO$	u{{))*G!8!8ekk55 	ekk55 	U[[33	
 	U[[^^ 	u{{// 	!!5;;#7#7 	!!5;;#;#; 	""EKK$9$9 	ekkoo 	u{{// 	 5 5 	u{{33 	 5 5 	u{{33  	EKK--!" 	EKK--#$ 	  %++"9"9ELL00U\\00-A0  ' D	8!! 	DA+3+<+<+@+@+CAi  $$Q'(	DD
  F###*/++*>*>*B*B1*EAgellA&'F
 [[%%-- BellAt4Iq8I11::>>qA+B H    c                      t         j                  j                  D  ch c]+  } t         j                  j                  j	                  |       - c} S c c} w )zJ
    Set of all prim functions, e.g., torch._prims.add in all_prims()
    )r   r2   r5   r6   r7   )r?   s    rA   	all_primsrE   H   s7    
 38,,2F2FGQELL!!%%a(GGGs   0Ac            
       J    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y)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                       y)NF )_s    rA   <lambda>zTorchRefsMode.<lambda>b   s    rC   c                 .    || _         || _        || _        y )N)strictshould_fallback_fnprims_mode_cls)selfrM   rN   rO   s       rA   __init__zTorchRefsMode.__init___   s     "4,rC   N	orig_functypesargskwargsc                 $   |i }|t         v s|t               v r"| j                         5   ||i |cd d d        S t               }|j	                  |d       }|Ot        |t        j                  j                        r+t        j                  j                  j	                  |d       }n_|]t        |t        j                  j                        r9t        |dd       }|*t        j                  j                  j	                  |d       }|1| j                  | ||||      r ||i |S | 5   ||i |cd d d        S | j                  r+t        dt        j                   j#                  |              ||i |S # 1 sw Y   HxY w# 1 sw Y   UxY w)Ndefaultzno _refs support for )r	   rE   rO   rB   r7   
isinstancer   _ops
OpOverload_decompdecomposition_tableOpOverloadPacketr9   rN   rM   RuntimeError	overridesresolve_name)rP   rR   rS   rT   rU   mappingfuncrW   s           rA   __torch_function__z TorchRefsMode.__torch_function__i   s    >F 22i9;6N$$& 2 $1&12 2#%{{9d+ <Jy%**2G2GH==4488DID\jEJJ4O4OPiD9G"}}88<<WdK&&tYdFK $1&11 -T,V,- -;;'(D(DY(O'PQ  $)&));2 2.- -s   E9(F9FF)rI   N)__name__
__module____qualname____doc__r   rQ   r   r   r   r   r   rc   rI   rC   rA   rG   rG   P   sR      +"	- !!%)*)* )* sm	)*
 )*rC   rG   )	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   rE   r_   TorchFunctionModerG   rI   rC   rA   <module>ru      s     " : :          : T3 3l TH HB*EOO55 B*rC   