
    iF                       d 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	Z	ddl
Z
ddlmZmZ ddlZddlmZ ddlmc mZ ddlmZmZmZmZ ddlmZmZm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) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddlm1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZDmEZEmFZF erddlGmHZH ddlImJZJ  G d d      ZK G d de=      ZL G d de=      ZM G d de=      ZN G d deN      ZO G d de=      ZP G d  d!e=      ZQ G d" d#e=      ZRd$ ZS G d% d&e=      ZTej                   G d' d(             ZV G d) d*eF      ZW G d+ d,eF      ZX G d- d.e=      ZY G d/ d0e=      ZZ G d1 d2e=      Z[ G d3 d4e=      Z\ G d5 d6e=      Z] G d7 d8e=      Z^ ej                  d9      d:        Z` ej                  d9      d;        Za G d< d=e=      Zb G d> d?e=      Zc G d@ dAe=      Zd G dB dCe=      Ze G dD dEe=      Zf G dF dGe=      Zg G dH dIe=      Zh G dJ dKeh      Zi G dL dMeh      Zjej                  ehej                  ehej                  ejiZn G dN dOe=      Zo G dP dQe=      Zp G dR dSe=      Zqy)Ta  
This module contains miscellaneous variable tracker implementations for various Python types
and features used in Dynamo's symbolic execution. These classes help track and propagate
information about different kinds of variables during graph capture.

Key classes include:
- SuperVariable: Handles super() calls and method resolution
- ExceptionVariable: Tracks exception objects
- RandomVariable: Manages random number generators
- GetAttrVariable: Tracks attribute access
- MethodWrapperVariable: Handles method wrappers
- PythonModuleVariable: Tracks Python modules
- NumpyVariable: Handles numpy functions and types
- StringFormatVariable: Manages string formatting
- DebuggingVariable: Handles print and logging
    N)OptionalTYPE_CHECKING   )configgraph_break_hintstrace_rules	variables)create_call_functioncreate_call_function_excreate_instruction)$do_not_convert_to_tracable_parameter)raise_observed_exceptionunimplemented)GuardBuilderinstall_guard)unpatched_nn_module_init)
AttrSourceGenericAttrSourceGetItemSourceTypeMROSource
TypeSourceWeakRefCallSource)	check_unspec_or_constant_argscmp_name_to_op_mappingidentityis_tensor_base_attr_getteristypelist_methodsproxy_args_kwargsraise_args_mismatchtuple_methods   )#AsPythonConstantNotImplementedErrorraise_type_error_excVariableTracker)ConstantVariable)NestedUserFunctionVariableUserFunctionVariable)call_random_fnis_standard_setattrUserDefinedObjectVariable)	PyCodegen)InstructionTranslatorc                       e Zd Zy)NO_SUCH_SUBOBJN)__name__
__module____qualname__     V/var/www/html/engine/venv/lib/python3.12/site-packages/torch/_dynamo/variables/misc.pyr/   r/   P   s    r4   r/   c                        e Zd Zh ej                  Zdd fdZd fdZd fdZdddeddfd	Z		 	 	 	 	 	 	 	 dd
Z
 xZS )SuperVariablereturnc                 @    t        |   di | || _        || _        y Nr3   )super__init__typevarobjvar)selfr=   r>   kwargs	__class__s       r5   r<   zSuperVariable.__init__Y   s%    "6" 
 r4   c                     j                  fd        | j                         | j                  . | j                         j                  t	        dd             y j                  t	        dd             y )Nc                  B     t        j                  t                    S N)r	   BuiltinVariabler;   )rA   codegens   r5   <lambda>z+SuperVariable.reconstruct.<locals>.<lambda>f   s    gi.G.G.N&O r4   r   Fr"   )add_push_nullr=   r>   extend_outputr
   r?   rF   rA   s    `r5   reconstructzSuperVariable.reconstructe   s`    OP;;"DKK !!"6q%"@A!!"6q%"@Ar4   txr-   c                    | j                   s.t        ddd| d| j                   d| j                    ddg       | j                  j                         }| j                   j	                         }| j                   j
                  rt        | j                   j
                        nd }t        |t              r,| j                   j                  }| j                   j
                  }d }|j                  }	 |j                  |      d	z   }t        |t!        |            D ]W  }	||	   j"                  j%                  |t&              x}
s)|
t&        us2|rt)        t+        t-        |      |	      |      }|
|fc S  t        d
dd| d| j                   d| j                    dddg       y # t        $ r t        t        ||      |      d fcY S w xY w)Nz1-arg super not implemented z"Dynamo failed to trace attribute `z$` accessed via `super()` (for type `z` and object `z4`) because one-argument of super() is not supported.z-Use two-argument super(type, object_or_type).gb_typecontextexplanationhintsr"   zUnable to resolve super getattrz8`) because the resolved attribute type is not supported.z0Ensure the attribute exists in the parent class.z(Check the arguments passed to `super()`.)r>   r   r=   as_python_constantpython_typesourcer   
issubclasstypevalue__mro__index
ValueErrorgetattrr;   rangelen__dict__getr/   r   r   r   )r?   rL   namesearch_typetype_to_usetype_to_use_sourcerV   
search_mrostart_indexr[   resolved_getattrrA   s              r5   _resolved_getattr_and_sourcez*SuperVariable._resolved_getattr_and_sourcen   s   {{5@ G,,0LL>} UDD D	 ll557 kk--/.2kk.@.@Jt{{))*d 	 k4(++++K!%!3!3 ((
	H$**;7!;K ;J8 
	4E#-e#4#=#=#A#A$#WWW#>9)!+)-8J*KUS " ,V33
	4 	5<TF C((,~^DKK= QDD C:
	
'  	H 5k:DA4GG	Hs   2F% %!G	G	rb   r%   c                    | j                  | |      \  }}t        j                  j                  |      st	        | |      S |r(t        |j                  t        j                               t        j                  j                  ||      S )NrV   )
ri   r	   r&   
is_literalGetAttrVariabler   
make_guardr   CONSTANT_MATCHcreate)r?   rL   rb   rY   rV   s        r5   var_getattrzSuperVariable.var_getattr   ss     99$Ev))44U;"4..&++L,G,GHI))00v0FFr4   c                    | j                  | |      \  }}|t        j                  u rt        t              S |t
        j                  j                  j                  u r| j                  }ddl	m
} t        |t        j                        rkt        |j                  |      rU|sS|sQt               5  t!        j"                  |t$        |      }	|	j'                  || j                  g|z   |      cd d d        S t)        dd|  d| d| d| d| dg t*        j,                  	       n| j                  j.                  rt1        |d
      r|j2                  dk(  rt        j4                  j7                  |      rt|j8                  }
t1        |
d      r%|
j:                  dk(  rt        j<                  |
      }n#|j>                  }t        j4                  |
|      }|jA                  |d||      S t        |tB              rYt        |jD                  tF        jH                        r5t!        j"                  ||jD                  |      }	|	j'                  |||      S t        |tJ              rt        |jD                  tF        jH                        rt        | j                  t        j4                        r| j                  }nbd }| j                  j.                  rtM        | j                  j.                        }t!        j"                  || j                  jN                  |      }t!        j"                  ||jD                  tQ        |d            }	|	j'                  ||g||      S t        |tF        jH                        r9t!        j"                  |||      }	|	j'                  || j                  g|z   |      S t        |tF        jR                        r=t        jT                  |jD                  | j                  |      j'                  |||      S tW        |      r:t        | j                  t              r  | j                  jX                  |g|i |S |t        jZ                  u r|d   }	 |j]                         }|j`                  j                  jc                  | j                        s4t)        dd|  d| d| j                   ddgt*        jd                  	       |j`                  j                  jg                  | j                  |t        jh                                t        jj                  d       S t        | j                  t        jl                        r@|| j                  jn                  v r(| j                  jp                  jA                  ||||      S t        | j                  t        jr                        r@|| j                  jt                  v r(| j                  jv                  jA                  ||||      S t        | j                  t        jx                        r0|tz        v r(| j                  j|                  jA                  ||||      S t        | j                  t        j~                        r0|t        v r(| j                  j                  jA                  ||||      S |t        j                  u r|d   j                  }|j`                  j                  j                  | j                  |      r^|j`                  j                  j                  | j                  |d      }t        |t        jh                        rt        t        |       |S 	 t        j                  | j                  j                  |      }d }| j                  j.                   t        | j                  j.                  |      }t!        j"                  ||      S |t
        j                  j                  u r|d   }i }|d   j                  }|d   j                  j                         D ]$  \  }}|j                  j]                         }|||<   & |j                  j                  }d|j                  _N        	 |j'                  |||      ||j                  _N        S t        |tF        j                        rN|t        j                         v r8t!        j"                  |||      }|j'                  || j                  g|z   |      S t)        dd|  d| d| d| dd g	       y # 1 sw Y   'xY w# t^        $ r"}t)        dd|  d| ddg|       Y d }~d }~ww xY w# t        $ r t        t        |       Y w xY w# ||j                  _N        w xY w)!Nr   )AttributeMutationNewrk   z#Unsupported super().__init__() callcall_method  z0Dynamo encountered a super().__init__() call on zK that resolved to a `torch.nn.Module.__init__()` call that we cannot trace.rO   r0   __new__r1   builtins__func__r   z7Non-constant attribute given to `super().__delattr__()`zbDynamo requires the attribute name passed to `super().__delattr__(...)` to be a constant (string).zEEnsure the attribute name is a string literal or a constant variable.)rP   rQ   rR   rS   from_exczFAttempted super().__delattr__() on an object without mutation trackingzmDynamo needs to track mutations on an object before `super().__delattr__` can be used on it. But the object (z3) doesn't have attribute mutation tracking enabled.z<Ensure the object is tracked by Dynamo's side effect system.T)
