
    7h                     T   S r SSKrSSKrSSK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  SSKJrJr  \(       a  SSKJr  \R(                  \R*                  \R,                  \R.                  \R*                  \R*                  \R.                  \R.                  \R0                  \R0                  \R2                  \R2                  \R4                  \R4                  \R6                  \R6                  \R8                  \R8                  \R:                  \R:                  0
r\R(                  \R0                  \R,                  \R2                  \R0                  \R0                  \R2                  \R2                  \R*                  \R0                  \R.                  \R2                  \R4                  \R4                  \R6                  \R6                  \R8                  \R8                  \R:                  \R:                  0
r\R(                  \R4                  \R,                  \R6                  \R0                  \R4                  \R2                  \R6                  \R*                  \R4                  \R.                  \R6                  \R4                  \R4                  \R6                  \R6                  \R8                  \R8                  \R:                  \R:                  0
r \R(                  \R8                  \R,                  \R:                  \R*                  \R8                  \R.                  \R:                  \R8                  \R8                  \R:                  \R:                  \R0                  \R8                  \R2                  \R:                  \R4                  \R8                  \R6                  \R:                  0
r!S	 r"\RF                  " S
S9 " S S\5      5       r$\RF                  " S
S9 " S S\5      5       r%\RF                  " S
S9 " S S\5      5       r&\RF                  " S
S9 " S S\5      5       r'\RF                  " S
S9 " S S\5      5       r(\RF                  " S
S9 " S S\
5      5       r)\RF                  " S
S9 " S S\)5      5       r*\RF                  " S
S9 " S S\
5      5       r+\RF                  " S
S9 " S S\
5      5       r,\RF                  " S
S9 " S S\5      5       r-\RF                  " S
S9 " S  S!\
5      5       r.\RF                  " S
S9 " S" S#\+5      5       r/\RF                  " S
S9 " S$ S%\+5      5       r0\RF                  " S
S9 " S& S'\5      5       r1 " S( S)\Rd                  5      r3\RF                  " S
S9 " S* S+\
5      5       r4\RF                  " S
S9 " S, S-\
5      5       r5\RF                  " S
S9 " S. S/\
5      5       r6\RF                  " S
S9 " S0 S1\
5      5       r7\RF                  " S
S9 " S2 S3\
5      5       r8\RF                  " S
S9 " S4 S5\
5      5       r9 " S6 S7\
5      r:\RF                  " S
S9 " S8 S9\
5      5       r;\RF                  " S
S9 " S: S;\
5      5       r<\RF                  " S
S9 " S< S=\
5      5       r=\RF                  " S
S9 " S> S?\
5      5       r>\RF                  " S
S9 " S@ SA\
5      5       r?\RF                  " S
S9 " SB SC\<5      5       r@\RF                  " S
S9 " SD SE\<5      5       rA\RF                  " S
S9 " SF SG\
5      5       rB\RF                  " S
S9 " SH SI\
5      5       rC\RF                  " S
S9 " SJ SK\
5      5       rD\RF                  " S
S9 " SL SM\
5      5       rE\RF                  " S
S9 " SN SO\E5      5       rF\RF                  " S
S9 " SP SQ\F5      5       rG\RF                  " S
S9 " SR SS\E5      5       rH\RF                  " S
S9 " ST SU\5      5       rI\RF                  " S
S9 " SV SW\5      5       rJ\RF                  " S
S9 " SX SY\5      5       rK\RF                  " S
S9 " SZ S[\
5      5       rL\RF                  " S
S9 " S\ S]\
5      5       rM\RF                  " S
S9 " S^ S_\
5      5       rN\RF                  " S
S9 " S` Sa\
5      5       rO\RF                  " S
S9 " Sb Sc\5      5       rP\RF                  " S
S9 " Sd Se\5      5       rQSfSg.Sh\Si\\R   4Sj jjrSSfSg.Sh\4Sk jjrTSh\Si\U4Sl jrVSh\Si\\R   4Sm jrWSh\4Sn jrXSh\So\4Sp jrY\R                  Sh\4Sq j5       r[\R                  Sh\4Sr j5       r\\R                  Sh\4Ss j5       r]\R                  Sh\4St j5       r^\R                  Sh\4Su j5       r_\R                  Sh\4Sv j5       r`g)wa  
This module provides Source classes that track the origins of values in PyTorch Dynamo.
Sources represent where values come from (e.g. local variables, globals, attributes) and
are used for guard generation and code reconstruction during compilation.

The module includes specialized sources for:
- Local variables and synthetic locals
- Global variables and constants
- Object attributes and method calls
- NN module specialization (specialized vs unspecialized)
- Random values and tensor properties
- Default argument handling
- FSDP (Fully Sharded Data Parallel) modules

Sources play a key role in Dynamo's guard system by tracking value origins for
guard generation, and in code reconstruction by providing methods to rebuild
the code needed to recreate values.
    N)AnyOptionalTYPE_CHECKINGUnion)ChainedSourceGuardSourceSource   )utils)create_call_functioncreate_instruction)	PyCodegenc                     [        U [        5      (       a  g U R                  5       [        R                  :X  a  g g! [
         a     gf = fNTF)
isinstanceConstantSourceguard_sourcer   CONSTANTNotImplementedErrorsources    N/var/www/fran/franai/venv/lib/python3.13/site-packages/torch/_dynamo/source.pyis_constant_sourcer   c   sR    &.)) K$8$88 9
   s   "= 
A
	A
T)frozenc                   l    \ rS rSr% \\S'   Sr\\S'   Sr\	\
\      \S'   Sr\\S'   SS jrS	 rS
 rSrg)LocalSourceo   
