
    Ph                        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mZ d dlm	Z	 ddl
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mZmZ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#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9  ejt                  e;      Z<ejz                  j|                  fZ?ej                  j                  j                  ej                  gZDej                  ej                  j                  ej                  j                  ej                  ej\                  j                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  j                  j                  j                  ej                  ejz                  j                  gZZej\                  j                         rPeZj                  ej\                  j                  ej\                  j                  ej\                  j                  g       ej                  j                  dej                  j                  dejz                  j                  dej                  j                  j                  dej                  j                  dej                  j                  j                  dej                  j                  diZj G d de)      Zk G d dek      Zl G d dek      Zm G d dek      Zny# e$ r dZY !w xY w)    N)DictList)_StreamBase   )install_guard)configpolyfill	variables)torch_get_name) get_registered_device_interfaces)unimplemented)GuardBuilder)check_constant_argscheck_unspec_python_argshas_torch_functionistypeproductproxy_args_kwargstensortype_to_dtype   )VariableTracker)AutocastModeVariableNullContextVariableTorchFunctionDisableVariable)is_constant_pg_functionsis_from_localProcessGroupVariable) TorchHigherOrderOperatorVariable)ListVariableTupleVariable)can_dispatch_torch_functiondispatch_torch_functionFTc                   V     e Zd ZdZed        Z fdZd Zd Zd Z	d Z
d Zd	 Z xZS )
BaseTorchVariablezHcommon base for all torch.* functions, classes, modules and other thingsc                 f    t        |j                  t        j                                | ||      S )Nsource)r   
make_guardr   FUNCTION_MATCH)clsvaluer'   s      hC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/variables/torch.pycreate_with_sourcez$BaseTorchVariable.create_with_sourceg   s.    f''(C(CDE
 	
    c                 2    t        |   di | || _        y )N )super__init__r+   )selfr+   kwargs	__class__s      r,   r2   zBaseTorchVariable.__init__o   s    "6"
r.   c                     t        t        dt        t                     }dt        j                  dd|      z   }|j                  |t        d      S )Nallowed_fn___z[^a-zA-Z0-9_]+_F)r   r+   idresubsetup_globally_cached)r3   codegennameunique_var_names       r,   reconstructzBaseTorchVariable.reconstructs   sF    e{2e9+%>?(93!EE,,_eUKKr.   c                     | j                   S Nr+   r3   s    r,   as_proxyzBaseTorchVariable.as_proxyx       zzr.   c                 ,    t        | j                        S rC   )typer+   rE   s    r,   python_typezBaseTorchVariable.python_type{   s    DJJr.   c                     | j                   S rC   rD   rE   s    r,   as_python_constantz$BaseTorchVariable.as_python_constant~   rG   r.   c                 l    t        | j                  |      }t        j                  j	                  |      S rC   )hasattrr+   r
   ConstantVariablecreate)r3   txr?   results       r,   call_hasattrzBaseTorchVariable.call_hasattr   s)    T*))0088r.   c                 \    | j                   t        v ryt        | j                   dd       dk(  S )NT
__module__math)r+   constant_fold_functionsgetattrrE   s    r,   can_constant_fold_throughz+BaseTorchVariable.can_constant_fold_through   s*    ::00tzz<6&@@r.   )__name__rU   __qualname____doc__classmethodr-   r2   rA   rF   rJ   rL   rS   rY   __classcell__r5   s   @r,   r$   r$   d   s=    R
 