deleted_ok   FzFAttempted to call a super() attribute that is not a function or methodz4Dynamo does not know how to trace the call `super().z()` because `super().z(` is not a function or method attribute.zMEnsure the attribute accessed via `super()` is a standard method or function.)Rri   objectr<   LambdaVariabler   torchnnModuler>   side_effectsrs   
isinstancer	   r+   mutation_typer   r%   buildr   call_functionr   r   	DIFFICULTrV   hasattrr0   UserDefinedClassVariableis_supported_new_method__self__r1   rE   membercall_methodstaticmethodrx   typesFunctionTypeclassmethodr   
value_typer   
MethodTypeUserMethodVariabler*   method_setattr_standard__delattr__rT   NotImplementedErroroutputis_attribute_mutation
DYNAMO_BUG
store_attrDeletedVariabler&   UserDefinedDictVariable_dict_methods_dict_vtUserDefinedSetVariable_set_methods_set_vtUserDefinedTupleVariabler!   	_tuple_vtUserDefinedListVariabler   _list_vt__getattribute__rY   has_pending_mutation_of_attr	load_attrr   AttributeErrorr   _C_disabled_torch_function_implitemsvtsymbolic_torch_function_statetorch_function_subclass_enabledMethodDescriptorTyper   get_tensor_method)r?   rL   rb   argsr@   inner_fnrV   r>   rs   fn_vtuser_clsuser_cls_vtuser_cls_sourcecls_variable
cls_sourceattrexc	attr_nameresult
attr_valueattr_sourcefunc	tf_kwargstf_argshash_key_vtvalue_vtkey_strtx_oldfn_vars                                r5   r   zSuperVariable.call_method   sN     <<T4H& v&!(++111[[F; 69#F#FGv335IJ9; Q+114VE !..rDKK=43GP	Q Q A*4&$qaxH!  "1!1 9-778 KK*-!!Y.22JJ8T((Hx.83F3F*3T'77A"(--'@@_ **2y$GG,/Ju115
 $))"h.?.?OE&&r488+.:u114
 $++y'I'IJ  ${{ "
;;%%!+DKK,>,>!?J.44..
  $))H%%j.LE &&rL+@4+@&II%"4"45#))"hvFE&&rDKK=4+?HH%"2"23//!!4;;vmBf-. !*zKK20
 74;;66rKDKFKK+++7D..0 99))??Ld*4&$8!#{{m ,(!(
 W*55 II""--T9#<#<#> --d33t{{I$E$EFDKK555;;''33BdFKKt{{I$D$DEDKK444;;&&222tT6JJt{{I$F$FGM);;((44RtVLLt{{I$E$EFL(;;''33BdFKK000 QIyy%%BBY //99KKt :  fi&?&?@,^R@=#44T[[5F5F	R
 K{{!!-/0B0BIN"((ZEE???
 7DI1gmmG)-a)<)<)> .%X%..;;=%-	'". 55UUFOTB,,L))"gyA  00P x!;!;<K99;; %**2x@F''T[[MD,@&II'"4&$0v24& 9,, `
	
eQ QV ' 
U*4&$8!L ` !	 	
D " =(<=4  00PsB   -=d"d *e	 %e) d	e$ee	e&%e&)e<rD   r8   NrF   r,   rL   r-   rL   r-   r   list[VariableTracker]r@   dict[str, VariableTracker]r8   r%   )r0   r1   r2   r%   _nonvar_fieldsr<   rK   ri   strrq   r   __classcell__rA   s   @r5   r7   r7   T   sy    		'	'N
B?
BG5 GS GEV G W
#W
 &	W

 -W
 
W
r4   r7   c                   n     e Zd Z	 d	 d fdZddZddZd Zdddedefd	Z fd
Z	 fdZ
d ZeZ xZS )ExceptionVariablec                    t         |   ||       || _        || _        |r$t	        d|  d| dg t
        j                         t        d       | _        t        d       | _	        t        d      | _
        t        d       | _        y )N)rV   r   z,Keyword args passed to exception constructorz with kwargs zRDynamo does not know how to handle keyword args passed to an exception constructorrO   F)r;   r<   exc_typer   r   r   SUPPORTABLEr&   __context__	__cause____suppress_context____traceback__)r?   r   r   init_kwargsrV   r   rA   s         r5   r<   zExceptionVariable.__init__  s     	mD 	F&k];p6)556	 ,D1 *$/$4U$;! .d3r4   c                     || _         y rD   )r   )r?   rQ   s     r5   set_contextzExceptionVariable.set_context  s
    "r4   c                      j                   fd       j                   j                         j                  t	         j                        d       dt
        dd f fd} |d        |d        |d       y )	Nc                  P     j                  dj                  j                        S )Nrw   )load_import_fromr   r0   rF   r?   s   r5   rG   z/ExceptionVariable.reconstruct.<locals>.<lambda>  s    G,,Z9O9OP r4   Frb   r8   c                     t        |       }t        |t              r|j                  dv sJ |       y j	                           |       j                  j                  d             j                  |        y )N)TFNr   )r]   r   r&   rY   dup_toprI   rot_nr   )rb   r   rF   r?   s     r5   codegen_attrz3ExceptionVariable.reconstruct.<locals>.codegen_attr  sh    4&Dd,-zz%88>$>8!%%gmmA&67""4(r4   r   r   r   )rH   foreachr   r   r_   r   )r?   rF   r   s   `` r5   rK   zExceptionVariable.reconstruct  sl    P	
 			"c$))ne4	)s 	)t 	) 	]#[!+,r4   c                     | j                   S rD   )r   r?   s    r5   rU   zExceptionVariable.python_type  s    }}r4   rL   r-   name_varvalc                    fd}|j                         }|dk(  r| j                  |       n|dk(  r|j                         sHt        |t        j
                  t        j                  t        j                  t        j                  f      r"|| _	        t	        j                  d      | _        n |d       n|dk(  r#|j                  dd      r|| _        nf |d       n]|dk(  r/|j                         r|| _        n@t        d	d
|  d| ddg       n)t        dd
|  d| d| dg t        j                          t	        j                  d       S )Nc                 >    t        t        t        |       g       y )N)r   )r   	TypeErrorr&   )msgrL   s    r5   raise_errorz3ExceptionVariable.call_setattr.<locals>.raise_error  s    $Y:J3:O9PQr4   r   r   Tz9exception cause must be None or derive from BaseExceptionr   Fr   z<Set Exception object `__traceback__` attribute to not-`None`zcall_setattr ru   zwDynamo does not support setting the attribute '__traceback__' on tracked exception objects to anything other than None.zYAvoid setting '__traceback__' on exception objects within traced code, or set it to None.rO   z4Unsupported attribute assignment on Exception objectz/Dynamo does not support setting the attribute 'z{' on tracked exception objects. Only `__context__`, `__cause__`, `__suppress_context__`, and `__traceback__` are supported.)rT   r   is_constant_noner   r	   rE   r   !UserDefinedExceptionClassVariable"UserDefinedExceptionObjectVariabler   r&   r   is_constant_matchr   r   r   r   )r?   rL   r   r   r   rb   s    `    r5   call_setattrzExceptionVariable.call_setattr  sc   	R **,= S![ ##%--//??@@	* "%,5,F,Ft,L)WX++$$T51,/)WX_$##%%("Z+D64&9!'A
 N'vQtf56 ZZ 7)556 ))$//r4   c                     |dk(  r | j                   |g| S |dk(  r"|\  }| j                  |t        d      |       | S t        |   ||||      S )N__setattr__with_tracebackr   )r   r&   r;   r   )r?   rL   rb   r   r@   tbrA   s         r5   r   zExceptionVariable.call_method	  sf    = $4$$R/$//%%DRb"2?"CRHK7&r4v>>r4   c                    |dk(  r| j                   S |dk(  r| j                  S |dk(  r| j                  S |dk(  rt        j                  d       S |dk(  r+t        j
                  | j                  | j                        S t        | %  ||      S )Nr   r   r   r   r   rk   )
r   r   r   r	   r&   ListVariabler   rV   r;   rq   )r?   rL   rb   rA   s      r5   rq   zExceptionVariable.var_getattr  s    = ###[ >>!++,,,_$--d33V^))$))DKKHHw"2t,,r4   c                 N    | j                   j                   d| j                   dS )N())rA   r0   r   r   s    r5   __str__zExceptionVariable.__str__   s$    ..))*!DMM?!<<r4   )NNNr   )rQ   r   r   )r0   r1   r2   r<   r   rK   rU   r%   r   r   rq   r   __repr__r   r   s   @r5   r   r     s^     LP4	44#-*70#70 "70 	70r?-= Hr4   r   c                       e Zd ZdZy)UnknownVariablez
    It could be anything!
    Nr0   r1   r2   __doc__r3   r4   r5   r  r  &  s    r4   r  c                   <     e Zd ZdZd fd	Z	 	 	 	 	 	 	 	 ddZ xZS )DelayGraphBreakVariablez^
    Used to insert a dummy variable in the stack to do the graph break at CALL_FUNCTION.
    c                 2    t        |   di | || _        y r:   )r;   r<   r   )r?   r   r@   rA   s      r5   r<   z DelayGraphBreakVariable.__init__1  s    "6"r4   c                     t        dd| j                   d| j                  j                   d| j                   g        y )Nz#Unsupported function call (delayed)zsource: z@Dynamo determined that a graph break should occur when calling `z`. Reason: rO   )r   rV   rb   r   r?   rL   r   r@   s       r5   r   z%DelayGraphBreakVariable.call_function5  sE     	9t{{m,![[--.k$((E	