local_nameFis_inputNdynamismis_derefed_cell_contentsc                     U R                   (       a  UR                  U R                  5        g UR                  UR	                  U R                  5      5        g N)r!   
load_derefr   append_outputcreate_loadselfcodegens     r   reconstructLocalSource.reconstruct   s:    ((t/!!'"5"5doo"FG    c                 "    [         R                  $ r#   )r   LOCALr(   s    r   r   LocalSource.guard_source   s       r,   c                 4    S[        U R                  5       S3$ )NzL[])reprr   r/   s    r   nameLocalSource.name   s    D)*!,,r,    r)   r   )__name__
__module____qualname____firstlineno__str__annotations__r   boolr    r   	frozensetr!   r*   r   r4   __static_attributes__r6   r,   r   r   r   o   sE    O Hd *.Hhy~&-
 &+d*H!-r,   r   c                   6    \ rS rSr% \\S'   SS jrS rS rSr	g)	SyntheticLocalSource   r   c                 X    UR                  UR                  U R                  5      5        g r#   )r%   r&   r   r'   s     r   r*    SyntheticLocalSource.reconstruct   s    g11$//BCr,   c                 "    [         R                  $ r#   )r   SYNTHETIC_LOCALr/   s    r   r   !SyntheticLocalSource.guard_source   s    ***r,   c                 $    SU R                   < S3$ )NzSYNTHETIC_LOCAL[r2   )r   r/   s    r   r4   SyntheticLocalSource.name   s    !$//!4A66r,   r6   Nr7   
r8   r9   r:   r;   r<   r=   r*   r   r4   r@   r6   r,   r   rB   rB      s    OD+7r,   rB   c                   6    \ rS rSr% \\S'   S rSS jrS rSr	g)	RandomValueSource   random_call_indexc                 "    [         R                  $ r#   )r   RANDOM_VALUEr/   s    r   r   RandomValueSource.guard_source   s    '''r,   c                    UR                  UR                  UR                  R                  R                  5      5        UR                  UR                  U R                  5      5        UR                  [        S5      5        g NBINARY_SUBSCR)r%   r&   txoutputrandom_values_varcreate_load_constrO   r   r'   s     r   r*   RandomValueSource.reconstruct   s^    g11'**2C2C2U2UVWg778N8NOP0ABr,   c                      SU R                    3$ )Nrandom_value_)rO   r/   s    r   r4   RandomValueSource.name   s    t55677r,   r6   Nr7   )
r8   r9   r:   r;   intr=   r   r*   r4   r@   r6   r,   r   rM   rM      s    (C
8r,   rM   c                   6    \ rS rSr% \\S'   SS jrS rS rSr	g)	GlobalSource   global_namec                 V    UR                  UR                  U R                  SS95        g NTaddr%   create_load_globalrb   r'   s     r   r*   GlobalSource.reconstruct   s&    g889I9It8TUr,   c                 "    [         R                  $ r#   r   GLOBALr/   s    r   r   GlobalSource.guard_source       !!!r,   c                 4    S[        U R                  5       S3$ )NG[r2   r3   rb   r/   s    r   r4   GlobalSource.name   s    D))*+1--r,   r6   Nr7   rK   r6   r,   r   r`   r`      s    V".r,   r`   c                   6    \ rS rSr% \\S'   SS jrS rS rSr	g)	GlobalWeakRefSource   rb   c                 j   ^ ^ TR                  UU 4S j5        TR                  [        SS5      5        g )Nc                  V   > T R                  T R                  TR                  SS95      $ rd   rg   r)   r(   s   r   <lambda>1GlobalWeakRefSource.reconstruct.<locals>.<lambda>   s)    G))**4+;+;*Fr,   r   Fadd_push_nullextend_outputr   r'   s   ``r   r*   GlobalWeakRefSource.reconstruct   s.    	

 	21e<=r,   c                 "    [         R                  $ r#   rk   r/   s    r   r    GlobalWeakRefSource.guard_source   rn   r,   c                 4    S[        U R                  5       S3$ )Nrp   z]()rq   r/   s    r   r4   GlobalWeakRefSource.name   s    D))*+3//r,   r6   Nr7   rK   r6   r,   r   rt   rt      s    >"0r,   rt   c                   *    \ rS rSrSS jrS rS rSrg)WeakRefCallSource   c                 j   ^ ^ TR                  UU 4S j5        TR                  [        SS5      5        g )Nc                  (   > T " TR                   5      $ r#   baserx   s   r   ry   /WeakRefCallSource.reconstruct.<locals>.<lambda>   s    gdii&8r,   r   Fr{   r'   s   ``r   r*   WeakRefCallSource.reconstruct   s(    8921e<=r,   c                 6    U R                   R                  5       $ r#   r   r   r/   s    r   r   WeakRefCallSource.guard_source       yy%%''r,   c                 <    U R                   R                  5        S3$ )Nz()r   r4   r/   s    r   r4   WeakRefCallSource.name   s    )).."#2&&r,   r6   Nr7   r8   r9   r:   r;   r*   r   r4   r@   r6   r,   r   r   r      s    >('r,   r   c                       \ rS rSrSrg)CallFunctionNoArgsSource   r6   Nr8   r9   r:   r;   r@   r6   r,   r   r   r          r,   r   c                   <    \ rS rSr% \\S'   S rS	S jrS rS r	Sr
g)

AttrSource   memberc                 :   U R                   (       d   S5       eSU R                  ;   as  U R                  R                  S5      n[        R	                  U S[        U R                   SR                  US S 5      5      5        [        R	                  U SUS   5        g g Nz9Can't construct an AttrSource without a valid base source.r   r   r   r   splitobject__setattr__r   joinr(   member_partss     r   __post_init__AttrSource.__post_init__       yyUUUy$++;;,,S1LfjCHH\#2=N4OP tX|B/?@ r,   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g r#   r   r}   create_load_attrsr   r'   s     r   r*   AttrSource.reconstruct   +    		g77DEr,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   AttrSource.guard_source   r   r,   c                     U R                   R                  5       (       d,  SU R                  R                  5        SU R                   < S3$ U R                  R                  5        SU R                    3$ )Nzgetattr(, )r   )r   isidentifierr   r4   r/   s    r   r4   AttrSource.name   s[    {{''))diinn./r$++BB)).."#1T[[M22r,   r6   Nr7   r8   r9   r:   r;   r<   r=   r   r*   r   r4   r@   r6   r,   r   r   r      s    KAF(3r,   r   c                   <    \ rS rSr% \\S'   S rS	S jrS rS r	Sr
g)
GenericAttrSource   r   c                 :   U R                   (       d   S5       eSU R                  ;   as  U R                  R                  S5      n[        R	                  U S[        U R                   SR                  US S 5      5      5        [        R	                  U SUS   5        g g r   r   r   s     r   r   GenericAttrSource.__post_init__   r   r,   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g r#   r   r'   s     r   r*   GenericAttrSource.reconstruct  r   r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   GenericAttrSource.guard_source  r   r,   c                 Z    SU R                   R                  5        SU R                  < S3$ )Nzobject.__getattribute__(r   r   r   r4   r   r/   s    r   r4   GenericAttrSource.name  s'    )$))..*:);2dkk_ANNr,   r6   Nr7   r   r6   r,   r   r   r      s    KAF(Or,   r   c                   .    \ rS rSr% Sr\\S'   SS jrSrg)LocalCellSourcei  zw
Conceptually, this class is `LocalSource` for cell objects implicitly
generated by Python (e.g., captured variables).
r   c                 X    UR                  UR                  U R                  5      5        g r#   )r%   create_load_closurer   r'   s     r   r*   LocalCellSource.reconstruct  s!     	g99$//JKr,   r6   Nr7   )	r8   r9   r:   r;   __doc__r<   r=   r*   r@   r6   r,   r   r   r     s    
 OLr,   r   c                   :    \ rS rSr% Sr\\S'   S	S jrS rS r	Sr
g)

GradSourcei&  gradr   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g r#   r   r'   s     r   r*   GradSource.reconstruct*  r   r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   GradSource.guard_source.  r   r,   c                 T    U R                   R                  5        SU R                   3$ )Nr   r   r/   s    r   r4   GradSource.name1  s#    )).."#1T[[M22r,   r6   Nr7   )r8   r9   r:   r;   r   r<   r=   r*   r   r4   r@   r6   r,   r   r   r   &  s    FCF(3r,   r   c                       \ rS rSrS rSrg)ParamBufferSourcei5  c                 D    [         U R                  R                  5          $ r#   #_GUARD_SOURCE_SPECIALIZED_NN_MODULEr   r   r/   s    r   r   ParamBufferSource.guard_source7      24993I3I3KLLr,   r6   Nr8   r9   r:   r;   r   r@   r6   r,   r   r   r   5  s    Mr,   r   c                       \ rS rSrSrg)UnspecializedParamBufferSourcei<  r6   Nr   r6   r,   r   r   r   <  r   r,   r   c                   B    \ rS rSr% Sr\\   \S'   S rS r	S r
S rSrg)	EphemeralSourceiJ  Ndescc                 "    [         R                  $ r#   )r   	EPHEMERALr/   s    r   r   EphemeralSource.guard_sourceN      $$$r,   c                 L    SU R                   b  SU R                   -    S3$ S S3$ )Nz
<ephemeralz:  >)r   r/   s    r   r4   EphemeralSource.nameQ  s1    		0ED499,NaPP2NaPPr,   c                     [         er#   r   r(   fns     r   
make_guardEphemeralSource.make_guardT      !!r,   c                     gNTr6   r/   s    r   is_ephemeralEphemeralSource.is_ephemeralW      r,   r6   )r8   r9   r:   r;   r   r   r<   r=   r   r4   r   r   r@   r6   r,   r   r   r   J  s%    D(3-%Q"r,   r   c                   &    \ rS rSrSrSrSrS rSrg)TensorPropertyi[  r   r
      c                 |    U [         R                  L a  gU [         R                  L a  gU [         R                  L a  gg )Nsizestridestorage_offset)r   SIZESTRIDESTORAGE_OFFSETr/   s    r   method_nameTensorProperty.method_name`  s:    >&&&^***^222# 3r,   r6   N)	r8   r9   r:   r;   r   r   r   r   r@   r6   r,   r   r   r   [  s    DFN$r,   r   c                   P    \ rS rSr% \\S'   Sr\\   \S'   S r	S
S jr
S rS rS	rg)TensorPropertySourceii  propNidxc                     U R                   c   eU R                  [        R                  L a  U R                  b   eg U R                  c   eg r#   )r   r  r   r   r  r/   s    r   r   "TensorPropertySource.__post_init__n  sD    yy$$$9955588###88'''r,   c                   ^ ^ TR                  UU 4S j5        T" T R                  5        T R                  b*  TR                  TR	                  T R                  5      5        TR                  [        T R                  b  SOSS5      5        g )Nc                  z   > T R                  [        R                  STR                  R	                  5        35      $ )Ncall_)load_import_fromr   r8   r  r   rx   s   r   ry   2TensorPropertySource.reconstruct.<locals>.<lambda>w  s.    G,,%		(=(=(?'@ Ar,   r   r
   F)r|   r   r  r%   rY   r}   r   r'   s   ``r   r*    TensorPropertySource.reconstructu  sn    	

 			88!!'";";DHH"EF dhh&:5I	