L
 9Ar.   r$   c                   *    e Zd ZdZd Z	 	 	 	 	 	 ddZy)TorchCtxManagerClassVariablezLPoints to a context manager class in torch.* that dynamo has implementationsc                 "    d| j                    dS )NzTorchCtxManagerClassVariable()rD   rE   s    r,   __repr__z%TorchCtxManagerClassVariable.__repr__       .tzzl!<<r.   c           
      D   ddl m}m}m} | j                  t
        j                  u rlt        |      dk(  rLt        |d   t        j                  j                        r%|j                  |d      }|j                  |||      S |j                  |d      S | j                  t
        j                  u rlt        |      dk(  rLt        |d   t        j                  j                        r%|j                  |d      }|j                  |||      S |j                  |d      S | j                  t
        j                  u r3t        |      dk(  r%|j                  ||d   j!                         d      S | j                  t
        j"                  u r#|j                  ||d   j!                               S t%        j&                  | j                        rPt)        | j                  t*              r6ddlm}  ||||j0                  j3                  d| j                  d	i             S | j                  t
        j4                  j6                  j8                  t
        j:                  j4                  j8                  t
        j<                  j4                  j8                  fv r!t?        j                  | j                  ||      S | j                  t
        j@                  jB                  t
        j@                  jD                  t
        jF                  j@                  jB                  t
        jF                  j@                  jD                  fv r*tH        jK                  d
| j                         tM               S | j                  t
        jN                  jP                  u r|s|rJ tS        j                  |      S y )Nr   )GradModeVariableInferenceModeVariableStreamVariabler   FT)initialized)wrap_fx_proxy_clscall_functionr0   z$Profiler function %s will be ignored)* rg   rh   ri   r+   torchno_gradlen
isinstancer
   	functionsBaseUserFunctionVariablerP   rl   enable_gradset_grad_enabledrL   inference_modeinspectisclass
issubclassr   torch._dynamo.variables.builderrk   outputcreate_proxyampautocast_modeautocastcudacpur   profilerprofilerecord_functionautogradlogwarningr   _CDisableTorchFunctionSubclassr   )	r3   rQ   argsr4   rg   rh   ri   ctxrk   s	            r,   rl   z*TorchCtxManagerClassVariable.call_function   s    	NM::&4yA~*Q,,EE# '--b%8((T6::'..r599ZZ5,,,4yA~*Q,,EE# '--b$7((T6::#**2t44ZZ5111c$i1n#**DG..0d +   ZZ5///(//DG4N4N4PQQ__TZZ(Z