r4   rD   r   r0   r1   r2   r  r<   r   r   r   s   @r5   r  r  ,  s8    
#
 &
 -	

 

r4   r  c                   D    e Zd ZdZddZdddeddfdZ	 	 	 	 	 	 	 	 dd	Zy
)ComptimeVariableza
    This variable is special, it lets you execute arbitrary code at
    Dynamo compile time
    c                     t        d      )Nzcomptime is special form)r   r?   rF   s     r5   rK   zComptimeVariable.reconstructJ  s    !"<==r4   rL   r-   rb   r8   r%   c                 z    ddl m } t        j                  |t        ||      t	        | j
                  |            S )Nr   )comptimerk   )r  r%   r   r]   r   rV   )r?   rL   rb   r  s       r5   rq   zComptimeVariable.var_getattrM  s3    ' $$$'
4;;0M
 	
r4   c           
         ddl m} |st        |      dkD  r&t        |ddt        |       dt        |       d       |d   }t	        |t
              r |j                          ||             nt	        |t              r|j                         }|j                  rt        |d|j                          t        j                  ||j                  |j                  j!                         |j"                  rt%        |j"                  j&                        nd d	      } | ||             nt)        d
t+        |             t,        j.                  j1                  d       S )Nr   )ComptimeContextz
comptime()zat most 2 args and 0 kwargsz
 args and  kwargsr   zOcomptime function must not have free variables, but these variables were free: r3   z"unsupported argument to comptime: )r  r  r_   r    r   r(   get_functionr'   get_codeclosurer$   co_freevarsr   r   	f_globalsfn_namerT   defaultstupler   RuntimeErrorrX   r	   r&   rp   )r?   rL   r   r@   r  fncoder   s           r5   r   zComptimeVariable.call_functionU  s-    	/ SY]-t9+ZF}G<	 !Wb./BOOob1267;;=Dzz$efjfvfvewx %%

--/,.KKbkk''(T D $%!CDH:NOO))0066r4   Nr   r   )r0   r1   r2   r  rK   r   rq   r   r3   r4   r5   r  r  D  sS    
>
5 
S 
EV 
,7#,7 &,7 -	,7
 
,7r4   r  c                   X     e Zd ZU ee   ed<   dZee   ed<   	 ddee   ddf fdZ xZ	S )CellVariablepre_existing_contentsN
local_namer8   c                 2    t        |   di | || _        y r:   )r;   r<   r   )r?   r   r@   rA   s      r5   r<   zCellVariable.__init__  s     	"6"%:"r4   rD   )
r0   r1   r2   r   r%   __annotations__r!  r   r<   r   r   s   @r5   r  r    sF     $O44 !%J$ BF;%-o%>;	; ;r4   r  c                         e Zd Zd fdZ xZS )NewGlobalVariablec                 $    t        |   di | y r:   r;   r<   r?   r@   rA   s     r5   r<   zNewGlobalVariable.__init__      "6"r4   r   )r0   r1   r2   r<   r   r   s   @r5   r%  r%    s    # #r4   r%  c                 (      fd}t         |_        |S )Nc                  (     j                   | i |S rD   )apply)r   r@   fn_clss     r5   trampoline_autograd_applyzDproduce_trampoline_autograd_apply.<locals>.trampoline_autograd_apply  s    v||T,V,,r4   )!produce_trampoline_autograd_apply_origin)r-  r.  s   ` r5   r/  r/    s    - )J%$$r4   c                   n     e Zd ZdZdhej
                  Zd fdZd	dZd	dZd	dZ		 	 	 	 	 	 d
dZ
 xZS )AutogradFunctionVariablez-represents a torch.autograd.Function subclassr-  c                 2    t        |   di | || _        y r:   )r;   r<   r-  )r?   r-  r@   rA   s      r5   r<   z!AutogradFunctionVariable.__init__  s    "6"r4   c           	      d   dfd}t        j                  |||f       rt        j                         rt        j
                  du rt        j                  d       ddlm	} ddl
m} | j                  j                  } || j                  j                        }|r1 || j                  j                  | j                  j                        }| j                  j                  }	|	t        j                   j"                  j                  ur*t%        dd|  d	| d	| d
ddgt&        j(                         | j                  j*                  }
|
t        j                   j"                  j*                  ur)t%        dd|  d	| d	| ddgt&        j(                         ddlm} | j0                  }|Ct3        j5                  | j                  j6                        | j                  j8                        } ||| j                  j:                  |t3        |d            j=                  ||      }| j0                  r~t3        | j0                  d      }t?        |jA                  tB        jD                               |r>t3        | j0                  d      }t?        |jA                  tB        jD                               |S | j0                  rt3        | j0                  d      }nd }| j                  j                  }tF        jI                  ||      }|g|}tK        |tL        jN                        ritQ        jR                  |      }tU        |      dz
  tU        |jV                        k(  r|dd  }t        jX                  ||      }|j=                  ||      S tK        |tL        jZ                        rPt]        j^                  |j`                  t]        jb                  | j                        |      j=                  ||      S t%        dd|  d	| d	| dte        |      j8                   ddg       y )NFc                     | j                         r| j                  durdt        | t        j                        r| j                        rdy y y )NFT)	is_tensorrequires_gradr   r	   NNModuleVariableis_training)r   r7  rL   s    r5   visitz2AutogradFunctionVariable.call_apply.<locals>.visit  sJ    ||~##50$(M"i889>>"%$(M & :r4   zNThe config.capture_autograd_function flag is deprecated, it's now always true.r   )#autograd_function_forward_rewritten)_is_setup_context_definedzUnsupported custom vjpzcall_apply ru   zgDynamo does not support tracing `torch.autograd.Function` subclasses that define a custom `vjp` method.z+Remove the custom `vjp` method if possible.z.Use standard `backward` instead if applicable.rO   zUnsupported custom jvpzgDynamo does not support tracing `torch.autograd.Function` subclasses that define a custom `jvp` method.z+Remove the custom `jvp` method if possible.r"   )AutogradFunctionApplyVariabler,  )r   rk   forwardsetup_contextz=Non-function or method in subclass of torch.autograd.FunctionzDynamo requires the `forward` attribute of a `torch.autograd.Function` subclass to be a standard Python function or method. Found type `z
` instead.zPEnsure the `forward` method is defined as a regular function or instance method.)3r%   r:  r~   is_grad_enabledr   capture_autograd_functionwarningswarn"torch._functorch.autograd_functionr;  torch.autograd.functionr<  r-  r>  r?  vjpautogradFunctionr   r   r   jvphigher_order_opsr=  rV   r   import_sourcer1   r0   backwardr   r   rn   r   CLOSURE_MATCHAutogradFunctionContextVariablerp   r   r   r   inspect	signaturer_   _parametersr   r   r	   r   rx   r   rX   )r?   rL   r   r@   r:  r;  r<  
forward_fnis_setup_ctx_definedvjp_fnjvp_fnr=  rV   r   fwd_srcsetup_ctx_srcr  ctxsigr   r7  s    `                  @r5   
call_applyz#AutogradFunctionVariable.call_apply  s   	) 	edF^4U224//58d J,,J#<T[[=V=V#W # AKK'')B)B
 [[__FU^^448884)$qax@!- FH +66 [[__FU^^448884)$qax@!- F*66
 H[[F~#$$T[[%;%;<dkk>R>R 0$$!&9	
 mBf-  {{$T[[)<g001K1KLM'$.t{{O$LM!-":":<;U;U"VWJ;;Y7FF[[  -44RvF|d|b%,,-##B'C4y1}COO 44ABx#))"b@E&&r488E,,-//224;;? mBf-	. W%dV1TF!F8<33783D3D2EZQ3
r4   c                 d   | j                   j                  }t        |d   j                        t        j
                  j                  j                  u sJ t        |t        j                        sJ t        | j                  d      }t        j                  |||      }|j                  |||      S )Nr   rL  rk   )r-  rL  rX   rY   r~   _dynamoexternal_utilsFakeBackwardCFunctionr   r   r   r   rV   r%   r   r   )r?   rL   r   r@   r  	fn_sourcer   s          r5   call_backwardz&AutogradFunctionVariable.call_backward.  s    [[!!DGMM"emm&B&B&X&XXXX"e00111t{{J7	%%b"Y?""2tV44r4   c                 ,    t        | j                        S rD   )r2  r-  r  s       r5   r   z&AutogradFunctionVariable.call_function7  s    '44r4   c           
         ddl m} |dk(  rwt        j                  | j                        rEt        | j                        } || |j                  j                  d|gt        ||             S | j                  |||      S |dk(  r| j                  |||      S | j                  t        | j                  |      nd }	 t        j                  | j                  |      }t!        |t"              r|j%                  | j                        }	|7t        j&                  |	      j)                  |	|      j+                  |||      S  t        j&                  |	      |	      j+                  |||      S t!        |t,              r3t/        j0                  |j2                  | |      j+                  |||      S t5        dd	|  d
| d| ddg       y # t        $ r d }Y w xY w)Nr"   )wrap_fx_proxyr,  r   )rL   proxyrL  rk   z$Unsupported autograd.Function methodrt   ru   ,Dynamo does not support calling the method `z` directly on the `torch.autograd.Function` instance. Supported methods include `apply`, `backward`, static methods, and class methods.znEnsure the method is decorated with `@staticmethod` or `@classmethod` if it's meant to be called on the class.rO   )builderrc  r   is_callable_allowedr-  r/  r   create_proxyr   rZ  r`  rV   r   rO  getattr_staticr   r   r   __get__lookupcreate_with_sourcer   r   r	   r   rx   r   )
r?   rL   rb   r   r@   rc  r.  rV   objr   s
             r5   r   z$AutogradFunctionVariable.call_method:  s    	+7?..t{{;,MKK-) %0"))00'1 +48  r488Z%%b$776:kk6MZT2SWF,,T[[$? #|,{{4;;/%#**40++D+@&r48 4;--d3D9GGD&  C- 33LL$v-D&12 B*4&$8!v 9!9
U) " s     G GGr   r   )rL   r-   r   r   r@   r   )r0   r1   r2   r  r%   r   r<   rZ  r`  r   r   r   r   s   @r5   r2  r2    sW    7 			'	'N
{z55>#> &	>
 ->r4   r2  c                   D    e Zd ZU  ej                  e      Zee   ed<   y)SavedTensorBox)default_factorytensorsN)	r0   r1   r2   dataclassesfieldlistrq  r%   r#  r3   r4   r5   ro  ro  {  s    %6[%6%6t%LGT/"Lr4   ro  c                        e Zd ZdZdddhej
                  Z	 	 	 	 	 d
	 d fdZeddd       Zd Z		 	 	 	 	 	 	 	 d fdZ