r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   !TensorPropertySource.guard_source  r   r,   c                    U R                   [        R                  L a*  U R                  R	                  5        SU R
                   S3$ U R                   [        R                  L a*  U R                  R	                  5        SU R
                   S3$ U R                   [        R                  L a,  U R
                  b   eU R                  R	                  5        S3$ [        SU R                    35      e)Nz.size()[r2   z
.stride()[z.storage_offset()z
unhandled )	r  r   r   r   r4   r  r   r   AssertionErrorr/   s    r   r4   TensorPropertySource.name  s    99+++iinn&'xz;;YY.///iinn&'z$((1==YY.77788###iinn&''899 :dii[!9::r,   r6   r7   )r8   r9   r:   r;   r   r=   r  r   r^   r   r*   r   r4   r@   r6   r,   r   r  r  i  s*    
C#(
(	;r,   r  c                   <    \ rS rSr% \\S'   S rS	S jrS rS r	Sr
g)
IndexedSourcei  r  c                 "    U R                   c   eg r#   r   r/   s    r   r   IndexedSource.__post_init__      yy$$$r,   c                     [         er#   r   r'   s     r   r*   IndexedSource.reconstruct  r   r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   IndexedSource.guard_source  r   r,   c                 X    SU R                    SU R                  R                  5        S3$ )N(r   r   )r  r   r4   r/   s    r   r4   IndexedSource.name  s'    488*Btyy~~/022r,   r6   Nr7   )r8   r9   r:   r;   r^   r=   r   r*   r   r4   r@   r6   r,   r   r  r    s    	H%"(3r,   r  c                   0    \ rS rSrS rSS jrS rS rSrg)	NegateSourcei  c                 "    U R                   c   eg r#   r   r/   s    r   r   NegateSource.__post_init__  r  r,   c                     [         er#   r   r'   s     r   r*   NegateSource.reconstruct  r   r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   NegateSource.guard_source  r   r,   c                 <    U R                   R                  5        S3$ )Nz
.__neg__()r   r/   s    r   r4   NegateSource.name  s    )).."#:..r,   r6   Nr7   	r8   r9   r:   r;   r   r*   r   r4   r@   r6   r,   r   r  r    s    %"(/r,   r  c                   0    \ rS rSrS rSS jrS rS rSrg)	ConvertIntSourcei  c                 "    U R                   c   eg r#   r   r/   s    r   r   ConvertIntSource.__post_init__  r  r,   c                 (    U" U R                   5        g r#   r   r'   s     r   r*   ConvertIntSource.reconstruct      		r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   ConvertIntSource.guard_source  r   r,   c                 >    SU R                   R                  5        S3$ )Nz!cast_symbool_to_symint_guardless(r   r   r/   s    r   r4   ConvertIntSource.name  s    2499>>3C2DAFFr,   r6   Nr7   r'  r6   r,   r   r)  r)    s    %(Gr,   r)  c                   0    \ rS rSrS rSS jrS rS rSrg)	FlattenScriptObjectSourcei  c                 "    U R                   c   eg r#   r   r/   s    r   r   'FlattenScriptObjectSource.__post_init__  r  r,   c                 (    U" U R                   5        g r#   r   r'   s     r   r*   %FlattenScriptObjectSource.reconstruct  r.  r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   &FlattenScriptObjectSource.guard_source  r   r,   c                 <    U R                   R                  5        S3$ )Nz.__obj_flatten__()r   r/   s    r   r4   FlattenScriptObjectSource.name  s    )).."##566r,   r6   Nr7   r'  r6   r,   r   r4  r4    s    %(7r,   r4  c                   0    \ rS rSrS rSS jrS rS rSrg)	ScriptObjectQualifiedNameSourcei  c                 "    U R                   c   eg r#   r   r/   s    r   r   -ScriptObjectQualifiedNameSource.__post_init__  r  r,   c                 (    U" U R                   5        g r#   r   r'   s     r   r*   +ScriptObjectQualifiedNameSource.reconstruct  r.  r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   ,ScriptObjectQualifiedNameSource.guard_source  r   r,   c                 <    U R                   R                  5        S3$ )Nz._type().qualified_name()r   r/   s    r   r4   $ScriptObjectQualifiedNameSource.name  s    )).."##<==r,   r6   Nr7   r'  r6   r,   r   r>  r>    s    %(>r,   r>  c                   *    \ rS rSrSS jrS rS rSrg)AttrProxySourcei  c                 (    U" U R                   5        g r#   r   r'   s     r   r*   AttrProxySource.reconstruct  r.  r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   AttrProxySource.guard_source  r   r,   c                 <    U R                   R                  5        S3$ )Nz.get_base()r   r/   s    r   r4   AttrProxySource.name  s    )).."#;//r,   r6   Nr7   r   r6   r,   r   rH  rH    s    (0r,   rH  c                       \ rS rSr% \\\4   \S'   Sr\	\S'   \
R                  " SSSS9r\\S'   \
R                  " SSSS9r\\S'   S rSS	 jrS
 rS rSrg)DefaultsSourcei  idx_keyFis_kw)initr3   comparefield_namec           
      h   U R                   (       d   S5       eU R                  (       a  [        U R                  [        5      (       d   e[
        R                  U SS5        [
        R                  U SU R                   R                  5        SU R                   SU R                   S35        g [        U R                  [        5      (       d   e[
        R                  U SS5        [
        R                  U SU R                   R                  5        SU R                   S	U R                   S
35        g )Nz]Base must be a valid source in order to properly track and guard this Defaults to its origin.rU  __kwdefaults__rV  r   z['z']__defaults__[r2   )
r   rR  r   rQ  r<   r   r   r4   rU  r^   r/   s    r   r   DefaultsSource.__post_init__  s    yy 	
k	
y ::dllC0000tW.>?g$)).."2!31TZZL4<<.PRS dllC0000tWn=g$)).."2!31TZZL$,,qQr,   c                    U" U R                   5        UR                  UR                  U R                  5      5        UR	                  UR                  U R                  5      5        UR	                  [        S5      5        g rT   )r   r}   r   rU  r%   rY   rQ  r   r'   s     r   r*   DefaultsSource.reconstruct  s\    		g77

CDg77EF0ABr,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   DefaultsSource.guard_source	  r   r,   c                     U R                   $ r#   )rV  r/   s    r   r4   DefaultsSource.name  s    zzr,   r6   Nr7   )r8   r9   r:   r;   r   r^   r<   r=   rR  r>   dataclassesrU  rV  r   r*   r   r4   r@   r6   r,   r   rP  rP    sa    38_E4""E5IE3I""E5IE3I"C(r,   rP  c                   ^   ^  \ rS rSr% \\S'   Sr\\S'   U 4S jrSS jr	S r
S rS	 rS
rU =r$ )GetItemSourcei  indexFindex_is_slicec                    > U R                   c   e[        U R                  [        5      (       a9  [        TU ]  SU R                  R                  5       5        [        TU ]  SS5        g g )Nre  rf  T)r   r   re  slicesuperr   
__reduce__)r(   	__class__s    r   r   GetItemSource.__post_init__  sU    yy$$$djj%((G)>)>)@AG 0$7 )r,   c                 0   U" U R                   5        U R                  (       a/  UR                  UR                  U R	                  5       5      5        O*UR                  UR                  U R
                  5      5        UR                  [        S5      5        g rT   )r   rf  r%   rY   unpack_slicere  r   r'   s     r   r*   GetItemSource.reconstruct  sj    		!!'";";D<M<M<O"PQ!!'";";DJJ"GH0ABr,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   GetItemSource.guard_source$  r   r,   c                 N    U R                   (       d   eU R                  u  pU" U6 $ r#   )rf  re  )r(   slice_class
slice_argss      r   rn  GetItemSource.unpack_slice'  s(    """""&**J''r,   c                    [        U R                  [        5      (       a   eU R                  (       a/  U R                  R                  5        SU R                  5       < S3$ U R                  R                  5        SU R                  < S3$ NrZ  r2   )r   re  r	   rf  r   r4   rn  r/   s    r   r4   GetItemSource.name,  sp     djj&1111iinn&'q):):)<(?qAAiinn&'qa88r,   r6   r7   )r8   r9   r:   r;   r   r=   rf  r>   r   r*   r   rn  r4   r@   __classcell__)rk  s   @r   rd  rd    s1    J ND 8C((
9 9r,   rd  c                   <    \ rS rSr% \\S'   S rS	S jrS rS r	Sr
g)
ConstDictKeySourcei7  re  c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   ConstDictKeySource.guard_source;  r   r,   c                    ^ TR                  U4S j5        T" U R                  5        TR                  TR                  U R                  5      5        TR                  [        SS5      5        g )Nc                  D   > T R                  [        R                  S5      $ )Ndict_keys_getitemr	  r   r8   r)   s   r   ry   0ConstDictKeySource.reconstruct.<locals>.<lambda>@  s    G,,U^^=PQr,   r   Fr|   r   r%   rY   re  r}   r   r'   s    `r   r*   ConstDictKeySource.reconstruct>  sU    Q	
 			g77

CD21e<=r,   c                 Z    SU R                   R                  5        SU R                  < S3$ )Nzlist(dict.keys(z))[r2   r   r4   re  r/   s    r   r4   ConstDictKeySource.nameF  s'     !1 2#djj^1EEr,   c                     gr   r6   r/   s    r   is_dict_keyConstDictKeySource.is_dict_keyJ  r   r,   r6   Nr7   )r8   r9   r:   r;   r   r=   r   r*   r4   r  r@   r6   r,   r   r{  r{  7  s    J(>Fr,   r{  c                   <    \ rS rSr% \\S'   S rS rS	S jrS r	Sr
g)
DictGetItemSourceiO  re  c                     SSK Jn  [        U R                  [        5      (       d#  UR                  U R                  5      (       d   eg g Nr
   )ConstantVariable	variablesr  r   re  r{  
is_literalr(   r  s     r   r   DictGetItemSource.__post_init__V  C    /JJ*
 
((44	5 54
r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   DictGetItemSource.guard_source]  r   r,   c                    U" U R                   5        [        U R                  [        5      (       a  U" U R                  5        O*UR	                  UR                  U R                  5      5        UR	                  [        S5      5        g rT   )r   r   re  r	   r%   rY   r   r'   s     r   r*   DictGetItemSource.reconstruct`  s^    		 djj&))DJJ!!'";";DJJ"GH0ABr,   c                    [        U R                  [        5      (       a8  U R                  R	                  5        SU R                  R	                  5        S3$ U R                  R	                  5        SU R                  < S3$ rw  r   re  r{  r   r4   r/   s    r   r4   DictGetItemSource.namek  sb    djj"455iinn&'q):(;1==iinn&'qa88r,   r6   Nr7   r8   r9   r:   r;   r   r=   r   r   r*   r4   r@   r6   r,   r   r  r  O  s    
 J5(	C9r,   r  c                   <    \ rS rSr% \\S'   S rS rS	S jrS r	Sr
g)
DictSubclassGetItemSourceit  re  c                     SSK Jn  [        U R                  [        5      (       d#  UR                  U R                  5      (       d   eg g r  r  r  s     r   r   'DictSubclassGetItemSource.__post_init__{  r  r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   &DictSubclassGetItemSource.guard_source  r   r,   c                 B  ^ TR                  U4S j5        T" U R                  5        [        U R                  [        5      (       a  T" U R                  5        O*TR                  TR                  U R                  5      5        TR                  [        SS5      5        g )Nc                  D   > T R                  [        R                  S5      $ )Ndict_getitemr  r  s   r   ry   7DictSubclassGetItemSource.reconstruct.<locals>.<lambda>      G,,U^^^Lr,   r   F)	r|   r   r   re  r	   r%   rY   r}   r   r'   s    `r   r*   %DictSubclassGetItemSource.reconstruct  sv     	L	

 			 djj&))DJJ!!'";";DJJ"GH21e<=r,   c                    [        U R                  [        5      (       a9  SU R                  R	                  5        SU R                  R	                  5        S3$ U R                  R	                  5        SU R                  < S3$ )Nzdict.__getitem__(r   r   rZ  r2   r  r/   s    r   r4   DictSubclassGetItemSource.name  sd    djj"455&tyy~~'7&84::??;L:MQOOiinn&'qa88r,   r6   Nr7   r  r6   r,   r   r  r  t  s    
 J5(>&9r,   r  c                   (    \ rS rSrSrSS jrS rSrg)ListGetItemSourcei  zQ
Same as GetItemSource with reconstruct and name overridden to be list specific.
c                   ^ TR                  U4S j5        T" U R                  5        U R                  (       a  [        S5      eTR	                  TR                  U R                  5      5        TR                  [        SS5      5        g )Nc                  D   > T R                  [        R                  S5      $ )Nlist_getitemr  r  s   r   ry   /ListGetItemSource.reconstruct.<locals>.<lambda>  r  r,   >List[slice] is a temporary object and should not have a sourcer   F)	r|   r   rf  RuntimeErrorr%   rY   re  r}   r   r'   s    `r   r*   ListGetItemSource.reconstruct  st    
 	L	

 			 P  !!'";";DJJ"GH21e<=r,   c                     [        U R                  [        5      (       a   eU R                  (       a  [	        S5      eSU R
                  R                  5        SU R                  < S3$ )Nr  zlist.__getitem__(r   r   )r   re  r	   rf  r  r   r4   r/   s    r   r4   ListGetItemSource.name  s[     djj&1111P  'tyy~~'7&84::.JJr,   r6   Nr7   )r8   r9   r:   r;   r   r*   r4   r@   r6   r,   r   r  r    s    >,
Kr,   r  c                   $    \ rS rSrSS jrS rSrg)TupleIteratorGetItemSourcei  c                    ^ TR                  U4S j5        T" U R                  5        TR                  TR                  U R                  5      5        TR                  [        SS5      5        g )Nc                  D   > T R                  [        R                  S5      $ )Ntuple_iterator_getitemr  r  s   r   ry   8TupleIteratorGetItemSource.reconstruct.<locals>.<lambda>  s    G,,U^^=UVr,   r   Fr  r'   s    `r   r*   &TupleIteratorGetItemSource.reconstruct  sU    V	
 			g77

CD21e<=r,   c                 Z    SU R                   R                  5        SU R                  < S3$ )Nz___tuple_iterator_getitem(r   r   r  r/   s    r   r4   TupleIteratorGetItemSource.name  s'    +DIINN,<+=R

~QOOr,   r6   Nr7   )r8   r9   r:   r;   r*   r4   r@   r6   r,   r   r  r    s    >Pr,   r  c                   *    \ rS rSrSS jrS rS rSrg)DataclassFieldsSourcei  c                    ^ TR                  U4S j5        T" U R                  5        TR                  [        SS5      5        g )Nc                  D   > T R                  [        R                  S5      $ )Ndataclass_fieldsr  r  s   r   ry   3DataclassFieldsSource.reconstruct.<locals>.<lambda>  s    G,,U^^=OPr,   r
   Fr|   r   r}   r   r'   s    `r   r*   !DataclassFieldsSource.reconstruct  s8    P	
 			21e<=r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   "DataclassFieldsSource.guard_source  r   r,   c                 >    SU R                   R                  5        S3$ )Nz___dataclass_fields(r   r   r/   s    r   r4   DataclassFieldsSource.name  s    %diinn&6%7q99r,   r6   Nr7   r   r6   r,   r   r  r    s    >(:r,   r  c                   0    \ rS rSrS rSS jrS rS rSrg)	
TypeSourcei  c                 "    U R                   c   eg r#   r   r/   s    r   r   TypeSource.__post_init__  r  r,   c                    ^ TR                  U4S j5        T" U R                  5        TR                  [        SS5      5        g )Nc                  (   > T R                  SS5      $ )Nbuiltinstyper	  r  s   r   ry   (TypeSource.reconstruct.<locals>.<lambda>  s    g&>&>z6&Rr,   r
   Fr  r'   s    `r   r*   TypeSource.reconstruct  s4    RS		21e<=r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   TypeSource.guard_source  r   r,   c                 >    SU R                   R                  5        S3$ )Nztype(r   r   r/   s    r   r4   TypeSource.name  s    tyy~~'(**r,   r6   Nr7   r'  r6   r,   r   r  r    s    %>
(+r,   r  c                   *    \ rS rSrSS jrS rS rSrg)OptimizerSourcei  c                 (    U" U R                   5        g r#   r   r'   s     r   r*   OptimizerSource.reconstruct  r.  r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   OptimizerSource.guard_source  r   r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r4   OptimizerSource.name      yy~~r,   r6   Nr7   r   r6   r,   r   r  r    s    ( r,   r  c                   *    \ rS rSrSS jrS rS rSrg)NNModuleSourcei  c                 (    U" U R                   5        g r#   r   r'   s     r   r*   NNModuleSource.reconstruct  r.  r,   c                 D    [         U R                  R                  5          $ r#   r   r/   s    r   r   NNModuleSource.guard_source  r   r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r4   NNModuleSource.name  r  r,   r6   Nr7   r   r6   r,   r   r  r    s    M r,   r  c                       \ rS rSrS rSrg)UnspecializedNNModuleSourcei  c                 D    [         U R                  R                  5          $ r#   )%_GUARD_SOURCE_UNSPECIALIZED_NN_MODULEr   r   r/   s    r   r   (UnspecializedNNModuleSource.guard_source  s    4TYY5K5K5MNNr,   r6   Nr   r6   r,   r   r  r    s    Or,   r  c                       \ rS rSrS rSrg)"UnspecializedBuiltinNNModuleSourcei  c                 D    [         U R                  R                  5          $ r#   )-_GUARD_SOURCE_UNSPECIALIZED_BUILTIN_NN_MODULEr   r   r/   s    r   r   /UnspecializedBuiltinNNModuleSource.guard_source  s    <TYY=S=S=UVVr,   r6   Nr   r6   r,   r   r  r    s    Wr,   r  c                       \ rS rSrS rSrg)FSDPNNModuleSourcei  c                 D    [         U R                  R                  5          $ r#   )_GUARD_SOURCE_FSDP_MODULEr   r   r/   s    r   r   FSDPNNModuleSource.guard_source  s    ()?)?)ABBr,   r6   Nr   r6   r,   r   r  r    s    Cr,   r  c                        \ rS rSrS rS rSrg)GlobalStateSourcei!  c                     gNr   r6   r/   s    r   r4   GlobalStateSource.name#      r,   c                 "    [         R                  $ r#   rk   r/   s    r   r   GlobalStateSource.guard_source&  rn   r,   r6   Nr8   r9   r:   r;   r4   r   r@   r6   r,   r   r  r  !  s    "r,   r  c                   <    \ rS rSr% \\S'   S rS rS	S jrS r	Sr
g)
TorchFunctionModeStackSourcei*  indc                 *    SU R                  5        S3$ )Nz$___get_torch_function_mode_stack_at(r   )
_get_indexr/   s    r   r4   !TorchFunctionModeStackSource.name.  s    5doo6G5HJJr,   c                 D    SSK Jn  UR                  U R                  5      $ )Nr
   )TorchFunctionModeStackVariable)variables.torch_functionr  get_mode_indexr  )r(   r  s     r   r	  'TorchFunctionModeStackSource._get_index1  s    L-<<TXXFFr,   c                    ^ TR                  U4S j5        TR                  TR                  U R                  5       5      /5        TR                  [	        SS5      5        g )Nc                  D   > T R                  [        R                  S5      $ )N get_torch_function_mode_stack_atr  r  s   r   ry   :TorchFunctionModeStackSource.reconstruct.<locals>.<lambda>8  s    G,, Br,   r
   F)r|   r}   rY   r	  r   r'   s    `r   r*   (TorchFunctionModeStackSource.reconstruct6  sQ    	

 	w889JKLM21e<=r,   c                 "    [         R                  $ r#   rk   r/   s    r   r   )TorchFunctionModeStackSource.guard_source?  rn   r,   r6   Nr7   )r8   r9   r:   r;   r^   r=   r4   r	  r*   r   r@   r6   r,   r   r  r  *  s    	HKG
>"r,   r  c                   <    \ rS rSr% \\S'   S	S jrS rS rS r	Sr
g)
r   iC  source_namec                 V    UR                  UR                  U R                  SS95        g )NFre   )r%   rh   r  r'   s     r   r*   ConstantSource.reconstructG  s&    g889I9Iu8UVr,   c                 "    [         R                  $ r#   )r   r   r/   s    r   r   ConstantSource.guard_sourceJ  s    ###r,   c                     U R                   $ r#   )r  r/   s    r   r4   ConstantSource.nameM  s    r,   c                     [         er#   r   r   s     r   r   ConstantSource.make_guardP  r   r,   r6   Nr7   )r8   r9   r:   r;   r<   r=   r*   r   r4   r   r@   r6   r,   r   r   r   C  s    W$ "r,   r   c                   2    \ rS rSrS\4S jrS rSS jrSrg)	NumpyTensorSourceiT  returnc                 >    SU R                   R                  5        S3$ )Nz___from_numpy(r   r   r/   s    r   r4   NumpyTensorSource.nameV  s    		 0133r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   NumpyTensorSource.guard_sourceY  r   r,   c                    ^ TR                  U4S j5        T" U R                  5        TR                  [        SS5      5        g )Nc                  (   > T R                  SS5      $ )Ntorch	as_tensorr  r  s   r   ry   /NumpyTensorSource.reconstruct.<locals>.<lambda>]  s    g&>&>w&Tr,   r
   Fr  r'   s    `r   r*   NumpyTensorSource.reconstruct\  s4    TU		21e<=r,   r6   Nr7   )	r8   r9   r:   r;   r<   r4   r   r*   r@   r6   r,   r   r"  r"  T  s    4c 4(>r,   r"  c                   (    \ rS rSrS\4S jrS rSrg)SubclassAttrListSourceib  r#  c                 <    U R                   R                  5        S3$ )Nz.__tensor_flatten__()[0]r   r/   s    r   r4   SubclassAttrListSource.named  s    )).."##;<<r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   #SubclassAttrListSource.guard_sourceg  r   r,   r6   Nr8   r9   r:   r;   r<   r4   r   r@   r6   r,   r   r/  r/  b  s    =c =(r,   r/  c                   (    \ rS rSrS\4S jrS rSrg)FloatTensorSourceim  r#  c                 >    SU R                   R                  5        S3$ )Nz___as_tensor(r   r   r/   s    r   r4   FloatTensorSource.nameo  s    tyy~~/022r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   FloatTensorSource.guard_sourcer  r   r,   r6   Nr4  r6   r,   r   r6  r6  m  s    3c 3(r,   r6  c                   (    \ rS rSrS\4S jrS rSrg)CallMethodItemSourceiv  r#  c                 <    U R                   R                  5        S3$ )Nz.item()r   r/   s    r   r4   CallMethodItemSource.namex  s    )).."#7++r,   c                 6    U R                   R                  5       $ r#   r   r/   s    r   r   !CallMethodItemSource.guard_source{  r   r,   r6   Nr4  r6   r,   r   r<  r<  v  s    ,c ,(r,   r<  c                        \ rS rSrS rS rSrg)ShapeEnvSourcei  c                     gr  r6   r/   s    r   r4   ShapeEnvSource.name  r  r,   c                 "    [         R                  $ r#   )r   	SHAPE_ENVr/   s    r   r   ShapeEnvSource.guard_source  r   r,   r6   Nr  r6   r,   r   rB  rB    s    %r,   rB  c                        \ rS rSrS rS rSrg)BackwardStateSourcei  c                     gr  r6   r/   s    r   r4   BackwardStateSource.name  r  r,   c                 "    [         R                  $ r#   )r   BACKWARD_STATEr/   s    r   r    BackwardStateSource.guard_source  s    )))r,   r6   Nr  r6   r,   r   rI  rI    s    *r,   rI  Fonly_allow_inputr   r#  c                    [        U [        5      (       a  [        U R                  US9$ [        U [        5      (       d  g U(       a  U R
                  (       d  g U R                  $ NrO  )r   r   get_local_source_namer   r   r   r   r   rP  s     r   rS  rS    sI    &-(($V[[CSTTfk**r,   c                    [        XS9S L$ rR  )rS  rT  s     r   is_from_local_sourcerV    s     KSWWWr,   c                     [        U 5      S L$ r#   )get_global_source_namer   s    r   is_from_global_sourcerY    s    !&)55r,   c                     [        U [        5      (       a  [        U R                  5      $ [        U [        5      (       d  g U R
                  $ r#   )r   r   rX  r   r`   rb   r   s    r   rX  rX    s:    &-((%fkk22fl++r,   c                     [        U [        5      (       a  [        U R                  5      $ [        U [        5      =(       a$    U R
                  =(       a    U R                  (       + $ r#   )r   r   is_from_nonlocal_sourcer   r   r!   r   r   s    r   r\  r\    sJ    &-((&v{{336;' 	 ++	 r,   targetc                 `    [        U [        5      (       a  [        U R                  U5      $ X:H  $ r#   )r   r   is_from_sourcer   )r   r]  s     r   r_  r_    s)    &-((fkk622r,   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   r  r   &is_from_unspecialized_nn_module_sourcer   r   s    r   ra  ra    s2    &566&-((5fkkBBr,   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   r  r   .is_from_unspecialized_builtin_nn_module_sourcer   r   s    r   rc  rc    s2    &<==&-((=fkkJJr,   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   r   r   )is_from_unspecialized_param_buffer_sourcer   r   s    r   re  re    s2    &899&-((8EEr,   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   r4  r   $is_from_flatten_script_object_sourcer   r   s    r   rg  rg    s2    &344	FM	*	*3FKK@@r,   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   r  r   is_from_optimizer_sourcer   r   s    r   ri  ri    s1    &/**&-(('44r,   c                    [        U [        5      (       a  g[        U [        5      (       a:  [        U R                  [        5      (       a  U R                  R
                  S:X  a  g[        U [        5      (       a:  [        U R                  [        5      (       a  U R                  R
                  S:X  a  g[        U [        5      (       a  [        U R                  5      $ g)NTrX  rY  F)	r   rP  r  r   r   r   rd  r   is_from_defaultsr   s    r   rk  rk    s    &.)) 	6,--v{{J//KK"22 	6=))v{{J//KK.0&-((,,r,   )ar   rb  enum	functoolstypingr   r   r   r   torch._guardsr   r   r	   r   r   bytecode_transformationr   r   r)   r   r.   LOCAL_SPECIALIZED_NN_MODULErl   GLOBAL_SPECIALIZED_NN_MODULELOCAL_UNSPECIALIZED_NN_MODULEGLOBAL_UNSPECIALIZED_NN_MODULE%LOCAL_UNSPECIALIZED_BUILTIN_NN_MODULE&GLOBAL_UNSPECIALIZED_BUILTIN_NN_MODULELOCAL_FSDP_MODULEGLOBAL_FSDP_MODULEr   r  r  r  r   	dataclassr   rB   rM   r`   rt   r   r   r   r   r   r   r   r   r   Enumr   r  r  r  r)  r4  r>  rH  rP  rd  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r"  r/  r6  r<  rB  rI  r<   rS  rV  r>   rY  rX  r\  r_  	lru_cachera  rc  re  rg  ri  rk  r6   r,   r   <module>r|     s
  &    6 6 < <  M " {>>@@++[-T-T,,k.V.V--{/X/X..0Z0Z55{7h7h668j8j!!;#@#@""K$B$B' #  {@@BB--{/X/X..0Z0Z++[-V-V,,k.X.X55{7h7h668j8j!!;#@#@""K$B$B) %" {HHJJ--{/`/`..0b0b++[-^-^,,k.`.`55{7h7h668j8j!!;#@#@""K$B$B1 - {4466++[-J-J,,k.L.L!!;#@#@""K$B$B--{/L/L..0N0N55{7T7T668V8V 	 d#-& - $-8 d#
76 
7 $
7 d#8 8 $8 d#
.6 
. $
. d#0& 0 $0$ d#	' 	' $	' d#	0 	 $	 d#3 3 $32 d#O O $O. d#Lf L $L, d#3 3 $3 d#M
 M $M d#	Z 	 $	 d#f  $ $TYY $ d#%;= %; $%;P d#3M 3 $3  d#/= / $/ d#G} G $G d#7 7 $7 d#>m > $>0m 0 d#!] ! $!H d##9M #9 $#9L d#  $. d#9 9 $9H d#'9 '9 $'9T d#%K %K $%KP d#
P 
P $
P d#:M : $: d#+ + $+  d# m   $  d# ]   $  d#O. O $O
 d#W)D W $W
 d#C C $C
 d#" " $" d#"6 " $"0 d#"V " $"  d#
> 
> $
> d#(] ( $( d#( ( $( d#(= ( $( d#%V % $% d#*& * $* ?D & QT  >C X X6& 6T 66 hsm F 6 6  6   6   f      V   V  r,   