
    N jx                    X   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KOJPrPJQrQ  SSKRJSrSJTrT  SSKUJVrVJWrWJXrX  \(       a  SSKYJZrZ  SSK[J\r\   " S S5      r] " S S\N5      r^ " S S\N5      r_ " S  S!\N5      r` " S" S#\N5      ra " S$ S%\N5      rb " S& S'\b5      rc " S( S)\N5      rd " S* S+\N5      re " S, S-\N5      rfS.\S/\S0\4   4S1 jrg " S2 S3\N5      rh\R                   " S4 S55      5       rj " S6 S7\X5      rk " S8 S9\X5      rl " S: S;\N5      rm " S< S=\N5      rn " S> S?\N5      ro " S@ SA\N5      rp " SB SC\N5      rq " SD SE\N5      rr\R                  " SSF9S/\t\R"                  \R                  4   4SG j5       rv\R                  " SSF9S/\t\R                  \R"                  4   4SH j5       rw " SI SJ\N5      rx " SK SL\N5      ry " SM SN\N5      rz " SO SP\N5      r{ " 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)CONSTANT_VARIABLE_NONE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=       m/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/_dynamo/variables/misc.pyr;   r;   V   s    rC   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__rH   rI   )selfrH   rI   rJ   	__class__s       rD   rO   SuperVariable.__init___   s#     	"6" 
 rC   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   BuiltinVariablerN   )rQ   codegens   rD   <lambda>+SuperVariable.reconstruct.<locals>.<lambda>q   s    gi.G.G.N&OrC   r   Fr-   )add_push_nullrH   rI   extend_outputr   rP   rW   rQ   s    `rD   reconstructSuperVariable.reconstructp   s`    OP;;"DKK !!"6q%"@A!!"6q%"@ArC   txr9   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()`.)rI   r   rH   as_python_constantpython_typesourcer"   
issubclasstypevalue__mro__index
ValueErrorgetattrrN   rangelen__dict__getr;   r   r    r!   )rP   r_   r`   search_typetype_to_usetype_to_use_sourcerj   
search_mrostart_indexro   resolved_getattrrQ   s              rD   _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rj   )
r|   r   r2   
is_literalGetAttrVariabler   
make_guardr   CONSTANT_MATCHcreate)rP   r_   r`   rm   rj   s        rD   var_getattrSuperVariable.var_getattr   sn     99"C))44U;;"4..&++L,G,GHI))000FFrC   argsc                 @   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OOU 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      (       a[  [        URD                  [F        RH                  5      (       a2  [         R"                  " XRD                  US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"                  " UURD                  [Q        US5      SS9n	U	R'                  X/UQU5      $ [        U[F        RH                  5      (       a6  [         R"                  " XUS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                  $ [        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      (       aO  U[        R                  " 5       ;   a6  [         R"                  " XUSS9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.rc   r>   __new__r?   builtinsTrj   realize__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.)rd   re   rf   rg   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.)
deleted_ok   F)r   zFAttempted 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|   rI   objectrO   LambdaVariabler&   torchnnModuleside_effectsr   
isinstancer   r7   mutation_typer   r0   buildr   call_functionr   r   	DIFFICULTrj   hasattrr>   UserDefinedClassVariableis_supported_new_method__self__r?   rV   membercall_methodstaticmethodr   typesFunctionTypeclassmethodr"   
value_typer   
MethodTypeUserMethodVariabler6   method_setattr_standard__delattr__rh   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__rm   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)rP   r_   r`   r   rJ   inner_fnrj   rI   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                                rD   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
 $))%%fdE &&r88+..:u114
 4
 $++y'I'IJJ  ${{ "
;;%%!+DKK,>,>!?J.44KK** 
 %%%#))!!!&*5	E &&r+@4+@&II%"4"455#))"vtTE&&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#<#<#> 3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NF''[[MD,@&II'"4&$0v24& 9,, `
	
 <;h ' 
U*4&$8!L ` !	 	
H " =(<=8  00PsB   :f,f= #*g) ?h
 ,
f:=
g&g!!g&)hh
h)rI   rH   rU   rW   r8   rK   N)r>   r?   r@   rA   r0   _nonvar_fieldsr   rO   r]   r   tupler   r|   r   listdictr   rB   __classcell__rQ   s   @rD   rF   rF   Z   s    		'	'N *.   $& 	
 
 "BB
)B
14B
	sJ%%	&B
HG5 GS G_ G e
#e
 e
 ?#	e

 S/)*e
 
e
 e
rC   rF   c                   v   ^  \ rS rSrS\R
                  S\SS4U 4S jjrS\4S jr	SS	S
\
S\4U 4S jjrSrU =r$ )FrameSummaryVariablei  frame_summaryrJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   )rN   rO   r   )rP   r   rJ   rQ   s      rD   rO   FrameSummaryVariable.__init__  s    "6"*rC   c                 "    [         R                  $ rU   )	tracebackFrameSummaryrP   s    rD   ri    FrameSummaryVariable.python_type  s    %%%rC   r_   r9   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   r2   r   r   r   r   r`   r   rN   r   rP   r_   r`   rQ   s      rD   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,,rC   )r   )r>   r?   r@   rA   r   r   r   rO   rl   ri   r   r0   r   rB   r   r   s   @rD   r   r     sP    +i&<&< + +PT +&T &	-5 	-S 	-_ 	- 	-rC   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\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_nextrJ   rK   Nc                 H   > [         TU ]  " S0 UD6  Xl        Uc   eX l        g rM   )rN   rO   r   r   )rP   r   r   rJ   rQ   s       rD   rO   TracebackVariable.__init__  s,     	"6"*"""rC   c                 "    U " [        U5      US9$ )N)r   )r   )clsr   r   s      rD   from_frame_summary$TracebackVariable.from_frame_summary  s     '6HHrC   objc                 ~    [        U [        5      =(       d'    [        U [        5      =(       a    U R                  5       $ rU   )r(   r   r2   is_constant_noner  s    rD   is_valid_traceback$TracebackVariable.is_valid_traceback  s0    c,- 
3()Dc.B.B.D	
rC   c                     [        U R                  [        5      (       a  U R                  /$ U R                  /U R                  R	                  5       -   $ rU   )r(   r   r2   r   
extract_tbr   s    rD   r  TracebackVariable.extract_tb  sD    $,, 011&&''""#dll&=&=&???rC   tbc                     U n[        U[        5      (       a(  X!L a  gUR                  n[        U[        5      (       a  M(  g)NTF)r(   r   r   )rP   r
  curr_tbs      rD   has_reference_cycle%TracebackVariable.has_reference_cycle  s;    8<W/00}ooG W/00 rC   c                 "    [         R                  $ rU   )r   TracebackTyper   s    rD   ri   TracebackVariable.python_type  s    """rC   r_   r9   name_varvalc                    UR                  5       nUS:X  a  U R                  U5      (       d  [        [        U5        [	        U[
        [        45      (       d   eU R                  U5      (       d+  [        U[
        5      (       a&  UR                  U 5      (       a  [        [        U5        X0l
        [        R                  $ )Nr   )rh   r  r   	TypeErrorr   r   r2   r  r(   rp   r   r   r1   )rP   r_   r  r  r`   s        rD   call_setattrTracebackVariable.call_setattr  s     **,9**3//(B7c$57G#HIIII'',,s-..33J3J43P3P(R8L///rC   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.rc   )r   r   r   r   r   SUPPORTABLErN   r   s      rD   r   TracebackVariable.var_getattr  s    9<<[ %%11"h??_$%%%Z:& 56l6)556	 w"2,,rC   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   r2   r   r  rN   r   )rP   r_   r`   r   rJ   rQ   s        rD   r   TracebackVariable.call_method  sZ     8--44T!W_EE]"$$R/$//w"2T::rC   )r   r   )r>   r?   r@   rA   r   r   r2   r   rO   r   r   r   r   r   r0   boolr  r   r  r  rl   r   r  ri   r  r   r   r   r   rB   r   r   s   @rD   r   r     s{   + *,<<= 	
 
$ I --I *,<<=I 
	I I 
 
D 
 

@D!7!7:N!NO @
o $ #T%"5"56 #0#0 "0 	0
 
0$-5 -S -_ - ;#; ; ?#	;
 S/)*; 
; ;rC   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	S4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_kwargsrj   r   rK   c                    > [         TU ]  XES9  Xl        X l        U(       a!  [	        SU  SU 3S/ [
        R                  QS9  [        U l        [        U l	        [        S5      U l        [        U l        S U l        g )N)rj   r   z,Keyword args passed to exception constructorz with kwargs zRDynamo does not know how to handle keyword args passed to an exception constructorrc   F)rN   rO   r$  r   r   r   r  r1   __context__	__cause__r2   __suppress_context____traceback__python_stack)rP   r$  r   r%  rj   r   rQ   s         rD   rO   ExceptionVariable.__init__.  s     	D 	F&k];p6)556	 -C +A5Ee5L!.D <@rC   re   c                     Xl         g rU   )r'  )rP   re   s     rD   set_contextExceptionVariable.set_contextO  s    "rC   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>   rW   rP   s   rD   rX   /ExceptionVariable.reconstruct.<locals>.<lambda>T  s    G,,Z9O9OPrC   Fr`   rK   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   )rq   r(   r2   rm   dup_topr[   rot_nr   )r`   r   rW   rP   s     rD   codegen_attr3ExceptionVariable.reconstruct.<locals>.codegen_attrY  sk    4&Dd,--zz%88>$>8!%%gmmA&67""4(rC   r'  r(  r)  )rZ   foreachr   r   rs   r   )rP   rW   r8  s   `` rD   r]   ExceptionVariable.reconstructR  sq    P	
 			"c$))ne4	)s 	)t 	) 	) 	]#[!+,rC   c                     U R                   $ rU   )r$  r   s    rD   ri   ExceptionVariable.python_typeg  s    }}rC   r_   r9   r  r  c                   ^ S[         S[        4U4S jjnUR                  5       nUS:X  a>  [        U[        [
        45      (       d   eU R                  U5        [        R0                  $ US:X  a  UR                  5       (       dM  [        U[        R                  [        R                  [        R                  [        R                  45      (       a1  X0l        [        R
                  " S5      U l        [        R0                  $ U" S5         [        R0                  $ US:X  aF  UR                  SS	5      (       a  X0l        [        R0                  $ U" S5         [        R0                  $ US
:X  aT  [        R!                  U5      (       d$  [#        [$        T[
        R&                  " S5      /S9  X0l        [        R0                  $ [+        SSU  SU 3SU S3/ [,        R.                  QS9  [        R0                  $ )NmsgrK   c                 8   > [        [        T[        U 5      /S9  g )Nr   )r   r  r2   )r?  r_   s    rD   raise_error3ExceptionVariable.call_setattr.<locals>.raise_errorp  s    $Y:J3:O9PQrC   r'  r(  Tz9exception cause must be None or derive from BaseExceptionr)  Fr*  z0__traceback__ must be a traceback object or NonerA  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.rc   )r   r	   rh   r   r#  r2   r.  r  r   rV   !UserDefinedExceptionClassVariable"UserDefinedExceptionObjectVariabler(  r)  is_constant_matchr   r  r   r  r   r*  r   r   r  r1   )rP   r_   r  r  rB  r`   s    `    rD   r  ExceptionVariable.call_setattrj  s   	RS 	RX 	R **,= c$57G#HIIIIS!R ///Q [ ##%%--//??@@	* * "%,5,F,Ft,L): ///7 WX6 ///5 ++$$T511,/)0 ///- WX, ///+ _$$77<<((//N "% /// N'vQtf56 ZZ 7)556 ///rC   r`   rJ   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  r2   rN   r   )rP   r_   r`   r   rJ   r
  rQ   s         rD   r   ExceptionVariable.call_method  sb     = $$R/$//%%DRb"2?"CRHK7&r>>rC   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   rj   rN   r   r   s      rD   r   ExceptionVariable.var_getattr  s    = ###[ >>!++,,,_$%%%V^))$tyy/$++NNw"2,,rC   c                 N    U R                   R                   SU R                   S3$ )N())rQ   r>   r$  r   s    rD   __str__ExceptionVariable.__str__  s$    ..))*!DMM?!<<rC   )r(  r'  r)  r*  r   r$  r+  )NNNr   )r>   r?   r@   rA   r   r   r0   r   r   r   r   rO   r.  r]   rl   ri   r  r   r   r   rQ  __repr__rB   r   r   s   @rD   r#  r#  ,  s?    :> $-1@@ OS()@ #./$6	@
 @ $d*@ 
@ @B#? #t #-*T 60#60 "60 	60
 
60p?#? ? ?#	?
 S/)*? 
? -5 -S -_ -= = HrC   r#  c                       \ rS rSrSrSrg)UnknownVariablei  z
It could be anything!
r=   Nr>   r?   r@   rA   __doc__rB   r=   rC   rD   rU  rU    s    rC   rU  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?  rJ   rK   c                 2   > [         TU ]  " S0 UD6  Xl        g rM   )rN   rO   r?  )rP   r?  rJ   rQ   s      rD   rO    DelayGraphBreakVariable.__init__  s    "6"rC   r_   r9   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 )Nrb   z#Unsupported function call (delayed)zsource: z@Dynamo determined that a graph break should occur when calling `z`. Reason: rc   )rj   r`   r   r?  )rP   r_   r   rJ   r`   s        rD   r   %DelayGraphBreakVariable.call_function  sS     [[(rdkk.>.>9t{{m,!F+dhhZ9	
rC   )r?  rU   )r>   r?   r@   rA   rW  r   r   rO   r   r0   r   r   rB   r   r   s   @rD   rY  rY    sj    C$J    
#
 '
 S/)*	

 

 
rC   rY  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
rK   Nc                     [        S5      e)Nzcomptime is special form)r   rP   rW   s     rD   r]   ComptimeVariable.reconstruct  s    !"<==rC   r_   r9   r`   c                     SSK J n  U R                  c   e[        R                  " U[	        X25      [        U R                  U5      S9$ )Nr   )comptimer   )rd  rj   r0   r   rq   r   )rP   r_   r`   rd  s       rD   r   ComptimeVariable.var_getattr  s?    '{{&&&$$'
4;;0M
 	
rC   r   rJ   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        [,        R.                  $ [	        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        [,        R.                  $ [)        S
[+        U5       35      e)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: )rd  rg  rs   r+   r   r4   get_functionr3   get_codeclosurer/   co_freevarsr   r   	f_globalsfn_namerh   defaultsr   r   RuntimeErrorrl   r   r1   )rP   r_   r   rJ   rg  fncoder   s           rD   r   ComptimeVariable.call_function  s:    	/ SY]-t9+ZF}G<	 !Wb.//OOob124 ///3 677;;=Dzz$efjfvfvewx %%

--/,.KKbkk''(T D $% /// !CDH:NOOrC   r=   r   )r>   r?   r@   rA   rW  r]   r   r0   r   r   r   r   rB   r=   rC   rD   r_  r_    sa    
>
5 
S 
_ 
-0#-0 '-0 S/)*	-0
 
-0rC   r_  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_namerJ   rK   c                 2   > [         TU ]  " S0 UD6  Xl        g rM   )rN   rO   rv  )rP   rv  rJ   rQ   s      rD   rO   CellVariable.__init__3  s     	"6"%:"rC   )rv  rU   )r>   r?   r@   rA   r0   __annotations__rw  r   r   rO   rB   r   r   s   @rD   ru  ru  &  sM     +T11 "Jd
! ?C;%4t%;;NQ;	; ;rC   ru  c                   4   ^  \ rS rSrS\SS4U 4S jjrSrU =r$ )NewGlobalVariablei:  rJ   rK   Nc                 &   > [         TU ]  " S0 UD6  g rM   rN   rO   rP   rJ   rQ   s     rD   rO   NewGlobalVariable.__init__;      "6"rC   r=   )r>   r?   r@   rA   r   rO   rB   r   r   s   @rD   r|  r|  :  s    # # # #rC   r|  fn_clsrK   .c                 R   ^  S[         S[         S[         4U 4S jjn[        Ul        U$ )Nr   rJ   rK   c                  (   > TR                   " U 0 UD6$ rU   )apply)r   rJ   r  s     rD   trampoline_autograd_applyDproduce_trampoline_autograd_apply.<locals>.trampoline_autograd_apply@  s    ||T,V,,rC   )r   !produce_trampoline_autograd_apply_origin)r  r  s   ` rD   r  r  ?  s/    - - - - )J%$$rC   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$ )AutogradFunctionVariableiH  z-represents a torch.autograd.Function subclassr  rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   )rN   rO   r  )rP   r  rJ   rQ   s      rD   rO   !AutogradFunctionVariable.__init__P  s    "6"rC   r_   r9   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      (       ai  [H        RJ                  " U5      n[M        U5      S-
  [M        URN                  5      :X  a  USS  n[         RP                  " TUUS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   rK   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    rD   visit2AutogradFunctionVariable.call_apply.<locals>.visit\  sR    ||~~##50$(M"i8899>>"%%$(M & :rC   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.rc   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_contextTr   z=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_enabledrj   "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	signaturers   
parametersr   r   r   r   r   r   rl   )rP   r_   r   rJ   r  rj   r  r  
forward_fnis_setup_ctx_definedvjp_fnjvp_fnr  apply_sourcer  fwd_srcsetup_ctx_srcrq  ctxsigr   r  s    `                   @rD   
call_apply#AutogradFunctionVariable.call_applyT  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NE&&r488E,,--//224;;? mB-	. W%dV1TF!F8<33783D3D2EZQ3
rC   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S9nUR                  XU5      $ )Nr   r  Tr   )r  r  rl   rm   r   _dynamoexternal_utilsFakeBackwardCFunctionr   r   r   rj   r   r0   r   r   )rP   r_   r   rJ   rq  	fn_sourcer   s          rD   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M""2V44rC   c                 ,    [        U R                  5      $ rU   )r  r  rP   r_   r   rJ   s       rD   r   &AutogradFunctionVariable.call_function  s     (44rC   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.rc   )builderr  r   is_callable_allowedr  r  r   create_proxyr*   r  r  rj   r   r  getattr_staticr   r   r   __get__lookupcreate_with_sourcer   r   r   r   r   r   )rP   r_   r`   r   rJ   r  r  rj   r  r   traceds              rD   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@   rA   rW  r0   r   r   rO   r   r   r   r  r  r   r   r   rB   r   r   s   @rD   r  r  H  s>   7 			'	'N
s c d {#{ ?#{ S/)*	{
 
{z5#5 ?#5 S/)*	5
 
55#5 '5 S/)*	5
 
$5@#@ @ ?#	@
 S/)*@ 
@ @rC   r  c                   F    \ rS rSr% \R
                  " \S9r\\   \	S'   Sr
g)SavedTensorBoxi+  )default_factorytensorsr=   N)r>   r?   r@   rA   dataclassesfieldr   r  r0   rz  rB   r=   rC   rD   r  r  +  s    %0%6%6t%LGT/"LrC   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  i0  zR
Tracks an autograd.Function() context using mutation tracking in side_effects.py
r  	inferencesaved_tensorsNrm   r   needs_input_grad.non_differentiablerJ   rK   c                 Z   > [         TU ]  " SXS.UD6  X0l        X@l        XPl        X`l        g N)rm   r   r=   )rN   rO   r  r  r  r  )	rP   rm   r   r  r  r  r  rJ   rQ   s	           rD   rO   (AutogradFunctionContextVariable.__init__<  s1     	FuFvF"* 0"4rC   r_   r9   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rU   )r  r  .0xs     rD   	<genexpr>9AutogradFunctionContextVariable.create.<locals>.<genexpr>U  s"     $UPT1[[]%Fq%FPTs   /1T)r  r  r  )r   r   r   track_object_newr   r  functionFunctionCtx	functoolspartialr  r  )r_   r   rJ   r  outs        rD   r   &AutogradFunctionContextVariable.createL  sz      $$UPT$UUii$$55NN##///,.!1	 

 
rC   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.rc   )r  r   r   r   r   s    rD   as_proxy(AutogradFunctionContextVariable.as_proxyc  sA    ::'#D6*25)445 zzrC   r`   c                   > US:X  a  [         TU ]  XX45      $ US:X  aD  U(       a  [        XS[        U5       S35        [	        U0 5      S   U l        [        R                  $ 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                  $ )Nr  mark_non_differentiablez0 kwargsrh  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`.rc   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)rN   r   r+   rs   r*   r  r   r1   r   r   r  r  r  rj   r/   r   r   track_save_for_backwardr  append)rP   r_   r`   r   rJ   argrQ   s         rD   r   +AutogradFunctionContextVariable.call_methodp  s    = 7&r>>..#BjS[M:QR&7b&A!&DD#333&&F&tfAdV46 -- 7)556 %S&tfAdV4Ow
 !!---~~T[[$X II""::4F t!!))*Q.)+D&C&&--c2 ///rC   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      $ rU   )r   r   )r   rJ   r`   rP   r_   s     rD   rX   =AutogradFunctionContextVariable.var_getattr.<locals>.<lambda>  s    (8(8T4:v(VrC   r  r  )r   r  r   r   r   r  r  r2   r   rj   r   r0   r   rm   rN   r   rP   r_   r`   rj   rQ   s   ``` rD   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,,rC   )r  r  r  r  )NFNNNNN)r>   r?   r@   rA   rW  r7   r   r   rl   r!  r   rO   r   r   r0   r   r   r   r  r   r   r   rB   r   r   s   @rD   r  r  0  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 
	 ,# 30#30 30 ?#	30
 S/)*30 
30j-5 -S -_ - -rC   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.
Nrm   r   rJ   rK   c                 *   > [         TU ]  " SXS.UD6  g r  r~  )rP   rm   r   rJ   rQ   s       rD   rO   AutogradEngineVariable.__init__  s     	FuFvFrC   r_   r9   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.rc   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   )rP   r_   r`   r   rJ   r   s         rD   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rC   r=   rU   )r>   r?   r@   rA   rW  r   r   _ImperativeEnginerl   r   rO   r   r   r0   r   r   rB   r   r   s   @rD   r  r    s     ?CGxx))G 334t;G 	G
 
G G%#% % ?#	%
 S/)*% 