d fd	Z xZS )rN  zZ
    Tracks an autograd.Function() context using mutation tracking in side_effects.py
    rd  	inferencesaved_tensorsc                 b    t        |   d||d| || _        || _        || _        || _        y N)rY   r   r3   )r;   r<   rv  rw  needs_input_gradnon_differentiable)	r?   rY   r   rv  rw  rz  r{  r@   rA   s	           r5   r<   z(AutogradFunctionContextVariable.__init__  s;     	FuFvF"* 0"4r4   c           
         d }|r|st        d |D              }| j                  j                  j                  d t        j
                  j                  j                  t        j                  t        dt               |      i       }|S )Nc              3   X   K   | ]"  }|j                         xr |j                   $ y wrD   )r6  r7  .0xs     r5   	<genexpr>z9AutogradFunctionContextVariable.create.<locals>.<genexpr>  s"     $U1Q[[]%Fq%F$Us   (*T)rv  rw  rz  )r  r   r   track_object_newr~   rG  functionFunctionCtx	functoolspartialrN  ro  )rL   r   r@   rz  outs        r5   rp   z&AutogradFunctionContextVariable.create  sx    $$UPT$UUii$$55NN##///,.!1	 

 
r4   c                 v    | j                   "t        dd|  dg t        j                         | j                   S )Nzproxy not setz	as_proxy zMDynamo requires the autograd.Function context to be initialized with a proxy.rO   )rd  r   r   r   r   s    r5   as_proxyz(AutogradFunctionContextVariable.as_proxy  sA    ::'#D6*25)445 zzr4   c                    |dk(  rt         |   ||||      S |dk(  rO|rt        ||dt        |       d       t	        |i       d   | _        t        j                  j                  d       S |dk7  r)t        dd|  d	| d
| dg t        j                         | j                  t        dd|  d	| ddg       | j                  s@|s| j                  st        |d       |j                   j"                  j%                  | |       t        | j                  j&                        dkD  rg | j                  _        |D ]'  }| j                  j&                  j)                  |       ) t        j                  j                  d       S )Nr   mark_non_differentiablez0 kwargsr  r   save_for_backwardz,Unsupported autograd.Function context methodrt   ru   re  z` on `autograd.Function` context objects. Supported methods are `__setattr__`, `save_for_backward` and `mark_non_differentiable`.rO   z9Unsupported autograd.Function context `save_for_backward`zjDynamo requires the `saved_tensors` attribute to be initialized on the `autograd.Function` context object.zEnsure that the `saved_tensors` attribute is properly initialized before calling `save_for_backward`. `save_for_backward` only supported on a newly constructed `torch.autograd.function.FunctionCtx`.z>save_for_backward() requires a source and no keyword arguments)r;   r   r    r_   r   r{  r	   r&   rp   r   r   r   rw  rv  rV   r$   r   r   track_save_for_backwardrq  append)r?   rL   rb   r   r@   argrA   s         r5   r   z+AutogradFunctionContextVariable.call_method  s    = 7&r4v>>..#BjS[M:QR&7b&A!&DD#--44T::&&F&tfAdV46 -- 7)556 %S&tfAdV4Ow
 ~~T[[$X II""::4F t!!))*Q.)+D& 	3C&&--c2	3))0066r4   c                     dv rt         fd      S dk(  r> j                  2t        j                  t	         j                  j
                              S dk(  r j                  )t        j                  j                   j                        S  j                  rAt         j                  d      }t        j                   j                  j                  |      S t         =        S )N)r  r  c                  ,    j                  | |      S rD   )r   )r   r@   rb   r?   rL   s     r5   rG   z=AutogradFunctionContextVariable.var_getattr.<locals>.<lambda>  s    (8(8T4(P r4   rw  rz  )r}   rw  r	   TupleVariablert  rq  rz  r&   rp   rV   r   r%   r   rY   r;   rq   r?   rL   rb   rV   rA   s   ``` r5   rq   z+AutogradFunctionContextVariable.var_getattr  s    CC!P  ?"t'9'9'E**40B0B0J0J+KLL%%$$0 11889N9NOO{{#DKK1CD&,,R1L1LfUUw"2t,,r4   )NFNNNr   NNr   r   )r0   r1   r2   r  r+   r   r<   r   rp   r  r   rq   r   r   s   @r5   rN  rN    s    
 	 
#	1	1	N 5 
5   "	27#27 &	27
 -27 
27h- -r4   rN  c                   B     e Zd ZdZ	 d	 d fdZ	 	 	 	 	 	 	 	 ddZ xZS )AutogradEngineVariablez;
    Represents a torch._C._ImperativeEngine instance.
    c                 *    t        |   d||d| y ry  r'  )r?   rY   r   r@   rA   s       r5   r<   zAutogradEngineVariable.__init__  s     	FuFvFr4   c                    |dk(  rt         j                  j                  j                  r|j                  s|j
                  sJ d       t        j                  |t         j                  j                  j                  j                        }|j                  ||j                  j                  j                         g||      S t        dd|  d| dg        y t        dd|  d| d	| d
g        y )Nqueue_callbackzXqueue_callback() is only supported when Compiled Autograd is enabled with fullgraph=Truez7Unsupported torch._C._ImperativeEngine.queue_callback()rt   ru   zYqueue_callback() is only supported when Compiled Autograd is enabled with fullgraph=True.rO   z-Unsupported torch._C._ImperativeEngine methodzgDynamo only supports the `queue_callback` method on a torch._C._ImperativeEngine instance, but found: `z`.)r~   r\  compiled_autogradin_compiled_autograd_region	one_grapherror_on_graph_breakr%   r   r]  FakeCompiledAutogradEnginer  r   r   r   get_ca_final_callbacks_varr   )r?   rL   rb   r   r@   r   s         r5   r   z"AutogradEngineVariable.call_method  s     ##}}..JJ||r'>'> n> (--MM00KKZZ **YY++FFHP4P  U*4&$8!H G&tfAdV4IIMbRr4   rD   r   r   r0   r1   r2   r  r<   r   r   r   s   @r5   r  r    sI     G
 
G%#% &	%
 -% 
%r4   r  c                   8     e Zd Zd fdZ	 	 	 	 	 	 	 	 ddZ xZS )r}   c                 2    t        |   di | || _        y r:   )r;   r<   r  )r?   r  r@   rA   s      r5   r<   zLambdaVariable.__init__4  s    "6"r4   c                 &     | j                   |i |S rD   )r  r  s       r5   r   zLambdaVariable.call_function8  s     tww'''r4   r   r   )r0   r1   r2   r<   r   r   r   s   @r5   r}   r}   3  s3    (#( &( -	(
 
(r4   r}   c                        e Zd Zddhej                  Zdd fdZ fdZdefdZe	de
j                  j                  fd       Zd	 Zd
 ZddZddZ	 	 	 	 	 	 	 	 ddZdddee   deeef   def fdZd Z xZS )rm   rb   py_typer8   c                     t        |   di | t        |t              sJ t        |t              sJ || _        || _        || _        y r:   )r;   r<   r   r%   r   rm  rb   r  )r?   rm  rb   r  r@   rA   s        r5   r<   zGetAttrVariable.__init__H  sH    "6"#///$$$$	r4   c                 P    | j                   | j                   S t        | 	         S rD   )r  r;   rU   r?   rA   s    r5   rU   zGetAttrVariable.python_typeP  s%    <<#<<7&((r4   c                 h    | j                   j                   d| j                   d| j                   dS Nr   z, r   )rA   r0   rm  rb   r   s    r5   r   zGetAttrVariable.__repr__V  s.    ..))*!DHH:R		{!DDr4   
base_proxyc                     t        | |      S rD   )r]   )r  r   s     r5   create_getattr_proxyz$GetAttrVariable.create_getattr_proxyY  s    z4((r4   c                 r    t         j                  | j                  j                         | j                        S rD   )rm   r  rm  r  rb   r   s    r5   r  zGetAttrVariable.as_proxy]  s&    33DHH4E4E4GSSr4   c                     | j                   j                         }	 t        || j                        S # t        $ r t        |  d      d w xY w)Nz is not a constant)rm  rT   r]   rb   r   r   )r?   constants     r5   rT   z"GetAttrVariable.as_python_constant`  sQ    88..0	M8TYY// 	M%.@&ABL	Ms	   2 ArL   r-   c                    t        | j                  t        j                        st        |j
                  j                  | j                  j                        }| j                  |j                  vrt        t        j                  || j                        }||j                  vrt        t        j                  ||      S rD   )r   rm  r	   r8  r   r   get_submodule
