
    ȅio                    T   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKJrJr  SSKJr  SSKJr  SSKJrJrJrJrJrJr  SSKrSSKJr  SSKJs  J r!  SSK"J#r#  SSK$J%r%  SS	K&J'r'  S
SK(J)r)J*r*J+r+J,r,  S
SK-J.r.J/r/J0r0  S
SK1J2r2  S
SK3J4r4J5r5  S
SK6J7r7J8r8  S
SK9J:r:  S
SK;J<r<J=r=J>r>J?r?J@r@JArA  S
SKJBrBJCrCJDrDJErEJFrFJGrGJHrHJIrIJJrJ  SSKKJLrLJMrMJNrN  SSKOJPrP  SSKQJRrRJSrS  SSKTJUrUJVrVJWrW  \(       a  SSKXJYrY  SSKZJ[r[   " S S5      r\ " S S\N5      r] " S S\N5      r^ " S  S!\N5      r_ " S" S#\N5      r` " S$ S%\N5      ra " S& S'\a5      rb " S( S)\N5      rc " S* S+\N5      rd " S, S-\N5      reS.\S/\S0\4   4S1 jrf " S2 S3\N5      rg\R                   " S4 S55      5       ri " S6 S7\W5      rj " S8 S9\W5      rk " S: S;\N5      rl " S< S=\N5      rm " S> S?\N5      rn " S@ SA\N5      ro " SB SC\N5      rp " SD SE\N5      rq\R                  " SSF9S/\s\R"                  \R                  4   4SG j5       ru\R                  " SSF9S/\s\R                  \R"                  4   4SH j5       rv " SI SJ\N5      rw " SK SL\N5      rx " SM SN\N5      ry " SO SP\N5      rz " SQ SR\N5      r{ " SS ST\N5      r| " SU SV\N5      r} " SW SX\N5      r~ " SY SZ\N5      r " S[ S\\5      r " S] S^\5      r\GR                  \\GR                  \\GR                  \0r " S_ S`\N5      r " Sa Sb\N5      r " Sc Sd\N5      rg)ea  
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)CallableSequence)Random)BuiltinFunctionType)AnyLiteralNoReturnTYPE_CHECKING	TypeGuardUnion)MutationType)TupleVariable)Source   )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                       \ rS rSrSrg)NO_SUCH_SUBOBJV    N)__name__
__module____qualname____firstlineno____static_attributes__r<       V/home/james-whalen/.local/lib/python3.13/site-packages/torch/_dynamo/variables/misc.pyr:   r:   V   s    rB   r:   c            
          ^  \ rS rSr1 \R
                  kr SS\S\S-  S\SS4U 4S jjjrSU 4S jjrS	S
