
    7h'[                    <   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	J
r
  SSKJr  SSKJrJrJrJrJr  SSKJr  SSKJr  SSKJr  SSKrSS	KJr  S
SKJrJrJrJr  S
SK J!r!J"r"J#r#  S
SK$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  S
SK/J0r0J1r1  S
SK2J3r3J4r4J5r5J6r6  S
SK7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@  SSKAJBrBJCrCJDrDJErE  SSKFJGrG   SSKHJIrI  \(       a  SSKKJLrL  SSKMJNrN  SSKOJPrPJQrQ  \" S\S9rRSrSSrT\" 5       rU " S S5      rVS\S\V4S  jrWS! rXSgShS" jjrYShS# jrZS$\[\\\E4   4S% jr]S& r^1 S'kr_S( r` " S) S*\E5      ra " S+ S,\a5      rb " S- S.\a5      rc " S/ S0\E5      rd " S1 S2\d5      re " S3 S4\a5      rf " S5 S6\f5      rg " S7 S8\b5      rh " S9 S:\h5      ri " S; S<\b5      rjShS= jrk " S> S?\a5      rl " S@ SA\l5      rm " SB SC\E5      rn " SD SE\n5      ro " SF SG\E5      rp " SH SI\p5      rqSJ rrShSK jrs " SL SM\b5      rt " SN SO\b5      ru " SP SQ\b5      rv " SR SS\E5      rw " ST SU\E5      rx " SV SW\E5      ry " SX SY\E5      rzSSZKOJ{r{J|r|J}r}J~r~   " S[ S\\~5      r\" 5       r " S] S^\E5      r " S_ S`\E5      r " Sa Sb\E5      r " Sc Sd\E5      r " Se Sf\E5      rg! \J a    SrI GNf = f)ia  
Function-related variable tracking classes for Dynamo's symbolic execution.

This module contains classes that track different types of functions during graph
compilation, including:
- User-defined functions and methods
- Built-in functions and methods
- Wrapped functions (e.g. from decorators)
- Special function types (e.g. functools.partial)
- Triton kernels and related function types

These classes are responsible for:
- Tracking function calls and their arguments
- Managing function closures and cell variables
- Handling function attributes and special methods
- Maintaining guards for function identity and closure contents
- Supporting function inlining and specialization
- Enabling proper symbolic execution of different function types

The variable trackers here work together with the rest of Dynamo to enable
accurate graph capture while handling Python's various function-related behaviors.
    N)SequenceFunctionType)AnyCallableOptionalTYPE_CHECKINGTypeVar)Never)patch)WeakKeyDictionary)get_stack_above_dynamo   )configgraph_break_hints	polyfills	variables)create_call_functioncreate_rot_nis_generator)