module_keyrb   r`   rO  ri  )r?   rL   rb   step1step2s        r5   const_getattrzGetAttrVariable.const_getattrg  s    $((I$>$>?%%		''(;(;<99ENN*%%&&udii8u~~%%%%%eT22r4   c                 |     || j                          |j                  |j                  | j                               y rD   )rm  rI   create_load_attrsrb   r  s     r5   rK   zGetAttrVariable.reconstructr  s+    g77		BCr4   r   r@   c                 R    | j                   j                  || j                  ||      S rD   )rm  r   rb   r  s       r5   r   zGetAttrVariable.call_functionv  s#     xx##B		4@@r4   c                    |dv r| j                   dk(  r|s|d   j                         rt        | j                  t        j
                  t        j                  t        j                  f      rq| j                  }|d   j                         }|j                  ||      r|j                  ||      S |dk(  rt        |      dk(  r|d   S t	        j                  d       S |dk(  r| j                   dk(  rt        |      dk(  r|d   j                         r|st        | j                  t        j
                  t        j                  t        j                  f      r[| j                  }|d   j                         }|j                  ||      rt	        j                  d      S t	        j                  d	      S |d
k(  r| j                   dk(  r|st        | j                  t        j
                        r%| j                  j                  ||d   |d   d      S t        | j                  t        j                        r| j                  j                  |       t        | A  ||||      S )N)__getitem__ra   r`   r   ra   r   r"   __contains__TF__setitem__)directly_update_dict)rb   is_python_constantr   rm  r	   r+   r8  r   rT   has_key_in_generic_dictrq   r_   r&   r   convert_to_unspecializedr;   r   )r?   rL   rb   r   r@   rm  keyrA   s          r5   r   zGetAttrVariable.call_method~  s    **		Z'Q**,77..66 ((Cq',,.C**2s3r3// u}t9>7N$55d;; N"		Z'D	QQ**,77..66 ((Cq',,.C**2s3 11$77 11%88]"tyyJ'>v$((I$G$GHxx77Qat 8   $((I$>$>?11"5w"2tT6::r4   c                 j   | j                   dk(  rSt        | j                  t        j                        r/|j
                  j                  j                  | j                        rJ d| j                  _        t        j                  || j                  j                  j                  | j                        S )Nr`   T)rb   r   rm  r	   r   r   r   has_pending_mutationban_mutationr%   r   rY   r`   rV   )r?   rL   s     r5   get_forwarded_dictz"GetAttrVariable.get_forwarded_dict  s~    II#488Y%G%GHII**??I	
J !%$$R)@)@$++NNr4   rD   r   r   r   r   )r0   r1   r2   r%   r   r<   rU   r   r   r   r~   fxProxyr  r  rT   r  rK   r   rt  dictr   r  r   r   s   @r5   rm   rm   A  s     
	'	'N)E# E ) ) )TM	3DA#A &A -	A
 
AB;#B; ?#	B;
 S/)*B; 
B;HOr4   rm   c                   Z     e Zd Zd fdZ	 	 	 	 	 	 	 	 d	 fdZd Zd Zd Zd Zd Z	 xZ
S )
MethodWrapperVariablec                 @    t        |   di | || _        i | _        y r:   )r;   r<   method_wrapper_builtin_fns)r?   r  r@   rA   s      r5   r<   zMethodWrapperVariable.__init__  s#    "6",r4   c           	         t        | j                        rxt        |d   t        j                        r[t        |      dk(  rt        |      dk(  st        |d       |d   j                  || j                  j                  j                        S | j                  j                  }| j                  j                  }|dk(  rUt        |      j                  }|t        j                  u rt        j                  t              j                  |||g||      S t        j                   dk\  r|t        j"                  d   u rx|dk(  rsddlm} t        |      dk(  r5|s3	 |j)                  || j                  |d   j+                                     S t3        d	d
|  d| d| dddgt4        j6                         t8        | u  |||      S # t,        $ r t/        t,        |       Y Vt0        $ r Y `w xY w)Nr   r"   z2tensor attribute getter takes exactly one argumentr<   )r{      r#  rj  )SourcelessBuilderz9unsupported type.__dict__['__annotations__'].__get__ callzcall_function , args: 
, kwargs: z{`torch.compile` only supports calling type.__dict__['__annotations__'].__get__ on a single constant argument (i.e. a type).zpMake sure your call to type.__dict__['__annotations__'] only has one positional argument (no keyword arguments).zMake sure the argument to type.__dict__['__annotations__'] is a constant (i.e. type). For example, `object`, `int`, `MyCustomClass`.rO   )r   r  r   r	   TensorVariabler_   r$   rq   r   r0   rX   r<   r|   rE   r   sysversion_infor`   rf  r  rp   rT   r   r   r#   r   r   r   r;   r   )	r?   rL   r   r@   self_objwrapper_namefn_objr  rA   s	           r5   r   z#MethodWrapperVariable.call_function  s    &d&9&9:zGY--@
 INs6{a'7$L 7&&r4+>+>+G+G+P+PQQ &&//**33 :%(^,,F( 008DDx&7$&7  ' DMM*;<<	)24yA~f,33D//Q0J0J0LM  S(htfJvhO?FR
 '22 w$Rv66' & A,^R@: s   1G G,!G,+G,c                      yNTr3   r   s    r5   r  z(MethodWrapperVariable.is_python_constant      r4   c                     | j                   S rD   )r  r   s    r5   rT   z(MethodWrapperVariable.as_python_constant  s    """r4   c                      yr  r3   r   s    r5   is_python_hashablez(MethodWrapperVariable.is_python_hashable  r  r4   c                 4    t        | j                               S rD   hashrT   r   s    r5   get_python_hashz%MethodWrapperVariable.get_python_hash      D++-..r4   c                 D    | j                         |j                         k(  S rD   rT   r?   others     r5   is_python_equalz%MethodWrapperVariable.is_python_equal       &&(E,D,D,FFFr4   r   r   )r0   r1   r2   r<   r   r  rT   r  r  r  r   r   s   @r5   r  r    sS    
@7#@7 &@7 -	@7
 
@7D#/Gr4   r  c                   8     e Zd Zd fdZd fdZd Zd Z xZS )GetSetDescriptorVariablec                 2    t        |   di | || _        y r:   )r;   r<   desc)r?   r  r@   rA   s      r5   r<   z!GetSetDescriptorVariable.__init__%  s    "6"	r4   c                     |dk(  rM| j                   rAt        | j                   d      }t        j                  || j                  j
                  |      S t        |   ||      S )Nrj  )rV   r   r%   r   r  rj  r;   rq   r  s       r5   rq   z$GetSetDescriptorVariable.var_getattr)  sR    9Y7F"((TYY->->GG7&r400r4   c                      yr  r3   r   s    r5   r  z+GetSetDescriptorVariable.is_python_constant0  r  r4   c                     | j                   S rD   )r  r   s    r5   rT   z+GetSetDescriptorVariable.as_python_constant3  s    yyr4   r   r   )r0   r1   r2   r<   rq   r  rT   r   r   s   @r5   r  r  $  s    1r4   r  c                        e Zd Zddhej                  Zdej                  ddf fdZd Zd Z	de
fdZdd	Zdd
Z xZS )PythonModuleVariablerY   is_torchr8   Nc                     t        |   di | || _        | j                  t        u xs% | j                  j                  j                  d      | _        y )Nztorch.r3   )r;   r<   rY   r~   r0   
startswithr  r?   rY   r@   rA   s      r5   r<   zPythonModuleVariable.__init__>  sD    "6"


e+Wtzz/B/B/M/Mh/Wr4   c                 "    t         j                  S rD   )r   
ModuleTyper   s    r5   rU   z PythonModuleVariable.python_typeC  s    r4   c                     | j                   S rD   rY   r   s    r5   rT   z'PythonModuleVariable.as_python_constantF      zzr4   c                 "    d| j                    dS )NzPythonModuleVariable(r   r  r   s    r5   r   zPythonModuleVariable.__repr__I  s    &tzzl!44r4   c                 l    t        | j                  |      }t        j                  j	                  |      S rD   )r   rY   r	   r&   rp   r?   rL   rb   r   s       r5   call_obj_hasattrz%PythonModuleVariable.call_obj_hasattrL  s)    T*))0088r4   c                    |j                   j                  j                  | |      r&|j                   j                  j                  | |      S | j                  s|| j
                  j                  vr	 t        | j
                  |      }n| j
                  j                  |   }| j                  xr t        | j                  |      }t        j                  ||      S # t        $ r t        t        |       Y Vw xY wrD   )r   r   r   r   r  rY   r`   r]   r   r   rV   r   r%   r   )r?   rL   rb   r   rV   s        r5   rq   z PythonModuleVariable.var_getattrP  s    99!!>>tTJ99))33D$??==D