S\	S\
\\S-  4   4U 4S jjrS	S
S\	S\4S jrS	S
S\	S\\   S\\	\4   S\4
S jrSrU =r$ )SuperVariableZ   Ntypevarobjvarkwargsreturnc                 >   > [         TU ]  " S0 UD6  Xl        X l        g Nr<   )super__init__rG   rH   )selfrG   rH   rI   	__class__s       rC   rN   SuperVariable.__init___   s#     	"6" 
 rB   c                   >^ TR                  UU4S j5        T" U R                  5        U R                  b.  T" U R                  5        TR                  [	        SS5      5        g TR                  [	        SS5      5        g )Nc                  D   > T" [         R                  " [        5      5      $ N)r   BuiltinVariablerM   )rP   codegens   rC   <lambda>+SuperVariable.reconstruct.<locals>.<lambda>q   s    gi.G.G.N&OrB   r   Fr-   )add_push_nullrG   rH   extend_outputr   rO   rV   rP   s    `rC   reconstructSuperVariable.reconstructp   s`    OP;;"DKK !!"6q%"@A!!"6q%"@ArB   txr8   namec                   > U R                   (       d+  [        SSSU SU R                   SU R                    S3S/S9  U R                   c   eU R                  R                  5       nU R                   R	                  5       nU R                   R
                  (       a  [        U R                   R
                  5      OS n[        U[        5      (       a,  U R                   R                  nU R                   R
                  nS nUR                  n UR                  U5      S	-   n[        U[!        U5      5       Hb  n	Xy   R"                  R%                  U[&        5      =n
(       d  M.  U
[&        Ld  M9  U(       a  [)        [+        [-        U5      U	5      U5      nX4s  $    [        S
SSU SU R                   SU R                    S3SS/S9  g ! [         a    [        [        X45      U5      S 4s $ f = f)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()`.)rH   r   rG   as_python_constantpython_typesourcer"   
issubclasstypevalue__mro__index
ValueErrorgetattrrM   rangelen__dict__getr:   r   r    r!   )rO   r^   r_   search_typetype_to_usetype_to_use_sourceri   
search_mrostart_indexrn   resolved_getattrrP   s              rC   _resolved_getattr_and_source*SuperVariable._resolved_getattr_and_sourcey   s    {{5@ G,,0LL>} UDD D	 {{&&&ll557 kk--/.2kk.@.@Jt{{))*d 	 k4((++++K!%!3!3 ((
	H$**;7!;K ;J8E#-#4#=#=#A#A$#WWW#>9)!+)-8J*KUS " ,33 9 	5<TF C((,~^DKK= QDD C:
	
'  	H 5:DA4GG	Hs   G	 	!G-,G-c                    U R                  X5      u  p4[        R                  R                  U5      (       d  [	        X5      $ U(       a(  [        UR                  [        R                  5      5        [        R                  R                  X4S9$ )Nri   )
r{   r   r1   
is_literalGetAttrVariabler   
make_guardr   CONSTANT_MATCHcreate)rO   r^   r_   rl   ri   s        rC   var_getattrSuperVariable.var_getattr   sn     99"C))44U;;"4..&++L,G,GHI))000FFrB   argsc                 F   U R                  X5      u  pVU R                  c   eU[        R                  L a  [	        [
        5      $ U[        R                  R                  R                  L a  U R                  nSSK	J
n  [        U[        R                  5      (       aw  [        UR                  U5      (       a\  U(       dU  U(       dN  [        5          [         R"                  " U[$        US9n	U	R'                  XR                  /U-   U5      sS S S 5        $ [)        SSU  SU SU SU 3SU S3/ [*        R,                  QS	9  GORU R                  R.                  (       a  [1        US
5      (       a  UR2                  S:X  a  [        R4                  R7                  U5      (       a|  UR8                  n
[1        U
S5      (       a'  U
R:                  S:X  a  [        R<                  " U
5      nO%Uc   eUR>                  n[        R4                  " XS9nURA                  USX45      $ [        U[B        5      (       aZ  [        URD                  [F        RH                  5      (       a1  [         R"                  " XRD                  US9n	U	R'                  XU5      $ [        U[J        5      (       Ga
  [        URD                  [F        RH                  5      (       a  [        U R                  [        R4                  5      (       a  U R                  nOhS nU R                  R.                  (       a  [M        U R                  R.                  5      n[         R"                  " UU R                  RN                  U5      nUc   e[         R"                  " XRD                  [Q        US5      S9n	U	R'                  X/UQU5      $ [        U[F        RH                  5      (       a5  [         R"                  " XUS9n	U	R'                  XR                  /U-   U5      $ [        U[F        RR                  5      (       a:  [        RT                  " URD                  U R                  US9R'                  XU5      $ [W        U5      (       a?  [        U R                  [        5      (       a   U R                  RX                  " U/UQ70 UD6$ U[        RZ                  L a  US   n UR]                  5       nUR`                  R                  Rc                  U R                  5      (       d1  [)        SSU  SU 3SU R                   S3S/[*        Rd                  QS	9  [        U[f        5      (       d   eUR`                  R                  Ri                  U R                  U[        Rj                  " 5       5        [        Rl                  " S 5      $ [        U R                  [        Rn                  5      (       a?  XPR                  Rp                  ;   a&  U R                  Rr                  RA                  XX45      $ [        U R                  [        Rt                  5      (       a?  XPR                  Rv                  ;   a&  U R                  Rx                  RA                  XX45      $ [        U R                  [        Rz                  5      (       a0  U[|        ;   a&  U R                  R~                  RA                  XX45      $ [        U R                  [        R                  5      (       a0  U[        ;   a&  U R                  R                  RA                  XX45      $ U[        R                  L Ga"  US   R                  nUR`                  R                  R                  U R                  U5      (       a`  UR`                  R                  R                  U R                  USS9n[        U[        Rj                  5      (       a  [        [        U5        U$ S n [        R                  U R                  R                  U5      nS nU R                  R.                  b   [        U R                  R.                  U5      n[         R"                  " UUU5      $ U[        R                  R                  L a  US   n0 nUS   R                  nUS   R                  R                  5        H%  u  nnUR                  R]                  5       nUUU'   M'     UR                  R                  nSUR                  lO         UR'                  UUU5      UUR                  lO        $ [        U[F        R                  5      (       aP  U[        R                  " 5       ;   a7  [         R"                  " XU5      nUR'                  XR                  /U-   U5      $ [)        SSU  SU 3SU SU S3S /S	9  g ! , (       d  f       N)= f! [^         a  n[)        SSU  SU 3SS/US9   S nAGNS nAff = f! [         a    [        [        U5         GNf = f! UUR                  lO        f = f)!Nr   )AttributeMutationNewr~   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.rb   r=   __new__r>   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.)rc   rd   re   rf   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.)Sr{   rH   objectrN   LambdaVariabler&   torchnnModuleside_effectsr   
isinstancer   r6   mutation_typer   r0   buildr   call_functionr   r   	DIFFICULTri   hasattrr=   UserDefinedClassVariableis_supported_new_method__self__r>   rU   membercall_methodstaticmethodr   typesFunctionTypeclassmethodr"   
value_typer   
MethodTypeUserMethodVariabler5   method_setattr_standard__delattr__rg   NotImplementedErroroutputis_attribute_mutation
DYNAMO_BUGstr
store_attrDeletedVariabler1   UserDefinedDictVariable_dict_methods_dict_vtUserDefinedSetVariable_set_methods_set_vtUserDefinedTupleVariabler,   	_tuple_vtUserDefinedListVariabler)   _list_vt__getattribute__rl   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)rO   r^   r_   r   rI   inner_fnri   rH   r   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                                rC   r   SuperVariable.call_method   s     <<RF{{&&& v&!(++111[[F; 69#F#FGGv335IJJ9;+114VE !..rKK=43GP	 <; A*4&$qaxH!  "1!1 9-778 KK*--!!Y.22JJ8TT((Hx..83F3F*3T/8/H/H/R)))"(--'@@ **2y$GG,//Ju115
 5
 $))".?.?OE&&r88+..:u114
 4
 $++y'I'IJJ  ${{ "
;;%%!+DKK,>,>!?J.44KK** 
 %%%#))%%j.LE &&r+@4+@&II%"4"455#))"vFE&&rKK=4+?HH%"2"233//!!4;;vmBf-. !**zKK20
 0
 ;;66rKDKFKK+++7D..0 99))??LLd*4&$8!#{{m ,(!(
 W*55 dC((((II""--T9#<#<#> --d33t{{I$E$EFFKK555;;''33BdKKt{{I$D$DEEKK444;;&&222TJJt{{I$F$FGGM);;((44RtLLt{{I$E$EFFL(;;''33BdKK000 QIyy%%BBY  //99KKt :  fi&?&?@@,^R@J= $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;; %**2@F''[[MD,@&II'"4&$0v24& 9,, `
	
s <;^ ' 
U*4&$8!L ` !	 	
H " =(<=6  00PsB   :f/g  %*g, h /
f= 
g)
g$$g),h
	h
h )rH   rG   rT   rV   r7   rJ   N)r=   r>   r?   r@   r0   _nonvar_fieldsr   rN   r\   r   tupler   r{   r   listdictr   rA   __classcell__rP   s   @rC   rE   rE   Z   s    		'	'N *.   $& 	
 
 "BB
)B
14B
	sJ%%	&B
HG5 GS G_ G _
#_
 _
 ?#	_

 S/)*_
 
_
 _
rB   rE   c                   h   ^  \ rS rSrS\R
                  S\SS4U 4S jjrSSS	\S\	4U 4S
 jjr
SrU =r$ )FrameSummaryVariablei  frame_summaryrI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   )rM   rN   r   )rO   r   rI   rP   s      rC   rN   FrameSummaryVariable.__init__  s    "6"*rB   r^   r8   r_   c                   > US:X  a3  [         R                  R                  U R                  R                  5      $ US:X  a3  [         R                  R                  U R                  R
                  5      $ US:X  a3  [         R                  R                  U R                  R                  5      $ US:X  a3  [         R                  R                  U R                  R                  5      $ [        TU ]%  X5      $ )Nlinenofilenamer_   line)
r   r1   r   r   r   r   r_   r   rM   r   rO   r^   r_   rP   s      rC   r    FrameSummaryVariable.var_getattr  s    8--44T5G5G5N5NOOZ--44T5G5G5P5PQQV^--44T5G5G5L5LMMV^--44T5G5G5L5LMMw"2,,rB   )r   )r=   r>   r?   r@   	tracebackFrameSummaryr   rN   r   r0   r   rA   r   r   s   @rC   r   r     sD    +i&<&< + +PT +	-5 	-S 	-_ 	- 	-rB   r   c            
       r  ^  \ rS rSrS\S\S \4   S\SS4U 4S jjr\	S\
R                  S\S \4   SS 4S j5       r\S	\S\4S
 j5       rS\\
R                  \-     4S jrSS S\4S jrS\\R,                     4S jrSSS\S\S\4S jrSSS\S\4U 4S jjrSSS\S\\   S\\\4   S\4
U 4S jjrSrU =r$ )TracebackVariablei  r   tb_nextrI   rJ   Nc                 H   > [         TU ]  " S0 UD6  Xl        Uc   eX l        g rL   )rM   rN   r   r   )rO   r   r   rI   rP   s       rC   rN   TracebackVariable.__init__  s,     	"6"*"""rB   c                 "    U " [        U5      US9$ )N)r   )r   )clsr   r   s      rC   from_frame_summary$TracebackVariable.from_frame_summary  s     '6HHrB   objc                 ~    [        U [        5      =(       d'    [        U [        5      =(       a    U R                  5       $ rT   )r(   r   r1   is_constant_noner   s    rC   is_valid_traceback$TracebackVariable.is_valid_traceback  s0    c,- 
3()Dc.B.B.D	
rB   c                     [        U R                  [        5      (       a  U R                  /$ U R                  /U R                  R	                  5       -   $ rT   )r(   r   r1   r   
extract_tbrO   s    rC   r  TracebackVariable.extract_tb  sD    $,, 011&&''""#dll&=&=&???rB   tbc                     U n[        U[        5      (       a(  X!L a  gUR                  n[        U[        5      (       a  M(  g)NTF)r(   r   r   )rO   r  curr_tbs      rC   has_reference_cycle%TracebackVariable.has_reference_cycle  s;    8<W/00}ooG W/00 rB   c                 "    [         R                  $ rT   )r   TracebackTyper  s    rC   rh   TracebackVariable.python_type  s    """rB   r^   r8   name_varvalc                    UR                  5       nUS:X  a  U R                  U5      (       d  [        [        U5        [	        U[
        5      (       d   eU R                  U5      (       d+  [        U[
        5      (       a&  UR                  U 5      (       a  [        [        U5        X0l	        [        R                  " S 5      $ )Nr   )rg   r   r   	TypeErrorr   r   r  r(   ro   r   r   r1   )rO   r^   r  r  r_   s        rC   call_setattrTracebackVariable.call_setattr  s     **,9**3//(B7c#45555'',,s-..33J3J43P3P(R8L))$//rB   r_   c                    > US:X  a  U R                   $ US:X  a  U R                  R                  US5      $ US:X  a  U R                  $ US:X  a  [        SU  S3S/ [        R
                  QS	9  [        TU ]	  X5      $ )
Nr   	tb_linenor   r   tb_lastiz traceback.tb_lasti not supportedz accessing 'tb_lasti'zNDynamo does not support accessing the tb_lasti attribute of traceback objects.rb   )r   r   r   r   r   SUPPORTABLErM   r   s      rC   r   TracebackVariable.var_getattr  s    9<<[ %%11"h??_$%%%Z:& 56l6)556	 w"2,,rB   r   c                    > US:X  a#  [         R                  R                  XS   L 5      $ US:X  a  U R                  " U/UQ76 $ [        TU ]  XX45      $ )N__eq__r   __setattr__)r   r1   r   r  rM   r   )rO   r^   r_   r   rI   rP   s        rC   r   TracebackVariable.call_method  sZ     8--44T!W_EE]"$$R/$//w"2T::rB   )r   r   )r=   r>   r?   r@   r   r   r1   r   rN   r   r   r   r   r   r0   boolr   r   r  r  rk   r   r  rh   r  r   r   r   r   rA   r   r   s   @rC   r   r     s|   + *,<<= 	
 
$ I --I *,<<=I 
	I I 
 
D 
 

@D!7!7:N!NO @
&9 d #T%"5"56 #0#0 "0 	0
 
0$-5 -S -_ - ;#; ; ?#	;
 S/)*; 
; ;rB   r   c                     ^  \ rS rSr   SS\S\\S4   S\\\4   S-  S\	S-  S\
S-  S	S4U 4S
 jjjrSS jrSS jrS	\4S jrSSS\S\S	\4S jrSSS\S\\   S\\\4   S	\4
U 4S jjrSSS\S	\4U 4S jjrS	\4S jr\rSrU =r$ )ExceptionVariablei#  Nexc_typer   .init_kwargsri   r   rJ   c                   > [         TU ]  XES9  Xl        X l        U(       a!  [	        SU  SU 3S/ [
        R                  QS9  [        S 5      U l        [        S 5      U l	        [        S5      U l
        [        S 5      U l        S U l        g )N)ri   r   z,Keyword args passed to exception constructorz with kwargs zRDynamo does not know how to handle keyword args passed to an exception constructorrb   F)rM   rN   r  r   r   r   r  r1   __context__	__cause____suppress_context____traceback__python_stack)rO   r  r   r   ri   r   rP   s         rC   rN   ExceptionVariable.__init__%  s     	D 	F&k];p6)556	 -=T,B +;4*@5Ee5L!.>t.D <@rB   c                     Xl         g rT   )r"  )rO   rd   s     rC   set_contextExceptionVariable.set_contextF  s    "rB   c                   ^ ^ TR                  UU 4S j5        TR                  T R                  5        TR                  [	        T R                  5      S5        S[
        SS 4UU 4S jjnU" S5        U" S5        U" S5        g )	Nc                  P   > T R                  STR                  R                  5      $ )Nr   )load_import_fromr  r=   rV   rO   s   rC   rW   /ExceptionVariable.reconstruct.<locals>.<lambda>K  s    G,,Z9O9OPrB   Fr_   rJ   c                 
  > [        TU 5      n[        U[        5      (       a  UR                  S;   d   U5       eg TR	                  5         T" U5        TR                  TR                  S5      5        TR                  U 5        g )N)TFNr   )rp   r(   r1   rl   dup_toprZ   rot_nr   )r_   r   rV   rO   s     rC   codegen_attr3ExceptionVariable.reconstruct.<locals>.codegen_attrP  sk    4&Dd,--zz%88>$>8!%%gmmA&67""4(rB   r"  r#  r$  )rY   foreachr   r   rr   r   )rO   rV   r3  s   `` rC   r\   ExceptionVariable.reconstructI  sq    P	
 			"c$))ne4	)s 	)t 	) 	) 	]#[!+,rB   c                     U R                   $ rT   )r  r  s    rC   rh   ExceptionVariable.python_type^  s    }}rB   r^   r8   r  r  c                 :  ^ S[         S[        4U4S jjnUR                  5       nUS:X  a*  [        U[        5      (       d   eU R                  U5        GO1US:X  a  UR                  5       (       dM  [        U[        R                  [        R                  [        R                  [        R                  45      (       a"  X0l        [        R                  " S5      U l        OU" S5        OUS:X  a'  UR                  SS	5      (       a  X0l        OzU" S5        OqUS
:X  aE  [        R!                  U5      (       d$  [#        [$        T[        R&                  " S5      /S9  X0l        O&[+        SSU  SU 3SU S3/ [,        R.                  QS9  [        R                  " S 5      $ )NmsgrJ   c                 8   > [        [        T[        U 5      /S9  g )Nr   )r   r  r1   )r:  r^   s    rC   raise_error3ExceptionVariable.call_setattr.<locals>.raise_errorg  s    $Y:J3:O9PQrB   r"  r#  Tz9exception cause must be None or derive from BaseExceptionr$  Fr%  z0__traceback__ must be a traceback object or Noner<  z4Unsupported attribute assignment on Exception objectzcall_setattr r   z/Dynamo does not support setting the attribute 'z{' on tracked exception objects. Only `__context__`, `__cause__`, `__suppress_context__`, and `__traceback__` are supported.rb   )r   r	   rg   r   r  r)  r   r   rU   !UserDefinedExceptionClassVariable"UserDefinedExceptionObjectVariabler#  r1   r$  is_constant_matchr   r   r   r  r   r%  r   r   r  )rO   r^   r  r  r=  r_   s    `    rC   r  ExceptionVariable.call_setattra  s   	RS 	RX 	R **,= c#45555S![ ##%%--//??@@	* * "%,5,F,Ft,L)WX++$$T511,/)WX_$$77<<((//N "%N'vQtf56 ZZ 7)556 ))$//rB   r_   rI   c                    > US:X  a  U R                   " U/UQ76 $ US:X  a"  Uu  nU R                  U[        S5      U5        U $ [        TU ]  XX45      $ )Nr  with_tracebackr%  )r  r1   rM   r   )rO   r^   r_   r   rI   r  rP   s         rC   r   ExceptionVariable.call_method  sb     = $$R/$//%%DRb"2?"CRHK7&r>>rB   c                 "  > US:X  a  U R                   $ US:X  a  U R                  $ US:X  a  U R                  $ US:X  a  U R                  $ US:X  a2  [        R
                  " [        U R                  5      U R                  S9$ [        TU ])  X5      $ )Nr"  r#  r$  r%  r   r~   )r"  r#  r$  r%  r   ListVariabler   r   ri   rM   r   r   s      rC   r   ExceptionVariable.var_getattr  s    = ###[ >>!++,,,_$%%%V^))$tyy/$++NNw"2,,rB   c                 N    U R                   R                   SU R                   S3$ )N())rP   r=   r  r  s    rC   __str__ExceptionVariable.__str__  s$    ..))*!DMM?!<<rB   )r#  r"  r$  r%  r   r  r&  )NNN)rd   r  rJ   Nr   )r=   r>   r?   r@   r   r   r0   r   r   r   r   rN   r)  r\   rk   rh   r  r   r   r   rL  __repr__rA   r   r   s   @rC   r  r  #  s1    :> $-1@@ OS()@ #./$6	@
 @ $d*@ 
@ @B#-*T 50#50 "50 	50
 
50n?#? ? ?#	?
 S/)*? 
? -5 -S -_ -= = HrB   r  c                       \ rS rSrSrSrg)UnknownVariablei  z
It could be anything!
r<   Nr=   r>   r?   r@   __doc__rA   r<   rB   rC   rP  rP    s    rB   rP  c                   p   ^  \ rS rSrSrSS\S-  S\SS4U 4S jjjrSS	S
\\	   S\
\\	4   S\	4S jrSrU =r$ )DelayGraphBreakVariablei  zV
Used to insert a dummy variable in the stack to do the graph break at CALL_FUNCTION.
Nr:  rI   rJ   c                 2   > [         TU ]  " S0 UD6  Xl        g rL   )rM   rN   r:  )rO   r:  rI   rP   s      rC   rN    DelayGraphBreakVariable.__init__  s    "6"rB   r^   r8   r   c                     U R                   c  SOU R                   R                  n[        SSU R                    3SU SU R                   3/ S9  g )Nra   z#Unsupported function call (delayed)zsource: z@Dynamo determined that a graph break should occur when calling `z`. Reason: rb   )ri   r_   r   r:  )rO   r^   r   rI   r_   s        rC   r   %DelayGraphBreakVariable.call_function  sS     [[(rdkk.>.>9t{{m,!F+dhhZ9	
rB   )r:  rT   )r=   r>   r?   r@   rR  r   r   rN   r   r0   r   r   rA   r   r   s   @rC   rT  rT    sj    C$J    
#
 '
 S/)*	

 

 
rB   rT  c                   b    \ rS rSrSrSS jrSSS\S\4S	 jrSSS
\	\   S\
\\4   S\4S jrSrg)ComptimeVariablei  zU
This variable is special, it lets you execute arbitrary code at
Dynamo compile time
rJ   Nc                     [        S5      e)Nzcomptime is special form)r   rO   rV   s     rC   r\   ComptimeVariable.reconstruct  s    !"<==rB   r^   r8   r_   c                     SSK J n  U R                  c   e[        R                  " U[	        X25      [        U R                  U5      S9$ )Nr   )comptimer~   )r_  ri   r0   r   rp   r   )rO   r^   r_   r_  s       rC   r   ComptimeVariable.var_getattr  s?    '{{&&&$$'
4;;0M
 	
rB   r   rI   c           
         SSK Jn  U(       d  [        U5      S:  a&  [        USS[        U5       S[        U5       S35        US   n[	        U[
        5      (       a  UR                  5       " U" U5      5        O[	        U[        5      (       a  UR                  5       nUR                  (       a  [        USUR                   35        [        R                  " UUR                  UR                  R!                  5       UR"                  (       a  [%        UR"                  R&                  5      OS S	5      nU" U" U5      5        O[)        S
[+        U5       35      e[,        R.                  R1                  S 5      $ )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: r<   z"unsupported argument to comptime: )r_  rb  rr   r+   r   r3   get_functionr2   get_codeclosurer/   co_freevarsr   r   	f_globalsfn_namerg   defaultsr   r   RuntimeErrorrk   r   r1   r   )rO   r^   r   rI   rb  fncoder   s           rC   r   ComptimeVariable.call_function  s1    	/ SY]-t9+ZF}G<	 !Wb.//OOob12677;;=Dzz$efjfvfvewx %%

--/,.KKbkk''(T D $%!CDH:NOO))0066rB   r<   r   )r=   r>   r?   r@   rR  r\   r   r0   r   r   r   r   rA   r<   rB   rC   rZ  rZ    sa    
>
5 
S 
_ 
-7#-7 '-7 S/)*	-7
 
-7rB   rZ  c                   j   ^  \ rS rSr% \S-  \S'   Sr\S-  \S'    S	S\S-  S\SS4U 4S jjjr	Sr
U =r$ )
CellVariablei  Npre_existing_contents
local_namerI   rJ   c                 2   > [         TU ]  " S0 UD6  Xl        g rL   )rM   rN   rq  )rO   rq  rI   rP   s      rC   rN   CellVariable.__init__)  s     	"6"%:"rB   )rq  rT   )r=   r>   r?   r@   r0   __annotations__rr  r   r   rN   rA   r   r   s   @rC   rp  rp    sM     +T11 "Jd
! ?C;%4t%;;NQ;	; ;rB   rp  c                   4   ^  \ rS rSrS\SS4U 4S jjrSrU =r$ )NewGlobalVariablei0  rI   rJ   Nc                 &   > [         TU ]  " S0 UD6  g rL   rM   rN   rO   rI   rP   s     rC   rN   NewGlobalVariable.__init__1      "6"rB   r<   )r=   r>   r?   r@   r   rN   rA   r   r   s   @rC   rw  rw  0  s    # # # #rB   rw  fn_clsrJ   .c                 R   ^  S[         S[         S[         4U 4S jjn[        Ul        U$ )Nr   rI   rJ   c                  (   > TR                   " U 0 UD6$ rT   )apply)r   rI   r}  s     rC   trampoline_autograd_applyDproduce_trampoline_autograd_apply.<locals>.trampoline_autograd_apply6  s    ||T,V,,rB   )r   !produce_trampoline_autograd_apply_origin)r}  r  s   ` rC   r  r  5  s/    - - - - )J%$$rB   c            
         ^  \ rS rSrSrS1\R                  krS\S\SS4U 4S jjrSS	S
\	\   S\
\\4   S\4S jrSS	S
\	\   S\
\\4   S\4S jrSS	S
\\   S\
\\4   SS 4S jrSS	S\S
\	\   S\
\\4   S\4
S jrSrU =r$ )AutogradFunctionVariablei>  z-represents a torch.autograd.Function subclassr}  rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   )rM   rN   r}  )rO   r}  rI   rP   s      rC   rN   !AutogradFunctionVariable.__init__F  s    "6"rB   r^   r8   r   c           	        ^^ SmS[         SS 4UU4S jjn[         R                  " XBU45        T(       Ga  [        R                  " 5       (       Gat  U R                  nSSKJn  SSKJn  U R                  R                  nU" U R                  R                  5      n	U	(       a3  U" U R                  R                  U R                  R                  5      nS nU R                  R                  n
U
[        R                  R                  R                  La'  [        SS	U  S
U S
U 3SSS/[         R"                  QS9  U R                  R$                  nU[        R                  R                  R$                  La&  [        SS	U  S
U S
U 3SS/[         R"                  QS9  SSKJn  UcJ  U	(       dC  [+        TR-                  U R                  R.                  5      U R                  R0                  5      nU=(       a
    [+        USS9nU" UU R                  R2                  UUS9R5                  TX#5      nU R                  (       a  U	(       a|  [+        U R                  S5      n[7        UR9                  [:        R<                  5      5        [+        U R                  S5      n[7        UR9                  [:        R<                  5      5        U$ U R                  (       a  [+        U R                  S5      nOS nU R                  R                  n[>        RA                  TX#5      nU/UQn[C        U[D        RF                  5      (       ah  [H        RJ                  " U5      n[M        U5      S-
  [M        URN                  5      :X  a  USS  n[         RP                  " TUUS9nUR5                  TX#5      $ [C        U[D        RR                  5      (       aN  [T        RV                  " URX                  [T        RZ                  " U R                  5      US9R5                  TX#5      $ [        SS	U  S
U S
U 3S[]        U5      R0                   S3S/S9  g )NFr   rJ   c                    > U R                  5       (       a  U R                  SLa  Sm[        U [        R                  5      (       a  U R                  T5      (       a  Smg g g )NFT)	is_tensorrequires_gradr   r   NNModuleVariableis_training)r   r  r^   s    rC   visit2AutogradFunctionVariable.call_apply.<locals>.visitR  sR    ||~~##50$(M"i8899>>"%%$(M & :rB   r   )#autograd_function_forward_rewritten)_is_setup_context_definedzUnsupported custom vjpzcall_apply r   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.rb   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   r~   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.)/r0   r  r   is_grad_enabledri   "torch._functorch.autograd_functionr  torch.autograd.functionr  r}  r  r  vjpautogradFunctionr   r   r  jvphigher_order_opsr  r   import_sourcer>   r=   backwardr   r   r   r   CLOSURE_MATCHAutogradFunctionContextVariabler   r   r   r   inspect	signaturerr   
parametersr   r   r   r   r   r   rk   )rO   r^   r   rI   r  ri   r  r  
forward_fnis_setup_ctx_definedvjp_fnjvp_fnr  apply_sourcer  fwd_srcsetup_ctx_srcrl  ctxsigr   r  s    `                   @rC   
call_apply#AutogradFunctionVariable.call_applyJ  s    	)o 	)$ 	) 	) 	eF^4U2244[[F 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~&:#$$T[[%;%;<dkk>R>R "Hj&HL/$$#	
 mB-  {{3$T[[)<g001K1KLM *4;; Hm66|7Q7QRSJ;;Y7FF[[  -44RF|d|b%,,--##B'C4y1}CNN 33ABx#))"b@E&&r488E,,--//224;;? mB-	. W%dV1TF!F8<33783D3D2EZQ3
rB   c                    U R                   R                  n[        US   R                  5      [        R
                  R                  R                  L d   e[        U[        R                  5      (       d   eU R                  c   e[        U R                  S5      n[        R                  " XUS9nUR                  XU5      $ )Nr   r  r~   )r}  r  rk   rl   r   _dynamoexternal_utilsFakeBackwardCFunctionr   r   r   ri   r   r0   r   r   )rO   r^   r   rI   rl  	fn_sourcer   s          rC   call_backward&AutogradFunctionVariable.call_backward  s     [[!!DGMM"emm&B&B&X&XXXX"e001111{{&&&t{{J7	%%bY?""2V44rB   c                 ,    [        U R                  5      $ rT   )r  r}  rO   r^   r   rI   s       rC   r   &AutogradFunctionVariable.call_function  s     (44rB   r_   c           
         SSK Jn  US:X  ax  [        R                  " U R                  5      (       aA  [        U R                  5      nU" UUR                  R                  " SU/[        X45      Q76 S9$ U R                  XU5      $ US:X  a  U R                  XU5      $ U R                  b  [        U R                  U5      OS n [        R                  " U R                  U5      n[!        U["        5      (       ap  UR%                  U R                  5      n	[        R&                  " U	5      n
U
c   eUb  U
R)                  XS9R+                  XU5      $ U
" U	5      R+                  XU5      $ [!        U[,        5      (       a/  [.        R0                  " UR2                  XS9R+                  XU5      $ [5        SS	U  S
U 3SU S3S/S9  g ! [         a    S n Nf = f)Nr-   )wrap_fx_proxyr  r   )r^   proxyr  r~   z$Unsupported autograd.Function methodr   r   ,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.rb   )builderr  r   is_callable_allowedr}  r  r   create_proxyr*   r  r  ri   r   r  getattr_staticr   r   r   __get__lookupcreate_with_sourcer   r   r   r   r   r   )rO   r^   r_   r   rI   r  r  ri   r   r   traceds              rC   r   $AutogradFunctionVariable.call_method  s    	+7?..t{{;;,MKK-) %))00'1 +48  r88Z%%b776:kk6MZT2SWF,,T[[$? #|,,{{4;;/$++D1)))% 11$1FTTf "$<55bGGC-- 33LL$-&12 B*4&$8!v 9!9
U- " s   !G GG)r}  )r=   r>   r?   r@   rR  r0   r   r   rN   r   r   r   r  r  r   r   r   rA   r   r   s   @rC   r  r  >  s>   7 			'	'N
s c d {#{ ?#{ S/)*	{
 
{z5#5 ?#5 S/)*	5
 
55#5 '5 S/)*	5
 
$5@#@ @ ?#	@
 S/)*@ 
@ @rB   r  c                   F    \ rS rSr% \R
                  " \S9r\\   \	S'   Sr
g)SavedTensorBoxi!  )default_factorytensorsr<   N)r=   r>   r?   r@   dataclassesfieldr   r  r0   ru  rA   r<   rB   rC   r  r  !  s    %0%6%6t%LGT/"LrB   r  c                   H  ^  \ rS rSrSrSSS1\R                  kr     SS\S\S-  S\	S\S-  S	\
\	S
4   S-  S\S-  S\SS4U 4S jjjr\  SSSS\\   S-  S\\\4   S-  S\4S jj5       rS\4S jrSSS\S\\   S\\\4   S\4
U 4S jjrSSS\S\4U 4S jjrSrU =r$ )r  i&  zR
Tracks an autograd.Function() context using mutation tracking in side_effects.py
r  	inferencesaved_tensorsNrl   r   needs_input_grad.non_differentiablerI   rJ   c                 Z   > [         TU ]  " SXS.UD6  X0l        X@l        XPl        X`l        g N)rl   r   r<   )rM   rN   r  r  r  r  )	rO   rl   r   r  r  r  r  rI   rP   s	           rC   rN   (AutogradFunctionContextVariable.__init__2  s1     	FuFvF"* 0"4rB   r^   r8   r   c                     S nU(       a  U(       d  [        S U 5       5      nU R                  R                  R                  S [        R
                  R                  R                  [        R                  " [        S[        5       US90 5      nU$ )Nc              3   f   #    U  H'  oR                  5       =(       a    UR                  v   M)     g 7frT   )r  r  .0xs     rC   	<genexpr>9AutogradFunctionContextVariable.create.<locals>.<genexpr>K  s"     $UPT1[[]%Fq%FPTs   /1T)r  r  r  )r   r   r   track_object_newr   r  functionFunctionCtx	functoolspartialr  r  )r^   r   rI   r  outs        rC   r   &AutogradFunctionContextVariable.createB  sz      $$UPT$UUii$$55NN##///,.!1	 

 
rB   c                 r    U R                   c  [        SSU  3S/ [        R                  QS9  U R                   $ )Nzproxy not setz	as_proxy zMDynamo requires the autograd.Function context to be initialized with a proxy.rb   )r  r   r   r   r  s    rC   as_proxy(AutogradFunctionContextVariable.as_proxyY  sA    ::'#D6*25)445 zzrB   r_   c                 N  > US:X  a  [         TU ]  XX45      $ US:X  aS  U(       a  [        XS[        U5       S35        [	        U0 5      S   U l        [        R                  R                  S 5      $ US:w  a&  [        SSU  S	U 3S
U S3/ [        R                  QS9  U R                  c  [        SSU  S	U 3SS/S9  U R                  c   eU R                  (       dI  U(       d  U R                  (       d  [        US5        UR                   R"                  R%                  X5        [        U R                  R&                  5      S:  a  / U R                  l        U H(  nU R                  R&                  R)                  U5        M*     [        R                  R                  S 5      $ )Nr  mark_non_differentiablez0 kwargsrc  r   save_for_backwardz,Unsupported autograd.Function context methodr   r   r  z` on `autograd.Function` context objects. Supported methods are `__setattr__`, `save_for_backward` and `mark_non_differentiable`.rb   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)rM   r   r+   rr   r*   r  r   r1   r   r   r   r  r  r  ri   r/   r   r   track_save_for_backwardr  append)rO   r^   r_   r   rI   argrP   s         rC   r   +AutogradFunctionContextVariable.call_methodf  s    = 7&r>>..#BjS[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&C&&--c2 ))0066rB   c                   >^ ^^ TS;   a  [        UU U4S j5      $ TS:X  a@  T R                  b3  [        R                  " [	        T R                  R
                  5      5      $ TS:X  a  T R                  b)  [        R                  R                  T R                  5      $ T R                  (       aB  [        T R                  S5      n[        R                  " TT R                  R                  U5      $ [        TT ]=  TT5      $ )N)r  r  c                  >   > TR                  TT[        U 5      U5      $ rT   )r   r   )r   rI   r_   rO   r^   s     rC   rW   =AutogradFunctionContextVariable.var_getattr.<locals>.<lambda>  s    (8(8T4:v(VrB   r  r  )r   r  r   r   r   r  r  r1   r   ri   r   r0   r   rl   rM   r   rO   r^   r_   ri   rP   s   ``` rC   r   +AutogradFunctionContextVariable.var_getattr  s    CC!V  ?"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,,rB   )r  r  r  r  )NFNNNNN)r=   r>   r?   r@   rR  r6   r   r   rk   r  r   rN   r   r   r0   r   r   r   r  r   r   r   rA   r   r   s   @rC   r  r  &  sw   
 	 
#	1	1	N #'$(48)-55 4K5 	5
 Tz5  c	*T15  $J5 5 
5 5   2648#'$. S/)*T1 
	 ,# 27#27 27 ?#	27
 S/)*27 
27h-5 -S -_ - -rB   r  c            
          ^  \ rS rSrSr SS\R                  R                  S\\R                  R                     S-  S\	SS4U 4S jjjr
S	S
S\S\\   S\\\4   S\4
S jrSrU =r$ )AutogradEngineVariablei  z3
Represents a torch._C._ImperativeEngine instance.
Nrl   r   rI   rJ   c                 *   > [         TU ]  " SXS.UD6  g r  ry  )rO   rl   r   rI   rP   s       rC   rN   AutogradEngineVariable.__init__  s     	FuFvFrB   r^   r8   r_   r   c                    US:X  a  [         R                  R                  R                  (       a  UR                  (       d  UR
                  (       d   S5       e[        R                  " U[         R                  R                  R                  R                  5      nUR                  UUR                  R                  R                  5       /UQ7U5      $ [        SSU  SU 3S/ S9  g [        SSU  SU 3S	U S
3/ S9  g )Nqueue_callbackzXqueue_callback() is only supported when Compiled Autograd is enabled with fullgraph=Truez7Unsupported torch._C._ImperativeEngine.queue_callback()r   r   zYqueue_callback() is only supported when Compiled Autograd is enabled with fullgraph=True.rb   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_breakr0   r   r  FakeCompiledAutogradEnginer  r   r   r   get_ca_final_callbacks_varr   )rO   r^   r_   r   rI   r   s         rC   r   "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rB   r<   rT   )r=   r>   r?   r@   rR  r   r   _ImperativeEnginerk   r   rN   r   r   r0   r   r   rA   r   r   s   @rC   r  r    s     ?CGxx))G 334t;G 	G
 
G G%#% % ?#	%
 S/)*% 
% %rB   r  c                   l   ^  \ rS rSrS\S\4   S\SS4U 4S jjrSS	S
\\   S\	\
\4   S\4S jrSrU =r$ )r   i  rl  .rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   )rM   rN   rl  )rO   rl  rI   rP   s      rC   rN   LambdaVariable.__init__  s    "6"rB   r^   r8   r   c                 &    U R                   " U0 UD6$ rT   rl  r  s       rC   r   LambdaVariable.call_function  s     ww'''rB   r  )r=   r>   r?   r@   r   r0   r   rN   r   r   r   r   rA   r   r   s   @rC   r   r     sf    8C$89 S T (#( '( S/)*	(
 
( (rB   r   c                     ^  \ rS rSrSS1\R
                  kr SS\S\S\S-  S\SS4
U 4S jjjr	S\4U 4S	 jjr
S\4S
 jr\S\R                  R                  S\S\4S j5       rS\4S jrS\4S jrSSS\S\4S jrSS jrSSS\\   S\\\4   S\4S jrSSS\S\\   S\\\4   S\4
U 4S jjrSSS\4S jrSrU =r$ )r   i  r_   py_typeNr   rI   rJ   c                    > [         TU ]  " S0 UD6  [        U[        5      (       d   e[        U[        5      (       d   eXl        X l        X0l        g rL   )rM   rN   r   r0   r   r   r_   r  )rO   r   r_   r  rI   rP   s        rC   rN   GetAttrVariable.__init__  sJ     	"6"#////$$$$$	rB   c                 R   > U R                   b  U R                   $ [        TU ]	  5       $ rT   )r  rM   rh   rO   rP   s    rC   rh   GetAttrVariable.python_type  s%    <<#<<7&((rB   c                 h    U R                   R                   SU R                   SU R                   S3$ NrJ  z, rK  )rP   r=   r   r_   r  s    rC   rN  GetAttrVariable.__repr__  s.    ..))*!DHH:R		{!DDrB   
base_proxyr   c                     [        X5      $ rT   )rp   )r  r   s     rC   create_getattr_proxy$GetAttrVariable.create_getattr_proxy  s    z((rB   c                 r    [         R                  U R                  R                  5       U R                  5      $ rT   )r   r  r   r  r_   r  s    rC   r  GetAttrVariable.as_proxy  s&    33DHH4E4E4GSSrB   c                     U R                   R                  5       n [        XR                  5      $ ! [         a    [        U  S35      S ef = f)Nz is not a constant)r   rg   rp   r_   r   r   )rO   constants     rC   rg   "GetAttrVariable.as_python_constant  sO    88..0	M8YY// 	M%.@&ABL	Ms	   1 Ar^   r8   c                    [        U R                  [        R                  5      (       d  [        eUR
                  R                  U R                  R                  5      nU R                  UR                  ;  a  [        e[        R                  " X0R                  5      nX$R                  ;  a  [        e[        R                  " XB5      $ rT   )r   r   r   r  r   r   get_submodule
module_keyr_   rs   r  r  )rO   r^   r_   step1step2s        rC   const_getattrGetAttrVariable.const_getattr  s    $((I$>$>??%%		''(;(;<99ENN*%%&&uii8~~%%%%%e22rB   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g rT   )r   rZ   create_load_attrsr_   r\  s     rC   r\   GetAttrVariable.reconstruct'  s+    g77		BCrB   r   c                 b    U R                   R                  XR                  [        U5      U5      $ rT   )r   r   r_   r   r  s       rC   r   GetAttrVariable.call_function+  s%     xx##B		4:vFFrB   c                 >  > US;   a  U R                   S:X  a  U(       d  US   R                  5       (       a  [        U R                  [        R
                  [        R                  [        R                  45      (       ax  U R                  nUS   R                  5       nUR                  X5      (       a  UR                  X5      $ US:X  a*  [        U5      S:X  a  US   $ [        R                  " S 5      $ GOUS:X  a  U R                   S:X  a  [        U5      S:X  a  US   R                  5       (       a  U(       d  [        U R                  [        R
                  [        R                  [        R                  45      (       aa  U R                  nUS   R                  5       nUR                  X5      (       a  [        R                  " S5      $ [        R                  " S	5      $ US
:X  a  U R                   S:X  a  U(       d  [        U R                  [        R
                  5      (       a!  U R                  R                  XS   US   SS9$ [        U R                  [        R                  5      (       a  U R                  R                  U5        [        TU ]A  XX45      $ )N)__getitem__rt   rs   r   rt   r   r-   __contains__TF__setitem__)directly_update_dict)r_   is_python_constantr   r   r   r6   r  r   rg   has_key_in_generic_dictr   rr   r1   r   convert_to_unspecializedrM   r   )rO   r^   r_   r   rI   r   keyrP   s          rC   r   GetAttrVariable.call_method3  s#    **		Z'Q**,,77..66  ((Cq',,.C**233r// u}t9>7N$55d;;	  N"		Z'D	QQ**,,77..66  ((Cq',,.C**233 11$77 11%88]"tyyJ'>v$((I$G$GHHxx77Qat 8   $((I$>$>??11"5w"2T::rB   c                    U R                   S:X  a]  [        U R                  [        R                  5      (       a4  UR
                  R                  R                  U R                  5      (       a   eSU R                  l        [        R                  " XR                  R                  R                  U R                  5      $ )Nrs   T)r_   r   r   r   r   r   r   has_pending_mutationban_mutationr0   r   rl   rs   ri   )rO   r^   s     rC   get_forwarded_dict"GetAttrVariable.get_forwarded_dictw  s    II#488Y%G%GHHII**??II	
J !%$$R)@)@$++NNrB   )r_   r   r  rT   r   )r=   r>   r?   r@   r0   r   r   rk   r   rN   rh   rN  r   r   fxProxyr  r  rg   r  r\   r   r   r   r   r   r3  rA   r   r   s   @rC   r   r     s    
	'	'N  $	  	
  
 )T )E# E ) )s )s ) )T# TMC M	3 7 	3s 	3s 	3DG#G 'G S/)*	G
 
GB;#B; B; ?#	B;
 S/)*B; 
B;HO%< O O OrB   r   c                      ^  \ rS rSrS\R
                  S\SS4U 4S jjrSSS	\\	   S\
\\	4   S\	4U 4S
 jjrS\S   4S jrS\R
                  4S jrS\S   4S jrS\4S jrS\S\4S jrSrU =r$ )MethodWrapperVariablei  method_wrapperrI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   )rM   rN   r9  )rO   r9  rI   rP   s      rC   rN   MethodWrapperVariable.__init__  s    "6",rB   r^   r8   r   c           	        > [        U R                  5      (       a~  [        US   [        R                  5      (       a\  [        U5      S:X  a  [        U5      S:X  d  [        US5        US   R                  XR                  R                  R                  5      $ U R                  R                  nU R                  R                  nUS:X  aX  [        U5      R                  nU[        R                  L a/  [        R                  " [        5      R                  UUU/UQU5      $ O[        R                   S:  a  U[        R"                  S   L a{  US:X  au  SSKJn  [        U5      S:X  a9  U(       d2   UR)                  XR                  US   R+                  5       5      5      $ [3        S	S
U  SU SU 3SSS/[4        R6                  QS9  [8        TU ]u  XU5      $ ! [,         a    [/        [,        U5         NS[0         a     N^f = f)Nr   r-   z2tensor attribute getter takes exactly one argumentrN   )r      ru  r  )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`.rb   )r'   r9  r   r   TensorVariablerr   r/   r   r   r=   rk   rN   r   rU   r   sysversion_infors   r  r>  r   rg   r   r   r.   r   r   r  rM   r   )	rO   r^   r   rI   self_objwrapper_namefn_objr>  rP   s	           rC   r   #MethodWrapperVariable.call_function  s    &d&9&9::zGY--@
 @
 INs6{a'7$L 7&&r+>+>+G+G+P+PQQ &&//**33 :%(^,,F( 008DD %%  ) ' DMM*;<<	)24yA~f,33//Q0J0J0LM  S(htfJvhO?FR
 '22 w$Rv66' & A,^R@: s   10G H5	H HTc                     gNTr<   r  s    rC   r+  (MethodWrapperVariable.is_python_constant      rB   c                     U R                   $ rT   r9  r  s    rC   rg   (MethodWrapperVariable.as_python_constant  s    """rB   c                     grI  r<   r  s    rC   is_python_hashable(MethodWrapperVariable.is_python_hashable  rK  rB   c                 4    [        U R                  5       5      $ rT   hashrg   r  s    rC   get_python_hash%MethodWrapperVariable.get_python_hash      D++-..rB   otherc                 r    [        U[        5      =(       a!    U R                  5       UR                  5       :H  $ rT   r   r0   rg   rO   rX  s     rC   is_python_equal%MethodWrapperVariable.is_python_equal  1    uo. H'')U-E-E-GG	
rB   rM  )r=   r>   r?   r@   r   MethodWrapperTyper   rN   r   r0   r   r   r   r   r+  rg   rP  intrU  r   r  r\  rA   r   r   s   @rC   r8  r8    s    -u'>'> -# -RV -D7#D7 'D7 S/)*	D7
 
D7LGDM #E$;$; #GDM / /
V 
 
 
rB   r8  c                      ^  \ rS rSrS\R
                  S\SS4U 4S jjrSSS	\S\	4U 4S
 jjr
S\S   4S jrS\R
                  4S jrSrU =r$ )GetSetDescriptorVariablei  descrI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   )rM   rN   rc  )rO   rc  rI   rP   s      rC   rN   !GetSetDescriptorVariable.__init__  s    "6"	rB   r^   r8   r_   c                    > US:X  aR  U R                   (       aA  [        U R                   S5      n[        R                  " XR                  R
                  U5      $ [        TU ]  X5      $ )Nr  )ri   r   r0   r   rc  r  rM   r   r  s       rC   r   $GetSetDescriptorVariable.var_getattr  sN    9Y7F"((YY->->GG7&r00rB   Tc                     grI  r<   r  s    rC   r+  +GetSetDescriptorVariable.is_python_constant  rK  rB   c                     U R                   $ rT   rc  r  s    rC   rg   +GetSetDescriptorVariable.as_python_constant  s    yyrB   rk  )r=   r>   r?   r@   r   GetSetDescriptorTyper   rN   r   r0   r   r   r+  rg   rA   r   r   s   @rC   rb  rb    se    U77 3 4 15 1S 1_ 1GDM E$>$>  rB   rb  c                      ^  \ rS rSrSS1\R
                  krS\R                  S\SS4U 4S jjr	S\
\R                     4S jrS\R                  4S	 jrS\4S
 jrSSS\S\4S jrSSS\S\4S jrSrU =r$ )PythonModuleVariablei  rl   is_torchrI   rJ   Nc                    > [         TU ]  " S0 UD6  Xl        U R                  [        L =(       d%    U R                  R                  R                  S5      U l        g )Nztorch.r<   )rM   rN   rl   r   r=   
startswithrp  rO   rl   rI   rP   s      rC   rN   PythonModuleVariable.__init__  sB    "6"


e+Wtzz/B/B/M/Mh/WrB   c                 "    [         R                  $ rT   )r   
ModuleTyper  s    rC   rh    PythonModuleVariable.python_type  s    rB   c                     U R                   $ rT   rl   r  s    rC   rg   'PythonModuleVariable.as_python_constant      zzrB   c                 "    SU R                    S3$ )NzPythonModuleVariable(rK  ry  r  s    rC   rN  PythonModuleVariable.__repr__  s    &tzzl!44rB   r^   r8   r_   c                 l    [        U R                  U5      n[        R                  R	                  U5      $ rT   )r   rl   r   r1   r   rO   r^   r_   r   s       rC   call_obj_hasattr%PythonModuleVariable.call_obj_hasattr  s+     T*))0088rB   c                    UR                   R                  R                  X5      (       a%  UR                   R                  R                  X5      $ S nU R                  (       d  X R
                  R                  ;  a   [        U R
                  U5      nOU R
                  R                  U   nU R                  =(       a    [        U R                  U5      n[        R                  " XU5      $ ! [         a    [        [        U5         N\f = frT   )r   r   r   r   rp  rl   rs   rp   r   r   ri   r   r0   r   )rO   r^   r_   r   ri   s        rC   r    PythonModuleVariable.var_getattr  s    99!!>>tJJ99))33D??
==D

(;(;;=$TZZ6
 ,,T2J>DKK!>$$RV<< " =(<=s   =C- -D
	D
)rp  rl   )r=   r>   r?   r@   r0   r   r   rv  r   rN   rk   rh   rg   r   rN  r1   r  r   rA   r   r   s   @rC   ro  ro    s     
	'	'NXe.. X# X$ X
 T%"2"23  E$4$4 5# 59)9149	9=5 =S =_ = =rB   ro  c            
          ^  \ rS rSrS\S\SS4U 4S jjrSSS	\S
\\   S\	\\4   S\4
S jr
SSS	\S\4S jrS\4S jrSU 4S jjrS\S   4S jrS\4S jrS\S\4S jrSrU =r$ )TypingVariablei  rl   rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   rM   rN   rl   rs  s      rC   rN   TypingVariable.__init__      "6"
rB   r^   r8   r_   r   c                 .   US:X  a:  [        U5      S:X  a+  U R                  US   R                  5          n[        U5      $ [	        SSU R                   SU SU SU 3S	U S
U R                   S3SU SU R                   S3/[
        R                  QS9  g )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 rb   )rr   rl   rg   r  r   r   r  )rO   r^   r_   r   rI   
new_typings         rC   r   TypingVariable.call_method#  s     = SY!^DG$>$>$@AJ!*--B'

|?4&QUPVV`ag`hiHNfgkgqgqfrrst$TF+djj\C"..		
rB   c                    SSK JnJn  U[        ;   a  [        R
                  " X5      $ UR                  R                  R                  X5      (       a%  UR                  R                  R                  X5      $ [        U R                  U5      nU R                  (       a$  [        U R                  U5      nU" X5      " U5      $ UR                  X5      $ )Nr-   )r>  VariableBuilder)r  r>  r  r%   r   r   r   r   r   r   rp   rl   ri   r   r   )rO   r^   r_   r>  r  rl   r   s          rC   r   TypingVariable.var_getattr8  s    ?)),,T8899!!>>tJJ99))33D??

D);;$T[[$7K"23E::$++B66rB   c                     U R                   $ rT   ry  r  s    rC   rg   !TypingVariable.as_python_constantH  r{  rB   c                    > [        U R                  [        R                  5      (       d  [        TU ]  U5      $ UR                  UR                  U R                  5      5        g rT   )r   rl   r   GenericAliasrM   r\   append_outputcreate_load_constr[   s     rC   r\   TypingVariable.reconstructK  sI    $**e&8&8997&w//0 	g77

CDrB   Tc                     grI  r<   r  s    rC   rP  !TypingVariable.is_python_hashableg  rK  rB   c                 4    [        U R                  5       5      $ rT   rS  r  s    rC   rU  TypingVariable.get_python_hashj  rW  rB   rX  c                 r    [        U[        5      =(       a!    U R                  5       UR                  5       :H  $ rT   rZ  r[  s     rC   r\  TypingVariable.is_python_equalm  r^  rB   ry  r   )r=   r>   r?   r@   r   rN   r   r   r0   r   r   r   rg   r\   r   rP  r`  rU  r   r  r\  rA   r   r   s   @rC   r  r    s    c S T 
#
 
 ?#	

 S/)*
 

*75 7S 7_ 7 C E8GDM / /
V 
 
 
rB   r  )maxsizec                      SSK Jn   0 nU R                  5        HS  u  p#UR                  R                  5        H0  u  pE[	        U5      (       d  M  [        X$S5      =n(       d  M,  XQU'   M2     MU     U$ )zX
This generates a mapping from numpy modules to their torch._numpy
modules equivalents.
r   )NP_TO_TNP_MODULEN)utilsr  r   rs   callablerp   )r  np_fn_to_tnp_fnnp_modtnp_modri  tnp_fnnp_fns          rC   get_np_to_tnp_mapr  t  sk     )O+113&//557OG $FT::5:-3E*  8 4 rB   c                  l    [        5       n U R                  5        VVs0 s H  u  pX!_M	     snn$ s  snnf )zs
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      rC   get_tnp_to_np_mapr    s.     	AWWY'YTQADY'''s   0c            
       d  ^  \ rS rSrSr\R                  4rS\S\SS4U 4S jjr	\
S\R                  S\4S	 j5       r\
S\R                  S\4S
 j5       rSSS\\   S\\\4   S\4S jrSSS\S\\   S\\\4   S\4
S jrS\4S jrS\4U 4S jjrS\S   4S jrS\4S jrS\S\4S jrSr U =r!$ )NumpyVariablei  zr
Wrapper around `numpy.*`. Currently, is able to trace a small subset of numpy functions as well as numpy dtypes.
rl   rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   r  rs  s      rC   rN   NumpyVariable.__init__  r  rB   rl  c                     UR                   R                  S5      n[        U5      S:  a  US S SS/:X  d   eXR                  ;   $ Nr  r   r   _numpy)r>   splitrr   constant_fold_functionsr   rl  mods      rC   can_constant_fold_through'NumpyVariable.can_constant_fold_through  sH    mm!!#&3x1}RaWh,?!???0000rB   c                     UR                   R                  S5      n[        U5      S:  a  US S SS/:X  d   e[        R	                  U5      $ r  )r>   r  rr   np_constant_collections_maprt   r  s      rC    get_constant_collection_for_func.NumpyVariable.get_constant_collection_for_func  sJ    mm!!#&3x1}RaWh,?!???*..r22rB   r^   r8   r   c                    [         R                  (       d.  [        SSU R                   SU SU 3SU R                   S3S/S9  S	S
KJn  SSKJn  [        5       R                  U R                  5      nUcA  [        SSU R                   SU SU SU S3	SU R                   S3/ [        R                  QS9  Uc   eU R                  U5      =n bh   U" U R                  " U Vs/ s H  oR                  5       PM     sn0 UR                  5        V	V
s0 s H  u  pXR                  5       _M     sn
n	D65      $ UR"                  S:X  aV  [         R$                  (       aA  [        SSU R                   SU SU SU S3	SU R                   S3SSU R                   S3/S9  UR'                  UR(                  X#5      u  p#U R+                  U5      (       a  [-        X#5      (       a  [.        R0                  R3                  U R                  5       " U Vs/ s H  oR                  5       PM     sn0 UR                  5        V	V
s0 s H  u  pXR                  5       _M     sn
n	D65      $ UR4                  R6                  " SU" U5      /[9        X#5      Q76 nUR3                  X5      $ s  snf s  sn
n	f ! [         aD    [        SSU R                   SU SU SU S3	SU R                   S3/ [        R                   QS9   g f = fs  snf s  sn
n	f )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.rb   r   )numpy_to_tensor_wrapperr-   )NumpyNdarrayVariablez8attempted to trace numpy function unsupported by PyTorchz  (corresponding torch function: rK  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   rl   r  r  tensorr  r  rt   r   r  r  rg   r   r.   
USER_ERRORr>   use_numpy_random_stream
patch_argsr=   r  r$   r   r1   r   r   r  r*   )rO   r^   r   rI   r  r  r   collection_variable_typr  r  r  r  s               rC   r   NumpyVariable.call_function  sV    !!Y*4::,htfJvhW@ MM M _ 	40 "&&tzz2<R*4::,htfJvhVvw{v||}~>tzzlJ[\&22	 '+'L'LT'RR#.JJ:>?$Q..0$?AGP12244P & #8822v.tzzl(4&
SYRZZz{  {A  AB  C"5djj\ B& !& W(A6	 0::4==$WLD--d33-d;; !1188++-:>?$Q..0$?AGP12244P  II**'- #40E
 (..r99e @P 7 
r.tzzl(4&
SYRZZz{  {A  AB  C"1$** >@ !@*55	
F @Ps=   J. $J#=J. J(/	J. K??L#J. .AK<;K<r_   c           	      b    [        SSU R                   SU SU 3S/ [        R                  QS9  g )Nz/attempted to trace numpy.* function as a methodr  r?  r@  z6Tracing numpy.* functions as methods is not supported.rb   )r   rl   r   r   )rO   r^   r_   r   rI   s        rC   r   NumpyVariable.call_method  s?     	E&tzzl(4&
6(SP",,		
rB   c                     U R                   $ rT   ry  r  s    rC   rg    NumpyVariable.as_python_constant  r{  rB   c                   > [         R                  (       aj  [        U R                  [        R
                  5      (       a  U R                  $ [        U R                  [        5      (       a  U R                  R                  $ [        TU ]%  5       $ rT   )
r   r  r   rl   enumEnumMetark   r=   rM   r  r  s    rC   r  NumpyVariable.as_proxy  s\    $**dmm44zz!$**d++ zz***w!!rB   Tc                     grI  r<   r  s    rC   rP   NumpyVariable.is_python_hashable&  rK  rB   c                 4    [        U R                  5       5      $ rT   rS  r  s    rC   rU  NumpyVariable.get_python_hash)  rW  rB   rX  c                 r    [        U[        5      =(       a!    U R                  5       UR                  5       :H  $ rT   rZ  r[  s     rC   r\  NumpyVariable.is_python_equal,  r^  rB   ry  )"r=   r>   r?   r@   rR  tnp
issubdtyper  r   rN   r   r   r   r  r  r  r   r0   r   r   r   r   r   r   rg   r  r   rP  r`  rU  r   r\  rA   r   r   s   @rC   r  r    sR     #~~/c S T  15+=+= 1$ 1 1
 3%2D2D 3 3 3
Y:#Y: 'Y: S/)*	Y:
 
Y:v
#
 
 ?#	

 S/)*
 

 $7 "# "GDM / /
V 
 
 
rB   r  c                   L   ^  \ rS rSrS\SS4U 4S jjrS\4S jrS	S jrSr	U =r
$ )
NullVariablei4  rI   rJ   Nc                 &   > [         TU ]  " S0 UD6  g rL   ry  rz  s     rC   rN   NullVariable.__init__5  r|  rB   c                     g)Nr  r<   r  s    rC   rN  NullVariable.__repr__8  s    rB   c                     [         R                  S:  a  [        SSS/ [        R                  QS9  UR                  [        S5      5        g )N)r      z0cannot reconstruct NullVariable in Python < 3.11ra   zdAttempted to generate PUSH_NULL instruction in Python < 3.11; where this instruction does not exist.rb   	PUSH_NULL)rB  rC  r   r   r   r  r   r\  s     rC   r\   NullVariable.reconstruct;  sL    g%J9&11 	0=>rB   r<   r   )r=   r>   r?   r@   r   rN   r   rN  r\   rA   r   r   s   @rC   r  r  4  s,    # # ## ? ?rB   r  c                       \ rS rSrSrSrg)r   iI  z"Marker used to implement delattr()r<   NrQ  r<   rB   rC   r   r   I  s    ,rB   r   c            
          ^  \ rS rSrSrS1\R                  kr\S\S\	\   S\
\\4   S\4S j5       rS\S\	\   S\
\\4   S\SS	4
U 4S
 jjrS\4S jrSS jrSrU =r$ )StringFormatVariableiM  zS
Represents a call to str.format(), we delay calling format until after the graph.
format_stringsym_args
sym_kwargsrJ   c                    [        S [        R                  " X#R                  5       5       5       5      (       a~  [        R
                  R                  UR                  " U Vs/ s H  oDR                  5       PM     sn0 UR                  5        VVs0 s H  u  pTXTR                  5       _M     snnD65      $ U " U[        U5      [        U5      5      $ s  snf s  snnf )Nc              3   B   #    U  H  nUR                  5       v   M     g 7frT   )r+  r  s     rC   r  .StringFormatVariable.create.<locals>.<genexpr>[  s#      
C   ""Cs   )all	itertoolschainvaluesr   r1   r   formatrg   r   r   r   )r   r  r  r  r  r  s         rC   r   StringFormatVariable.createT  s      
__X/@/@/BC
 
 
 --44$$6>?h**,h?=G=M=M=OP=OTQq..00=OP  =$x.$z2BCC	 @Ps   #CCrI   Nc                 x   > [         TU ]  " S0 UD6  [        U[        5      (       d   eXl        X l        X0l        g rL   )rM   rN   r   r   r  r  r  )rO   r  r  r  rI   rP   s        rC   rN   StringFormatVariable.__init__g  s8     	"6"-----* $rB   c                     U R                   R                   SU R                  < SU R                  < SU R                  < S3$ r  )rP   r=   r  r  r  r  s    rC   rN  StringFormatVariable.__repr__t  sB    ..))*!D,>,>+ADMMCTTVW[WfWfViijkkrB   c                   ^ ^ TR                  UU 4S jSS9  T" [        R                  " [        T R                  5      5      5        T R
                  R                  5        VVs0 s H%  u  p#[        R                  R                  U5      U_M'     nnnT" [        R                  " U5      5        TR                  [        SS5      5        g s  snnf )Nc                  z   > T R                  T R                  TR                  5      T R                  S5      /5      $ )Nr  )rZ   r  r  create_load_attrr.  s   rC   rW   2StringFormatVariable.reconstruct.<locals>.<lambda>y  s7    G))--d.@.@A,,X6rB   T)call_function_exF)rY   r   r   r   r  r  r   r1   r   ConstDictVariablerZ   r   )rO   rV   r  r  rI   s   ``   rC   r\    StringFormatVariable.reconstructw  s     " 	 	
 		''T]](;<=@D@U@U@W
@WI&&--a0!3@W 	 
 		++F345dEBC	
s   $,C)r  r  r  r   )r=   r>   r?   r@   rR  r0   r   r   r   r   r   r   r   rN   rN  r\   rA   r   r   s   @rC   r  r  M  s     &G(F(FGNDD ?+D o-.	D
 
D D$%% ?+% o-.	%
 % 
%l# lD DrB   r  c                   L   ^  \ rS rSrS\S\SS4U 4S jjrS\\   4S jrSr	U =r
$ )	ObjectVariablei  rl   rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   r  rs  s      rC   rN   ObjectVariable.__init__  r  rB   c                     [         $ rT   )r   r  s    rC   rh   ObjectVariable.python_type  s    rB   ry  )r=   r>   r?   r@   r   r   rN   rk   rh   rA   r   r   s   @rC   r  r    s2    f   T&\  rB   r  c            	          ^  \ rS rSrSrS\S\SS4U 4S jjr\S\S\\	R                  \	R                  -     4S	 j5       rS
SS\\   S\\\4   SS4S jrSS jr\S\S\\   S\\\4   S\4S j5       rSrU =r$ )DebuggingVariablei  zz
Represents a call to a debugging function like print(), or something
registered to config.reorderable_logging_functions.
rl   rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   r  rs  s      rC   rN   DebuggingVariable.__init__  r  rB   r   c                     [        U 5      =(       aX    [        U [        R                  [        R                  45      =(       a'    U [
        R                  R                  R                  ;   $ rT   )	r  r   r   r   r   r   r  r   reorderable_logging_functionsr   s    rC   is_reorderable_logging_function1DebuggingVariable.is_reorderable_logging_function  sO    
 SM J3!3!3U5N5N OPJu}}++III	
rB   r^   r8   r   c           	         UR                   (       a  g U R                  U R                  X#5      (       d.  [        SSU R                   SU SU 3SSU R                   S3/S9  UR                  R                  U [        U5      45        g )	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.rb   )exportcan_reorder_logsrl   r   debug_localsr  r   r  s       rC   r   DebuggingVariable.call_function  s     99$$TZZ>>dtzzl(4&
6(K@ :$**Egh 	d4j12rB   c                 V    U R                   c   eU R                   R                  U5      $ rT   )ri   r\   r\  s     rC   r\   DebuggingVariable.reconstruct  s'    {{&&&{{&&w//rB   rl  c                     [         R                  [         R                  [        4n[        R
                  " X/5      nU H  n[        XS5      (       a  M    g   g)zU
Run some additional checks for what sort of function calls can we
actually reorder.
FT)r   rA  r1   r  pytreetree_leavesr   )rl  r   rI   allowed_input_types	flat_argsr  s         rC   r  "DebuggingVariable.can_reorder_logs  sR     $$&& 
 &&~6	Cc77  rB   ry  r   )r=   r>   r?   r@   rR  r   rN   r   r   r   r   r   r
  r   r0   r   r   r   r\   r  r  rA   r   r   s   @rC   r  r    s    
c S T  

	5%%(A(AA	B
 
3#3 '3 S/)*	3
 
3.0 S  tCH~ RV  rB   r  c                   f   ^  \ rS rSrSrS\S\SS4U 4S jjrSS	S
\\   S\	\
\4   S\4S jrSrU =r$ )IgnoredFunctionVariablei  zD
Represents a call to an arbitrary function that should be ignored.
rl   rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   r  rs  s      rC   rN    IgnoredFunctionVariable.__init__  r  rB   r^   r8   r   c                 @    [         R                  R                  S 5      $ rT   )r   r1   r   r  s       rC   r   %IgnoredFunctionVariable.call_function  s     ))0066rB   ry  r=   r>   r?   r@   rR  r   rN   r   r0   r   r   r   rA   r   r   s   @rC   r  r    sa    c S T 7#7 '7 S/)*	7
 
7 7rB   r  c            
       ~   ^  \ rS rSrSrS\R                  S\SS4U 4S jjrSS	S
\	S\
\   S\\	\4   S\4
S jrSrU =r$ )LoggingLoggerVariablei  z2
Represents a call to any logging.Logger methods.
rl   rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   r  rs  s      rC   rN   LoggingLoggerVariable.__init__  r  rB   r^   r8   r_   r   c                    UR                   (       a  [        R                  R                  S 5      $ [	        U R
                  US 5      n[	        USS 5      n[        R                  R                  R                  nXW;   d  Xg;   a  [        R                  R                  S 5      $ [        SSU R
                   SU SU SU 3SS/S	9  g )
Nr   z8logging.Logger method not supported for non-export caseszmethod: r  r?  r@  z>logging.Logger methods are not supported for non-export cases.zJAdd the logging method to `torch._dynamo.config.ignore_logging_functions`.rb   )r  r   r1   r   rp   rl   r   r  r   ignore_logging_functionsr   )rO   r^   r_   r   rI   methodr  
ignore_sets           rC   r   !LoggingLoggerVariable.call_method  s     99--44T::T406:t4 ]]))BB
8#9--44T::Ntzzl!D6$z&RX\		
rB   ry  )r=   r>   r?   r@   rR  loggingLoggerr   rN   r   r   r0   r   r   rA   r   r   s   @rC   r!  r!    so    gnn   
#
 
 ?#	

 S/)*
 

 
rB   r!  c            
          ^  \ rS rSrSr SSKJrJr	J
r  S\S\S	S
4U 4S jjr\S	\4S j5       rS	\4S jrSSS\S\\   S\\\4   S	\4
S jrSSS\S	\4S jrSrU =r$ ! \ a    \" SS0 5      r	\" SS0 5      r Nef = f)ConstantLikeVariablei  z8self.value is a compile-time constant, but not a literalr   )dtypefloatinggenericinvalid_typer<   rl   rI   rJ   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rL   r  rs  s      rC   rN   ConstantLikeVariable.__init__   r  rB   c                     [        U R                  5      nUR                  S:X  a  UR                  $ UR                   SUR                   3$ )z4Dynamically compute the prefix from the value's typer   r  )rk   rl   r>   r?   )rO   ts     rC   _error_prefix"ConstantLikeVariable._error_prefix$  sD      <<:%>>!,,q 011rB   c                     U R                   $ rT   ry  r  s    rC   rg   'ConstantLikeVariable.as_python_constant/  r{  rB   r^   r8   r_   r   c                    / 0 pe U Vs/ s H  owR                  5       PM     nnUR                  5        VV	s0 s H  u  pXR                  5       _M     nnn	[        U R                  U5      " U0 UD6n
[        R                  R                  U
5      (       a  [        R                  R                  U
5      $ [        U
[        R                  5      (       a  [        U
5      $ [        S
U R                   SU SU SU SU
 3	SU R                   SU SU
 S3/ [        R                   QS	9  g s  snf s  sn	nf ! [         a8    [        SU R                   SU SU SU S3SU R                   SU S3S/S	9   GNf = f)Nz0constant-like method call with non-constant argsr  z(*z, **rK  zAttempted to call z with non-constant args.zFEnsure that the args to the method call are constant (int, str, etc.).rb   z6constant-like method call with unsupported return typez) returned z, got unsupported return value )rg   r   r   r   r5  rp   rl   r   r1   r   r   r   reMatchr,  r   r  )rO   r^   r_   r   rI   cargsckwargsr  r  r  r   s              rC   r    ConstantLikeVariable.call_method2  s    Rw	59:T))+TE:=C\\^L^TQq..00^GL T*E=W=%%0088--44V<<fbhh'''//L))*!D6D6fX[QWPXY,T-?-?,@$Gfgmfnnop"..		
' ;L" 	J--.avRvT&K01C1C0DAdVKcd\		s,   D3 D(D3 D-D3 (D3 3>E54E5c                    [        U R                  U5      n[        X0R                  5      (       a  [	        U5      n[        X0R
                  5      (       a  [        U5      $ [        U[        5      (       a%  [        X0R                  5      (       a  [        U5      $ [        R                  R                  U5      (       a  [        R                  R                  U5      $ [        X5      $ rT   )rp   rl   r   np_floatingfloatnp_dtypeNumpyDTypeVariablerk   rj   
np_genericr  r   r1   r   r   r   r  s       rC   r    ConstantLikeVariable.var_getattrX  s    T*f..//6]Ffmm,,%f--fd##
6??(K(K ((%%0088--44V<<t**rB   ry  )r=   r>   r?   r@   rR  numpyr-  rB  r.  r@  r/  rD  ImportErrorrk   r   rN   propertyr   r5  rg   r   r0   r   r   r   rA   r   r   s   @rC   r,  r,    s    B
0	
 	
c S T  2s 2 2C $
#$
 $
 ?#	$

 S/)*$
 
$
L+5 +S +_ + +}  0>2r2B/	0s   
A A;:A;r,  c                   8   ^  \ rS rSrSrS\SS4U 4S jjrSrU =r$ )TorchVersionVariableif  ztorch.__version__rI   rJ   Nc                    > UR                  S[        R                  5        US   [        R                  L d   e[        TU ]  " S0 UD6  g )Nrl   r<   )
setdefaultr   __version__rM   rN   rz  s     rC   rN   TorchVersionVariable.__init__i  sA    '5#4#45g%"3"3333"6"rB   r<   )	r=   r>   r?   r@   r5  r   rN   rA   r   r   s   @rC   rJ  rJ  f  s     'M# # # #rB   rJ  c                   "    \ rS rSrS\4S jrSrg)rC  io  rJ   c                 B    U R                   R                  R                  $ )a  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).
)rl   rk   r=   r  s    rC   r  NumpyDTypeVariable.as_proxyp  s     zz'''rB   r<   N)r=   r>   r?   r@   r   r  rA   r<   rB   rC   rC  rC  o  s    (# (rB   rC  c                   b   ^  \ rS rSrSrS\SS4U 4S jjrSSS	\\   S\	\
\4   SS
4S jrSrU =r$ )RandomClassVariablei  zrandom.RandomrI   rJ   Nc                 &   > [         TU ]  " S0 UD6  g rL   ry  rz  s     rC   rN   RandomClassVariable.__init__  r|  rB   r^   r8   r   RandomVariablec                 $   [        U5      S:  d  U(       a"  [        SSU SU 3S/ [        R                  QS9  [        U5      S:X  a  [        R
                  R                  S 5      OUS   n[        U[        R                  R                  5       S9$ )	Nr-   z'random.Random() with improper argumentszargs: r@  z=random.Random() with > 1 arg or with kwargs is not supported.rb   r   )seedr   )
rr   r   r   r  r   r1   r   rV  baseValueMutationNew)rO   r^   r   rI   rX  s        rC   r   !RandomClassVariable.call_function  s     t9q=FA j9[&11	 ;>d)q.y))006dSTgY^^%D%D%F
 	
rB   r<   r  r   s   @rC   rS  rS    sX    # # #
#
 '
 S/)*	

 

 
rB   rS  c            
         ^  \ rS rSrSrS1\R                  kr1 Skr  SS\R                  S-  S\S-  S\
S	S4U 4S
 jjjrS	\\R                     4S jrS	\R                  4S jr\S\	S	\4S j5       r\S\\\\S4   \S-  4   S	S4S j5       r\S\\\\S4   \S-  4   S	\4S j5       r\S\S	\\\\S4   \S-  4   4S j5       rSSS\S\\   S\\\4   S	\4
U 4S jjrSS jrSrU =r$ )rV  i  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randrX  rI   rJ   c                 D  > [         TU ]  " S0 UD6  Ub\  U R                  U5      (       d   e[        R                  " 5       U l        U R                  R                  UR                  5       5        g Ub  UR                  5       OS n[        R                  " U5      U l        g rL   )rM   rN   is_supported_random_objr]  r   setstategetstaterg   )rO   ra  rX  rI   rP   s       rC   rN   RandomVariable.__init__  s|     	"6"//5555 --/DKKK  1040@4**,dD ---DKrB   c                 "    [         R                  $ rT   )r]  r   r  s    rC   rh   RandomVariable.python_type  s    }}rB   c                     U R                   $ rT   r]  r  s    rC   rg   !RandomVariable.as_python_constant  s    {{rB   r  c                    [        U 5      [        R                  La  g[        R                  " [
        R                  S5       H  n[        X5      (       d    g[        X5      n[        R                  " U5      (       a1  U[        [        R                  U5      R                  U 5      :w  a    gMl  [        USS 5      [        [        R                  U5      Ld  M    g   g)NF)rX  re  rd  r   T)rk   r]  r   r  r  rV  _supported_fn_namesr   rp   r  	isbuiltinr  )r  r_   meths      rC   rc  &RandomVariable.is_supported_random_obj  s    9FMM)OO..0P
D 3%%3%D  &&76==$7??DD  E 4T2'&--QU:VV 
 rB   state.c                     [        U 5      [        L d   e[        U S   5      [        L d   e[        U S   5      [        L d   e[        S U S    5       5      (       d   eU S   b  [        U S   5      [        L d   eg g )Nr   r-   c              3   D   #    U  H  n[        U5      [        L v   M     g 7frT   )rk   r`  r  s     rC   r  -RandomVariable.check_state.<locals>.<genexpr>  s     48a47c>8s    r   )rk   r   r`  r  rA  )rq  s    rC   check_stateRandomVariable.check_state  s    E{e###E!H~$$$E!H~&&&45844444Qx4a>U#:::#:rB   c                 r   [         R                  U 5        [        R                  " [        R                  R                  U S   5      [        R                  " U S    Vs/ s H"  n[        R                  R                  U5      PM$     sn5      [        R                  R                  U S   5      /5      $ s  snf )Nr   r-   r   )rV  ru  r   r   r1   r   )rq  r  s     rC   
wrap_stateRandomVariable.wrap_state  s    ""5)&&**11%(;''CH8L8aY//66q98L **11%(;
 	
 Ms   )B4c                 P    U R                  5       n[        R                  U5        U$ rT   )rg   rV  ru  )rq  	state_objs     rC   unwrap_stateRandomVariable.unwrap_state  s&     ,,.	""9-rB   r^   r8   r_   r   c                   >^^ TS:X  a  UR                   R                  R                  U 5        U R                  R                  " U Vs/ s H  oUR                  5       PM     sn0 UR                  5        VVs0 s H  u  pgXgR                  5       _M     snnD6  [        R                  R                  S 5      $ TS:X  a)  U R                  U R                  R                  5       5      $ TS:X  aq  UR                   R                  R                  U 5        U R                  R                  U R                  US   5      5        [        R                  R                  S 5      $ TU R                  ;   a  UR                   R                  R                  U 5        U R                  R                  5       mS[        S[        S[        4UU4S jjn[!        U R                  T5      " U Vs/ s H  oUR                  5       PM     sn0 UR                  5        V	V
s0 s H  u  pXR                  5       _M     sn
n	D6  [#        XX45      $ [$        TU ]M  UTX45      $ s  snf s  snnf s  snf s  sn
n	f )	NrX  re  rd  r   r   rI   rJ   c                  t   > [         R                  " 5       nUR                  T5        [        UT5      " U 0 UD6$ rT   )r]  r   rd  rp   )r   rI   rr_   rq  s      rC   call_random_meth4RandomVariable.call_method.<locals>.call_random_meth	  s1    MMO

5!q$'888rB   )r   r   mutationr]  rX  rg   r   r   r1   r   rx  re  rd  r|  rm  r   rp   r4   rM   r   )rO   r^   r_   r   rI   r  r.  r  r  r  r  rq  rP   s     `        @rC   r   RandomVariable.call_method  s    6>II""++D1KK267$Q&&($7AGPXS3..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 9s 9s 9 9 DKK&267$Q&&($79?H1**,,H
 ""EEw"2tT::7 8P* 8Hs   	I8I#II!c                 8  ^ TR                  U4S j5        TR                  SS5        TR                  5         TR                  S5        T" U R	                  U R
                  R                  5       5      5        TR                  SS5        TR                  5         g )Nc                  n   > T R                  T R                  [        5      T R                  S5      /5      $ )Nr   )rZ   create_load_python_moduler]  r  rV   s   rC   rW   ,RandomVariable.reconstruct.<locals>.<lambda>	  s1    G))55f=,,X6rB   r   Frd  r-   T)rY   r   r1  r   rx  r]  re  pop_topr\  s    `rC   r\   RandomVariable.reconstruct	  sz    	
 	a' 	*% 4 4 678a&rB   rj  r  r   ) r=   r>   r?   r@   rR  r0   r   rm  r]  r   r   rN   rk   rh   rg   r   r  rc  r   r`  rA  ru  r   rx  r|  r   r   r   r   r\   rA   r   r   s   @rC   rV  rV    s    			'	'N
 &*'+.mmd". $. 	.
 
. .T&--0 FMM  V   $ ;5eCHout|!CD ; ; ; 

%U38_edl BC 

 

 

 	sE#s(OUT\1	2 %;#%; %; ?#	%;
 S/)*%; 
%;N rB   rV  c                      ^  \ rS rSr\SSS\R                  \   S\S-  S\SS 4
S	 j5       r	S
\
S\
S\SS4U 4S jjrSSS\\
   S\\\
4   S\
4S jrSS jrS\4S jrS\4S jrS\S\4S jrSrU =r$ )WeakRefVariablei.	  r^   r8   weakref_valueri   NoptionsrJ   c                     Uc   eUR                   nU=(       a    [        US5      n[        R                  " XU5      nU" 5       nU=(       a    [	        U5      n[        R                  " XU5      nX#S'   [        X40 UD6$ )N__callback__ri   )r  r   r0   r   r#   r  )	r^   r  ri   r  callbackcallback_sourcecallback_vtreferentreferent_vts	            rC   r   WeakRefVariable.build/	  s     !!! -- GZ%G%++B/J ?5-f5%++B&A"{C7CCrB   r  r  c                 >   > [         TU ]  " S0 UD6  Xl        X l        g rL   )rM   rN   r  r  )rO   r  r  r  rP   s       rC   rN   WeakRefVariable.__init__A	  s!     	#7#&&rB   r   rI   c                     U R                   $ rT   )r  r  s       rC   r   WeakRefVariable.call_functionH	  s     rB   c                    ^ TR                  U4S j5        T" U R                  5        T" U R                  5        TR                  [	        SS5      5        g )Nc                  (   > T R                  SS5      $ )Nweakrefref)r-  r  s   rC   rW   -WeakRefVariable.reconstruct.<locals>.<lambda>Q	  s    g&>&>y%&PrB   r   F)rY   r  r  rZ   r   r\  s    `rC   r\   WeakRefVariable.reconstructP	  sD    PQ  !  !21e<=rB   c                 6    U R                   R                  5       $ rT   )r  rP  r  s    rC   rP  "WeakRefVariable.is_python_hashableV	  s    2244rB   c                 6    U R                   R                  5       $ rT   )r  rU  r  s    rC   rU  WeakRefVariable.get_python_hashY	  s    //11rB   rX  c                 x    [        U[        5      (       d  gU R                  R                  UR                  5      $ )NF)r   r  r  r\  r[  s     rC   r\  WeakRefVariable.is_python_equal]	  s/    %11//0A0ABBrB   )r  r  r   )r=   r>   r?   r@   r   r  ReferenceTyper   r   r   r0   rN   r   r   r   r   r\   r  rP  r`  rU  r   r\  rA   r   r   s   @rC   r  r  .	  s    D#D,,S1D D 	D
 
D D '*'9H'UX'	' #  '  S/)*	 
 
 >5D 52 2CV C C CrB   r  )rR  r  r  r  r  r  r)  r]  r:  rB  r   r   r  collections.abcr   r   r   r   typingr   r   r	   r
   r   r   torch._Cr   torch._numpyr  r  torch.utils._pytreer  _pytreer  torch._dynamo.variables.baser   torch._dynamo.variables.listsr   torch._guardsr   ra   r   r   r   r   bytecode_transformationr   r   r   create_parameter_opr   r   r   r   guardsr   r   mutation_guardr   ri   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   rY  r.   r/   r0   r  r1   	functionsr2   r3   user_definedr4   r5   r6   torch._dynamo.codegenr7   torch._dynamo.symbolic_convertr8   r:   rE   r   r   r  rP  rT  rZ  rp  rw  r  r  	dataclassr  r  r  r   r   r8  rb  ro  r  	lru_cacher   r   r  r  r  r  r   r  r  r  r  r!  r,  rJ  rC  finfoiinfor-  r  rS  rV  r  r<   rB   rC   <module>r     sJ  "        	 
    .  % J J   $ $ 5 7   @ @ 
 G 9 0 5 
 
 
 
 ' G X X /D	 	R
O R
j
-? -"`; `;FU Upo 
o 
2?7 ?7D;? ;(# #
%c %hsCx6H %` `F M M MC-&? C-L26 2j(_ (NOo NOb[
O [
| &)=? )=XS
_ S
l Q4 9 95;M;M MN   ( Q(4 2 2E4M4M MN (  (]
O ]
B?? ?*-o -9D? 9Dx_ B BJ7o 7$$
O $
NR+? R+j#/ #(- ( II#II#II! 
/ 
6P_ Pf2Co 2CrB   