% %rC   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  rq  .rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   )rN   rO   rq  )rP   rq  rJ   rQ   s      rD   rO   LambdaVariable.__init__  s    "6"rC   r_   r9   r   c                 &    U R                   " U0 UD6$ rU   rq  r  s       rD   r   LambdaVariable.call_function  s     ww'''rC   r
  )r>   r?   r@   rA   r   r0   r   rO   r   r   r   r   rB   r   r   s   @rD   r   r     sf    8C$89 S T (#( '( S/)*	(
 
( (rC   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  rJ   rK   c                    > [         TU ]  " S0 UD6  [        U[        5      (       d   e[        U[        5      (       d   eXl        X l        X0l        g rM   )rN   rO   r   r0   r   r  r`   r  )rP   r  r`   r  rJ   rQ   s        rD   rO   GetAttrVariable.__init__  sJ     	"6"#////$$$$$	rC   c                 R   > U R                   b  U R                   $ [        TU ]	  5       $ rU   )r  rN   ri   rP   rQ   s    rD   ri   GetAttrVariable.python_type  s%    <<#<<7&((rC   c                 h    U R                   R                   SU R                   SU R                   S3$ NrO  z, rP  )rQ   r>   r  r`   r   s    rD   rS  GetAttrVariable.__repr__  s.    ..))*!DHH:R		{!DDrC   
base_proxyr   c                     [        X5      $ rU   )rq   )r  r   s     rD   create_getattr_proxy$GetAttrVariable.create_getattr_proxy  s    z((rC   c                 r    [         R                  U R                  R                  5       U R                  5      $ rU   )r   r  r  r  r`   r   s    rD   r  GetAttrVariable.as_proxy  s&    33DHH4E4E4GSSrC   c                     U R                   R                  5       n [        XR                  5      $ ! [         a    [        U  S35      S ef = f)Nz is not a constant)r  rh   rq   r`   r   r   )rP   constants     rD   rh   "GetAttrVariable.as_python_constant   sO    88..0	M8YY// 	M%.@&ABL	Ms	   1 Ar_   r9   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      $ rU   )r   r  r   r  r   r   get_submodule
module_keyr`   rt   r  r  )rP   r_   r`   step1step2s        rD   const_getattrGetAttrVariable.const_getattr'  s    $((I$>$>??%%		''(;(;<99ENN*%%&&uii8~~%%%%%e22rC   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g rU   )r  r[   create_load_attrsr`   ra  s     rD   r]   GetAttrVariable.reconstruct2  s+    g77		BCrC   r   c                 b    U R                   R                  XR                  [        U5      U5      $ rU   )r  r   r`   r   r  s       rD   r   GetAttrVariable.call_function6  s%     xx##B		4:vFFrC   c                 2  > US;   a  U R                   S:X  a  U(       d  US   R                  5       (       a  [        U R                  [        R
                  [        R                  [        R                  45      (       ar  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                  $ 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 ]E  XX45      $ )N)__getitem__ru   rt   r   ru   r   r-   __contains__TF__setitem__)directly_update_dict)r`   is_python_constantr   r  r   r7   r  r   rh   has_key_in_generic_dictr   rs   r1   r2   r   convert_to_unspecializedrN   r   )rP   r_   r`   r   rJ   r  keyrQ   s          rD   r   GetAttrVariable.call_method>  s    **		Z'Q**,,77..66  ((Cq',,.C**233r// u}t9>7N$;;;	  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::rC   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      $ )Nrt   T)r`   r   r  r   r   r   r   has_pending_mutationban_mutationr0   r   rm   rt   rj   )rP   r_   s     rD   get_forwarded_dict"GetAttrVariable.get_forwarded_dict  s    II#488Y%G%GHHII**??II	
J !%$$R)@)@$++NNrC   )r`   r  r  rU   r   )r>   r?   r@   rA   r0   r   r   rl   r   rO   ri   rS  r   r   fxProxyr  r  rh   r$  r]   r   r   r   r   r   r8  rB   r   r   s   @rD   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rC   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_wrapperrJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   )rN   rO   r>  )rP   r>  rJ   rQ   s      rD   rO   MethodWrapperVariable.__init__  s    "6",rC   r_   r9   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  aY  [        U5      R                  nU[        R                  L a/  [        R                  " [        5      R                  UUU/UQU5      $ GO}[        R                   S:  a  U[        R"                  S   L a|  US:X  av  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  OU[        R"                  S   L a  US:X  d  U[        R"                  S   L a  US:X  a  SSKJn  [        U5      S:X  a9  U(       d2   UR)                  XR                  US   R+                  5       5      5      $ U[        R"                  S   L a  SOSn[3        SU S3S
U  SU SU 3SU S3SU S3SU S3/[4        R6                  QS9  [8        T	U ]u  XU5      $ ! [,         a    [/        [,        U5         GN,[0         a     GN8f = f! [0         a     Nf = f)Nr   r-   z2tensor attribute getter takes exactly one argumentrO   )r      rz  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`.rc   rn   rt   zunsupported type.__dict__['z'].__get__ callz5`torch.compile` only supports calling type.__dict__['z7'].__get__ on a single constant argument (i.e. a type).z&Make sure your call to type.__dict__['zC'].__get__ only has one positional argument (no keyword arguments).z)Make sure the argument to type.__dict__['zT'].__get__ is a constant (i.e. type). For example, `object`, `int`, `MyCustomClass`.)r'   r>  r   r   TensorVariablers   r/   r   r   r>   rl   rO   r   rV   r   sysversion_infort   r  rC  r   rh   r   r   r.   r   r   r  rN   r   )
rP   r_   r   rJ   self_objwrapper_namefn_objrC  r   rQ   s
            rD   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 $--	22|y7Pj11li6O24yA~f,33//Q0J0J0LM  &y)AA	z  5i[P(htfJvhOST]S^ _? ? =YK HF F?	{ KR R
 '22 w$Rv66a & A,^R@: 4 ; s*   20J2  0K 2K	KK