(;(;;=$TZZ6
 ,,T2J>DKK!>$$RV<< " =(<=s   2C C98C9r   )r0   r1   r2   r%   r   r   r  r<   rU   rT   r   r   r   rq   r   r   s   @r5   r  r  7  s\     
	'	'NXe.. XT X
 5# 59=r4   r  c                   l     e Zd Zd fdZ	 	 	 	 	 	 	 	 ddZdddefdZd Zd fdZd	 Z	d
 Z
d Z xZS )TypingVariablec                 2    t        |   di | || _        y r:   r;   r<   rY   r  s      r5   r<   zTypingVariable.__init__a      "6"
r4   rL   r-   c                 0   |dk(  r9t        |      dk(  r+| j                  |d   j                            }t        |      S t	        dd| j                   d| d| d| d	| d
| j                   dd| d| j                   dgt
        j                         y )Nr  r"   r   z,unsupported method call on `typing` variableztyping variable: z, method name: r  r  z.`torch.compile` does not support method call `z` on `typing` variable f.zAvoid calling the z method on rO   )r_   rY   rT   r  r   r   r   )r?   rL   rb   r   r@   
new_typings         r5   r   zTypingVariable.call_methode  s     = SY!^DG$>$>$@AJ!*--B'

|?4&QUPVV`ag`hiHNfgkgqgqfrrst$TF+djj\C"..		
r4   rb   c                    ddl m}m} |t        v rt	        j
                  | |      S |j                  j                  j                  | |      r|j                  j                  | |      S t        | j                  |      }| j                  r%t        | j                  |      }  |||      |      S |j                  ||      S )Nr"   )r  VariableBuilder)rf  r  r  r   r	   rm   r   r   r   r   r]   rY   rV   r   rp   )r?   rL   rb   r  r  rY   r   s          r5   rq   zTypingVariable.var_getattrz  s    ?)),,T48899!!>>tTJ??,,T488

D);;$T[[$7K3?2{3E::$++B66r4   c                     | j                   S rD   r  r   s    r5   rT   z!TypingVariable.as_python_constant  r  r4   c                     t        | j                  t        j                        st        |   |      S |j                  |j                  | j                               y rD   )r   rY   r   GenericAliasr;   rK   append_outputcreate_load_constrJ   s     r5   rK   zTypingVariable.reconstruct  sF    $**e&8&897&w//0 	g77

CDr4   c                      yr  r3   r   s    r5   r  z!TypingVariable.is_python_hashable  r  r4   c                 4    t        | j                               S rD   r  r   s    r5   r  zTypingVariable.get_python_hash  r  r4   c                 D    | j                         |j                         k(  S rD   r  r  s     r5   r  zTypingVariable.is_python_equal  r  r4   r   r   )rF   r,   r8   N)r0   r1   r2   r<   r   r   rq   rT   rK   r  r  r  r   r   s   @r5   r  r  `  sb    
#
 &	

 -
 

*75 7S 7 E8/Gr4   r  )maxsizec                      ddl m}  i }| j                         D ]H  \  }}|j                  j                         D ]&  \  }}t	        |      st        ||d      x}s"|||<   ( J |S )zd
    This generates a mapping from numpy modules to their torch._numpy
    modules equivalents.
    r   )NP_TO_TNP_MODULEN)utilsr  r   r`   callabler]   )r  np_fn_to_tnp_fnnp_modtnp_modr  tnp_fnnp_fns          r5   get_np_to_tnp_mapr    sz     )O+113 4&//557 	4OGV $FGT::5:-3OE*	44 r4   c                  j    t               } | j                         D ci c]  \  }}||
 c}}S c c}}w )z
    This is just the reverse mapping of get_np_to_tnp_map() - mapping from
    torch._numpy modules to numpy equivalents.
    )r  r   )mkvs      r5   get_tnp_to_np_mapr#    s.     	AWWY'TQAqD'''s   /c                        e Zd ZdZej
                  fZd fdZed        Z	ed        Z
	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZd Z fdZd	 Zd
 Zd Z xZS )NumpyVariablezz
    Wrapper around `numpy.*`. Currently, is able to trace a small subset of numpy functions as well as numpy dtypes.
    c                 2    t        |   di | || _        y r:   r  r  s      r5   r<   zNumpyVariable.__init__  r  r4   c                     |j                   j                  d      }t        |      dk\  r