get_dynamo_observed_exceptionhandle_observed_exceptionInfiniteGeneratorErrorObservedExceptionObservedGeneratorExitObservedUserStopIterationraise_observed_exception	SkipFrameunimplemented_v2Unsupported)GuardBuilderinstall_guard)
AttrSourceConstantSourceDefaultsSourceGetItemSource)	check_constant_argscheck_unspec_or_constant_argscmp_name_to_op_mappingcountersidentityis_functionis_wrapper_or_member_descriptoristype	make_cell   )#AsPythonConstantNotImplementedErrorAttributeMutationNewValueMutationNewVariableTrackerConstantVariable)_fsdp_param_group)	PyCodegenInstructionTranslator)TritonGridTypeTritonKernelType_F)bound      c                   0    \ rS rSrS\4S jrS\4S jrSrg)FunctionSpech   funcc                    UR                   nUR                  nUR                  U l        UR                  U l        UR                  U l        US U R                   U l        X0R                  U R
                   U l	        U R                  U R                  -   U l
        X0R
                  U R
                  U R                  -    U l        U R
                  U R                  -   nUR                  [        -  (       a  X4   OS U l        X@R                  (       a  SOS-  nUR                  [        -  (       a
  X4   U l        g S U l        g )Nr0   r   )__code__co_varnamesco_posonlyargcountposonly_countco_argcount	arg_countco_kwonlyargcountkwonly_countposonly_namespos_or_kw_namesall_pos_nameskwonly_namesco_flags
CO_VARARGSvarargs_nameCO_VARKEYWORDS
varkw_name)selfrD   codevnoffs        [/var/www/fran/franai/venv/lib/python3.13/site-packages/torch/_dynamo/variables/functions.py__init__FunctionSpec.__init__i   s    }}!44)) 22 4$"4"45!"4"4t~~F!//$2F2FF~~ARAR0RSnnt000'+}}z'ABGt%%q1,%)]]^%C"'    c           
         UR                   =(       d    SU l        UR                  =(       d    0 U l        [	        [        U R                  [        U R                  5      * S  [        [        U R                  5      5      5      5      U l	        g N )
__defaults__defaults__kwdefaults__
kwdefaultsdictziprP   lenrangepos_default_map)rW   rD   s     r[   update_defaultsFunctionSpec.update_defaults{   si     ))/R--3  $""C$6#6#895T]]AS;TU 
r^   )rP   rK   rc   re   rM   rQ   rj   rO   rI   rN   rT   rV   N)__name__
__module____qualname____firstlineno__r   r\   rk   __static_attributes__ra   r^   r[   rB   rB   h   s    N\ N$	
L 	
r^   rB   rD   returnc                 ^    [         R                  U 5      nUc  [        U 5      nU[         U '   U$ N)_spec_cachegetrB   )rD   specs     r[   	_get_specrx      s.    ??4 D|D! DKr^   c                    [        U 5      nUR                  U 5        0 n[        U5      n[        UR                  5       H  u  pU[        U5      :  a  [        XU   5      Xi'   M&  X;   a;  XR                  ;   a  [        U	 S35      e[        XR                  U	5      5      Xi'   Mf  XR                  ;   a@  UR                  U	   n
S nU(       a  [        X*5      n[        XR                  U
   U5      Xi'   M  [        SU	 35      e   U[        UR                  5      S  nUR                  (       a"  [        U[        U5      5      XeR                  '   O4U(       a-  [        S[        U5       S[        UR                  5       35      eUR                   Hq  n	X;   a  [        XR                  U	5      5      Xi'   M&  XR                   ;   a0  S nU(       a
  [        X)SS9n[        XR                   U	   U5      Xi'   Me  [        SU	 35      e   UR"                  (       a  [        X5      XeR"                  '   U$ U(       a  [        S[%        U5       35      eU$ )	Nz is positional-onlyz&Missing required positional argument: z#Too many positional arguments: got z, expected T)is_kwz(Missing required keyword-only argument: zUnexpected keyword arguments: )rx   rk   rf   	enumeraterP   rh   wrap_bound_argrN   	TypeErrorpoprj   r%   rc   rT   tuplerQ   re   rV   list)rD   tx	fn_sourceargskwargsrw   barem_kwinameidxdefault_sourceextrakwdefault_sources                 r[   bind_args_cachedr      s   T?D	B&\F T//0s4y=%bq'2BH^)))4&(; <==%b**T*:;BH)))&&t,C!N!/	!?%b--*<nMBHDTFKLL 1" T''(*+E .r5< @	1#d)KDL^L^H_G`a
 	

 !!>%b**T*:;BH__$##1)#N %b//$*?AQRBHFtfMNN " ,R8?? I 
8fGHHIr^   c                     [        U[        5      (       a  U$ U(       d  [        R                  " X5      $ [        R                  R                  X5      $ rt   )
isinstancer4   buildr   LazyVariableTrackercreate)r   valsources      r[   r|   r|      sA    #''
$$R-- ,,33C@@r^   c                     [        UR                  5       5       H/  u  p#[        U[        [        45      (       d  M"  [        X5      X'   M1     g rt   )r   itemsr   r   rf   r|   )r   resultkvs       r[   wrap_args_kwargsr      s6    V\\^$a%''&r-FI %r^   r   c                     U R                   R                  nUR                   H<  nUR                  5       nXA;   a   UR	                  XQR                  U5      5        XQU'   M>     g)z
Update `result` to add mapping from local name to new cells created
directly by `code`, or update SideEffects in `parent` if the a local cell is
already in `result` (cell argument).
N)outputside_effectsco_cellvarstrack_cell_new
store_cellr~   )parentr   rX   r   r   new_cells         r[   init_cellvarsr      sV     ==--L  ..0> ##Hjj.>?t !r^   c                     SSK Jn  U" XX#U5      nXXl        [        U[        5      (       a  SSKJn	  [        U	" U5      5      nUb  [        U[        5      (       d   eXhl        U$ )Nr   r   pairwise)	typesr   rd   r   r   	itertoolsr   rf   __annotations__)
rX   	f_globalsr   rc   closurere   annotationsr   rD   r   s
             r[   _create_nested_fnr      s_     #AD$+u%%&8K01 *[$"?"???&Kr^   >   __doc__rF   __closure____globals__rb   rd   r   c                 >   U=(       a    [        X#5      n [        R                  " X5      nU[
        ;   a  [        X5      nU(       a   [        R                  R                  WU5      $ [        R                  " U W5      $ ! [         a    [	        [        U 5         Nof = frt   )r#   inspectgetattr_staticAttributeErrorr   fn_known_dunder_attrsgetattrr   r   r   r4   r   )r   fnr   r   subobjs        r[   fn_var_getattrr     s    0
60F5''1 $$",,33FFCC  V,,  5 	!45s   A? ?BBc                   \    \ rS rSrS rS r        SS jrSSS\S\4S	 jr	S
 r
S rSrg)BaseUserFunctionVariablei  c                 6    U R                  5       R                  $ rt   get_codeco_filenamerW   s    r[   get_filename%BaseUserFunctionVariable.get_filename      }}***r^   c                 6    U R                  5       R                  $ rt   r   co_namer   s    r[   get_name!BaseUserFunctionVariable.get_name      }}&&&r^   r   r:   rr   c                 L    UR                  U / U R                  5       QUQU5      $ rt   )inline_user_function_return	self_argsrW   r   r   r   s       r[   call_function&BaseUserFunctionVariable.call_function  s,     --d4Ndnn6F4N4NPVWWr^   r   c                     Sn [        U R                  5       U5      n[
        R                  R                  U5      $ ! [         a     US:X  a  [        U [        5      (       a  Sn NHf = f)NFrm   T)hasattrget_functionNotImplementedErrorr   NestedUserFunctionVariabler   r6   r   rW   r   r   r   s       r[   call_obj_hasattr)BaseUserFunctionVariable.call_obj_hasattr'  sh     	T..0$7F ))0088 # 	z!j7Q&R&R	s   = 'A'&A'c                 p    [        [        R                  " U R                  5       5      R                  5      $ rt   )r   r   	signaturer   
parametersr   s    r[   inspect_parameter_names0BaseUserFunctionVariable.inspect_parameter_names3  s'    G%%d&7&7&9:EEFFr^   c                     0 $ rt   ra   rW   r   s     r[   closure_vars%BaseUserFunctionVariable.closure_vars6      	r^   ra   Nr   r:   r   list[VariableTracker]r   dict[str, VariableTracker]rr   r4   )rm   rn   ro   rp   r   r   r   strr4   r   r   r   rq   ra   r^   r[   r   r     sd    +'X#X &X -	X
 
X
9)
914
9	
9Gr^   r   c                      ^  \ rS rSrSrSS1\R                  kr\S 5       rSSU 4S jjjr	U 4S jr
S	 rS
 rS rS rS rS rS\\\4   4S jrSSS\4S jrSSS\S\4S jr        SU 4S jjrSrU =r$ )UserFunctionVariablei:  z-Some unsupported user-defined global functionr   is_constantc                 ^    [        UR                  [        R                  5      5        U " XS9$ Nr   )r"   
make_guardr!   CLOSURE_MATCHclsvaluer   s      r[   create_with_source'UserFunctionVariable.create_with_sourceC  s&    f''(B(BCD5((r^   rr   c                 R  > [         TU ]  " S	0 UD6  [        USS5      (       a  SU l        OSU l        [	        U[
        R                  [        R                  R                  45      (       d  [        SU SS/[        R                  QS9  [        R                  " USU5      nXl        g )
N_dynamo_marked_constantFTz1can't handle functions not implemented in python z2Dynamo can only handle functions defined in pythonz9Move usage of this function out of `torch.compile` regiongb_typecontextexplanationhints_torchdynamo_inlinera   )superr\   r   r   r   r   r   torchjitScriptFunctionr   r   INFERENCE_MODEr   r   r   rW   r   r   r   	__class__s       r[   r\   UserFunctionVariable.__init__H  s    "6"20%88#D$D "u115993K3KLMMK$PO&55	 ##B(=rB&(r^   c                 b   > [        U [        5      (       a  U R                  $ [        TU ]  5       $ rt   )r.   r   r   r   as_python_constantrW   r  s    r[   r  'UserFunctionVariable.as_python_constantb  s(    $,--77Nw)++r^   c                     / $ rt   ra   r   s    r[   r   UserFunctionVariable.self_argsh  r   r^   c                     U R                   $ rt   r   r   s    r[   r   !UserFunctionVariable.get_functionk      wwr^   c                 .    U R                   R                  $ rt   )r   rF   r   s    r[   r   UserFunctionVariable.get_coden  s    wwr^   c                 "    [         R                  $ rt   r   r   r   s    r[   python_type UserFunctionVariable.python_typeq      !!!r^   c                 4    [        U R                  SS 5      S L$ N__self__)r   r   r   s    r[   has_selfUserFunctionVariable.has_selft  s    tww
D1==r^   c                 .    U R                   R                  $ rt   )r   r   r   s    r[   get_globals UserFunctionVariable.get_globalsw  s    ww"""r^   c                 n   U R                   (       a   eU R                  n[        U[        5      (       d  [	        S5      eUR
                  R                  n[        XEU R                  X#5      n[        XUR                  5        U R                  R                  =(       d    Sn[        U5      [        U R                  R                  R                  5      :X  d   e[        [        R                   " 5       U R                  R                  R                  U5       H  u  pn
UR
                  R"                  nX;   a  X   nOU R                  (       aa  [%        ['        U R                  S5      U5      n['        US5      n [(        R*                  " XR,                  U5      nUR5                  XU5      nO3 [(        R*                  " XR,                  5      nUR5                  SX5      nXU	'   M     U$ ! [.         a    [0        R2                  " 5       n Nqf = f! [.         a    [0        R2                  " 5       n Nbf = f)z
Assume `args` and `kwargs` are VariableTracker arguments for a call to
this function, create new bindings for initial locals.
z'Only supports regular Python functions.ra   r   cell_contentsN)r   r   r   r   r}   r   root_txr   r   r   rF   r   rh   co_freevarsrg   r   countr   r&   r#   r4   r   r  
ValueErrorr   DeletedVariabletrack_cell_existing)rW   r   r   r   r   r  r   r   r   r   cellr   cell_varclosure_cellclosure_cell_contentscontents_vars                   r[   	bind_argsUserFunctionVariable.bind_argsz  s   
 ####!%"l++EFF--''!"t{{DIfbkk2''%%+7|s477#3#3#?#?@@@@"OOtww//;;W 
OCt "==55L#'-,t{{M:C  )3<(Q%?#2#8#8 2 24I$L (;; ?#2#8#8ASAS#TL (;;D$U#4LE 
H ' " ?#,#<#<#>L? " ?#,#<#<#>L?s$   <!G-1 H-HHH43H4r   r:   r   c                     U[         ;   a  [        R                  " X5      $ [        XR                  U R
                  U5      $ rt   )r)   r   GetAttrVariabler   r   r   rW   r   r   s      r[   var_getattr UserFunctionVariable.var_getattr  s3    )),,T88b''4;;==r^   c                 l    [        U R                  U5      n[        R                  R	                  U5      $ rt   )r   r   r   r6   r   r   s       r[   r   %UserFunctionVariable.call_obj_hasattr  s+     $'))0088r^   c           
        > U R                   [        R                  R                  L a   U Vs/ s H  oDR	                  5       PM     nnUR                  5        VVs0 s H  u  pgXgR	                  5       _M     nnn[        R                  R                  " U0 UD6R                  n	[        R                  " U	5      $ U R                   [        R                  R                  L Ga  [        R                  " U R                   5      R                  " U0 UD6nUR                  S   n[!        U["        5      (       dP  UR%                  5       nSUR&                   S3n[)        SSU R*                   SU SU S	3U/ [,        R.                  QS
9  [!        U[0        5      (       d)  UR3                  5       nSU S3n[)        SU  USU S3S/S
9  UR                   n[        R4                  " USS9$ U R6                  (       a%  [9        XR                   U R3                  5       X#5      $ UR:                  R<                  R>                  (       dt  U R                   [        R                  R@                  RB                  L aC  [        R                  RD                  RG                  U5         [H        TU ]  XU5      sS S S 5        $ UR:                  R<                  RL                  (       a  UR:                  R<                  RN                  (       ds   SSK(J)n  Ubi  U R                   URV                  URX                  4;   aC  [        R                  RD                  RO                  U5         [H        TU ]  XU5      sS S S 5        $ [H        TU ]  XU5      $ s  snf s  snnf ! [         a  n
[        SU SU 35      U
eS n
A
ff = f! , (       d  f       GN= f! [T         a    S n Nf = f! , (       d  f       Nq= f)NzCannot convert patch_dynamo_config args/kwargs to constants. Please fix your call to patch_dynamo_config by using simpler inputs. args: z
, kwargs: r   z=`nonstrict_trace` expects a callable, but got value of type <>zTypeError from user codezcall_function(, )r   z(Applying `nonstrict_trace` to function <zk>; however, `nonstrict_trace` currently requires the function to be defined outside `torch.compile` region.zLimitation of `nonstrict_tracezmake sure definition of z is outside z`torch.compile` regionTnonstrict_traceable)	FSDPState)-r   r   _dynamopatch_dynamo_configr  r   changesr   DynamoConfigPatchVariabler1   RuntimeErrornonstrict_tracer   r   bindr   r   r   r  rm   r   r   r   
USER_ERRORr   r   TorchInGraphFunctionVariabler   invoke_and_store_as_constantr   current_tracer,unsafe_allow_externally_visible_side_effectsutils8_disable_side_effect_safety_checks_for_current_subtracerr   2allow_externally_visible_side_effects_in_subtracerr   r   under_activation_checkpoint#allow_side_effects_under_checkpoint/torch.distributed.fsdp._fully_shard._fsdp_stater8  	Exception_pre_forward_post_forward)rW   r   r   r   arg
args_constkeyr   kwargs_constr;  er>   fn_vartypmsgfn_namer   r8  r  s                     r[   r   "UserFunctionVariable.call_function  s{    77emm777BFG$3446$
GBH,,. BPhcC//11.     --;;#/'  !::7CC 77emm333%%dgg.33TDVDEZZ]Ff&>??((*UVYVbVbUccde 6,TZZL4&6(!L #*55	 f&:;; //+@	  Ju  v <#f #27)<H0	 B99"RVWW/GGT]]_d 
 		((UU}}""[[\ ++^^ w,Rv>  II$$@@II,,PP!U $&&''5 * ]]//SSTVW 706B XWw$Rv66W H  7 "!F*VH6 	`   ! 	! XWs_   N NN N8AN N1 O ON 
N.N))N.1
O OO
O#)r   r   Frr   Nr   )rm   rn   ro   rp   r   r   _nonvar_fieldsclassmethodr   r\   r  r   r   r   r  r  r  rf   r   r4   r)  r.  r   r   rq   __classcell__r  s   @r[   r   r   :  s    7 	 
"	0	0N ) )) )4, ">#5c?6J1K 5n>5 >S >
9)9149	9U7#U7 &U7 -	U7
 
U7 U7r^   r   c                   Z   ^  \ rS rSrSSU 4S jjjr\S 5       r        SS jrSrU =r	$ )	BuiltinMethodVariablei  c                 t   > [         TU ]  " S0 UD6  [        U[        R                  5      (       d   eXl        g r`   )r   r\   r   r   BuiltinMethodTyper   r   s       r[   r\   BuiltinMethodVariable.__init__  s1    "6""e556666r^   c                     U R                   nU R                  nU[        L =(       a    US:H  =(       d    [        U5      [        L =(       a    US:H  $ )N__new____contains__)r  rm   r   type	frozenset)objmethod_selfmethod_names      r[   is_supported_builtin_method1BuiltinMethodVariable.is_supported_builtin_method  sI    llll u$A	)A 
*L{n/L	
r^   c                     U R                   R                  nU R                   R                  nU R                  =(       a    [	        U R                  S5      n[
        R                  " XU5      nUR                  XX#5      $ r  )r   r  rm   r   r#   r4   r   call_method)rW   r   r   r   ri  r   
obj_sourceobj_vts           r[   r   #BuiltinMethodVariable.call_function%  s`     gg&&ww[[HZZ%H
 &&r
C!!"D99r^   r
  rX  rY  r   )
rm   rn   ro   rp   r\   staticmethodrk  r   rq   r\  r]  s   @r[   r_  r_    sQ     
 
 

:#
: &
: -	
:
 

: 
:r^   r_  c            
          ^  \ rS rSrS\R
                  S\S   4U 4S jjrS rS r	S r
S	 rS
 rS r S r\rS$S jrS rS rS rS rS rS rS\R.                  4S jrS\\   4S jrS%S jrS rS rS rSSS\ SSSS SS!4
U 4S" jjr!S#r"U =r#$ )&LocalGeneratorObjectVariablei2  rX   inline_tracerr:   c                 J   > [         TU ]  " S0 UD6  Xl        X l        X0l        g r`   )r   r\   rX   r   ru  )rW   rX   r   ru  r   r  s        r[   r\   %LocalGeneratorObjectVariable.__init__3  s%     	"6"	"*r^   c                     U R                   $ rt   )rX   r   s    r[   r   %LocalGeneratorObjectVariable.get_code?  s    yyr^   c                 6    U R                  5       R                  $ rt   r   r   s    r[   r   )LocalGeneratorObjectVariable.get_filenameB  r   r^   c                 6    U R                  5       R                  $ rt   r   r   s    r[   r   %LocalGeneratorObjectVariable.get_nameE  r   r^   c                     [         ert   )r   r   s    r[   r   )LocalGeneratorObjectVariable.get_functionH  s    !!r^   c                     gNFra   r   s    r[   r  %LocalGeneratorObjectVariable.has_selfK      r^   c                 "    U R                  5       $ rt   )r   r   s    r[   rm   %LocalGeneratorObjectVariable.__name__N  s    }}r^   c                 V    U R                   R                   SU R                  5        S3$ )N(r5  )r  rm   r   r   s    r[   __str__$LocalGeneratorObjectVariable.__str__Q  s'    ..))*!DMMO+<A>>r^   c                    SSK Jn  SSKJnJnJn  UR                  " 5       nU" U5      nU" U5      nU" U5      n	U   U   U	   U R                  U5      n
U
R                  (       d  U R                  U5      U l
        [        R                  " U R                  5      R                  U5        S S S 5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N(= f! , (       d  f       g = f)Nr   )"disallow_side_effects_in_generator)r:    save_and_restart_speculation_log(temporarely_allow_writes_to_output_graph)torch._dynamo.side_effectsr  torch._dynamo.symbolic_convertr:   r  r  
current_tx_get_inline_tracergenerator_exhaustedforce_unpack_var_sequenceremaining_itemsr   ListIteratorVariablereconstruct)rW   codegenr  r:   r  r  r   savedisallowtemptracers              r[   r  (LocalGeneratorObjectVariable.reconstructV  s    Q	
 	
 #--//35b97;8T,,R0F--'+'E'Eb'I$**4+?+?@LLWU	 "8TTTT88TTs;   C%CA(C*C2C%
CC
C"	C%%
C3c                 :    U R                   R                  XU5      $ rt   )r   r)  r   s       r[   r)  &LocalGeneratorObjectVariable.bind_argsi  s    ww  622r^   c                     U R                   $ rt   r   r   s    r[   r  (LocalGeneratorObjectVariable.get_globalsl      ~~r^   c                 "    [         R                  $ rt   )r   GeneratorTyper   s    r[   r  (LocalGeneratorObjectVariable.python_typeo  s    """r^   c                 p    SSK Jn  U R                  c  UR                  X/ 0 5      U l        U R                  $ Nr   )InliningInstructionTranslator)r  r  ru  build_inline_tracer)rW   r   r  s      r[   r  /LocalGeneratorObjectVariable._get_inline_tracerr  s9    P%!>!R!R"b"D !!!r^   c                    U R                  U5      nU R                  5       (       a  [        [        U5         [        R
                  " [        S[        S   05         UR                  5       sS S S 5        [        S==   [        S   -  ss'   $ ! , (       d  f       Os= f! [         a  nSUl	        UeS nAf[         a    e [         aC  n[        R                  R                  R                  U R!                  5       5        ["        UeS nAff = f [        S==   [        S   -  ss'   g ! [        S==   [        S   -  ss'   f = f)Nunimplementedinline_callT)r  _is_generator_exhaustedr   StopIterationr   rf   r*   inline_call_r   r  r   r    r   r9  
eval_frame	skip_coder   r   )rW   r   r  rR  s       r[   next_variable*LocalGeneratorObjectVariable.next_variable{  s
   ((,''))$]B7	A H8O&PQ**, RQ _%-)@@% RQ  	)-F&G% 	 	#MM$$..t}}?"	# R _%-)@@%H_%-)@@%sS   $B B,	B 
BB D) B 
D)	B22D	>DDD) )Ec                     gr  ra   r   s     r[   has_unpack_var_sequence4LocalGeneratorObjectVariable.has_unpack_var_sequence  r  r^   rr   c                     gNTra   r   s     r[   has_force_unpack_var_sequence:LocalGeneratorObjectVariable.has_force_unpack_var_sequence  s    r^   c                 @    / nU R                  XR                  5        U$ rt   )force_apply_to_var_sequenceappend)rW   r   r   s      r[   r  6LocalGeneratorObjectVariable.force_unpack_var_sequence  s    ((]];r^   c                 n      U" U R                  U5      5        M  ! [         a    [        U5         g f = frt   )r  r   r   )rW   r   r   s      r[   r  8LocalGeneratorObjectVariable.force_apply_to_var_sequence  s>    4%%b)*  - )"-s    44c                     U R                  U5      n UR                  U5        g ! [         a  nUR                  U5         S nAg S nAff = frt   )r  _raise_exception_variabler   exception_handler)rW   r   excr  rR  s        r[   _setup_exception-LocalGeneratorObjectVariable._setup_exception  sH    ((,	(,,S1  	( $$Q''	(s   % 
A
AA
c                 ^    U R                   S L =(       d    U R                   R                  S:H  $ )Nr   )ru  instruction_pointerr   s    r[   _is_generator_just_started7LocalGeneratorObjectVariable._is_generator_just_started  s*    !!T)XT-?-?-S-SWX-XXr^   c                 0    [        U R                  SS5      $ )Nr  F)r   ru  r   s    r[   r  4LocalGeneratorObjectVariable._is_generator_exhausted  s    t))+@%HHr^   r   r   r   r   r   r   r4   c                   > US:X  a  U R                  U5      $ US:X  a  U $ US:X  a  U R                  5       (       a7  [        U5      (       a'  [        S U 5       5      (       d  [	        [
        U5        U R                  U5      nUR                  U5        U R                  U5      $ US:X  a  U R                  U5      nU R                  5       (       d  U R                  5       (       a  SUl	        [        R                  " S 5      $  U R                  U[        R                  " [        S5      5        [        R                   S:  a7  UR"                  R$                  S	:X  a  SUl	        [        R                  " S 5      $  U R                  U5      (       a  [	        [(        U5        OUS
:X  a  U R                  U5      n U R                  U[        U5      S:X  a  US   OUS   5        U R                  U5      n[1        S[2        40 5      n U R                  U[        R                  " US5      5        U R                  U5        [	        [(        U5        U$ [6        TU ]q  XX45        g ! [&         a     SUl	        [        R                  " S 5      s $ f = f! [&         a     SUl	        [        R                  " S 5      s $ [*         a    UR,                  c   eUR,                  s $ f = f! [.         a    e f = f! [5        U5       a     U$ f = f)N__next____iter__sendc              3   l   #    U  H*  n[        U[        5      =(       a    UR                  S L v   M,     g 7frt   )r   r6   r   ).0rN  s     r[   	<genexpr>;LocalGeneratorObjectVariable.call_method.<locals>.<genexpr>  s0      # s$45K#))t:KK#s   24closeTra   )      CALL_INTRINSIC_1throwr  r0   r   __InternalThrowException)r  r  rh   allr   r}   r  	push_manyr  r  r   r6   r  ExceptionVariableGeneratorExitsysversion_infonext_instructionopnamer   r=  r   symbolic_resultr   rf  rK  r   r   rn  )	rW   r   r   r   r   r  retvalexc_typer  s	           r[   rn  (LocalGeneratorObjectVariable.call_method  s    :%%b))ZKV^ ..00SYY  #   -Y;,,R0FT"%%b))W_ ,,R0F..00D4P4P4R4R-1* 11$778%%	33M2F( $$///66:LL15F.$55d;;.%%b)),\2> W_ ,,R0F
 %%bSY!^$q'aQ
 ''+F| 6bIH?%%b)*E*EhPR*ST""2&
 )v>MBd3a ) 8-1* 11$778 ) 8-1* 11$77, .
 --999---., % N 1:  MsI   A5I# <&J ;)K# 8K2 #'JJ'K 9$K K #K/2LL)rX   r   ru  r  r  r8   rY  )$rm   rn   ro   rp   r   CodeTyper   r\   r   r   r   r   r  r  __repr__r  r)  r  r  r  r  r  builtinsboolr  r   r4   r  r  r  r  r  r   rn  rq   r\  r]  s   @r[   rt  rt  2  s    
+nn
+   78	
++'"? HV&3#"A08== tO/D 
(YIz4#z4 z4 &	z4
 -z4 
z4 z4r^   rt  c                       \ rS rSrSrSrg)4ContextlibContextManagerLocalGeneratorObjectVariableir  z
.. note::

    This is only used when the function is annotated with @contextlib.contextmanager

    It is a special case of a generator function as we do not allow return a context manager
    from a torch.compile function.
ra   N)rm   rn   ro   rp   r   rq   ra   r^   r[   r  r  r  s    r^   r  c                   b   ^  \ rS rSrSr\S.S\4U 4S jjjrS rS r	        S
S jr
S	rU =r$ )LocalGeneratorFunctionVariablei  zlfunctions that behaves like iterators

.. note::

    This is a wrapper around (Nested)UserFunctionVariable
)generator_clsvtc                >   > [         TU ]  " S0 UD6  Xl        X l        g r`   )r   r\   r  r  )rW   r  r  r   r  s       r[   r\   'LocalGeneratorFunctionVariable.__init__  s      	"6"*r^   c                     XR                   R                  R                  5       ;   a  [        X5      $ [        U R                  U5      $ rt   )r  __dict__keysr   r  )rW   r   s     r[   __getattr__*LocalGeneratorFunctionVariable.__getattr__  s7    >>**//114&&tww%%r^   c                 6    SSK Jn  UR                  UU UU5      $ r  )r  r  r  )rW   r   r   r   r  s        r[   _build_inline_tracer3LocalGeneratorFunctionVariable._build_inline_tracer  s$    P,@@	
 	
r^   c                    [        U R                  R                  5       5      (       d   eU R                  XU5      nU R                  R                  5       nU R                  R	                  5       nU R                  UUUU R                  S9$ r   )r   r  r   r  r  r  r   )rW   r   r   r   ru  rX   r   s          r[   r   ,LocalGeneratorFunctionVariable.call_function  s     DGG,,.////11"FCww!GG'')	 !!;;	 " 
 	
r^   )r  r  r   )rm   rn   ro   rp   r   rt  r4   r\   r  r  r   rq   r\  r]  s   @r[   r  r    sY     3		+	+ 	+&


#
 &
 -	

 

 
r^   r  c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )3FunctionDecoratedByContextlibContextManagerVariablei  za
.. note::

    This is only used when the function is annotated with @contextlib.contextmanager
c                 4   > [         TU ]  " U4S[        0UD6  g )Nr  )r   r\   r  )rW   r  r   r  s      r[   r\   <FunctionDecoratedByContextlibContextManagerVariable.__init__  s%    	
N	
 	
r^   c                    > [         TU ]  XU5      n[        U[        R                  R
                  R                  5      (       d   eSUl        U$ r  )r   r  r   r   r9  symbolic_convert&InliningGeneratorInstructionTranslatoris_generator_from_ctx_manager)rW   r   r   r   r  r  s        r[   r  HFunctionDecoratedByContextlibContextManagerVariable._build_inline_tracer  sR    
 -b?MM**QQ
 
 	
 
 04,r^   ra   )	rm   rn   ro   rp   r   r\   r  rq   r\  r]  s   @r[   r   r     s    
 r^   r   c                      ^  \ rS rSrSrSU 4S jjrS\4S jrS rS r	        SU 4S
 jjr
U 4S jrSS	S\4U 4S jjrSrU =r$ )UserMethodVariablei  z$Some unsupported user-defined methodrr   c                 6   > [         TU ]  " SSU0UD6  X l        g )Nr   ra   r   r\   rh  )rW   r   rh  r   r  s       r[   r\   UserMethodVariable.__init__  s    )B)&)r^   c                 h    U R                   R                   SU R                   SU R                   S3$ )Nr  r4  r5  )r  rm   r   rh  r   s    r[   r  UserMethodVariable.__repr__  s.    ..))*!DGG9BtxxjBBr^   c                     U R                   /$ rt   rh  r   s    r[   r   UserMethodVariable.self_args      zr^   c                 "    [         R                  $ rt   )r   
MethodTyper   s    r[   r  UserMethodVariable.python_type  s    r^   r   r:   c                   > SSK Jn  U" U R                  5      (       aE  / U R                  5       QUQn[        R
                  " U R                  SS9nUR                  XU5      $ UR                  R                  5       (       a  [        U R                  [        R                  5      (       a  [        U R                  SS5      nUb  UR                  S5      (       a  US:w  d  U R                  (       a9  U R                  R                  XR                  R                   X#U R                  S	9$ Ol["        be  U R                  ["        R$                  R&                  L a>  [        R(                  " U R                  5      R                  XR                  /UQ7U5      $ U R                  (       aO  [        U R                  R*                  U R                  R                   5      n[-        XU R/                  5       X#5      $ [0        T	U ]  XU5      $ )
Nr   )is_nonstrict_trace_callableTr6  rn    z	torch.nn.ztorch.nn.utils.parametrize)constant)trace_rulesr  r   r   r   rA  r   r   is_root_tracerr   rh  NNModuleVariabler   
startswithr   rn  rm   r7   FSDPParamGroupuse_training_stateTorchCtxManagerClassVariabler   rB  r   r   )
rW   r   r   r   r  	call_argsvarmodule_attrr   r  s
            r[   r    UserMethodVariable.call_function  s    	>&tww//2$..*2T2I88TC $$RF;; 99##%%*HHi00+
 +
 "$''<<K '**;77#??##xx++(($AQAQ ,   $ ),;;NNN99$''BPPXX%%v  )9)9:B/VVw$Rv66r^   c                 &   > [         TU ]  5       SS  $ Nr0   )r   r   r  s    r[   r   *UserMethodVariable.inspect_parameter_names!  s    w.044r^   r   c                    > U R                   =(       a    [        U R                   U5      nUS:X  a  U R                  $ US:X  a!  [        R                  " XR
                  U5      $ [        TU ]  X5      $ )Nr  __func__)r   r#   rh  r4   r   r   r   r.  )rW   r   r   r   r  s       r[   r.  UserMethodVariable.var_getattr$  s\    >DKK!>:88O:"((WWf==w"2,,r^   r  rY  r   )rm   rn   ro   rp   r   r\   r   r  r   r  r   r   r.  rq   r\  r]  s   @r[   r	  r	    sm    .C# C ;7#;7 &;7 -	;7
 
;7z5-5 -S - -r^   r	  c                   R   ^  \ rS rSrSU 4S jjr        SU 4S jjrS rSrU =r$ )WrappedUserMethodVariablei-  c                    > UR                  SS 5        UR                  SS 5        [        TU ]  " UR                  UR                  40 UD6  Xl        X l        g )Nr   rh  )r~   r   r\   r   rh  wrappedr   rW   r.  r   r   r  s       r[   r\   "WrappedUserMethodVariable.__init__.  sE    

4

5$W[[;F;r^   c                    > U R                   R                  U5        [        TU ]  XU5      nU R                   R	                  U5        U$ rt   r   enterr   r   exitrW   r   r   r   r   r  s        r[   r   'WrappedUserMethodVariable.call_function5  ?     	2&r8"r^   c                    ^ ^ TR                  UU 4S j5        T" T R                  5        TR                  [        SS5      5        g )Nc                  (   > T " TR                   5      $ rt   r   r  rW   s   r[   <lambda>7WrappedUserMethodVariable.reconstruct.<locals>.<lambda>A      gdll&;r^   r0   Fadd_push_nullr.  extend_outputr   rW   r  s   ``r[   r  %WrappedUserMethodVariable.reconstruct@  4    ;<21e<=r^   r   r.  rY  r   	rm   rn   ro   rp   r\   r   r  rq   r\  r]  s   @r[   r,  r,  -  =    	#	 &	 -		
 
	> >r^   r,  c                   R   ^  \ rS rSrSU 4S jjr        SU 4S jjrS rSrU =r$ )WrappedUserFunctionVariableiF  c                 x   > UR                  SS 5        [        TU ]  " UR                  40 UD6  Xl        X l        g )Nr   )r~   r   r\   r   r.  r   r/  s       r[   r\   $WrappedUserFunctionVariable.__init__G  s1    

4.v.r^   c                    > U R                   R                  U5        [        TU ]  XU5      nU R                   R	                  U5        U$ rt   r2  r5  s        r[   r   )WrappedUserFunctionVariable.call_functionM  r7  r^   c                    ^ ^ TR                  UU 4S j5        T" T R                  5        TR                  [        SS5      5        g )Nc                  (   > T " TR                   5      $ rt   r:  r;  s   r[   r<  9WrappedUserFunctionVariable.reconstruct.<locals>.<lambda>Y  r>  r^   r0   Fr?  rB  s   ``r[   r  'WrappedUserFunctionVariable.reconstructX  rD  r^   rE  rY  r   rF  r]  s   @r[   rI  rI  F  s=    	#	 &	 -		
 
	> >r^   rI  c                     S nU Vs/ s H
  oe" U5      PM     nnUR                  5        VVs0 s H  u  pxXu" U5      _M     nnnU" U0 UD6n	U R                  R                  U	U[        U5      S9$ s  snf s  snnf )Nc                     [        U [        R                  5      (       a  U R                  5       $ U R	                  5       $ rt   )r   r   TensorVariableget_real_valuer  )xs    r[   convert-invoke_and_store_as_constant.<locals>.convert_  s3    a1122##%%##%%r^   r   )r   r   register_attr_or_moduler$   )
r   r   r   r   r   rW  rV  r   r   ress
             r[   rB  rB  ^  s    &
 !%%1GAJD%(.7amF7
d
f
C99,,d# -   &7s
   A1A6c                      ^  \ rS rSrS1\R
                  kr S SU 4S jjjrS rS rS r	S r
SS	S
\S\4S jrU 4S jrS rU 4S jrS rS rS rSS jrSrU =r$ )r   in  r   c	                   > U	R                  S5      c  U	R                  [        5       S9  [        T
U ]  " S0 U	D6  [        UR                  5       [        5      (       d   e[        UR                  5       [        R                  5      (       d   e[        U[        5      (       d   eXl        X l        X0l        X@l        XPl        X`l        Xpl        Xl        g )Nmutation_typer]  ra   )rv   updater2   r   r\   r   r  r   r   r  rf   rV  rX   r   rc   re   r   r   
wrapped_fn)rW   rV  rX   r   rc   re   r   r   r`  r   r  s             r[   r\   #NestedUserFunctionVariable.__init__t  s     ::o&.MM(<(>M?"6"'446<<<<$113U^^DDDD)T****	" $&5?r^   c                     / $ rt   ra   r   s    r[   r   $NestedUserFunctionVariable.self_args  r   r^   c                 6    U R                   R                  5       $ rt   )rX   r  r   s    r[   r   #NestedUserFunctionVariable.get_code  s    yy++--r^   c                 "    [         R                  $ rt   r  r   s    r[   r  &NestedUserFunctionVariable.python_type  r  r^   c                    U R                   (       a  [        e[        R                  " U R                  R                  5       U R                  U R                  R                  5       5      nU R                  (       a  U R                  R                  5       Ul	        U R                  (       a  U R                  R                  5       Ul        U R                  (       ac  U R                  R                  5       n[        U[        5      (       a  SSKJn  [#        U" U5      5      n[        U["        5      (       d   eX!l        U$ )Nr   r   )r   r   r   r   rX   r  r   rV  rc   rb   re   rd   r   r   r   r   r   rf   r   )rW   rD   r   r   s       r[   r   'NestedUserFunctionVariable.get_function  s    <<%%!!II((*NNLL++-

 == $ @ @ BD??"&//"D"D"FD**==?K+u--."8K#89 k40000#. r^   r   r:   name_varr   c                 x    UR                   R                  R                  XR                  U5        [	        S 5      $ rt   )r   r   
store_attrr   r6   )rW   r   rj  r   s       r[   call_setattr'NestedUserFunctionVariable.call_setattr  s-     			))$D%%r^   c                 V   > US:X  a  U R                   " U/UQ76 $ [        TU ]	  XX45      $ )N__setattr__)rm  r   rn  rW   r   r   r   r   r  s        r[   rn  &NestedUserFunctionVariable.call_method  s3    = $$R/$//w"2T::r^   c                     U R                   S L$ rt   )r   r   s    r[   has_closure&NestedUserFunctionVariable.has_closure  s    ||4''r^   c                 b   > US:X  a  U R                   R                  5       $ [        TU ]  X5      $ )Nrm   )rV  r  r   const_getattr)rW   r   r   r  s      r[   rw  (NestedUserFunctionVariable.const_getattr  s.    :<<2244w$R..r^   c                     gr  ra   r   s    r[   r  #NestedUserFunctionVariable.has_self  r  r^   c                     U R                   $ rt   r  r   s    r[   r  &NestedUserFunctionVariable.get_globals  r  r^   c                 `   U R                  5       n[        R                  " UU R                  U R                  R                  5       U R                  (       a  [        U R                  R                  5      OS [        S [        [        U R                  5       R                  5      5       5       5      5      nU R                  (       a  U R                  R                  5       Ul        [        R                   " U5      R"                  " U0 UD6nUR%                  5         ['        UR(                  R                  5       5      n[+        UR,                  R.                  U5        [1        XU5        [3        UR                  5       H)  u  pX;  d   eU R4                  R                  U   n
XU	'   M+     U$ )Nc              3   8   #    U  H  n[        S 5      v   M     g 7frt   )r/   )r  _s     r[   r  7NestedUserFunctionVariable.bind_args.<locals>.<genexpr>  s     S+Ra)D//+Rs   )r   r   r   r   rV  r  rc   r   r   ri   rh   r  re   keys_as_python_constantrd   r   r   r?  apply_defaultsrf   	argumentsr   r   r  r   r{   r   )rW   r   r   r   rX   rD   r>   r   r   r   r$  s              r[   r)  $NestedUserFunctionVariable.bind_args  s9   }}!!NNLL++-*.--E$--%%&TS5T]]_5P5P1Q+RSS
 ??"&//"I"I"KD!!$',,d=f=eoo++-...7fd+"4#3#34IC%%%<<%%c*D4L 5
 r^   c                   ^ TR                  U4S j5        T" U R                  5        TR                  TR                  U R                  5      /5        T" [
        R                  " U R                  R                  R                  5      5        U R                  (       a  T" U R                  5        O!TR                  TR                  S 5      /5        U R                  (       a  T" U R                  5        O!TR                  TR                  S 5      /5        U R                  (       a  T" U R                  5        O!TR                  TR                  S 5      /5        U R                  (       a=   U R                  R                  5       nTR                  TR                  U5      /5        O!TR                  TR                  S 5      /5        TR                  [!        SS5      5        U R"                  (       aw  TR                  U4S j5        T" U R"                  5        TR                  [!        SS5      5        TR                  [%        S5      5        TR                  [!        SS5      5        SS	KJn  UR*                  " 5       nUR,                  R.                  R1                  U 5      (       a~  UR,                  R.                  R2                  U    R5                  5        HH  u  pVTR7                  5         T" U5        TR                  [%        S5      5        TR9                  U5        MJ     g g ! [         a    T" U R                  5         GNf = f)
Nc                  0   > T R                  [        S5      $ )Nr   )load_import_fromrm   r  s   r[   r<  8NestedUserFunctionVariable.reconstruct.<locals>.<lambda>  s    G,,X7JKr^      Fc                  (   > T R                  SS5      $ )N	functoolswrapsr  r  s   r[   r<  r    s    00gFr^   r0   r   Tr   r9   )r@  rX   rA  create_load_const_uncheckedr   r6   r   r   r   rc   create_load_constr   re   r   r  r   r   r`  r   r  r:   r  r   r   has_pending_mutationstore_attr_mutationsr   dup_toprl  )rW   r  r   r:   r   r   r   s    `     r[   r  &NestedUserFunctionVariable.reconstruct  s   K	
 			wBB4>>RST ''		(?(?@A==DMM"!!7#<#<T#B"CD<<DLL!!!7#<#<T#B"CD??DOO$!!7#<#<T#B"CD*"..AAC%%88EF !!7#<#<T#B"CD21e<=??!!F DOO$!!"6q%"@A!!,q/2!!"6q$"?@ 	I"--/99!!66t<<!yy55JJ eg  !%%l1o6""4(  =) ' *(()*s   /;L/ /MM)r   r   rX   rc   r   rV  re   r`  rt   rY  r  )rm   rn   ro   rp   r   rZ  r\   r   r   r  r   r4   rm  rn  rt  rw  r  r  r)  r  rq   r\  r]  s   @r[   r   r   n  s    	!	0	0N  @ 
@ @:."0&#& "& 	&;
(/
08) 8)r^   r   c                   R   ^  \ rS rSrSU 4S jjr        SU 4S jjrS rSrU =r$ )!WrappedNestedUserFunctionVariablei!  c           
      
  > UR                  SS 5        UR                  SS 5        UR                  SS 5        UR                  SS 5        UR                  SS 5        UR                  SS 5        UR                  SS 5        UR                  SS 5        [        TU ]	  UR                  UR                  UR
                  UR                  UR                  UR                  UR                  UR                  5        Xl        X l        g )	NrV  rX   r   rc   re   r   r   r`  )r~   r   r\   rV  rX   r   rc   re   r   r   r`  r.  r   r/  s       r[   r\   *WrappedNestedUserFunctionVariable.__init__"  s    

9d#

64 

;%

:t$

<&

=$'

9d#

<&OOLLOO		
 r^   c                    > U R                   R                  U5        [        TU ]  XU5      nU R                   R	                  U5        U$ rt   r2  r5  s        r[   r   /WrappedNestedUserFunctionVariable.call_function8  r7  r^   c                    ^ ^ TR                  UU 4S j5        T" T R                  5        TR                  [        SS5      5        g )Nc                  (   > T " TR                   5      $ rt   r:  r;  s   r[   r<  ?WrappedNestedUserFunctionVariable.reconstruct.<locals>.<lambda>D  r>  r^   r0   Fr?  rB  s   ``r[   r  -WrappedNestedUserFunctionVariable.reconstructC  rD  r^   rE  rY  r   rF  r]  s   @r[   r  r  !  s=    ,	#	 &	 -		
 
	> >r^   r  c                      ^  \ rS rSrSS1\R
                  krSSU 4S jjjrS r\S 5       r	        SS	 jr
SS
 jrSSS\4S jrSrU =r$ )SkipFunctionVariableiI  r   reasonc                 >   > [         TU ]  " S0 UD6  Xl        X l        g r`   )r   r\   r   r  )rW   r   r  r   r  s       r[   r\   SkipFunctionVariable.__init__P  s    "6"
r^   c                     U R                   $ rt   r   r   s    r[   r  'SkipFunctionVariable.as_python_constantU  s    zzr^   c                 ~    [        U5      (       d(  [        UR                  [        R                  5      5        U " XS9$ r   )r-   r"   r   r!   FUNCTION_MATCHr   s      r[   r   'SkipFunctionVariable.create_with_sourceX  s3    .u55 &++L,G,GHI5((r^   r   r:   c           	      n   [         R                  " U R                  SS5      (       aT  [         R                  " U R                  SS 5      n[        S[	        U R                  5      SU R                   SU S3S/S	9  g U R                  [
        R                  R                  L aA  UR                  S
S 5      nU(       a  UR                  5       n[        SSU SU S3SU 3S/S	9  g U R                  [
        R                  R                  L a7  UR                  S
S 5      nU(       a  UR                  5       n[        SU 35      e[        R                  (       aH  SSKJn  UR!                  XR                  5      n[#        U[$        5      (       d  UR'                  XU5      $ [)        U R                  SS5      n	[)        U R                  SS 5      n
U
c  SO
[	        U
5      n [         R*                  " U R                  5      nSU	 SU S3nSU	 S3/nSU;  a  USU	 S3S /-  nU	S/:X  a  S0n/ nU R6                  (       a  U R6                  OS1n[        S2S3U S4U	 S5U 3UUS	9  g ! [,         a    S!S"1nX;   a  S#U S$U	 S3nS%S&/n NaU
bb  U
R/                  S'5      (       aL  S(U S$U	 S$3nS)/n[
        R                  R0                  R3                  US*-   S*R5                  U5      -   5         NS+U S$U	 S,3nS-S./n[
        R                  R0                  R3                  US*-   S*R5                  U5      -   5         GNf = f)6N_torchdynamo_disableF_torchdynamo_disable_msgz1Skip calling `torch.compiler.disable()`d functionzSkip calling function `z>` since it was wrapped with `torch.compiler.disable` (reason: r5  z(Remove the `torch.compiler.disable` callr   rU  z%Call to `torch._dynamo.graph_break()`z0Called `torch._dynamo.graph_break()` with args `z`, kwargs ``z$User-inserted graph break. Message: z.Remove the `torch._dynamo.graph_break()` call.z9Skip frame due to `torch._dynamo.skip_frame()`. Message: r0   SourcelessBuilderro   z<unknown qualname>rn   z<unknown module>z?Dynamo developers have intentionally marked that the function `z` in file `z` should not be traced.zAvoid calling the function `z`.r9  z:Apply `@torch._dynamo.dont_skip_tracing` to the function `zw` to force tracing into the function. More graph breaks may occur as a result of attempting to trace into the function.z Please file an issue to PyTorch._abc	_warningsz6Dynamo does not know how to trace the Python builtin `.zIf you are attempting to call a logging function (e.g. `_warnings.warn`), you can try adding it to `torch._dynamo.config.reorderable_logging_functions`.zKPlease file an issue on GitHub so the PyTorch team can add support for it. optreez*Dynamo cannot trace optree C/C++ function zi Consider using torch.utils._pytree - https://github.com/pytorch/pytorch/blob/main/torch/utils/_pytree.py
z/Dynamo does not know how to trace the builtin `z.` This function is either a Python builtin (e.g. _warnings.warn) or a third-party C/C++ Python extension (perhaps created with pybind).zIf it is a Python builtin, please file an issue on GitHub so the PyTorch team can add support for it and see the next case for a workaround.a  If it is a third-party C/C++ Python extension, please either wrap it into a PyTorch-understood custom operator (see https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html for more details) or, if it is traceable, use `torch.compiler.allow_in_graph`.allow_in_graphzFound an allow_in_graph decorator to a function which is created inside the parent function that is getting compiled. This is not supported for now.z<missing reason>z,Attempted to call function marked as skippedzmodule: z, qualname: z, skip reason: )r   r   r   r   r   r   r9  graph_breakrv   r  
skip_framer   r   dont_skip_tracingbuilderr  r   r   r  r   r   getfiler}   r  rE  	warn_oncejoinr  )rW   r   r   r   rU  graph_break_msgskip_frame_msgr  
rebuilt_fnqualname	module_ormodule_namepathr   r   known_python_builtin_modulesr  s                    r[   r   "SkipFunctionVariable.call_functiona  s    !!$**.DeLL((5OQUVCKDJJ5djj\ B::=aA ? ZZ5==444$jj5O"1"D"D"F?J4&P[\b[ccdeB?BSTD	 ZZ5==333#ZZt4N!/!B!B!DKNK[\  ''6 /55b**E
!*.BCC%33BfEEtzz>;OPH

L$?I090A,s9~K8Ytzz2UV^U_ `  $v%<> 
 38*B? D(TU]T^ _l l ;	 EX ++? 
 $(KKT[[5GFF";-|H:_U[T\]'	]  %Y06/D,<'=(27  
iGE *y/C/CH/M/M$N{m[\]e\ffg"hK^E
 MM''11+2DtyyQVGW2WX J+VWX`Wa ba b  m;E MM''11+2DtyyQVGW2WXK%Ys!   AI  L4 A#L4%AL43L4c                 h    [         R                  R                  [        U R                  U5      5      $ rt   )r   r6   r   r   r   r-  s      r[   r   %SkipFunctionVariable.call_obj_hasattr  s$    ))00T1JKKr^   r   c                     U[         ;   a  [        R                  " X5      $ [        XR                  U R
                  U5      $ rt   )r)   r   r,  r   r   r   r-  s      r[   r.   SkipFunctionVariable.var_getattr  s3    )),,T88b**dkk4@@r^   )r  r   rt   rY  r   r   r:   )rm   rn   ro   rp   r4   rZ  r\   r  r[  r   r   r   r   r.  rq   r\  r]  s   @r[   r  r  I  s     
	'	'N 
 ) )v#v &v -	v
 
vpLA5 AS A Ar^   r  c                   R   ^  \ rS rSrSU 4S jjr        SU 4S jjrS rSrU =r$ )WrappedSkipFunctionVariablei  c                    > UR                  SS 5        UR                  SS 5        [        TU ]  " UR                  4SUR                  0UD6  Xl        X l        g )Nr   r  )r~   r   r\   r   r  r.  r   r/  s       r[   r\   $WrappedSkipFunctionVariable.__init__  sH    

7D!

8T"Hw~~HHr^   c                    > U R                   R                  U5        [        TU ]  XU5      nU R                   R	                  U5        U$ rt   r2  r5  s        r[   r   )WrappedSkipFunctionVariable.call_function  r7  r^   c                    ^ ^ TR                  UU 4S j5        T" T R                  5        TR                  [        SS5      5        g )Nc                  (   > T " TR                   5      $ rt   r:  r;  s   r[   r<  9WrappedSkipFunctionVariable.reconstruct.<locals>.<lambda>  r>  r^   r0   Fr?  rB  s   ``r[   r  'WrappedSkipFunctionVariable.reconstruct  rD  r^   rE  rY  r   rF  r]  s   @r[   r  r    rG  r^   r  c                   `   ^  \ rS rSrSrSU 4S jjrS	U 4S jjrS r        S
S jrSr	U =r
$ )WrapperUserFunctionVariablei  a  
Used to represent a wrapper object that contains the actual callable as an
attribute. For example, torch.jit.script/trace have the original function at
their _torchdynamo_inline attribute. Similarly, functions with
__script_if_tracing_wrapper have the original attr at "__original_fn".
c                 >   > [         TU ]  " S0 UD6  Xl        X l        g r`   )r   r\   wrapper_objattr_to_trace)rW   r  r  r   r  s       r[   r\   $WrapperUserFunctionVariable.__init__  s    "6"&*r^   c                    > X R                   :X  a`  [        U R                  U R                   5      nU R                  =(       a    [	        U R                  U5      n[
        R                  " XU5      $ [        TU ]!  X5      $ rt   )	r  r   r  r   r#   r4   r   r   r.  )rW   r   r   r   r   r  s        r[   r.  'WrapperUserFunctionVariable.var_getattr	  sc    %%%$**D,>,>?C[[BZT%BF"((&99w"2,,r^   c                     / $ rt   ra   r   s    r[   r   %WrapperUserFunctionVariable.self_args  r   r^   c                    [        U R                  S5      (       Gaw  [        U R                  U R                  S 5      n[        USS5      =(       d    SnUR	                  SSS9S   S:w  Ga(  S	n[
        R                  R                  R                  U5        [
        R                  R                  R                  R                  S
5      nUR                  [        R                  5      (       a  [
        R                  R                  R                  5       n[!        5       U-   nUS   R"                  US   R$                  4n	SR'                  [(        R*                  " U5      5      n
SU	S    SU	S    S3nU[-        U
5      -  nUR/                  U5        U R1                  5       U-   n[2        R4                  " [6        R8                  5      R;                  UU [2        R<                  " U R                  5      /UQU5      $ )N
cache_inforn   r  r  r0   )maxsplitr   r   a  Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.ztorch._dynamoz)call to a lru_cache wrapped function at: :r  )r   r  r   r  splitr   r9  rE  r  logging	getLoggerisEnabledForDEBUG_guardsTracingContextextract_stackr   filenamelinenor  	tracebackformat_listr   debugr   r   r   r   getattr_and_tracer   r6   )rW   r   r   r   	target_fnr  rU  dynamo_logger
user_stack	frame_locuser_stack_formatteduser_stack_traceall_argss                r[   r   )WrapperUserFunctionVariable.call_function  s    4##\22 0 0$2D2DdKI!)\2>D"K  q 1!4?K  ##--c2 % 3 3 ; ; E Eo V --gmm<<!&!=!=!K!K!MJ!7!9J!FJ!+B!8!8*R.:O:O PI+-7793H3H3T+U()RS\]^S_R``abklmbnaooq'r$$,@(AA$!''(89>>#d*--''

-9--d.@.@AMHM
	
r^   )r  r  rY  r  r   )rm   rn   ro   rp   r   r\   r.  r   r   rq   r\  r]  s   @r[   r  r    sG    +
-&
#&
 &&
 -	&

 
&
 &
r^   r  c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )WrapperUserMethodVariablei=  z
Similar to WrapperUserFunctionVariable, but for methods. The only delta is
saving the vt for `self` object of the method which is then used by
WrapperUserFunctionVariable in `call_function` method.
c                 4   > [         TU ]  " X40 UD6  X0l        g rt   r  )rW   r  r  self_objr   r  s        r[   r\   "WrapperUserMethodVariable.__init__D  s    >v>r^   c                     U R                   /$ rt   r  r   s    r[   r   #WrapperUserMethodVariable.self_argsH  r  r^   r  rY  )	rm   rn   ro   rp   r   r\   r   rq   r\  r]  s   @r[   r  r  =  s     r^   r  c                  \    [         R                  R                  5       (       a  SSKJn   U $ 0 $ )Nr   traceable_collective_remaps)r   distributedis_available)torch.distributed._functional_collectivesr  r  s    r[   _traceable_collective_remapsr  L  s)    %%''	
 +*Ir^   c                     [         R                  R                  5       (       d   S5       eU[        5       R	                  5       ;   d   eUR
                  nU R                  S5      n[        X25      $ )NzIllegal invocation.z)torch.distributed._functional_collectives)r   r  r  r  valuesrm   import_sourcer#   )r   r   
inner_namepath_sources       r[   _traceable_collectives_sourcer  W  sc    ))++B-BB+-/668888J""#NOKk..r^   c                      ^  \ rS rSrSrS	U 4S jjr\S
S j5       r\S 5       r\S
S j5       r	        SS jr
SrU =r$ )!CollectiveFunctionRewriteVariablei`  a  
Some of the torch.distributed.* collective APIs are possible to rewrite to 'traceable' collectives.

This class provides both a way to check if a function is remappable, and perform the remapping.

In the case that a function is 'remappable' but only for some combinations of call-time arguments,
we check the args at `call_function` time and fall back to graph-breaking if needed.  This is no worse
than status-quo as we currently graph-break on all distributed.* collectives.
c                b   > [         TU ]  " U40 UD6  [        U[        5      (       d   eX l        g rt   )r   r\   r   r   replacement_var)rW   r   r  r   r  s       r[   r\   *CollectiveFunctionRewriteVariable.__init__k  s/    &v&/+?@@@@.r^   c                 f    [         R                  X5      u  pE[        U4[        U4SU0UD6US.UD6$ )Nr   )r  r   )r  rewriter   )r   old_fnr   optionsnew_fn
new_sources         r[   r   (CollectiveFunctionRewriteVariable.createp  sI    >FFrR0
0V
VgV
 	
 	
r^   c                 V    [         R                  " U 5      =(       a    U [        5       ;   $ rt   )r   
isfunctionr  )variables    r[   can_rewrite-CollectiveFunctionRewriteVariable.can_rewritez  s%     x(WX9U9W-W	
r^   c                 6    [        5       U   nU[        X5      4$ rt   )r  r  )r   r   r  s      r[   r  )CollectiveFunctionRewriteVariable.rewrite  s     -/34R@@@r^   c                    SS K Jn  SSKJn  [        R
                  " U R                  5      n[        UR                  " U0 UD6R                  5      nSnSU;   aU  US   R                  5       (       a=  [        SU R                   SU< SU< 3SU R                   3/ [        R                  QS	9  U R                  UR                  UR                  UR                   4;   ap  UR#                  S
5      nUb  UR$                  OUR&                  S
   R(                  nX;  a  [+        SU 35      e[,        R.                  R1                  XX   5      US
'   U R2                  R5                  XU5      $ )Nr   )REDUCE_OP_TO_STRra   async_opz)async_op=True for distributed collectivesz, args=	, kwargs=z3`torch.compile` doesn't support `async_op=True for r   opzUnsupported all_reduce op: )torch.distributedr  r  r"  r   r   r   rf   r?  r  r  r   r   SUPPORTABLE
all_reducereduce_scatter_tensor_reduce_scatter_baserv   r   r   defaultr!  r   r6   r   r  r   )	rW   r   r   r   distr"  r   reduce_op_var	reduce_ops	            r[   r   /CollectiveFunctionRewriteVariable.call_function  sd    	)N %%dgg.	innd5f5??@F:$6$I$I$K$KC77)8dWJvi8QRVRYRYQZ[&22	 77OO&&%%
 

 #JJt,M !, ##))$/77 
 0 #>yk!JKK$55<< +F4L ##11"FCCr^   )r  rY  r  r   )rm   rn   ro   rp   r   r\   rr  r   r  r  r   rq   r\  r]  s   @r[   r  r  `  s    /
 
 
 
 

 A A,D#,D &,D -	,D
 
,D ,Dr^   r  c                   <   ^  \ rS rSr        SU 4S jjrSrU =r$ )FunctoolsWrapsVariablei  c                    >^ U(       d+  [        T5      S:X  a  U4S jn[        R                  " U5      $ [        TU ]  UTU5      $ )Nr0   c                    > [        U [        R                  5      (       a  U R                  TS   S9$ [	        SU  S/ [
        R                  QS9  g )Nr   )r`  zfunctools.wrapsz]`torch.compile` can't trace `functools.wraps` on functions defined outside the compile regionr   )r   r   r   cloner   r   r'  )r   r   s    r[   r  3FunctoolsWrapsVariable.call_function.<locals>.wraps  sQ    b)"F"FGG88tAw877 -!d *66	r^   )rh   r   LambdaVariabler   r   )rW   r   r   r   r  r  s     `  r[   r   $FunctoolsWrapsVariable.call_function  s>     #d)q.
 ++E22w$Rv66r^   ra   r   )rm   rn   ro   rp   r   rq   r\  r]  s   @r[   r1  r1    s3    7#7 &7 -	7
 
7 7r^   r1  c                   4    \ rS rSrS r        SS jrSrg)CollectionsNamedTupleFunctioni  c                     U R                   $ rt   r
  r   s    r[   r  0CollectionsNamedTupleFunction.as_python_constant  r  r^   c                    [        X#5      nU(       a~  U 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n[        R
                  " U[        5       S9$ [        SSU< SU< 3S/ [        R                  QS9  g s  snf s  snnf )Nr^  znamedtuple constructionzargs=r$  z?`torch.compile` only support certain input types for namedtupler   )
r'   r   r  r   r   UserDefinedClassVariabler3   r   r   r'  )	rW   r   r   r   constant_argsrV  r   r   r   s	            r[   r   +CollectionsNamedTupleFunction.call_function  s     ,D9GG267$Q&&($79?H1**,,HE 55%5%7  	-tgZy)Y"..		
 8Hs   B6B;ra   Nr   )rm   rn   ro   rp   r  r   rq   ra   r^   r[   r9  r9    s2    
#
 &
 -	

 

r^   r9  c                      ^  \ rS rSrS\SS4U 4S jjrS rSS jrS r        SS jr	S	S
S\
S\4S jrS	S
S\
4S jrS rS rSrU =r$ )FunctoolsPartialVariablei  rD   rr   Nc                    > [         TU ]  " S0 UD6  Xl        [        U[        5      (       d   eX l        [        U[        5      (       d   eX0l        [        R                  " [        5      U l        g r`   )r   r\   rD   r   r   r   rf   keywordsr  partialr+   
fake_value)rW   rD   r   rC  r   r  s        r[   r\   !FunctoolsPartialVariable.__init__  s\    "6"	$%%%%	(D))))  $++H5r^   c                 "    [         R                  $ rt   )r  rD  r   s    r[   r  $FunctoolsPartialVariable.python_type  s       r^   c                 R  ^ TR                  U4S j5        T" U R                  5        U R                  (       a  TR                  U R                  5        U R                  (       d2  TR                  [        [        U R                  5      S-   S5      5        g TR                  U R                  R                  5       5        [        U R                  R                  5       5      nTR                  TR                  [        U5      [        U R                  5      -   S-   US5      5        g )Nc                  (   > T R                  SS5      $ )Nr  rD  r  r  s   r[   r<  6FunctoolsPartialVariable.reconstruct.<locals>.<lambda>  s    g&>&>{I&Vr^   r0   F)r@  rD   r   foreachrC  rA  r   rh   r	  r   r  create_call_function_kw)rW   r  r  s    ` r[   r  $FunctoolsPartialVariable.reconstruct  s    VW		99OODII&}}!!"6s499~7I5"QR,,./T]]'')*++CIDII,F,JDRWX	
r^   c                 "    U R                  5       $ rt   r  r   s    r[   r   %FunctoolsPartialVariable.get_function	      &&((r^   r   r:   c                 x    U R                   U-   n0 U R                  EUEnU R                  R                  XU5      $ rt   )r   rC  rD   r   )rW   r   r   r   merged_argsmerged_kwargss         r[   r   &FunctoolsPartialVariable.call_function  s<     ii$&34==3F3yy&&rFFr^   r   c                     [         R                  R                  [        [        R
                  " [        5      U5      5      $ rt   )r   r6   r   r   r  rD  r+   r-  s      r[   r   )FunctoolsPartialVariable.call_obj_hasattr  s2     ))00I%%h/6
 	
r^   c                    U R                   =(       a    [        U R                   U5      nUS:X  a  U R                  $ US:X  a  [        R                  " U R
                  US9$ US:X  aW  U R                  R                  5        VVs0 s H  u  pE[        R                  " U5      U_M     nnn[        R                  " XcS9$ U[        ;   a  [        R                  " X5      $ [        [        U5        g s  snnf )NrD   r   r   rC  )r   r#   rD   r   ListVariabler   rC  r   r6   r   ConstDictVariabler)   r,  r   r   )rW   r   r   r   r   r   r   s          r[   r.  $FunctoolsPartialVariable.var_getattr  s    >DKK!>6>996>))$))FCC:?C}}?R?R?TU?Ttq%,,Q/2?TEU..uDD)),,T88 4	 Vs   #C/c                 B   [         R                  " U R                  R                  5       /U R                   Vs/ s H  oR                  5       PM     snQ70 U R
                  R                  5        VVs0 s H  u  p#X#R                  5       _M     snnD6$ s  snf s  snnf rt   )r  rD  rD   r  r   rC  r   )rW   rN  r   r   s       r[   r  +FunctoolsPartialVariable.as_python_constant,  s      II((*
26))<)3$$&)<
 6:]]5H5H5JK5JTQq&&((5JK
 	
<K   B
4Bc                 B   [         R                  " U R                  R                  5       /U R                   Vs/ s H  oR                  5       PM     snQ70 U R
                  R                  5        VVs0 s H  u  p!X!R                  5       _M     snnD6$ s  snf s  snnf )zcSimilar to as_python_constant(), but add ID_MATCH guards to try to force things to become constants)r  rD  rD   guard_as_python_constantr   rC  r   )rW   r   r   s      r[   ra  1FunctoolsPartialVariable.guard_as_python_constant3  s      II..0
48II>Iq((*I>
 <@==;N;N;PQ;P41q,,..;PQ
 	
>Qr_  )r   rE  rD   rC  r  r   )rm   rn   ro   rp   r4   r\   r  r  r   r   r   r   r.  r  ra  rq   r\  r]  s   @r[   rA  rA    s    	6_ 	64 	6!
)G#G &G -	G
 
G
)
14
	
55 5S 5

 
r^   rA  c                     ^  \ rS rSrSSS1\R
                  kr\\R                  S\	\
S\4   \R                  4   4S j5       5       r\S 5       rS\SS	4U 4S
 jjr\S\4S j5       rS rS r        SS jr      SS jrS rSrU =r$ )PolyfilledFunctionVariablei<  r   r`  traceable_fnrr   .c                     0 $ rt   ra   )r   s    r[   _get_polyfill_handlers1PolyfilledFunctionVariable._get_polyfill_handlersD  s	     	r^   c                 ^    [        UR                  [        R                  5      5        U " XS9$ r   )r"   r   r!   r  r   s      r[   r   -PolyfilledFunctionVariable.create_with_sourceI  s&    f''(C(CDE5((r^   Nc                 D  > [         TU ]  " S0 UD6  Xl        U R                  5       R	                  X5      n[        U5      (       d   SU SU 35       eS H,  n[        X4S 5      nU(       d  M  [        U5      (       d   eUn  O   [        SU S35      eX0l        X`l	        g )NzPolyfill handler z is not callable for )__torch_dynamo_polyfill____python_implementation__z# does not have a traceable functionra   )
r   r\   r   rg  rv   callabler   r=  r`  re  )rW   r   r   handlercandidate_attr	candidatere  r  s          r[   r\   #PolyfilledFunctionVariable.__init__O  s    "6"--/33B;  X$5gY>STVSW"XX 
N  >Iy	****(
 #G9,OP  & ,r^   c                     U R                   $ rt   )re  r   s    r[   polyfill_fn&PolyfilledFunctionVariable.polyfill_fnf  s       r^   c                 0    [        U R                  SS5      $ )N*__torch_dynamo_can_constant_fold_through__F)r   r`  r   s    r[   can_constant_fold_through4PolyfilledFunctionVariable.can_constant_fold_throughj  s    OOI5
 	
r^   c                 "    U R                  5       $ rt   rP  r   s    r[   r   'PolyfilledFunctionVariable.get_functiono  rR  r^   c                 r   U R                  5       (       a  [        X#5      (       aw  U R                  " U Vs/ s H  oDR                  5       PM     sn0 UR	                  5        VVs0 s H  u  pVXVR                  5       _M     snnD6n[
        R                  " X5      $ U R                  [        R                  L Ga<  [        U5      S:X  Ga,  U(       Gd$  [        US   [        R                  [        R                  45      (       a  [        S US   R                   5       5      (       a  [        R                  R!                  UUR"                  R%                  S[&        R(                  [+        S US   R                   5       5      40 5      [&        R(                  " US   R                   Vs/ s H:  n[        U[        R,                  5      (       a  UR.                  OUR0                  PM<     sn5      S9$ [
        R                  " XR2                  5      nUR5                  XU5      $ s  snf s  snnf s  snf )Nr0   r   c              3     #    U  H~  n[        U[        R                  5      =(       a    [        UR                  [        5      =(       d7    [        U[        R
                  5      =(       a    UR                  5       [        L v   M     g 7frt   )r   r   r6   r   intSymNodeVariabler  )r  rV  s     r[   r  ;PolyfilledFunctionVariable.call_function.<locals>.<genexpr>  sd       'A Ay99:Wz!''SV?W Yq)";";<WTWAWY&s   BBr   c              3   @   #    U  H  oR                  5       v   M     g 7frt   )as_proxy)r  as     r[   r  r    s     ?A::<<s   )sym_num)rx  r(   r   r  r   r4   r   r  sumrh   r   r   rZ  TupleVariabler  r  r   r   create_proxyr   sym_sumr   r6   r   r  re  r   )	rW   r   r   r   rV  r   r   r   traceable_function_variables	            r[   r   (PolyfilledFunctionVariable.call_functionr  s    ))++0M1
 1
 6:;d**,d;=C\\^L^TQq..00^L  #((44 GGx||#D	Q47Y%;%;Y=T=T$UVV  a   ,,33		&&#MM?a??A	  "&a "/A  *!Y-G-GHH GG!"+ "/	 4  ( '6&;&;B@Q@Q&R#*886JJO <L4s   H)%H.-AH4c                 v   US:X  a  U R                  XU5      $ [        U R                  US 5      nUc   SU SU R                   35       e[        U5      (       d   SU SU R                   35       e0 nU R                  (       a  [        U R                  U5      US'   [        U40 UD6nUR                  XU5      $ )N__call__zMember z not found in z is not callable in r   )r   r   r   r,   r   r#   rd  )rW   r   r   r   r   methodr  polyfilled_method_variables           r[   rn  &PolyfilledFunctionVariable.call_method  s     :%%b77$-!JWTF.	#JJ!6""QgdV3Gy$QQ";; *4;; =GH%?%R'%R")77&IIr^   c                     U R                   $ rt   r
  r   s    r[   r  -PolyfilledFunctionVariable.as_python_constant  r  r^   )r   re  r`  r   r   r   r   r   rr   r4   )rm   rn   ro   rp   r4   rZ  r[  r  cacherf   r   r   r   r   rg  r   r=   r\   propertyrt  rx  r   r   rn  r  rq   r\  r]  s   @r[   rd  rd  <  s    
	'	'	N __tHS#X,>@R@R,R'S    ) )
-2 -D -. !R ! !

)2K#2K &2K -	2K
 
2KhJ &	J
 -J 
J& r^   rd  c                       \ rS rSrS rSrg)TracebackVariablei  c                     g rt   ra   r   s       r[   r   TracebackVariable.call_function  s    sr^   ra   Nrm   rn   ro   rp   r   rq   ra   r^   r[   r  r    s    2r^   r  c                   :   ^  \ rS rSrU 4S jrS rS rS rSrU =r	$ )SysFunctionVariablei  c                 2   > [         TU ]  " S0 UD6  Xl        g r`   )r   r\   r   )rW   r   r   r  s      r[   r\   SysFunctionVariable.__init__  s    "6"
r^   c                 z   [        UR                  5      (       aK  UR                  S   nUR                  nS n[        R                  " X5      U[        R                  " X5      /nOA[
        R                  " S 5      [
        R                  " S 5      [
        R                  " S 5      /n[
        R                  " U5      $ )Nr  )rh   exn_vt_stackr  r4   r   r   r6   r  )rW   r   exnrT  tbr   s         r[   exc_infoSysFunctionVariable.exc_info  s    r//"%C,,CB%%b.%%b-E **40**40**40E
 &&u--r^   c                 >    U R                  U5      R                  S   $ r&  )r  r   r   s     r[   	exceptionSysFunctionVariable.exception  s    }}R &&q))r^   c                     U R                   [        R                  L a  U R                  U5      $ U R                   [        R                  L d   eU R                  U5      $ rt   )r   r  r  r  r   s       r[   r   !SysFunctionVariable.call_function  sF    ::%==$$zzS]]***~~b!!r^   r  )
rm   rn   ro   rp   r\   r  r  r   rq   r\  r]  s   @r[   r  r    s    .$*" "r^   r  ) create_tma_experimental_metadatacreate_tma_stable_metadataTMADescriptorMetadataTritonHOPifierc                       \ rS rSrS\S\4S jrS\S\4S jr	S\S\4S jr
S\\R                  R                  R                  S	4   4S
 jrS rS rS rS rS\S\4S jrSSS\\   SS4S jrS\4S jrSrg)DynamoTritonHOPifieri  rU  rr   c                     [        U5      ert   )r    )rW   rU  s     r[   raise_unsupported&DynamoTritonHOPifier.raise_unsupported  s    #r^   maybe_callablec                 .    [        U[        [        45      $ rt   )r   r   r   )rW   r  s     r[   is_callable DynamoTritonHOPifier.is_callable  s    79MN
 	
r^   r   c                     UR                   $ rt   r  )rW   r   s     r[   	get_valueDynamoTritonHOPifier.get_value  s    yyr^   .c                     SSK Jn  [        X5      (       a  UR                  5       $ [	        SS[        U5       3S/ [        R                  QS9  g )Nr0   )BaseListVariablez/unsupported grid type for triton hop check_gridzgrid type = z;`torch.compile` only supports list-like grid for check_gridr   )listsr  r   r  r   rf  r   r'  )rW   gridr  s      r[   
check_gridDynamoTritonHOPifier.check_grid  sK    +d--==?"I&tDzl3Y&22	r^   c                     UR                  5        VVs0 s H%  u  pE[        R                  R                  U5      U_M'     nnnUR	                  X2/0 5      nU$ s  snnf rt   )r   r   r6   r   r   )rW   r  metar   r   r   s         r[   	call_gridDynamoTritonHOPifier.call_grid  sS    DHJJLQLDA	**11!4a7LQ!!"fb1 Rs   ,Ac                 X    SSK Jn  UR                  XA5      nUR                  XBU5      nU$ )Nr0   r  )r  r  r   r   )	rW   user_fnr   r   r   r  r  wrapped_user_functionr   s	            r[   call_user_defined_fn)DynamoTritonHOPifier.call_user_defined_fn  s-    . 1 8 8 E&44RvFr^   c                 l    SSK Jn  U" U[        UR                  U 5      5      R	                  U5      nU$ )Nr0   )VariableBuilder)r  r  r#   kernel_source_wrap)rW   user_objr   r  r   r  wrapped_user_objs          r[   wrap_user_defined_obj*DynamoTritonHOPifier.wrap_user_defined_obj  s7    ,*
811dV=

%/ 	  r^   c                 r    UR                  U5      nU Vs/ s H  o3R                  " 5       PM     nnU$ s  snf rt   )unpack_var_sequencera  )rW   configsr   r   s       r[   maybe_unpack_configs)DynamoTritonHOPifier.maybe_unpack_configs  s<    --b1 DKK72247K Ls   4r   c                 n    UR                  5       (       d  U R                  S5        UR                  5       $ )Nz`@triton.heuristics must return constant values because configs can only contain constant values.)is_python_constantr  ra  )rW   r   s     r[   maybe_unpack_heuristic_result2DynamoTritonHOPifier.maybe_unpack_heuristic_result$  s3    ((**""r ..00r^   r  TritonKernelVariabler   c                     UR                   c  [        U5      S:w  a  U R                  S5        [        U5      " UR                  UR
                  US   UR                  S9$ )Nr0   z7Triton kernels should be called with only a single gridr   )kernel
kernel_idxr  r  )r  rh   r  rf  r  r  r   )rW   r  r   s      r[   call_getitem!DynamoTritonHOPifier.call_getitem.  sZ     ==$D	Q""I H~??**a"//	
 	
r^   c                 `   SSK Jn  SSKJn  0 n[	        UR                  5       5       HH  nX8   n	[        U	[        [        45      (       d  M$  U	R                  5       Xx'   U	R                  5       X8'   MJ     UR                  5        VV	s0 s H%  u  p[        R                  R                  U5      U	_M'     n
nn	SSKJnJn  UR                  5        VV	s0 s H'  u  p[        X5      (       d  M  XR#                  5       _M)     nnn	U
R                  5        VV	s0 s H  u  p[        X5      (       a  M  X_M     nnn	UR%                  5        Hb  n	U	R'                  5       n	[        U	[        R(                  [        R*                  45      (       a  MD  U R-                  S[/        U	5       S35        Md     UR1                  U5      nU" U[2        5      nUR4                  R7                  SUS	UR8                  UUUUR;                  5       S
.5        [        R                  " S 5      $ s  sn	nf s  sn	nf s  sn	nf )Nr0   r5   )r[  r   )kernel_side_tabletriton_kernel_wrapper_mutationz.Unexpected argument type for a Triton kernel: r  r   ra   )r  constant_args_idxr  tma_descriptor_metadatar   )r  r6   dictsr[  r   r  r   !TMADescriptorExperimentalVariableTMADescriptorStableVariableto_metadata
get_tensorr   r   r   *torch._higher_order_ops.triton_kernel_wrapr  r  r  r	  realizerT  r  r  repradd_constant_argsrf   r   r  r  r  )rW   r  gridscombined_args_rawr   r6   r[  r  r   r   combined_argsr  r  r>  non_constant_argsr  r  s                    r[   call_HOPDynamoTritonHOPifier.call_HOP@  s   ., :<',,./A!$A57RS  ./]]_'*'(||~!$ 0 *//1
1 &&--a0!31 	 

	
 *//1
1!. &A##%%1 	 
 &++-
-a2 AD- 	 
 #))+A		Aa)":":I<U<U!VWW&&DT!WIQO , .??N !2D9
		*&11%6+B--/		
 ))
 	
]



s   ,HH$+H$H*/H*ra   N)rm   rn   ro   rp   r   r   r  r   r  r  r  r   r   fxproxyProxyr  r  r  r  r  r  r   r  r6   r  rq   ra   r^   r[   r  r    s    S U 
# 
$ 

S S %(<(<c(A"B  1C 1C 1
(
 sm
 
 	
$C
BR C
r^   r  c                      ^  \ rS rSr% S\S'   S\S'   \\   \S'   S\S'   SU 4S
 jjr        SS jr      SU 4S jjr	S\
S	\
4S jrSrU =r$ )r  i  r;   r  r<   r  r  r#   r  rr   c                    > UR                  SS 5      U l        [        TU ]  " S0 UD6  [        R                  XX#5        g )Nr  ra   )r~   r  r   r\    dynamo_triton_hopifier_singletoninit_variable)rW   r  r  r  r   r  s        r[   r\   TritonKernelVariable.__init__  s6    #ZZ>"6"(66tZVr^   c                 .    [         R                  XX15      $ rt   )r  call_triton_kernelr   s       r[   r   "TritonKernelVariable.call_function  s     0BB
 	
r^   c                    > US:X  a  [         R                  X5      $ US:X  a  [         R                  XXA5      $ [        TU ]  XX45      $ )N__getitem__run)r  r  call_runr   rn  rq  s        r[   rn   TritonKernelVariable.call_method  sL     = 3@@LLU]3<<TTT w"2T::r^   rN  c                 ~    SSK Jn  SSKJn  [	        X5      (       a   UR
                  " UR                  5       5      $ U$ )Nr0   r5   )r  )r  r6   tensorr  r   r   evaluate_expr)rW   rN  r6   r  s       r[   specialize_symbolic(TritonKernelVariable.specialize_symbolic  s4    .+ c++#**3+<+<+>??
r^   )r  rY  r   r  )rm   rn   ro   rp   r   r   r~  r\   r   rn  r   r  rq   r\  r]  s   @r[   r  r    s    
W

#
 &
 -	

 

; &	;
 -; 
;s s  r^   r  c                   R   ^  \ rS rSr        SU 4S jjrS rSS jrS rSrU =r	$ )	r  i  c                    > [        U[        R                  5      (       d   e[        TU ]  " S0 UD6  Xl        X l        X0l        X@l        g r`   )	r   r   DataPtrVariabler   r\   data_ptrdims
block_dimselement_size)rW   r  r  r  r  r   r  s         r[   r\   *TMADescriptorExperimentalVariable.__init__  sC     (I$=$=>>>>"6" 	$(r^   c                     [        U R                   Vs/ s H  oR                  5       PM     snU R                   Vs/ s H  oR                  5       PM     snU R                  R                  5       5      $ s  snf s  snf rt   )r  r  r  r  r  )rW   dims     r[   r  -TMADescriptorExperimentalVariable.to_metadata  s[    /'+yy1y\\^y1'+7\\^7&&(
 	
17s
   A6A;
c                   ^ ^ TR                  UU 4S j5        T R                  R                  T5        / T R                  QT R                  QT R
                  PnTR                  U5        TR                  [        U5      S-   S5        g )Nc                  V   > T R                  SS[        TR                  5       S35      $ )Nz$triton.tools.experimental_descriptorcreate_d_tma_descriptor)r  rh   r  r;  s   r[   r<  ?TMADescriptorExperimentalVariable.reconstruct.<locals>.<lambda>  s)    G,,6#dii.))9:r^   r0   F)	r@  r  r  r  r  r  rL  r   rh   )rW   r  r   s   `` r[   r  -TMADescriptorExperimentalVariable.reconstruct  sp    	
 	!!'*@@T__@d.?.?@c$i!mU3r^   c                 .    U R                   R                  $ rt   )r  from_tensorr   s    r[   r  ,TMADescriptorExperimentalVariable.get_tensor  s    }}(((r^   )r  r  r  r  )r  zvariables.DataPtrVariabler  list[ConstantVariable]r  r  r  r6   r  
rm   rn   ro   rp   r\   r  r  r  rq   r\  r]  s   @r[   r  r    sB    )-) ') -	)
 ))

4) )r^   r  c                   N   ^  \ rS rSr    SU 4S jjrS rSS jrS	S jrSrU =r	$ )
r  i  c                    > [        U[        R                  5      (       d   e[        TU ]  " S0 UD6  Xl        X l        g r`   )r   r   rT  r   r\   r  block_shape)rW   r  r   r   r  s       r[   r\   $TMADescriptorStableVariable.__init__  s9     &)":":;;;;"6"&r^   c                 H    [        U R                  R                  5       5      $ rt   )r  r   r  r   s    r[   r  'TMADescriptorStableVariable.to_metadata  s!    )%%'
 	
r^   c                    ^ TR                  U4S j5        TR                  S5        U R                  R                  T5        T" U R                  5        TR                  S5        g )Nc                  (   > T R                  SS5      $ )Nztriton.tools.tensor_descriptorTensorDescriptorr  r  s   r[   r<  9TMADescriptorStableVariable.reconstruct.<locals>.<lambda>  s    G,,0"r^   r  r   )r@  load_methodr  r  r   rn  rB  s    `r[   r  'TMADescriptorStableVariable.reconstruct  sT    	
 	M*(  !Ar^   c                     U R                   $ rt   )r  r   s    r[   r  &TMADescriptorStableVariable.get_tensor  s    {{r^   )r   r  )r  variables.TensorVariabler   zvariables.ListVariabler  )rr   r,  r  r]  s   @r[   r  r    s.    	'*	' .	'


 r^   r  c                   N   ^  \ rS rSrS\SS4U 4S jjr        SS jrSrU =r$ )	'CreateTMADescriptorExperimentalVariablei  rankrr   Nc                 B   > US;   d   e[         TU ]  " S0 UD6  Xl        g )N)r0   r   ra   )r   r\   r/  )rW   r/  r   r  s      r[   r\   0CreateTMADescriptorExperimentalVariable.__init__ 	  s&    
 v~~"6"	r^   c                 $   SU;   a  US   OUS   n[        U[        R                  5      (       d  [        SU R                   S35      eU R                  S:X  a@  [        U5      [        U5      -   S:X  d   eSU;   a  US   OUS   /nSU;   a  US   OUS	   /nO][        U5      [        U5      -   S
:X  d   eSU;   a  US   OUS   SU;   a  US   OUS	   /nSU;   a  US   OUS   SU;   a  US   OUS   /nSU;   a  US   OUS   n[        UUUUS9$ )Nptrr   z8Please ensure there were no graph breaks between create_z3d_tma_descriptor and the upstream .data_ptr() call.r0   r?   r  	block_dimr      dim1dim0
block_dim1r  
block_dim0r  r  )r  r  r  r  )r   r   r
  r    r/  rh   r  )rW   r   r   r   r3  r  r  r  s           r[   r   5CreateTMADescriptorExperimentalVariable.call_function		  sd     %fUmDG#y8899)) %$$  99>t9s6{*a///!&&ud1gD (3f'<{#$q'J t9s6{*a///"(F"2vQ"(F"2vQD
 )5(>|$DG(4(>|$DGJ 2@61Ivn-tTVx0!%	
 	
r^   )r/  r   )	rm   rn   ro   rp   r~  r\   r   rq   r\  r]  s   @r[   r.  r.    sJ     
	(
#(
 &(
 -	(

 
(
 (
r^   r.  c                   .    \ rS rSr        SS jrSrg)!CreateTMADescriptorStableVariablei4	  c                 V    SU;   a  US   OUS   nSU;   a  US   OUS   n[        UUS9$ )Nr  r   r   r0   )r  r   )r  )rW   r   r   r   r  r   s         r[   r   /CreateTMADescriptorStableVariable.call_function5	  sF     &.%7!T!W/</Ff]+DQRG*#
 	
r^   ra   Nr   r  ra   r^   r[   r<  r<  4	  s-    
#
 &
 -	

 

r^   r<  rt   r  )r   r  r  r   r   r  r  r  r   collections.abcr   r   typingr   r   r   r	   r
   typing_extensionsr   unittest.mockr   weakrefr   r   torch._dynamo.excr   r  r   r   r   r   bytecode_transformationr   r   r   r  r   r   r   r   r   r   r   r   r   r    guardsr!   r"   r   r#   r$   r%   r&   rE  r'   r(   r)   r*   r+   r,   r-   r.   r/   baser1   r2   r3   r4   r  r6   #torch.distributed.fsdp._fully_shardr7   ModuleNotFoundErrortorch._dynamo.codegenr8   r  r:   r  r;   r<   r=   rS   rU   ru   rB   rx   r   r|   r   rf   r   r   r   r   r   r   r   r_  rt  r  r  r   r	  r,  rI  rB  r   r  r  r  r  r  r  r  r  r1  r9  rA  rd  r  r  r  r  r  r  r  r  r  r  r  r.  r<  ra   r^   r[   <module>rK     s  .      
   $  B B #  %  4 > > V V   1 N N
 
 
  'E
 /D T"
  !
 
>L \ 2j	A. $sO';"<  "( -" DW73 W7t:4 :<}4? }4@

 
4
%= 4
n"<V-- V-r> 2 >2>"6 >0 p)!9 p)f%>(B %>PWA? WAt>"6 >2>
/ >
B ; /QD(< QDh71 74
$8 
:N
 N
b~ ~B3 3
"/ "B X
> X
v $8#9  +? +\$) $)N/ B2
o 2
j
 
EG  s   J JJ