K,+K,Tc                     gNTr=   r   s    rD   r0  (MethodWrapperVariable.is_python_constant      rC   c                     U R                   $ rU   r>  r   s    rD   rh   (MethodWrapperVariable.as_python_constant  s    """rC   c                     grN  r=   r   s    rD   is_python_hashable(MethodWrapperVariable.is_python_hashable  rP  rC   c                 4    [        U R                  5       5      $ rU   hashrh   r   s    rD   get_python_hash%MethodWrapperVariable.get_python_hash      D++-..rC   otherc                 r    [        U[        5      =(       a!    U R                  5       UR                  5       :H  $ rU   r   r0   rh   rP   r]  s     rD   is_python_equal%MethodWrapperVariable.is_python_equal   1    uo. H'')U-E-E-GG	
rC   rR  )r>   r?   r@   rA   r   MethodWrapperTyper   rO   r   r0   r   r   r   r   r0  rh   rU  intrZ  r   r!  ra  rB   r   r   s   @rD   r=  r=    s    -u'>'> -# -RV -a7#a7 'a7 S/)*	a7
 
a7FGDM #E$;$; #GDM / /
V 
 
 
rC   r=  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  descrJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   )rN   rO   rh  )rP   rh  rJ   rQ   s      rD   rO   !GetSetDescriptorVariable.__init__  s    "6"	rC   r_   r9   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  )rj   r   r0   r   rh  r  rN   r   r  s       rD   r   $GetSetDescriptorVariable.var_getattr  sN    9Y7F"((YY->->GG7&r00rC   Tc                     grN  r=   r   s    rD   r0  +GetSetDescriptorVariable.is_python_constant  rP  rC   c                     U R                   $ rU   rh  r   s    rD   rh   +GetSetDescriptorVariable.as_python_constant  s    yyrC   rp  )r>   r?   r@   rA   r   GetSetDescriptorTyper   rO   r   r0   r   r   r0  rh   rB   r   r   s   @rD   rg  rg    se    U77 3 4 15 1S 1_ 1GDM E$>$>  rC   rg  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  rm   is_torchrJ   rK   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=   )rN   rO   rm   r   r>   
startswithru  rP   rm   rJ   rQ   s      rD   rO   PythonModuleVariable.__init__!  sB    "6"


e+Wtzz/B/B/M/Mh/WrC   c                 "    [         R                  $ rU   )r   
ModuleTyper   s    rD   ri    PythonModuleVariable.python_type&  s    rC   c                     U R                   $ rU   rm   r   s    rD   rh   'PythonModuleVariable.as_python_constant)      zzrC   c                 "    SU R                    S3$ )NzPythonModuleVariable(rP  r~  r   s    rD   rS  PythonModuleVariable.__repr__,  s    &tzzl!44rC   r_   r9   r`   c                 l    [        U R                  U5      n[        R                  R	                  U5      $ rU   )r   rm   r   r2   r   rP   r_   r`   r   s       rD   call_obj_hasattr%PythonModuleVariable.call_obj_hasattr/  s+     T*))0088rC   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rU   )r   r   r   r   ru  rm   rt   rq   r   r   rj   r   r0   r   )rP   r_   r`   r   rj   s        rD   r    PythonModuleVariable.var_getattr5  s    99!!>>tJJ99))33D??
==D

(;(;;=$TZZ6
 ,,T2J>DKK!>$$RV<< " =(<=s   =C- -D
	D
)ru  rm   )r>   r?   r@   rA   r0   r   r   r{  r   rO   rl   ri   rh   r   rS  r2   r  r   rB   r   r   s   @rD   rt  rt    s     
	'	'NXe.. X# X$ X
 T%"2"23  E$4$4 5# 59)9149	9=5 =S =_ = =rC   rt  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$ )TypingVariableiF  rm   rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   rN   rO   rm   rx  s      rD   rO   TypingVariable.__init__G      "6"
rC   r_   r9   r`   r   c                    US:X  a:  [        U5      S:X  a+  U R                  US   R                  5          n[        U5      $ US:X  ak  [        U5      S:X  a\  U(       dU  [	        US   [        5      =(       a    U R                  US   R                  :H  n[
        R                  R                  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   r  z,unsupported method call on `typing` variableztyping variable: z, method name: rD  rE  z.`torch.compile` does not support method call `z` on `typing` variable f.zAvoid calling the z method on rc   )rs   rm   rh   r  r(   r   r2   r   r   r   r  )rP   r_   r`   r   rJ   
new_typingr   s          rD   r   TypingVariable.call_methodK  s    = SY!^DG$>$>$@AJ!*--X4yA~fQ8XTZZ4PQ7===X 1188@@B'

|?4&QUPVV`ag`hiHNfgkgqgqfrrst$TF+djj\C"..		
rC   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-   )rC  VariableBuilder)r  rC  r  r%   r   r   r   r   r   r   rq   rm   rj   r   r   )rP   r_   r`   rC  r  rm   r   s          rD   r   TypingVariable.var_getattrd  s    ?)),,T8899!!>>tJJ99))33D??

D);;$T[[$7K"23E::$++B66rC   c                     U R                   $ rU   r~  r   s    rD   rh   !TypingVariable.as_python_constantt  r  rC   c                    > [        U R                  [        R                  5      (       d  [        TU ]  U5      $ UR                  UR                  U R                  5      5        g rU   )r   rm   r   GenericAliasrN   r]   append_outputcreate_load_constr\   s     rD   r]   TypingVariable.reconstructw  sI    $**e&8&8997&w//0 	g77

CDrC   Tc                     grN  r=   r   s    rD   rU  !TypingVariable.is_python_hashable  rP  rC   c                 4    [        U R                  5       5      $ rU   rX  r   s    rD   rZ  TypingVariable.get_python_hash  r\  rC   r]  c                 r    [        U[        5      =(       a!    U R                  5       UR                  5       :H  $ rU   r_  r`  s     rD   ra  TypingVariable.is_python_equal  rc  rC   r~  r   )r>   r?   r@   rA   r   rO   r   r   r0   r   r   r   rh   r]   r   rU  re  rZ  r   r!  ra  rB   r   r   s   @rD   r  r  F  s    c S T 
#
 
 ?#	

 S/)*
 

275 7S 7_ 7 C E8GDM / /
V 
 
 
rC   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   rt   callablerq   )r  np_fn_to_tnp_fnnp_modtnp_modrn  tnp_fnnp_fns          rD   get_np_to_tnp_mapr    sk     )O+113&//557OG $FT::5:-3E*  8 4 rC   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      rD   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.
rm   rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   r  rx  s      rD   rO   NumpyVariable.__init__  r  rC   rq  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?   splitrs   constant_fold_functionsr   rq  mods      rD   can_constant_fold_through'NumpyVariable.can_constant_fold_through  sH    mm!!#&3x1}RaWh,?!???0000rC   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  rs   np_constant_collections_mapru   r  s      rD    get_constant_collection_for_func.NumpyVariable.get_constant_collection_for_func  sJ    mm!!#&3x1}RaWh,?!???*..r22rC   r_   r9   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: rD  rE  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.rc   r   )numpy_to_tensor_wrapperr-   )NumpyNdarrayVariablez8attempted to trace numpy function unsupported by PyTorchz  (corresponding torch function: rP  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   rm   r  r  tensorr  r  ru   r   r  r  rh   r   r.   
USER_ERRORr?   use_numpy_random_stream
patch_argsr>   r  r$   r   r2   r   r   r  r*   )rP   r_   r   rJ   r  r  r   collection_variable_typr  r  r  r  s               rD   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  rD  rE  z6Tracing numpy.* functions as methods is not supported.rc   )r   rm   r   r   )rP   r_   r`   r   rJ   s        rD   r   NumpyVariable.call_method1  s?     	E&tzzl(4&
6(SP",,		
rC   c                     U R                   $ rU   r~  r   s    rD   rh    NumpyVariable.as_python_constantA  r  rC   c                   > [         R                  (       aj  [        U R                  [        R
                  5      (       a  U R                  $ [        U R                  [        5      (       a  U R                  R                  $ [        TU ]%  5       $ rU   )
r   r  r   rm   enumEnumMetarl   r>   rN   r  r  s    rD   r  NumpyVariable.as_proxyD  s\    $**dmm44zz!$**d++ zz***w!!rC   Tc                     grN  r=   r   s    rD   rU   NumpyVariable.is_python_hashableR  rP  rC   c                 4    [        U R                  5       5      $ rU   rX  r   s    rD   rZ  NumpyVariable.get_python_hashU  r\  rC   r]  c                 r    [        U[        5      =(       a!    U R                  5       UR                  5       :H  $ rU   r_  r`  s     rD   ra  NumpyVariable.is_python_equalX  rc  rC   r~  )"r>   r?   r@   rA   rW  tnp
issubdtyper  r   rO   r   r   r   r!  r  r  r   r0   r   r   r   r   r   r   rh   r  r   rU  re  rZ  r   ra  rB   r   r   s   @rD   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 
 
 
rC   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
$ )
NullVariablei`  rJ   rK   Nc                 &   > [         TU ]  " S0 UD6  g rM   r~  r  s     rD   rO   NullVariable.__init__a  r  rC   c                     g)Nr  r=   r   s    rD   rS  NullVariable.__repr__d  s    rC   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.11rb   zdAttempted to generate PUSH_NULL instruction in Python < 3.11; where this instruction does not exist.rc   	PUSH_NULL)rG  rH  r   r   r   r  r   ra  s     rD   r]   NullVariable.reconstructg  sL    g%J9&11 	0=>rC   r=   r   )r>   r?   r@   rA   r   rO   r   rS  r]   rB   r   r   s   @rD   r  r  `  s,    # # ## ? ?rC   r  c                       \ rS rSrSrSrg)r   iu  z"Marker used to implement delattr()r=   NrV  r=   rC   rD   r   r   u  s    ,rC   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$ )StringFormatVariableiy  zS
Represents a call to str.format(), we delay calling format until after the graph.
format_stringsym_args
sym_kwargsrK   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rU   )r0  r  s     rD   r  .StringFormatVariable.create.<locals>.<genexpr>  s#      
C   ""Cs   )all	itertoolschainvaluesr   r2   r   formatrh   r   r   r   )r   r  r  r  r  r  s         rD   r   StringFormatVariable.create  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rJ   Nc                 x   > [         TU ]  " S0 UD6  [        U[        5      (       d   eXl        X l        X0l        g rM   )rN   rO   r   r   r  r  r  )rP   r  r  r  rJ   rQ   s        rD   rO   StringFormatVariable.__init__  s8     	"6"-----* $rC   c                     U R                   R                   SU R                  < SU R                  < SU R                  < S3$ r  )rQ   r>   r  r  r  r   s    rD   rS  StringFormatVariable.__repr__  sB    ..))*!D,>,>+ADMMCTTVW[WfWfViijkkrC   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  )r[   r  r  create_load_attrr3  s   rD   rX   2StringFormatVariable.reconstruct.<locals>.<lambda>  s7    G))--d.@.@A,,X6rC   T)call_function_exF)rZ   r   r   r   r  r  r   r2   r   ConstDictVariabler[   r   )rP   rW   r  r  rJ   s   ``   rD   r]    StringFormatVariable.reconstruct  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@   rA   rW  r0   r   r   r   r   r   r   r   rO   rS  r]   rB   r   r   s   @rD   r  r  y  s     &G(F(FGNDD ?+D o-.	D
 
D D$%% ?+% o-.	%
 % 
%l# lD DrC   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  rm   rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   r  rx  s      rD   rO   ObjectVariable.__init__  r  rC   c                     [         $ rU   )r   r   s    rD   ri   ObjectVariable.python_type  s    rC   r~  )r>   r?   r@   rA   r   r   rO   rl   ri   rB   r   r   s   @rD   r  r    s2    f   T&\  rC   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.
rm   rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   r  rx  s      rD   rO   DebuggingVariable.__init__  r  rC   r  c                     [        U 5      =(       aX    [        U [        R                  [        R                  45      =(       a'    U [
        R                  R                  R                  ;   $ rU   )	r  r   r   r   r   r   r  r   reorderable_logging_functionsr  s    rD   is_reorderable_logging_function1DebuggingVariable.is_reorderable_logging_function  sO    
 SM J3!3!3U5N5N OPJu}}++III	
rC   r_   r9   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: rD  rE  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.rc   )exportcan_reorder_logsrm   r   debug_localsr  r   r  s       rD   r   DebuggingVariable.call_function  s     99$$TZZ>>dtzzl(4&
6(K@ :$**Egh 	d4j12rC   c                 V    U R                   c   eU R                   R                  U5      $ rU   )rj   r]   ra  s     rD   r]   DebuggingVariable.reconstruct  s'    {{&&&{{&&w//rC   rq  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   rF  r2   r  pytreetree_leavesr   )rq  r   rJ   allowed_input_types	flat_argsr  s         rD   r  "DebuggingVariable.can_reorder_logs  sR     $$&& 
 &&~6	Cc77  rC   r~  r   )r>   r?   r@   rA   rW  r   rO   r   r   r   r   r   r  r   r0   r   r   r   r]   r!  r  rB   r   r   s   @rD   r
  r
    s    
c S T  

	5%%(A(AA	B
 
3#3 '3 S/)*	3
 
3.0 S  tCH~ RV  rC   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.
rm   rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   r  rx  s      rD   rO    IgnoredFunctionVariable.__init__	  r  rC   r_   r9   r   c                 "    [         R                  $ rU   )r   r1   r  s       rD   r   %IgnoredFunctionVariable.call_function  s     ///rC   r~  r>   r?   r@   rA   rW  r   rO   r   r0   r   r   r   rB   r   r   s   @rD   r  r    sa    c S T 0#0 '0 S/)*	0
 
0 0rC   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.
rm   rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   r  rx  s      rD   rO   LoggingLoggerVariable.__init__  r  rC   r_   r9   r`   r   c                 P   UR                   (       a  [        R                  $ [        U R                  US 5      n[        USS 5      n[
        R                  R                  R                  nXW;   d  Xg;   a  [        R                  $ [        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  rD  rE  z>logging.Logger methods are not supported for non-export cases.zJAdd the logging method to `torch._dynamo.config.ignore_logging_functions`.rc   )
r  r   r1   rq   rm   r   r  r   ignore_logging_functionsr   )rP   r_   r`   r   rJ   methodr  
ignore_sets           rD   r   !LoggingLoggerVariable.call_method  s     99333T406:t4 ]]))BB
8#9333Ntzzl!D6$z&RX\		
rC   r~  )r>   r?   r@   rA   rW  loggingLoggerr   rO   r   r   r0   r   r   rB   r   r   s   @rD   r&  r&    so    gnn   
#
 
 ?#	

 S/)*
 

 
rC   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=   rm   rJ   rK   Nc                 2   > [         TU ]  " S0 UD6  Xl        g rM   r  rx  s      rD   rO   ConstantLikeVariable.__init__L  r  rC   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  )rl   rm   r?   r@   )rP   ts     rD   _error_prefix"ConstantLikeVariable._error_prefixP  sD      <<:%>>!,,q 011rC   c                     U R                   $ rU   r~  r   s    rD   rh   'ConstantLikeVariable.as_python_constant[  r  rC   r_   r9   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, **rP  zAttempted to call z with non-constant args.zFEnsure that the args to the method call are constant (int, str, etc.).rc   z6constant-like method call with unsupported return typez) returned z, got unsupported return value )rh   r   r   r   r:  rq   rm   r   r2   r   r   r   reMatchr1  r   r  )rP   r_   r`   r   rJ   cargsckwargsr  r  r  r   s              rD   r    ConstantLikeVariable.call_method^  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      $ rU   )rq   rm   r   np_floatingfloatnp_dtypeNumpyDTypeVariablerl   rk   
np_genericr  r   r2   r   r   r   r  s       rD   r    ConstantLikeVariable.var_getattr  s    T*f..//6]Ffmm,,%f--fd##
6??(K(K ((%%0088--44V<<t**rC   r~  )r>   r?   r@   rA   rW  numpyr2  rG  r3  rE  r4  rI  ImportErrorrl   r   rO   propertyr   r:  rh   r   r0   r   r   r   rB   r   r   s   @rD   r1  r1  =  s    B
0	
 	
c S T  2s 2 2C %
#%
 %
 ?#	%

 S/)*%
 
%
N+5 +S +_ + +  0>2r2B/	0s   
A A;:A;r1  c                   8   ^  \ rS rSrSrS\SS4U 4S jjrSrU =r$ )TorchVersionVariablei  ztorch.__version__rJ   rK   Nc                    > UR                  S[        R                  5        US   [        R                  L d   e[        TU ]  " S0 UD6  g )Nrm   r=   )
setdefaultr   __version__rN   rO   r  s     rD   rO   TorchVersionVariable.__init__  sA    '5#4#45g%"3"3333"6"rC   r=   )	r>   r?   r@   rA   r:  r   rO   rB   r   r   s   @rD   rO  rO    s     'M# # # #rC   rO  c                   "    \ rS rSrS\4S jrSrg)rH  i  rK   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).
)rm   rl   r>   r   s    rD   r  NumpyDTypeVariable.as_proxy  s     zz'''rC   r=   N)r>   r?   r@   rA   r   r  rB   r=   rC   rD   rH  rH    s    (# (rC   rH  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.RandomrJ   rK   Nc                 &   > [         TU ]  " S0 UD6  g rM   r~  r  s     rD   rO   RandomClassVariable.__init__  r  rC   r_   r9   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
                  OUS   n[        U[        R                  R                  5       S9$ )	Nr-   z'random.Random() with improper argumentszargs: rE  z=random.Random() with > 1 arg or with kwargs is not supported.rc   r   )seedr   )	rs   r   r   r  r   r1   r[  baseValueMutationNew)rP   r_   r   rJ   r]  s        rD   r   !RandomClassVariable.call_function  s~     t9q=FA j9[&11	 47t9>y//tAwY^^%D%D%F
 	
rC   r=   r$  r   s   @rD   rX  rX    sX    # # #
#
 '
 S/)*	

 

 
rC   rX  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$ )r[  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>   rb  randintuniform	randrangeNrandr]  rJ   rK   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 rM   )rN   rO   is_supported_random_objrb  r   setstategetstaterh   )rP   rf  r]  rJ   rQ   s       rD   rO   RandomVariable.__init__  s|     	"6"//5555 --/DKKK  1040@4**,dD ---DKrC   c                 "    [         R                  $ rU   )rb  r   r   s    rD   ri   RandomVariable.python_type  s    }}rC   c                     U R                   $ rU   rb  r   s    rD   rh   !RandomVariable.as_python_constant  s    {{rC   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)r]  rj  ri  r   T)rl   rb  r   r  r  r[  _supported_fn_namesr   rq   r  	isbuiltinr  )r  r`   meths      rD   rh  &RandomVariable.is_supported_random_obj  s    9FMM)OO..0P
D 3%%3%D  &&76==$7??DD  E 4T2'&--QU:VV 
 rC   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rU   )rl   re  r  s     rD   r  -RandomVariable.check_state.<locals>.<genexpr>		  s     48a47c>8s    r   )rl   r   re  r  rF  )rv  s    rD   check_stateRandomVariable.check_state	  s    E{e###E!H~$$$E!H~&&&45844444Qx4a>U#:::#:rC   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   )r[  rz  r   r   r2   r   )rv  r  s     rD   
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$ rU   )rh   r[  rz  )rv  	state_objs     rD   unwrap_stateRandomVariable.unwrap_state	  s&     ,,.	""9-rC   r_   r9   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                  $ TS:X  a)  U R                  U R                  R                  5       5      $ TS:X  ab  UR                   R                  R                  U 5        U R                  R                  U R                  US   5      5        [        R                  $ 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 ]I  UTX45      $ s  snf s  snnf s  snf s  sn
n	f )	Nr]  rj  ri  r   r   rJ   rK   c                  t   > [         R                  " 5       nUR                  T5        [        UT5      " U 0 UD6$ rU   )rb  r   ri  rq   )r   rJ   rr`   rv  s      rD   call_random_meth4RandomVariable.call_method.<locals>.call_random_meth9	  s1    MMO

5!q$'888rC   )r   r   mutationrb  r]  rh   r   r   r1   r}  rj  ri  r  rr  r   rq   r5   rN   r   )rP   r_   r`   r   rJ   r  r3  r  r  r  r  rv  rQ   s     `        @rD   r   RandomVariable.call_method!	  s    6>II""++D1KK267$Q&&($7AGPXS3..00P 333Z??4;;#7#7#9::ZII""++D1KK  !2!247!;<333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   	H38H8H>4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   )r[   create_load_python_modulerb  r  rW   s   rD   rX   ,RandomVariable.reconstruct.<locals>.<lambda>J	  s1    G))55f=,,X6rC   r   Fri  r-   T)rZ   r   r6  r   r}  rb  rj  pop_topra  s    `rD   r]   RandomVariable.reconstructH	  sz    	
 	a' 	*% 4 4 678a&rC   ro  r  r   ) r>   r?   r@   rA   rW  r0   r   rr  rb  r   r   rO   rl   ri   rh   r   r!  rh  r   re  rF  rz  r   r}  r  r   r   r   r   r]   rB   r   r   s   @rD   r[  r[    s    			'	'N
 &*'+.mmd". $. 	.
 
. .T&--0 FMM  V   $ ;5eCHout|!CD ; ; ; 

%U38_edl BC 

 

 

 	sE#s(OUT\1	2 %;#%; %; ?#	%;
 S/)*%; 
%;N rC   r[  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_   r9   weakref_valuerj   NoptionsrK   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__rj   )r  r   r0   r   r#   r  )	r_   r  rj   r  callbackcallback_sourcecallback_vtreferentreferent_vts	            rD   r   WeakRefVariable.build\	  s     !!! -- GZ%G%++B/J ?5-f5%++B&A"{C7CCrC   r  r  c                 >   > [         TU ]  " S0 UD6  Xl        X l        g rM   )rN   rO   r  r  )rP   r  r  r  rQ   s       rD   rO   WeakRefVariable.__init__n	  s!     	#7#&&rC   r   rJ   c                     U R                   $ rU   )r  r  s       rD   r   WeakRefVariable.call_functionu	  s     rC   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)r2  r  s   rD   rX   -WeakRefVariable.reconstruct.<locals>.<lambda>~	  s    g&>&>y%&PrC   r   F)rZ   r  r  r[   r   ra  s    `rD   r]   WeakRefVariable.reconstruct}	  sD    PQ  !  !21e<=rC   c                 6    U R                   R                  5       $ rU   )r  rU  r   s    rD   rU  "WeakRefVariable.is_python_hashable	  s    2244rC   c                 6    U R                   R                  5       $ rU   )r  rZ  r   s    rD   rZ  WeakRefVariable.get_python_hash	  s    //11rC   r]  c                 x    [        U[        5      (       d  gU R                  R                  UR                  5      $ )NF)r   r  r  ra  r`  s     rD   ra  WeakRefVariable.is_python_equal	  s/    %11//0A0ABBrC   )r  r  r   )r>   r?   r@   rA   r   r  ReferenceTyper   r   r   r0   rO   r   r   r   r   r]   r!  rU  re  rZ  r   ra  rB   r   r   s   @rD   r  r  [	  s    D#D,,S1D D 	D
 
D D '*'9H'UX'	' #  '  S/)*	 
 
 >5D 52 2CV C C CrC   r  )rW  r  r  r  r  r  r.  rb  r?  rG  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   rb   r   r   r   r   bytecode_transformationr   r   r   create_parameter_opr   r   r   r   guardsr   r   mutation_guardr   rj   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r^  r.   r/   r0   r  r1   r2   	functionsr3   r4   user_definedr5   r6   r7   torch._dynamo.codegenr8   torch._dynamo.symbolic_convertr9   r;   rF   r   r   r#  rU  rY  r_  ru  r|  r  r  	dataclassr  r  r  r   r   r=  rg  rt  r  	lru_cacher   r   r  r  r  r  r   r  r  r
  r  r&  r1  rO  rH  finfoiinfor2  r  rX  r[  r  r=   rC   rD   <module>r     sJ  "        	 
    .  % J J   $ $ 5 7   @ @ 
 G 9 0 5 
 
 
 
 ? G X X /D	 	X
O X
v
-? -(`; `;FV Vro 
o 
2?0 ?0D;? ;(# #
%c %hsCx6H %` `F M M MD-&? D-N26 2j(_ (NOo NObx
O x
v &)=? )=XW
_ W
t 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0o 0$$
O $
NS+? S+l#/ #(- ( II#II#II! 
/ 
6P_ Pf2Co 2CrC   