|d d ddgk(  sJ || j                  v S Nr  r   r~   _numpy)r1   splitr_   constant_fold_functionsclsr  mods      r5   can_constant_fold_throughz'NumpyVariable.can_constant_fold_through  sJ    mm!!#&3x1}RaWh,?!???S0000r4   c                     |j                   j                  d      }t        |      dk\  r
|d d ddgk(  sJ t        j	                  |      S r(  )r1   r*  r_   np_constant_collections_mapra   r,  s      r5    get_constant_collection_for_funcz.NumpyVariable.get_constant_collection_for_func  sJ    mm!!#&3x1}RaWh,?!???*..r22r4   c                    t         j                  s1t        dd| j                   d| d| d| j                   ddg       d	d
lm} ddlm} t               j                  | j                        }|Dt        dd| j                   d| d| d| d	d| j                   dg t        j                         | j                  |      x}	 e	  | | j                  |D cg c]  }|j                          c}i |j                         D 	
ci c]  \  }	}
|	|
j                          c}
}	      S |j"                  dk(  rTt         j$                  rDt        dd| j                   d| d| d| d	d| j                   ddd| j                   dg       |j'                  |j(                  ||      \  }}| j+                  |      rt-        ||      rt.        j0                  j3                   | j                         |D cg c]  }|j                          c}i |j                         D 	
ci c]  \  }	}
|	|
j                          c}
}	      S  |j4                  j6                  d ||      gt9        ||       }|j3                  ||      S c c}w c c}
}	w # t        $ rG t        dd| j                   d| d| d| d	d| j                   dg t        j                          Y y w xY wc c}w c c}
}	w )Nz?attempted to trace numpy function with config.trace_numpy=Falsenumpy function: r  r  z"Attempted to trace numpy function z; while `torch._dynamo.config.trace_numpy` was set to False.zHSet `torch._dynamo.config.trace_numpy` to True to trace numpy functions.rO   r   )numpy_to_tensor_wrapperr"   )NumpyNdarrayVariablez8attempted to trace numpy function unsupported by PyTorchz  (corresponding torch function: r   z Can't find numpy numpy function z in torch._numpy.zTnumpy function that produces a const collection type encountered non-const argumentsznumpy function zs that produces a const collection type (e.g. np.dtype, np.iinfo/np.finfo) received arguments that are not constant.ztorch._numpy.randomzXattempted to trace torch._numpy.random function with config.use_numpy_random_stream=TruezAttempted to trace zD when `torch._dynamo.config.use_numpy_random_stream` is set to True.z<Set `torch._dynamo.config.use_numpy_random_stream` to False.zAvoid calling r  r   )r   trace_numpyr   rY   r  r5  tensorr6  r  ra   r   r   r2  rT   r   r#   
USER_ERRORr1   use_numpy_random_stream
patch_argsr0   r/  r   r	   r&   rp   r   rh  r   )r?   rL   r   r@   r5  r6  r   collection_variable_typr  r!  r"  rd  s               r5   r   zNumpyVariable.call_function  sQ    !!Y*4::,htfJvhW@ MM M _ 	40 "&&tzz2<R*4::,htfJvhVvw{v||}~>tzzlJ[\&22	 (,'L'LT'RR#.DJJ:>?Q!..0?AGPA1a2244P & #8822v.tzzl(4&
SYRZZz{  {A  AB  C"5djj\ B& !& W(A6	 0::4==$PVWLD&--d3-dF; !1188-D++-:>?Q!..0?AGPA1a2244P  +BII**'- #40E
 (..r599e @P 7 
r.tzzl(4&
SYRZZz{  {A  AB  C"1$** >@ !@*55	
F @Ps=   J J5J J&	J =K-*K2J AK*)K*c           	      h    t        dd| j                   d| d| dg t        j                         y )Nz/attempted to trace numpy.* function as a methodr4  r  r  z6Tracing numpy.* functions as methods is not supported.rO   )r   rY   r   r   )r?   rL   rb   r   r@   s        r5   r   zNumpyVariable.call_methodC  s?     	E&tzzl(4&
6(SP",,		
r4   c                     | j                   S rD   r  r   s    r5   rT   z NumpyVariable.as_python_constantS  r  r4   c                     t         j                  r`t        | j                  t        j
                        r| j                  S t        | j                  t              r| j                  j                  S t        | %         S rD   )
r   r7  r   rY   enumEnumMetarX   r0   r;   r  r  s    r5   r  zNumpyVariable.as_proxyV  sV    $**dmm4zz!$**d+ zz***w!!r4   c                      yr  r3   r   s    r5   r  z NumpyVariable.is_python_hashabled  r  r4   c                 4    t        | j                               S rD   r  r   s    r5   r  zNumpyVariable.get_python_hashg  r  r4   c                 D    | j                         |j                         k(  S rD   r  r  s     r5   r  zNumpyVariable.is_python_equalj  r  r4   r   r   )r0   r1   r2   r  tnp
issubdtyper+  r<   r   r/  r2  r   r   rT   r  r  r  r  r   r   s   @r5   r%  r%    s      #~~/ 1 1
 3 3
X:#X: &X: -	X:
 
X:t
#
 &	

 -
 

 "/Gr4   r%  c                   4     e Zd Zd fdZdefdZddZ xZS )NullVariabler8   c                 $    t        |   di | y r:   r'  r(  s     r5   r<   zNullVariable.__init__p  r)  r4   c                      y)NrH  r3   r   s    r5   r   zNullVariable.__repr__s  s    r4   c                     t         j                  dk  rt        dddg t        j                         |j                  t        d             y )N)r{      z0cannot reconstruct NullVariable in Python < 3.11rN   zdAttempted to generate PUSH_NULL instruction in Python < 3.11; where this instruction does not exist.rO   	PUSH_NULL)r  r  r   r   r   r  r   r  s     r5   rK   zNullVariable.reconstructv  sL    g%J9&11 	0=>r4   r   r   )r0   r1   r2   r<   r   r   rK   r   r   s   @r5   rH  rH  o  s    ## ?r4   rH  c                       e Zd ZdZy)r   z"Marker used to implement delattr()Nr  r3   r4   r5   r   r     s    ,r4   r   c                   f     e Zd ZdZdhej
                  Zed        Zd fdZde	fdZ
d	dZ xZS )
StringFormatVariablez[
    Represents a call to str.format(), we delay calling format until after the graph.
    format_stringc                    t        d t        j                  ||j                               D              r{t        j
                  j                   |j                  |D cg c]  }|j                          c}i |j                         D ci c]  \  }}||j                          c}}      S  | |t        |      t        |            S c c}w c c}}w )Nc              3   <   K   | ]  }|j                           y wrD   )r  r~  s     r5   r  z.StringFormatVariable.create.<locals>.<genexpr>  s!      
   "
s   )all	itertoolschainvaluesr	   r&   rp   formatrT   r   rt  r  )r-  rQ  sym_args
sym_kwargsr"  r!  s         r5   rp   zStringFormatVariable.create  s     
__Xz/@/@/BC
 
 --44$$$6>?a**,?=G=M=M=OPTQq!..00P  =$x.$z2BCC	 @Ps   CCr8   c                 r    t        |   di | t        |t              sJ || _        || _        || _        y r:   )r;   r<   r   r   rQ  rY  rZ  )r?   rQ  rY  rZ  r@   rA   s        r5   r<   zStringFormatVariable.__init__  s9    "6"----* $r4   c                     | j                   j                   d| j                  d| j                  d| j                  dS r  )rA   r0   rQ  rY  rZ  r   s    r5   r   zStringFormatVariable.__repr__  sB    ..))*!D,>,>+ADMMCTTVW[WfWfViijkkr4   c                     j                   fdd        t        j                   j                                j                  j                         D ci c]%  \  }}t        j                  j                  |      |' }}} t        j                  |             j                  t        dd             y c c}}w )Nc                  z     j                   j                  j                         j                  d      g      S )NrX  )rI   r  rQ  create_load_attrr   s   r5   rG   z2StringFormatVariable.reconstruct.<locals>.<lambda>  s9    G))--d.@.@A,,X6 r4   T)call_function_exF)rH   r	   r  rY  rZ  r   r&   rp   ConstDictVariablerI   r   )r?   rF   r!  r"  r@   s   ``   r5   rK   z StringFormatVariable.reconstruct  s     " 	 	
 		''67@D@U@U@W
8<1I&&--a0!3
 
 		++F345dEBC	
s   *C r   r   )r0   r1   r2   r  r%   r   r   rp   r<   r   r   rK   r   r   s   @r5   rP  rP    sJ     &G(F(FGND D%l# lDr4   rP  c                   V     e Zd ZdZd fdZed        ZddZd	dZed
d       Z	 xZ
S )DebuggingVariablez
    Represents a call to a debugging function like print(), or something
    registered to config.reorderable_logging_functions.
    c                 2    t        |   di | || _        y r:   r  r  s      r5   r<   zDebuggingVariable.__init__  r  r4   c                     t        |       xrR t        | t        j                  t        j                  f      xr& | t
        j                  j                  j                  v S rD   )	r  r   r   r   BuiltinFunctionTyper~   r\  r   reorderable_logging_functions)rm  s    r5   is_reorderable_logging_functionz1DebuggingVariable.is_reorderable_logging_function  sO     SM J3!3!3U5N5N OPJu}}++III	
r4   c           	         |j                   ry | j                  | j                  ||      s1t        dd| j                   d| d| dd| j                   dg       |j                  j                  | t        |      f       y )	NzJattempted to reorder a debugging function that can't actually be reorderedzfn: r  r  zl`torch.compile` can only reorder functions where the arguments are Tensors, constants, or string formatters.z#Avoid calling the logging function z" with args that are not supported.rO   )exportcan_reorder_logsrY   r   debug_localsr  rt  r  s       r5   r   zDebuggingVariable.call_function  s    99$$TZZv>dtzzl(4&
6(K@ :$**Egh 	d4j12r4   c                 8    | j                   j                  |      S rD   )rV   rK   r  s     r5   rK   zDebuggingVariable.reconstruct  s    {{&&w//r4   c                     t         j                  t         j                  t        f}t	        j
                  ||g      }|D ]  }t        ||      r y y)zm
        Run some additional checks for what sort of function calls can we
        actually reorder.
        FT)r	   r  r&   rP  pytreetree_leavesr   )r  r   r@   allowed_input_types	flat_argsr  s         r5   rk  z"DebuggingVariable.can_reorder_logs  sY     $$&& 
 &&f~6	 	Cc#67	 r4   r   r   r   )r8   T)r0   r1   r2   r  r<   r   rh  r   rK   rk  r   r   s   @r5   rc  rc    s?    
 
 
3$0  r4   rc  c                   <     e Zd ZdZd fdZ	 	 	 	 	 	 	 	 ddZ xZS )LoggingLoggerVariablez<
    Represents a call to any of logging.Logger methods
    c                 2    t        |   di | || _        y r:   r  r  s      r5   r<   zLoggingLoggerVariable.__init__  r  r4   c                 Z   |j                   ry t        | j                  |d       }t        |dd       }||hj                  t        j
                  j                  j                        rt        j                  j                  d       S t        dd| j                   d| d| d| ddg	       y )
Nrx   z8logging.Logger method not supported for non-export caseszmethod: r  r  r  z>logging.Logger methods are not supported for non-export cases.zFAdd the logging method to `torch._dynamo.config.ignore_logger_methods.rO   )rj  r]   rY   intersectionr~   r\  r   ignore_logger_methodsr	   r&   rp   r   )r?   rL   rb   r   r@   methodr  s          r5   r   z!LoggingLoggerVariable.call_method  s     99T406:t4H**5==+?+?+U+UV--44T::Ntzzl!D6$z&RXX		
r4   r   r   r  r   s   @r5   rt  rt    s8    
#
 &	

 -
 

r4   rt  c                        e Zd ZdZ	 ddlmZmZm	Z
 d fdZed        Zd	 Zd
ddee   deeef   defdZd
ddedefdZ xZS # e$ r  eddi       Z eddi       ZY Nw xY w)ConstantLikeVariablez8self.value is a compile-time constant, but not a literalr   )dtypefloatinggenericinvalid_typer3   r8   c                 2    t        |   di | || _        y r:   r  r  s      r5   r<   zConstantLikeVariable.__init__#  r  r4   c                     t        | j                        }|j                  dk(  r|j                  S |j                   d|j                   S )z4Dynamically compute the prefix from the value's typerw   r  )rX   rY   r1   r2   )r?   ts     r5   _error_prefixz"ConstantLikeVariable._error_prefix'  sD      <<:%>>!,,q 011r4   c                     | j                   S rD   r  r   s    r5   rT   z'ConstantLikeVariable.as_python_constant2  r  r4   rL   r-   r   r@   c                    	 |D cg c]  }|j                          }}|j                         D ci c]  \  }}||j                          }	}} t        | j                  |      i 	}
t        j                  j                  |
      rt        j                  j                  |
      S t        |
t        j                        rt        |
      S t        d
| j                   d| d| d| d|
 	d| j                   d| d|
 dg t        j                   	       y c c}w c c}}w # t        $ r; t        d| j                   d| d| d| dd| j                   d| ddg	       Y w xY w)Nz0constant-like method call with non-constant argsr  z(*z, **r   zAttempted to call z with non-constant args.zFEnsure that the args to the method call are constant (int, str, etc.).rO   z6constant-like method call with unsupported return typez) returned z, got unsupported return value )rT   r   r   r   r  r]   rY   r	   r&   rl   rp   r   reMatchr{  r   r   )r?   rL   rb   r   r@   r  cargsr!  r"  ckwargsr   s              r5   r   z ConstantLikeVariable.call_method5  s   	59:Q))+:E:=C\\^LTQq!..00LGL +T*E=W=%%008--44V<<fbhh''//L))*!D6D6fX[QWPXY,T-?-?,@$Gfgmfnnop"..		
' ;L" 	J--.avRvT&K01C1C0DAdVKcd\	 	s-   D& DD& D D& D& &A E*)E*rb   c                    t        | j                  |      }t        || j                        rt	        |      }t        || j
                        rt        |      S t        |t              r!t        || j                        rt        |      S t        j                  j                  |      rt        j                  j                  |      S t        | |      S rD   )r]   rY   r   np_floatingfloatnp_dtypeNumpyDTypeVariablerX   rW   