K-PI$		&&#JJ		 	 ZZII##,,JJNN##IIMM""
 

 (..tzz4HHZZNN""NN**NN##++NN##33	
 
 KK>

K&((ZZ588@@@''/66r:: Ar.   Nr   zList[VariableTracker]r4   zDict[str, VariableTracker]returnr   )rZ   rU   r[   r\   rd   rl   r0   r.   r,   ra   ra      s'    V=7;/7;9U7;	7;r.   ra   c                   0    e Zd ZdZd Z	 	 	 	 	 	 ddZd Zy)TorchInGraphFunctionVariablez@Points to a torch function/method that should be put in FX graphc                 "    d| j                    dS )NzTorchInGraphFunctionVariable(rc   rD   rE   s    r,   rd   z%TorchInGraphFunctionVariable.__repr__   re   r.   c                 $   $%&'( ddl m}m}m}m}m}m$m%m}	 ddl	m
}
m} t        ||      }t        ||      } j                         ru|s|rq|j                    j!                         |D cg c]  }|j!                          c}i |j#                         D ci c]  \  }}||j!                          c}}      S  j$                  t&        v r|s|rJ  j$                  t(        j*                  j,                  t(        j.                  j0                  j,                  fv r|j3                          |j                  t&         j$                           S  j$                  t(        j4                  j6                  j8                  t(        j4                  j:                  j<                  fv r<t?        j@                   j$                   jB                        jE                  |||      S  j$                  t(        jF                  jH                  u r0ddl	m%}   |       |t(        jF                  jI                               S  j$                  tL        jN                  k(  r7|s5|s3ddl	m%} |jQ                    |       |tR        jN                        ||      S  j$                  t(        jT                  t(        jF                  jV                  fv rtY        |      dk(  sJ t[        |d   %      sN j$                  t(        jF                  jV                  u r9t[        |d   |	      r*t]        |d   j$                  d      r|j                  d      S |j                  d	      S  j$                  t(        j^                  t(        j`                  fv rd }|r|d   }nd
|v sJ |d
   }t[        |%      r|jb                   j$                  t(        j^                  u r%|j                  |jb                  j^                        S  j$                  t(        j`                  u r%|j                  |jb                  j`                        S te        d j$                         y y  j$                  t(        jf                  u rEt[        |d   %      r6|d   jh                  '|j                  tk        |d   jh                              S  j$                  tl        v r8tY        |      dk(  sJ t[        |d   %      sJ |d   jo                  |dg i       S  j$                  t(        jp                  jr                  jt                  jv                  t(        jp                  jr                  jt                  jx                  t(        jp                  jr                  jt                  jz                  t(        jp                  jr                  jt                  j|                  t(        jp                  jr                  jt                  j~                  fv r j                  |||      S  j$                  t(        j                  u r>|s|rJ t        |j                         |j                  t)        j                               S  j$                  t(        j                  u r1tY        |      dk(  r#|j                  ||d   j!                               S  j$                  t(        j                  u r>|s|rJ t        |j                         |j                  t)        j                               S  j$                  t(        j                  j                  j                  u r3tY        |      dk(  sJ |j                  ||d   j!                               S  j$                  t(        j                  j                  u rD|s|rJ t        t        j                         |j                  |j                  j                        S  j$                  t(        jF                  j                  t(        jF                  j                  t(        jF                  j                  fv r%|rJ |j                  t        d |D                    S t         fdt               D cg c]  \  }}|j                   c}}D              r%tY        |      dk(  sJ |j                  ||d         S  j$                  t(        j                  u rlt        j                  st        d       t        st        d        |%| |j                  j                  dt(        j                  gt        |i        d       S t        |||      rt        | ||      S  j$                  t(        j                  j                  u rtY        |      dk(  sJ |d   S  j$                  t(        j                  j                  j                  u rtY        |      dk(  sd|v sJ d       tY        |      dkD  r|d   n|d   }t[        |%      sJ d       t)        j                  d|jb                  |j                        }|j                  t(        j                  j                  j                  |            S  j$                  t(        jf                  k(  r[tY        |      dk(  rMt[        |d   %      r>tY        |      dk(  r0 |
| |j                  j                  ddgt        ||             S  j$                  t(        j                  j                  j                  t(        j                  j                  j                  j                  fv rFtY        |      dk(  r8tY        |      dk(  r*t[        |d   %      r|d   jo                  |d|d   gi       S  j$                  t(        j                  j                  j                  t(        j                  j                  j                  j                  gu rFtY        |      dk(  r8tY        |      dk(  r*t[        |d   %      r|d   jo                  |d|d   gi       S  j$                  t(        j                  k(  rtY        |      dk(  rd|v rtY        |      dk(  rt        t(        j                        jE                  ||dd  i       }t        t(        j                        jE                  |||d   gi       }t        t(        j                        jE                  ||d   |gi       S t         j$                        r`tY        |      dk(  sJ d       t[        |d   t              sJ  j%                  |d   j!                               }ddl	m%}   |       ||      S t         j$                        r|dd  D cg c]  }|j!                          c}&|j#                         D ci c]  \  }}||j!                          c}}(&( fd}d  j$                  j                  z   |_r         |
| |j                  j                  d|gt        |d   gi              S  j$                  t(        j                  j                  u r<|j                  d!t(        j                        t(        j                  k(  rt        d"      t        $fd#|D              }t        d$ |D              }h d%}t         j$                  d&d'      d(k(  rU j$                  j                  |v r=|r;|r9d)t         j$                         d*}t        j                  |       t        |       j$                  }t        $fd+|D              r% j$                  tL        j                  k(  rdd,l}m~} |}|t(        j                  u rH$%'fd-'d } |r|d   } n	d.|v r|d.   } t[        | %      s" '|       rt(        j                  j                  } |
| |j                  j                  d|gt        ||             }t[        |%      r"d/|v r|d/   j!                         rt        d0       d1|v rt[        |d1   t         j                        r|d1   j!                         t[        |t              rt[        |d1   t        t        f      sJ |d1   j"                  D cg c]  }|j                  |       }!}t	        |!      D ]2  \  }"}#|#|j
                  v s|j"                  |"   |j
                  |#<   4 |S t[        |%      rt[        |d1   %      sJ |d1   jB                  rC|d1   |j                  j                  v r'|d1   jh                  |jh                  k7  rt        d2       d3|d1   j                  j                  j                  v sJ t(        j                  j                  |d1   j                  j                  j                  d3         st        d4       |j                  |d1         }#|#|j
                  v r||j
                  |#<   |S t        d5t        |d1                 |S c c}w c c}}w c c}}w c c}w c c}}w c c}w )6Nr   )rO   DeterministicAlgorithmsVariable!DisabledSavedTensorsHooksVariablerg   StreamContextVariableSymNodeVariableTensorVariableUserDefinedObjectVariable)wrap_fx_proxyrk   r&   )SourcelessBuilderr   __torch_function__TFinputzcalling sizec              3   2   K   | ]  }t        |        y wrC   )r   ).0as     r,   	<genexpr>z=TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>W  s     84a&q)4s   c              3   :   K   | ]  }j                   |u   y wrC   rD   )r   methodr3   s     r,   r   z=TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>Y  s&      
 JJ& s   z-torch.from_numpy. config.trace_numpy is Falsez(torch.from_numpy. NumPy is not availablerl   )
target_clsrQ   proxyexample_valuer   tensorz%Expect 1 input to cudnn.is_acceptablez2Expect input to cudnn.is_acceptable to be a tensor)dtypedevicecall_methodnumelrQ   r   stride   r+   zExpected one arg (pg)c                 0     j                   | gi S rC   rD   )xargs_as_valuekwargs_as_valuer3   s    r,   fn_with_prim_typeszFTorchInGraphFunctionVariable.call_function.<locals>.fn_with_prim_types  s    !tzz!GmGGGr.   zprim layoutz3torch.compile does not support strided NestedTensorc              3   6   K   | ]  }t        |        y wrC   rq   r   r   r   s     r,   r   z=TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>  s     *XSWa:a+ISW   c              3   p   K   | ].  }t        |t        j                  t        j                  f       0 y wrC   )rq   r
   rO   r   r   r   s     r,   r   z=TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>  s0      %A 1y999;T;TUVs   46>   adddivmulr<   sqrtrU   rm   rn   zCalling z on only torch.SymInt arguments is not yet supported.
To support this behavior, we need to allow const-propping tensors that store symint data.
For now, dynamo will explicitly graph break when it encounters user code with this behavior.
c              3   6   K   | ]  }t        |        y wrC   r   r   s     r,   r   z=TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>  s     @4a:a14r   )sym_sqrtc                     t        | f      ryt        | t              rt        fd| j                  D              S y)NTc              3   .   K   | ]  } |        y wrC   r0   )r   ycheck_any_unspecs     r,   r   zWTorchInGraphFunctionVariable.call_function.<locals>.check_any_unspec.<locals>.<genexpr>
  s     "H1#3A#6s   F)rq   r   anyitems)r   r   r   r   s    r,   r   zDTorchInGraphFunctionVariable.call_function.<locals>.check_any_unspec  s9    !!no%FG##A|4""H"HHH  %r.   datarequires_gradzfactory functions that return tensors that require grad are not supported.
Either create the tensor outside the compiled region, or do not set the tensor to require_gradoutz*out variants with resizing on graph inputsr   z9out= op was called where output tensor was non-contiguouszout variant of )rm   rO   r   r   rg   r   r   r   r   builderr   rk   r   r   rY   rP   rL   r   r+   tracing_state_functionsrn   _utilsis_compiling_dynamoexternal_utilsmark_inconsistent_side_effects
_functorchvmap	vmap_impleager_transforms	grad_implr   maker'   rl   	overridesget_default_nowrap_functionsr   rV   radiansinline_user_function_returnr	   	is_tensoris_tensor_likerp   rq   rN   is_floating_point
is_complexr   AssertionErrorr   r   r   !REWRITE_OPS_TO_TENSOR_SIZE_METHODr   nnmodulesutils_single_pair_triple
_quadruple_ntuple_call_ntupleis_grad_enabledr   _guards_singletonuse_deterministic_algorithms$are_deterministic_algorithms_enabledr   graphdisable_saved_tensors_hooksr   _is_torch_function_enabledr   r{   torch_function_enabledr   has_torch_function_variadichas_torch_function_unaryr   r   stream
from_numpyr   trace_numpyr   npr|   	as_tensorr   r!   r"   jitannotatebackendscudnnis_acceptabler   r   opsatensym_sizeint
sym_strideaddcdivr   r   r   r   r   r   r   rZ   nestednested_tensorgetstridedallrX   strr   r   r   torch.fx.experimental.sym_noder   _refsr
   r    r   find_symbolic_locals_name	enumeratesymbolic_locals	graphargsr   nodemeta_prims_commonis_contiguousrI   ))r3   rQ   r   r4   rO   r   r   rg   r   r   r   rk   constant_argsunspec_python_argsr   kvr   	input_argr9   device_interfacetensor_variable
tensor_inprR   invocation_resultr   any_symints_or_symfloatsall_ints_or_floatsbin_opsmsgfn_r   data_argoutput_tensor_namesidxr?   r   r   r   r   r   s)   `                                   @@@@@r,   rl   z*TorchInGraphFunctionVariable.call_function   s   		
 		
 		
 	>+D&95dFC))+BT#**)'')6:;da**,d;=C\\^L^TQq!..00^L  ZZ22F**zz)),,99  113#**+B4::+NOOZZ!!++--77
 
 488

{{ mBf-. ZZ5??GGG
 3&$&EOO@@B  ZZ4<<'BT211#!#B(8(894  ZZEOOU__-K-KLLt9>!>$q'>2

eoo<<<tAw(ABDGMM+?@'..t44'..u55ZZ##
 
 I G	&((("7O	)^49T::!8!88+229??3T3TUUZZ5#3#33+229??3M3MNN(8DJJ<)@AA :U4 JJ%++%47N3Q(#**747<<+@AAZZ<<t9>!>d1g~6667&&r62r::ZZHH""**HH""((HH""**HH""--HH""**
 
 $$Rv66ZZ5000''*<<=#**5+@+@+BCCZZ5===#d)q.299DG..0  ZZ5EEE''9KKL#**5+U+U+WXXZZ5>>//KKKt9>!>4;;DG..0  ZZ588>>>''6HHI#**299+K+KLLZZOO..OO77OO44
 

 :#**8488   
 ,L+M+M'A' !''+M
 
 t9>!>(//DG<<ZZ5+++%%MNHI$),bii,,#OO 'tR0
 #	 	 )T6:*2tT6BBZZ599---t9>!>7NZZ5>>//=== D	Q(f"47674),TQd1gF8<LO DCD  ..7M7MJ $**$$22:>  JJ%++%D	Q47N3Fq  !,bii,,! 'tV4  JJ599>>22EIINN4K4K4O4OPPD	QFq 47N3 7&&r6DG9bAAJJ599>>44eiinn6O6O6S6STTD	QFq 47N37&&r8d1gYCCJJ%--'D	Q6!Fq  2%))<JJDHbF 2%))<JJVVG_-rF 0		:HHT!Wf%r  &djj1 t9>:#::>d1g';<<< $

47+E+E+G H 3&$&r+<==4::& >B!"XFXQ113XFMEK\\^T^TQq!"6"6"88^TOH +2DJJ4G4G*G' ,bii,,#& 'Qy"5  JJ%,,444

8U]]3u}}D UVV'**XSW*X'X$!$ %% " ;G

L"5@JJ''72,&		TZZ 
 C #C((
 **C@4@@::*G"Cell"	%  #AwHv%%f~H "(N;@PA
  ++,,C+,bii,,# 'tV4O ?N;#v-?+>>@b
 6%=)*D*DE5M446>
 o}=%fUmm\5RSSSAGATAT+ATA44Q7AT ( + &//B%C	T2#5#557F7L7LS7QB..t4 &D8 #"3  @%fUm^DDDu,,"5MRYY-@-@@"5M../2F2FF &&RS*fUm.A.A.F.F.K.KKKK ..<<u++0055oF
 &W 77uFDr1113B**40 #" "OD4G3H"IJ""c <Ldf GTV+s+   .AHAH$AH*.AH0AH5BAH;c                    | j                   t        j                  j                  j                  j
                  u r|d   j                         n#| j                   j                  d   j                  t        t              sJ |rJ fd}| j                   t        j                  j                  j                  j
                  u rt        j                  |      S  ||d         S )z1inline behavior of torch.nn.modules.utils._ntupler   c                    | j                        r-t        j                  t        | j	                                    S | j                         rct        j                  j                  t        j                  j                  j                  j                        | j                                     S t        d|  d       y )Nztorch.nn.modules.utils._ntuple(rc   )has_unpack_var_sequencer
   r    listunpack_var_sequenceis_python_constantrO   rP   rn   r   r   r   r   rL   r   )r+   countrQ   s    r,   handle_ntuplez@TorchInGraphFunctionVariable._call_ntuple.<locals>.handle_ntupled  s    ,,R0 ..22267  ))+ 1188HH$$**2259%:R:R:TU   ?waHIr.   )r+   rn   r   r   r   r   rL   __closure__cell_contentsrq   r   r
   LambdaVariable)r3   rQ   r   r4   r+  r*  s    `   @r,   r   z)TorchInGraphFunctionVariable._call_ntuple[  s    ::))//777G..0EJJ**1-;;E%%%%z	J ::))//777++M:: a))r.   Nr   )rZ   rU   r[   r\   rd   rl   r   r0   r.   r,   r   r      s1    J=H#/H#9UH#	H#T*r.   r   c                   L     e Zd ZdZ fdZd Z fdZ	 	 	 	 	 	 ddZd Z xZ	S )TorchVariablez3Points to a module, classes or functions in torch.*c                    t        |t        j                  t        j                  f      rJ d       t	        |   |fi | 	 t        | j                  dd       }|y t        |t        j                        r-|j                  }t        j                  d|      s
J d|        y t        |t!        t        j"                  j$                  j&                              ry t        |t(              ry t        | d      # t        $ r)}dt        |      v sJ t        |             d }Y d }~d }~wt        $ r)}dt        |      v sJ t        |             d }Y d }~d }~ww xY w)Nzshould use ConstantVariable__self__zNo such operatorzUnknown attributez^(torch|math)([.]|$)z__self__ set to z found with __self__ set)rq   rn   r   r   r1   r2   rX   r+   RuntimeErrorr  r   types
ModuleTyperZ   r;   matchrI   r   _get_tracing_stater2  torch_special_class_types)r3   r+   r4   self_should_be_noneer?   r5   s         r,   r2   zTorchVariable.__init__z  sJ   EKK.
 	)(	) 
 	)&)	'")$**j$"G &+U-=-=>&//D883T:U>Ntf<UU:ehh&A&A&J&J!K
 +-FG E7*B!CDD+  	'%Q/7Q7/"& 	'&#a&08#a&80"&	's$   C< <	ED))E5EEc                 "    d| j                    dS )NzTorchVariable(rc   rD   rE   s    r,   rd   zTorchVariable.__repr__  s    

|1--r.   c                 $   t        | j                  t        j                  t        j                  j
                  t        j                  f      rt        | j                        S t        | j                  t              rt        S t        | %         S rC   )
rq   r+   rn   Tensorr   Moduler   rI   r1   rJ   )r3   r5   s    r,   rJ   zTorchVariable.python_type  sX    djj5<<%,,"OP

##djj$'Kw"$$r.   c                 Z   ddl m} ddlm} t	        ||      }t        ||      }| j                         ru|s|rq|j                   | j                         |D cg c]  }|j                          c}i |j                         D 	
ci c]  \  }	}
|	|
j                          c}
}	      S t        | j                  t              rt        | j                  t        j                  j                         ru| j                  t        j                  j"                  u r| j%                  |||      S t'        j(                  | j                  | j*                        j-                  |||      S t/        |||      rt1        || ||      S t3        | j                  t4        j6                        rt9        d       y t:        r| j                  t<        v rt?        |      dk(  rt3        |d   t@              r{t?        |d   j                        dkD  r`tC        d |d   j                  D              rA || |jD                  jF                  dt        jH                  gtK        ||       	      }|g} || |jD                  jF                  d| j                  gtK        ||       	      }|S c c}w c c}
}	w )
Nr   rO   r   r&   z,TypeError("'module' object is not callable")r   c              3   P   K   | ]  }t        |t        j                           y wrC   )rq   r
   r   r   s     r,   r   z.TorchVariable.call_function.<locals>.<genexpr>  s     WA
1i&>&>?s   $&rl   r   )&rm   rO   r   r   r   r   rY   rP   rL   r   r   r+   rI   ry   rn   r   r>  CrossEntropyLoss_call_cross_entropy_lossr
   UserDefinedClassVariabler'   rl   r!   r"   rq   r4  r5  r   r   r   rp   r   r  r{   r|   stackr   )r3   rQ   r   r4   rO   r   r  r  r   r  r  stackedr  s                r,   rl   zTorchVariable.call_function  sH    	'*+D&95dFC))+BT#**)'')6:;da**,d;=C\\^L^TQq!..00^L  DJJ%*TZZ*QzzUXX66644RvFF 99JJt{{-D&12 )T6:*2tT6BB