np_genericr%  r	   r&   rl   rp   rm   r  s       r5   rq   z ConstantLikeVariable.var_getattrZ  s    T*fd../6]Ffdmm,%f--fd#
64??(K ((%%008--44V<<tT**r4   r   )r0   r1   r2   r  numpyr|  r  r}  r  r~  r  ImportErrorrX   r<   propertyr  rT   rt  r%   r  r   r   rq   r   r   s   @r5   r{  r{    s    B0	
 	
 2 2#
##
 ?#	#

 S/)*#
 
#
J+5 +S +_ +w  0>2r2B/0s   
A A"!A"r{  c                   $     e Zd ZdZd fdZ xZS )TorchVersionVariableztorch.__version__c                     |j                  dt        j                         |d   t        j                  u sJ t        |   di | y )NrY   r3   )
setdefaultr~   __version__r;   r<   r(  s     r5   r<   zTorchVersionVariable.__init__k  sA    '5#4#45g%"3"3333"6"r4   r   )r0   r1   r2   r  r<   r   r   s   @r5   r  r  h  s    'M# #r4   r  c                       e Zd Zd Zy)r  c                 B    | j                   j                  j                  S )a0  Similar to how numpy dtype descriptors (e.g. np.float32 ) are handled by NumpyVariable:

        np.dtype() objects are serialized as strings, torch._numpy wrappers will normalize to the torch dtype.
        This also handles unsupported things nicely (i.e. structured arrays and object arrays).
        )rY   rX   r0   r   s    r5   r  zNumpyDTypeVariable.as_proxyr  s     zz'''r4   N)r0   r1   r2   r  r3   r4   r5   r  r  q  s    (r4   r  c                   ,     e Zd ZdZd fdZddZ xZS )RandomClassVariablezrandom.Randomc                 $    t        |   di | y r:   r'  r(  s     r5   r<   zRandomClassVariable.__init__  r)  r4   c                 "   t        |      dkD  s|r%t        dd| d| dg t        j                         t        |      dk(  rt        j
                  j                  d       n|d   }t        |t        j                  j                               S )	Nr"   z'random.Random() with improper argumentszargs: r  z=random.Random() with > 1 arg or with kwargs is not supported.rO   r   )seedr   )
r_   r   r   r9  r	   r&   rp   RandomVariablebaseValueMutationNew)r?   rL   r   r@   r  s        r5   r   z!RandomClassVariable.call_function  s    t9q=FA j9[&11	 ;>d)q.y))006dSTgY^^%D%D%F
 	
r4   r   r   r	  r   s   @r5   r  r    s    #
r4   r  c                        e Zd ZdZdhej
                  Zh dZ	 	 ddeej                     dee   ddf fdZ
d	 Zd
 Zed        Zed        Zed        Zed        Zdddee   deeef   def fdZddZ xZS )r  zrandom.Random()

    Implemented by wrapping a VariableTracker around a random.Random object.
    The supported methods for the random.Random object cannot be overridden.
    Assumes that random objects behave the same given a set seed or state.
    random>   r  randintuniform	randrangeNrandr  r8   c                 0   t        |   di | |V| j                  |      sJ t        j                         | _        | j                  j                  |j                                y ||j                         nd }t        j                  |      | _        y r:   )r;   r<   is_supported_random_objr  RandomsetstategetstaterT   )r?   r  r  r@   rA   s       r5   r<   zRandomVariable.__init__  sy     	"6"//555 --/DKKK  1040@4**,dD ---DKr4   c                 "    t         j                  S rD   )r  r  r   s    r5   rU   zRandomVariable.python_type  s    }}r4   c                     | j                   S rD   )r  r   s    r5   rT   z!RandomVariable.as_python_constant  s    {{r4   c                    t        |       t        j                  uryt        j                  t
        j                  d      D ]  }t        | |      s yt        | |      }t        j                  |      r/|t        t        j                  |      j                  |       k7  s_ yt        |dd       t        t        j                  |      us y y)NF)r  r  r  rx   T)rX   r  r  rU  rV  r  _supported_fn_namesr   r]   rO  	isbuiltinrj  )r   rb   meths      r5   r  z&RandomVariable.is_supported_random_obj  s    9FMM)OO..0P
 	!D 3%3%D  &76==$7??DD 4T2'&--QU:VV 	! r4   c                     t        |       t        u sJ t        | d         t        u sJ t        | d         t        u sJ t        d | d   D              sJ | d   t        | d         t        u sJ y y )Nr   r"   c              3   >   K   | ]  }t        |      t        u   y wrD   )rX   intr~  s     r5   r  z-RandomVariable.check_state.<locals>.<genexpr>  s     4a47c>4s   r   )rX   r  r  rT  r  )states    r5   check_statezRandomVariable.check_state  s}    E{e###E!H~$$$E!H~&&&4584444Qx4a>U#:::#:r4   c                 h   t         j                  |        t        j                  t        j                  j                  | d         t        j                  | d   D cg c]!  }t        j                  j                  |      # c}      t        j                  j                  | d         g      S c c}w )Nr   r"   r   )r  r  r	   r  r&   rp   )r  r  s     r5   
wrap_statezRandomVariable.wrap_state  s    ""5)&&**11%(;''CH8LaY//66q9L **11%(;
 	
 Ms   &B/c                 P    | j                         }t        j                  |       |S rD   )rT   r  r  )r  	state_objs     r5   unwrap_statezRandomVariable.unwrap_state  s$    ,,.	""9-r4   rL   r-   r   r@   c                    dk(  r|j                   j                  j                  |         | j                  j                  |D cg c]  }|j                          c}i |j                         D ci c]  \  }}||j                          c}} t        j                  j                  d       S dk(  r)| j                  | j                  j                               S dk(  rq|j                   j                  j                  |        | j                  j                  | j                  |d                t        j                  j                  d       S | j                  v r|j                   j                  j                  |        | j                  j                         fd} t        | j                        |D cg c]  }|j                          c}i |j                         D 	
ci c]  \  }	}
|	|
j                          c}
}	 t!        ||||      S t"        | I  |||      S c c}w c c}}w c c}w c c}
}	w )Nr  r  r  r   c                  r    t        j                         }|j                          t        |      | i |S rD   )r  r  r  r]   )r   r@   rrb   r  s      r5   call_random_methz4RandomVariable.call_method.<locals>.call_random_meth  s3    MMO

5!'wq$'888r4   )r   r   mutationr  r  rT   r   r	   r&   rp   r  r  r  r  r  r]   r)   r;   r   )r?   rL   rb   r   r@   r  r  r   r  r!  r"  r  rA   s     `        @r5   r   zRandomVariable.call_method  s    6>II""++D1DKK267Q!&&(7AGPXS#3..00P --44T::Z??4;;#7#7#9::ZII""++D1KK  !2!247!;<--44T::T---II""++D1KK((*E9 'GDKK&267Q!&&(79?HA1a**,,H
 ""&6fEEw"2tT6::7 8P* 8Hs   H45H9H?3Ic                 6   j                  fd       j                  dd       j                          j                  d        | j	                  | j
                  j                                      j                  dd       j                          y )Nc                  n     j                   j                  t               j                  d      g      S )Nr  )rI   create_load_python_moduler  r_  rF   s   r5   rG   z,RandomVariable.reconstruct.<locals>.<lambda>  s3    G))55f=,,X6 r4   r   Fr  r"   T)rH   r   r   r   r  r  r  pop_topr  s    `r5   rK   zRandomVariable.reconstruct  sz    	
 	a' 	*% 4 4 678a&r4   r  r   )r0   r1   r2   r  r%   r   r  r   r  r  r<   rU   rT   r   r  r  r  r  rt  r  r   r   rK   r   r   s   @r5   r  r    s     			'	'N
 )-*..v}}%. '.
 
.  $ ; ; 

 

  
%;#%; ?#	%;
 S/)*%; 
%;Nr4   r  c                   `     e Zd Zed        Z fdZ	 	 	 	 	 	 	 	 ddZd	dZd Zd Z	d Z
 xZS )
WeakRefVariablec                    |j                  d      }|j                  }|xr t        |d      }t        j                  | ||      } |       }|xr t        |      }t        j                  | ||      }||d<   t        ||fi |S )NrV   __callback__)ra   r  r   r%   r   r   r  )	rL   weakref_valueoptionsrV   callbackcallback_sourcecallback_vtreferentreferent_vts	            r5   r   zWeakRefVariable.build*  s    X& -- GZ%G%++B/J ?5-f5%++B&A"{KC7CCr4   c                 @    t        |   di | || _        || _        y r:   )r;   r<   r  r  )r?   r  r  r  rA   s       r5   r<   zWeakRefVariable.__init__6  s#    #7#&&r4   c                     | j                   S rD   )r  r  s       r5   r   zWeakRefVariable.call_function;  s     r4   c                     j                  fd        | j                          | j                         j                  t	        dd             y )Nc                  (     j                  dd      S )Nweakrefref)r   r  s   r5   rG   z-WeakRefVariable.reconstruct.<locals>.<lambda>D  s    g&>&>y%&P r4   r   F)rH   r  r  rI   r
   r  s    `r5   rK   zWeakRefVariable.reconstructC  sD    PQ  !  !21e<=r4   c                 6    | j                   j                         S rD   )r  r  r   s    r5   r  z"WeakRefVariable.is_python_hashableI  s    2244r4   c                 6    | j                   j                         S rD   )r  r  r   s    r5   r  zWeakRefVariable.get_python_hashL  s    //11r4   c                 L    | j                   j                  |j                         S rD   )r  r  r  s     r5   r  zWeakRefVariable.is_python_equalP  s    //0A0ABBr4   r   r   )r0   r1   r2   r   r   r<   r   rK   r  r  r  r   r   s   @r5   r  r  )  s\    	D 	D'
 #  &  -	 
 
 >52Cr4   r  )rr  rr  r@  r  rO  rU  r  r  r  r   rB  typingr   r   torch._Cr~   torch._numpyr)  rE  torch.utils._pytreer  _pytreero  rN   r   r   r   r	   bytecode_transformationr
   r   r   create_parameter_opr   r   r   r   guardsr   r   mutation_guardr   rV   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r  r#   r$   r%   r  r&   	functionsr'   r(   user_definedr)   r*   r+   torch._dynamo.codegenr,   torch._dynamo.symbolic_convertr-   r/   r7   r   r  r  r  r  r%  r/  r2  	dataclassro  rN  r  r}   rm   r  r  r  r  	lru_cacher  r#  r%  rH  r   rP  rc  rt  r{  r  r  finfoiinfor|  r1  r  r  r  r3   r4   r5   <module>r     s  "       	 
   *   $ $ @ @ 
 G 9 0 5 
 
 
 
 ' G X X /D	 	B
O B
J
J JZo 
o 
0=7 =7@;? ;(# #
%S Sl M M M{-&? {-|26 2j(_ (HOo HOVUGO UGp &&=? &=RPG_ PGf Q  ( Q(  (YGO YGz?? ?*-o -.D? .Db9 9x
O 
BO+? O+d#/ #(- ( II#II#II! 
/ 
,N_ Nb(Co (Cr4   