E$4$45JK
 JJ"55INtAw5Q&*WaWW (0"))00' +48  y+,bii,,#JJ 'tV4O #"] <Ls   J"J'c                 B  	
 ddl m} |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      fd} ||i |\  	
	
fd}t        j                  |      S )	aj  
        functional: input, target, weight=None, size_average=None, ignore_index=- 100, reduce=None, reduction='mean',
        label_smoothing=0.0

        non functional ctor: weight=None, size_average=None, ignore_index=- 100, reduce=None, reduction='mean',
        label_smoothing=0.0

        non functional loss call: input, target, optional_output
        r   r@  Nimeang        c                     | |||||fS rC   r0   )weightsize_averageignore_indexreduce	reductionlabel_smoothings         r,   normalize_argsz>TorchVariable._call_cross_entropy_loss.<locals>.normalize_args  s       r.   c                     ddl m}  | j                  j                  dt        j
                  j                  j                  gt        | |	gi              S )Nr   rA  rl   r   )	r   r   r{   r|   rn   r   
functionalcross_entropyr   )
r   targetr   rM  rP  
reduce_argrO  rL  rQ   rK  s
      r,   fake_cross_entropy_losszGTorchVariable._call_cross_entropy_loss.<locals>.fake_cross_entropy_loss	  sq    . ,bii,,#HH''55 '!""((&%+	  r.   )rm   rO   rP   r
   r.  )r3   rQ   r   r4   rO   rQ  rW  rM  rP  rV  rO  rL  rK  s    `     @@@@@@r,   rD  z&TorchVariable._call_cross_entropy_loss  s     	' $**40)006)006#**40&--f5,33C8	0 D+F+	
	 	0 ''(?@@r.   r   )
rZ   rU   r[   r\   r2   rd   rJ   rl   rD  r^   r_   s   @r,   r0  r0  w  s;    =EB.%<#/<#9U<#	<#|>Ar.   r0  )orw   loggingrV   r;   r4  typingr   r   torch._streambaser   guardsr   numpyr   ModuleNotFoundErrortorch._Crn   torch._refstorch.fxtorch.nntorch.onnx.operatorsrm   r   r	   r
   allowed_functionsr   r  r   excr   r   r   r   r   r   r   r   r   r   baser   ctx_managerr   r   r   distributedr   r   r   higher_order_opsr   listsr   r    torch_functionr!   r"   	getLoggerrZ   r   r   	Generatorr8  onnx	operatorsshape_as_tensor_shape_as_tensorr   _assertr   _get_device_indexr   is_availabler   finfoget_autocast_gpu_dtypeget_default_dtypeiinfois_autocast_cache_enabledis_autocast_cpu_enabledis_autocast_enabledr   r   r   rS  
_Reductionget_enumpromote_types_get_privateuse1_backend_namerW   extendis_initializedget_rankget_world_sizer   is_scripting
is_tracingr7  fx_symbolic_traceis_fx_tracingis_in_onnx_exportr   r   r   r   r$   ra   r   r0  r0   r.   r,   <module>r     s      	   ) "      * * . ?  !   " 
 W V > . Pg! #XX//1  
JJ((	% ! 
MM	LL""	JJ	LL	""	KK	  		KK	##	!!				HH""++		HH**# * 	!!#"",,&&,,	
 
IIE	II%	HH	HH**E	JJ  %	MM  --t	LLt $A $AN=;#4 =;@i*#4 i*XjA% jAS  	Bs   M MM