
    3j                     x   S r SSKrSSKrSSKrSSKJr  SSKJr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JrJr  \(       a  SS
KJr  \R4                  \R6                  \R8                  \R:                  \R6                  \R6                  \R:                  \R:                  \R<                  \R<                  \R>                  \R>                  \R@                  \R@                  \RB                  \RB                  \RD                  \RD                  \RF                  \RF                  0
r$\R4                  \R<                  \R8                  \R>                  \R<                  \R<                  \R>                  \R>                  \R6                  \R<                  \R:                  \R>                  \R@                  \R@                  \RB                  \RB                  \RD                  \RD                  \RF                  \RF                  0
r%\R4                  \R@                  \R8                  \RB                  \R<                  \R@                  \R>                  \RB                  \R6                  \R@                  \R:                  \RB                  \R@                  \R@                  \RB                  \RB                  \RD                  \RD                  \RF                  \RF                  0
r&\R4                  \RD                  \R8                  \RF                  \R6                  \RD                  \R:                  \RF                  \RD                  \RD                  \RF                  \RF                  \R<                  \RD                  \R>                  \RF                  \R@                  \RD                  \RB                  \RF                  0
r'S\S\(4S jr)S\S-  S\*4S jr+SS\S\(S\*4S jjr,\" SS9 " S S\5      5       r-\" SS9 " S S\5      5       r.\" SS9 " S S\5      5       r/\" SS9 " S S\5      5       r0\" SS9 " S S\5      5       r1\" SS9 " S S \5      5       r2\" SS9 " S! S"\5      5       r3\" SS9 " S# S$\35      5       r4\" SS9 " S% S&\5      5       r5\" SS9 " S' S(\55      5       r6\" SS9 " S) S*\5      5       r7\" SS9 " S+ S,\5      5       r8\" SS9 " S- S.\5      5       r9\" SS9 " S/ S0\5      5       r:\" SS9 " S1 S2\5      5       r;\" SS9 " S3 S4\5      5       r<\" SS9 " S5 S6\5      5       r=\" SS9 " S7 S8\55      5       r>\" SS9 " S9 S:\55      5       r?\" SS9 " S; S<\5      5       r@\" SS9 " S= S>\5      5       rA " S? S@\R                  5      rC\" SS9 " SA SB\5      5       rD\" SS9 " SC SD\5      5       rE\" SS9 " SE SF\5      5       rF\" SS9 " SG SH\5      5       rG\" SS9 " SI SJ\5      5       rH\" SS9 " SK SL\5      5       rI\" SS9 " SM SN\5      5       rJ " SO SP\5      rK\" SS9 " SQ SR\5      5       rL\" SS9 " SS ST\5      5       rM\" SS9 " SU SV\5      5       rN\" SS9 " SW SX\5      5       rO\" SS9 " SY SZ\5      5       rP\" SS9 " S[ S\\5      5       rQ\" SS9 " S] S^\M5      5       rR\" SS9 " S_ S`\M5      5       rS\" SS9 " Sa Sb\5      5       rT\" SS9 " Sc Sd\5      5       rU\" SS9 " Se Sf\5      5       rV\" SS9 " Sg Sh\5      5       rW\" SS9 " Si Sj\5      5       rX\" SS9 " Sk Sl\X5      5       rY\" SS9 " Sm Sn\Y5      5       rZ\" SS9 " So Sp\X5      5       r[\" SS9 " Sq Sr\5      5       r\\" SS9 " Ss St\5      5       r]\" SS9 " Su Sv\5      5       r^\" SS9 " Sw Sx\5      5       r_\" SS9 " Sy Sz\5      5       r`\" SS9 " S{ S|\5      5       ra\" SS9 " S} S~\5      5       rb\" SS9 " S S\5      5       rc\" SS9 " S S\5      5       rd\" SS9 " S S\5      5       re\" SS9 " S S\5      5       rf\R                  SS.S\S\(S\*S-  4S jj5       rh\R                  SS.S\S\(S\(4S jj5       ri\R                  S\S\(4S j5       rj\R                  S\S-  S\*S-  4S j5       rk\R                  S\S\(4S j5       rl\R                  S\S\(4S j5       rm\R                  S\S\S\(4S j5       rn\R                  S\S\(4S j5       ro\R                  S\S\(4S j5       rp\R                  S\S\(4S j5       rq\R                  S\S\(4S j5       rr\R                  S\S\(4S j5       rs\R                  S\S\(4S j5       rt\R                  S\S\(4S j5       rug)a  
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)Callable)AnyTYPE_CHECKING)device)ChainedSourcedataclass_with_cached_hashGuardGuardSourceSource   )utils)create_binary_subscrcreate_build_tuplecreate_call_function)	PyCodegensourcereturnc                     [        U [        5      (       a  g U R                  [        R                  :X  a  g g! [
         a     gf = fNTF)
isinstanceConstantSourceguard_sourcer
   CONSTANTNotImplementedErrorr   s    N/home/wildlama/miniconda3/lib/python3.13/site-packages/torch/_dynamo/source.pyis_constant_sourcer   m   sO    &.))+"6"66 7
   s   9 
AAc                 D    U c  g U R                   $ ! [         a     gf = f)Nz<unknown source>)namer   r   s    r   _get_source_debug_namer    y   s+    ~!	&;;" 	&%	&s    
Fs
apply_reprc                     U(       a  [        U 5      n O[        U 5      n U R                  SS5      R                  SS5      $ )a	  
Escapes curly brackets for format strings.
e.g. "frozenset({0})" becomes "frozenset({{0}})".
This is used by _name_template for example, because it's
expected to return a format string, but we may wish to include
strings that should not be accidentally formatted.
{z{{}z}})reprstrreplace)r!   r"   s     r   _esc_strr)      s7     GF99S$''T22    T)frozenc                       \ rS rSr% \\S'   Sr\\S'   Sr\	\   S-  \S'   Sr
\\S'   SS	 jr\S\4S
 j5       r\R                   S\4S j5       rSrg)LocalSource   
local_nameFis_inputNdynamismis_derefed_cell_contentsr   c                     U R                   (       a  UR                  U R                  5        g UR                  UR	                  U R                  5      5        g N)r2   
load_derefr/   append_outputcreate_loadselfcodegens     r   reconstructLocalSource.reconstruct   s:    ((t/!!'"5"5doo"FGr*   c                 "    [         R                  $ r4   )r
   LOCALr9   s    r   r   LocalSource.guard_source   s       r*   c                 2    S[        U R                  SS9 S3$ )NzL[Tr"   ]r)   r/   r?   s    r   _name_templateLocalSource._name_template   s    HT__>?qAAr*    r:   r   r   N)__name__
__module____qualname____firstlineno__r'   __annotations__r0   boolr1   	frozensetr2   r;   propertyr
   r   	functoolscached_propertyrE   __static_attributes__rG   r*   r   r-   r-      sz    O Hd '+Hint#*
 &+d*H !k ! ! B B Br*   r-   c                   Z    \ rS rSr% \\S'   S	S jr\S\4S j5       r	\S\4S j5       r
Srg)
TempLocalSource   r/   r   Nc                 X    UR                  UR                  U R                  5      5        g r4   r6   r7   r/   r8   s     r   r;   TempLocalSource.reconstruct       g11$//BCr*   c                 "    [         R                  $ r4   )r
   
TEMP_LOCALr?   s    r   r   TempLocalSource.guard_source   s    %%%r*   c                     [        S5      e)NzhCannot create guard on TempLocalSource - this is an internal Dynamo bug. Please file an issue on GitHub.r   r?   s    r   rE   TempLocalSource._name_template   s    !v
 	
r*   rG   rH   )rI   rJ   rK   rL   r'   rM   r;   rP   r
   r   rE   rS   rG   r*   r   rU   rU      sE     OD &k & & 
 
 
r*   rU   c                   n    \ rS rSr% \\S'   S	S jr\S\4S j5       r	\
R                  S\4S j5       rSrg)
SyntheticLocalSource   r/   r   Nc                 X    UR                  UR                  U R                  5      5        g r4   rX   r8   s     r   r;    SyntheticLocalSource.reconstruct   rZ   r*   c                 "    [         R                  $ r4   )r
   SYNTHETIC_LOCALr?   s    r   r   !SyntheticLocalSource.guard_source   s    ***r*   c                 2    S[        U R                  SS9 S3$ )NzSYNTHETIC_LOCAL[TrB   rC   rD   r?   s    r   rE   #SyntheticLocalSource._name_template   s    !(4??t"L!MQOOr*   rG   rH   rI   rJ   rK   rL   r'   rM   r;   rP   r
   r   rQ   rR   rE   rS   rG   r*   r   rb   rb      sL    OD +k + + P P Pr*   rb   c                   n    \ rS rSr% \\S'   \S\4S j5       rS	S jr	\
R                  S\4S j5       rSrg)
RandomValueSource   random_call_indexr   c                 "    [         R                  $ r4   )r
   RANDOM_VALUEr?   s    r   r   RandomValueSource.guard_source   s    '''r*   Nc                    UR                  UR                  UR                  R                  R                  5      5        UR                  UR                  U R                  5      5        UR                  [        5       5        g r4   )r6   r7   txoutputrandom_values_varcreate_load_constro   r   r8   s     r   r;   RandomValueSource.reconstruct   s\    g11'**2C2C2U2UVWg778N8NOP245r*   c                 2    S[        U R                  5       3$ )Nrandom_value_)r)   ro   r?   s    r   rE    RandomValueSource._name_template   s    x(>(>?@AAr*   rG   rH   )rI   rJ   rK   rL   intrM   rP   r
   r   r;   rQ   rR   r'   rE   rS   rG   r*   r   rm   rm      sJ    (k ( (6
 B B Br*   rm   c                   n    \ rS rSr% \\S'   S	S jr\S\4S j5       r	\
R                  S\4S j5       rSrg)
GlobalSource   global_namer   Nc                 V    UR                  UR                  U R                  SS95        g NTaddr6   create_load_globalr   r8   s     r   r;   GlobalSource.reconstruct   s&    g889I9It8TUr*   c                 "    [         R                  $ r4   r
   GLOBALr?   s    r   r   GlobalSource.guard_source       !!!r*   c                 2    S[        U R                  SS9 S3$ )NG[TrB   rC   r)   r   r?   s    r   rE   GlobalSource._name_template   s    HT--$?@BBr*   rG   rH   rk   rG   r*   r   r~   r~      sM    V "k " " C C Cr*   r~   c                   n    \ rS rSr% \\S'   S	S jr\S\4S j5       r	\
R                  S\4S j5       rSrg)
GlobalWeakRefSource   r   r   Nc                 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      $ r   r   r:   r9   s   r   <lambda>1GlobalWeakRefSource.reconstruct.<locals>.<lambda>   s)    G))**4+;+;*Fr*   r   Fadd_push_nullextend_outputr   r8   s   ``r   r;   GlobalWeakRefSource.reconstruct   s.    	

 	21e<=r*   c                 "    [         R                  $ r4   r   r?   s    r   r    GlobalWeakRefSource.guard_source  r   r*   c                 2    S[        U R                  SS9 S3$ )Nr   TrB   z]()r   r?   s    r   rE   "GlobalWeakRefSource._name_template  s    HT--$?@DDr*   rG   rH   rk   rG   r*   r   r   r      sL    > "k " " E E Er*   r   c                   6    \ rS rSrSS jr\S\4S j5       rSrg)WeakRefCallSourcei  r   Nc                 j   ^ ^ TR                  UU 4S j5        TR                  [        SS5      5        g )Nc                  (   > T " TR                   5      $ r4   baser   s   r   r   /WeakRefCallSource.reconstruct.<locals>.<lambda>  s    gdii&8r*   r   Fr   r8   s   ``r   r;   WeakRefCallSource.reconstruct  s(    8921e<=r*   c                     g)Nz{0}()rG   r?   s    r   rE    WeakRefCallSource._name_template  s    r*   rG   rH   	rI   rJ   rK   rL   r;   rP   r'   rE   rS   rG   r*   r   r   r     s"    >   r*   r   c                       \ rS rSrSrg)CallFunctionNoArgsSourcei  rG   NrI   rJ   rK   rL   rS   rG   r*   r   r   r         r*   r   c                   `    \ rS rSr% \\S'   S	S jrS
S jr\R                  S\4S j5       r
Srg)
AttrSourcei  memberr   Nc                     U R                   (       d   S5       eSU R                  ;  d   SU R                  < S35       eg )Nz9Can't construct an AttrSource without a valid base source.z,AttrSource member must not contain '.', got =. Use OutputGraph.get_chained_attr_source() for dotted paths.r   r   r?   s    r   __post_init__AttrSource.__post_init__  sE    yyUUUy$++% 	
:4;;/ JJ J	
%r*   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g r4   r   r   create_load_attrsr   r8   s     r   r;   AttrSource.reconstruct&  +    		g77DEr*   c                     U R                   R                  5       (       d  S[        U R                   SS9 S3$ S[        U R                   5       3$ )Nzgetattr({0}, TrB   ){0}.)r   isidentifierr)   r?   s    r   rE   AttrSource._name_template*  sG    {{''))$Xdkkd%K$LANN-.//r*   rG   r   NrH   rI   rJ   rK   rL   r'   rM   r   r;   rQ   rR   rE   rS   rG   r*   r   r   r     s3    K
F 0 0 0r*   r   c                   N    \ rS rSr% Sr\R                  " SS9r\\	S'   S	S jr
Srg)
CellContentsSourcei1  z
Source for closure cell contents that also stores the freevar name.
This allows guard failure messages to show which variable the closure cell refers to.
 )defaultfreevar_nameNc                 b    U R                   (       d   S5       eU R                  S:X  d   S5       eg )Nz@Can't construct a CellContentsSource without a valid base sourcecell_contentsz8CellContentsSource should only be used for cell_contentsr   r?   s    r   r    CellContentsSource.__post_init__:  s6    yy 	
N	
y {{o- 	
F	
-r*   rG   r   )rI   rJ   rK   rL   __doc__dataclassesfieldr   r'   rM   r   rS   rG   r*   r   r   r   1  s#    
 $))"5L#5
r*   r   c                   `    \ rS rSr% \\S'   S	S jrS
S jr\R                  S\4S j5       r
Srg)GenericAttrSourceiC  r   r   Nc                     U R                   (       d   S5       eSU R                  ;  d   SU R                  < S35       eg )Nz?Can't construct a GenericAttrSource without a valid base sourcer   z3GenericAttrSource member must not contain '.', got r   r   r?   s    r   r   GenericAttrSource.__post_init__G  sK    yy 	
M	
y $++% 	
A$++ QJ J	
%r*   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g r4   r   r8   s     r   r;   GenericAttrSource.reconstructP  r   r*   c                 2    S[        U R                  SS9 S3$ )Nzobject.__getattribute__({0}, TrB   r   r)   r   r?   s    r   rE    GenericAttrSource._name_templateT  s"     .ht{{t.T-UUVW	
r*   rG   r   rH   r   rG   r*   r   r   r   C  s3    K
F 
 
 
r*   r   c                   6    \ rS rSrSS jr\S\4S j5       rSrg)TypeDictSourcei\  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N__dict__r   r   r   r8   s     r   r;   TypeDictSource.reconstruct^  '    		g77
CDr*   c                     g)Nzdict({0}.__dict__)rG   r?   s    r   rE   TypeDictSource._name_templateb  s     $r*   rG   rH   r   rG   r*   r   r   r   \  s#    E $ $ $r*   r   c                   6    \ rS rSrSS jr\S\4S j5       rSrg)TypeMROSourceil  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N__mro__r   r8   s     r   r;   TypeMROSource.reconstructn  '    		g77	BCr*   c                     g)Nz{0}.__mro__rG   r?   s    r   rE   TypeMROSource._name_templater  s    r*   rG   rH   r   rG   r*   r   r   r   l  s#    D   r*   r   c                   .    \ rS rSr% Sr\\S'   SS jrSrg)LocalCellSourceiw  zw
Conceptually, this class is `LocalSource` for cell objects implicitly
generated by Python (e.g., captured variables).
r/   Nc                 X    UR                  UR                  U R                  5      5        g r4   )r6   create_load_closurer/   r8   s     r   r;   LocalCellSource.reconstruct  s!     	g99$//JKr*   rG   rH   )	rI   rJ   rK   rL   r   r'   rM   r;   rS   rG   r*   r   r   r   w  s    
 OLr*   r   c                   6    \ rS rSrSS jr\S\4S j5       rSrg)
CodeSourcei  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N__code__r   r8   s     r   r;   CodeSource.reconstruct  r   r*   c                     g)Nz{0}.__code__rG   r?   s    r   rE   CodeSource._name_template  s    r*   rG   rH   r   rG   r*   r   r   r     s#    E   r*   r   c                   6    \ rS rSrSS jr\S\4S j5       rSrg)ClosureSourcei  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N__closure__r   r8   s     r   r;   ClosureSource.reconstruct  s'    		g77FGr*   c                     g)Nz{0}.__closure__rG   r?   s    r   rE   ClosureSource._name_template  s     r*   rG   rH   r   rG   r*   r   r   r     s#    H ! ! !r*   r   c                   Z    \ rS rSr% Sr\\S'   S	S jr\R                  S\4S j5       r
Srg)

GradSourcei  gradr   r   Nc                 |    U" U R                   5        UR                  UR                  U R                  5      5        g r4   r   r8   s     r   r;   GradSource.reconstruct  r   r*   c                 2    S[        U R                  5       3$ )Nr   r   r?   s    r   rE   GradSource._name_template  s    -.//r*   rG   rH   )rI   rJ   rK   rL   r   r'   rM   r;   rQ   rR   rE   rS   rG   r*   r   r   r     s3    FCF 0 0 0r*   r   c                   @    \ rS rSr\R
                  S\4S j5       rSrg)ParamBufferSourcei  r   c                 <    [         U R                  R                     $ r4   #_GUARD_SOURCE_SPECIALIZED_NN_MODULEr   r   r?   s    r   r   ParamBufferSource.guard_source      24993I3IJJr*   rG   N	rI   rJ   rK   rL   rQ   rR   r
   r   rS   rG   r*   r   r  r    s$    Kk K Kr*   r  c                       \ rS rSrSrg)UnspecializedParamBufferSourcei  rG   Nr   rG   r*   r   r  r    r   r*   r  c                       \ rS rSr% Sr\S-  \S'   \S\4S j5       r	\
R                  S\4S j5       rS\S\4   S\4S	 jrS\4S
 jrSrg)EphemeralSourcei  Ndescr   c                 "    [         R                  $ r4   )r
   	EPHEMERALr?   s    r   r   EphemeralSource.guard_source      $$$r*   c                 \    U R                   b  SU R                   -   OSnS[        U5       S3$ )Nz: r   z
<ephemeral>)r  r)   )r9   r  s     r   rE   EphemeralSource._name_template  s/    #'99#8tdiibHTN+1--r*   fn.c                     [         er4   r_   r9   r  s     r   
make_guardEphemeralSource.make_guard      !!r*   c                     gNTrG   r?   s    r   is_ephemeralEphemeralSource.is_ephemeral      r*   rG   )rI   rJ   rK   rL   r  r'   rM   rP   r
   r   rQ   rR   rE   r   r   r	   r  rN   r   rS   rG   r*   r   r  r    sr    D#*%k % % . . ."Xc3h/ "E "d r*   r  c                   6    \ rS rSrSS jr\S\4S j5       rSrg)SkipGuardSourcei  r   Nc                 :    U R                   R                  U5        g r4   )r   r;   r8   s     r   r;   SkipGuardSource.reconstruct  s    		g&r*   c                     gNz{0}rG   r?   s    r   rE   SkipGuardSource._name_template      r*   rG   rH   r   rG   r*   r   r$  r$    s"    '   r*   r$  c                   .    \ rS rSrSrSrSrS\4S jrSr	g)	TensorPropertyi  r   r      r   c                     U [         R                  L a  gU [         R                  L a  gU [         R                  L a  g[	        S[        U 5       35      e)Nsizestridestorage_offset
unhandled )r,  SIZESTRIDESTORAGE_OFFSETAssertionErrorr)   r?   s    r   method_nameTensorProperty.method_name  sL    >&&&^***^222# :htn-=!>??r*   rG   N)
rI   rJ   rK   rL   r3  r4  r5  r'   r7  rS   rG   r*   r   r,  r,    s    DFN@S @r*   r,  c                   t    \ rS rSr% \\S'   Sr\S-  \S'   S
S jrSS jr	\
R                  S\4S j5       rS	rg)TensorPropertySourcei  propNidxr   c                     U R                   c   eU R                  [        R                  L a  U R                  b   eg U R                  c   eg r4   )r   r;  r,  r5  r<  r?   s    r   r   "TensorPropertySource.__post_init__  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                     > T R                  [        R                  S[        TR                  R                  5       5       35      $ )Ncall_)load_import_fromr   rI   r)   r;  r7  r   s   r   r   2TensorPropertySource.reconstruct.<locals>.<lambda>  s3    G,,%1F1F1H(I'J Kr*   r-  r   F)r   r   r<  r6   rw   r   r   r8   s   ``r   r;    TensorPropertySource.reconstruct  sn    	

 			88!!'";";DHH"EF dhh&:5I	
r*   c                 v   U R                   [        R                  L a  S[        U R                  5       S3$ U R                   [        R
                  L a  S[        U R                  5       S3$ U R                   [        R                  L a  U R                  b   eg[        S[        U R                   5       35      e)Nz{0}.size()[rC   z{0}.stride()[z{0}.storage_offset()r2  )r;  r,  r3  r)   r<  r4  r5  r6  r?   s    r   rE   #TensorPropertySource._name_template  s    99+++"8DHH#5"6a88YY.///$Xdhh%7$8::YY.77788###) :htyy.A-B!CDDr*   rG   r   rH   )rI   rJ   rK   rL   r,  rM   r<  r|   r   r;   rQ   rR   r'   rE   rS   rG   r*   r   r:  r:    sD    
Ct(
 	E 	E 	Er*   r:  c                   `    \ rS rSr% \\S'   S	S jrS
S jr\R                  S\
4S j5       rSrg)IndexedSourcei  r<  r   Nc                 "    U R                   c   eg r4   r   r?   s    r   r   IndexedSource.__post_init__"      yy$$$r*   c                     [         er4   r_   r8   s     r   r;   IndexedSource.reconstruct%  r  r*   c                 4    S[        U R                  5       S3$ )N(z, {0}))r)   r<  r?   s    r   rE   IndexedSource._name_template(  s    8DHH%&h//r*   rG   r   rH   )rI   rJ   rK   rL   r|   rM   r   r;   rQ   rR   r'   rE   rS   rG   r*   r   rH  rH    s2    	H%" 0 0 0r*   rH  c                   @    \ rS rSrSS jrS	S jr\S\4S j5       rSr	g)
NegateSourcei-  r   Nc                 "    U R                   c   eg r4   r   r?   s    r   r   NegateSource.__post_init__/  rK  r*   c                     [         er4   r_   r8   s     r   r;   NegateSource.reconstruct2  r  r*   c                     g)Nz{0}.__neg__()rG   r?   s    r   rE   NegateSource._name_template5  s     r*   rG   r   rH   
rI   rJ   rK   rL   r   r;   rP   r'   rE   rS   rG   r*   r   rR  rR  -  s'    %"   r*   rR  c                   @    \ rS rSrSS jrS	S jr\S\4S j5       rSr	g)
ConvertIntSourcei;  r   Nc                 "    U R                   c   eg r4   r   r?   s    r   r   ConvertIntSource.__post_init__=  rK  r*   c                 (    U" U R                   5        g r4   r   r8   s     r   r;   ConvertIntSource.reconstruct@      		r*   c                     g)Nz%cast_symbool_to_symint_guardless({0})rG   r?   s    r   rE   ConvertIntSource._name_templateC  s    6r*   rG   r   rH   rY  rG   r*   r   r[  r[  ;  s'    % 7 7 7r*   r[  c                   L    \ rS rSr% \\S'   S	S jrS
S jr\S\	4S j5       r
Srg)DynamicScalarSourceiH  is_intr   Nc                 "    U R                   c   eg r4   r   r?   s    r   r   !DynamicScalarSource.__post_init__L  rK  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builtinsr|   rB  r:   s   r   r   1DynamicScalarSource.reconstruct.<locals>.<lambda>T  s    g&>&>z5&Qr*   r   Fr   r   r   r   r8   s    `r   r;   DynamicScalarSource.reconstructO  s6    
 	QR		21e<=r*   c                     g)Nzint({0})rG   r?   s    r   rE   "DynamicScalarSource._name_templateX  s    r*   rG   r   rH   )rI   rJ   rK   rL   rN   rM   r   r;   rP   r'   rE   rS   rG   r*   r   rd  rd  H  s,    L%>   r*   rd  c                   @    \ rS rSrSS jrS	S jr\S\4S j5       rSr	g)
FlattenScriptObjectSourcei]  r   Nc                 "    U R                   c   eg r4   r   r?   s    r   r   'FlattenScriptObjectSource.__post_init___  rK  r*   c                 (    U" U R                   5        g r4   r   r8   s     r   r;   %FlattenScriptObjectSource.reconstructb  r`  r*   c                     g)Nz{0}.__obj_flatten__()rG   r?   s    r   rE   (FlattenScriptObjectSource._name_templatee  s    &r*   rG   r   rH   rY  rG   r*   r   rs  rs  ]  s'    % ' ' 'r*   rs  c                   @    \ rS rSrSS jrS	S jr\S\4S j5       rSr	g)
ScriptObjectQualifiedNameSourceij  r   Nc                 "    U R                   c   eg r4   r   r?   s    r   r   -ScriptObjectQualifiedNameSource.__post_init__l  rK  r*   c                 (    U" U R                   5        g r4   r   r8   s     r   r;   +ScriptObjectQualifiedNameSource.reconstructo  r`  r*   c                     g)Nz{0}._type().qualified_name()rG   r?   s    r   rE   .ScriptObjectQualifiedNameSource._name_templater  s    -r*   rG   r   rH   rY  rG   r*   r   r{  r{  j  s'    % . . .r*   r{  c                   6    \ rS rSrSS jr\S\4S j5       rSrg)AttrProxySourceiw  r   Nc                 (    U" U R                   5        g r4   r   r8   s     r   r;   AttrProxySource.reconstructx  r`  r*   c                     g)Nz{0}.get_base()rG   r?   s    r   rE   AttrProxySource._name_template{  s    r*   rG   rH   r   rG   r*   r   r  r  w  s"          r*   r  c                       \ rS rSr% \\-  \S'   Sr\\S'   \	R                  " SSSS9r
\\S'   \	R                  " SSSS9r\\S'   SS
 jrSS jr\R                  S\4S j5       rSrg	)DefaultsSourcei  idx_keyFis_kw)initr&   comparer   _namer   Nc           
      H   U R                   (       d   S5       eU R                  (       a}  [        U R                  [        5      (       d   e[
        R                  U SS5        [
        R                  U SS[        U R                  5       S[        U R                  5       S35        g [        U R                  [        5      (       d   e[
        R                  U SS5        [
        R                  U SS[        U R                  5       S	[        U R                  5       S
35        g )Nz]Base must be a valid source in order to properly track and guard this Defaults to its origin.r   __kwdefaults__r  r   z['z']__defaults__[rC   )
r   r  r   r  r'   object__setattr__r)   r   r|   r?   s    r   r   DefaultsSource.__post_init__  s    yy 	
k	
y ::dllC0000tW.>?$**-.b$,,1G0HK dllC0000tWn=g(<'=Qx?U>VVWXr*   c                    U" U R                   5        UR                  UR                  U R                  5      5        UR	                  UR                  U R                  5      5        UR	                  [        5       5        g r4   )r   r   r   r   r6   rw   r  r   r8   s     r   r;   DefaultsSource.reconstruct  sZ    		g77

CDg77EF245r*   c                     U R                   $ r4   )r  r?   s    r   rE   DefaultsSource._name_template  s    zzr*   rG   r   rH   )rI   rJ   rK   rL   r|   r'   rM   r  rN   r   r   r  r   r;   rQ   rR   rE   rS   rG   r*   r   r  r    ss    3YE4""E5IE3I""E5IE3I&6   r*   r  c                      ^  \ rS rSr% \\S'   Sr\\S'   SU 4S jjrSS jr	S\
4S jr\R                  S\4S	 j5       rS
rU =r$ )GetItemSourcei  indexFindex_is_slicer   c                    > U R                   c   e[        U R                  [        5      (       a9  [        TU ]  SU R                  R                  5       5        [        TU ]  SS5        g g )Nr  r  T)r   r   r  slicesuperr  
__reduce__)r9   	__class__s    r   r   GetItemSource.__post_init__  sU    yy$$$djj%((G)>)>)@AG 0$7 )r*   c                 .   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                  [        5       5        g r4   )r   r  r6   rw   unpack_slicer  r   r8   s     r   r;   GetItemSource.reconstruct  sh    		!!'";";D<M<M<O"PQ!!'";";DJJ"GH245r*   c                 N    U R                   (       d   eU R                  u  pU" U6 $ r4   )r  r  )r9   slice_class
slice_argss      r   r  GetItemSource.unpack_slice  s(    """""&**J''r*   c                     [        U R                  [        5      (       a   eU R                  (       a  S[	        U R                  5       SS9 S3$ S[	        U R                  SS9 S3$ )N{0}[TrB   rC   )r   r  r   r  r)   r  r?   s    r   rE   GetItemSource._name_template  s_    
 djj&1111HT%6%6%8TJK1MMHTZZDAB!DDr*   rG   r   rH   )rI   rJ   rK   rL   r   rM   r  rN   r   r;   r  r  rQ   rR   r'   rE   rS   __classcell__)r  s   @r   r  r    sL    J ND 86(e (
 E E Er*   r  c                   d    \ rS rSr% \\S'   S	S jr\R                  S\	4S j5       r
S\4S jrSrg)
ConstDictKeySourcei  r  r   Nc                    ^ 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rB  r   rI   rl  s   r   r   0ConstDictKeySource.reconstruct.<locals>.<lambda>  s    G,,U^^=PQr*   r-  Fr   r   r6   rw   r  r   r   r8   s    `r   r;   ConstDictKeySource.reconstruct  sU    Q	
 			g77

CD21e<=r*   c                 2    S[        U R                  SS9 S3$ )Nzlist(dict.keys({0}))[TrB   rC   r)   r  r?   s    r   rE   !ConstDictKeySource._name_template  s     )$**)N(OqQQr*   c                     gr  rG   r?   s    r   is_dict_keyConstDictKeySource.is_dict_key  r"  r*   rG   rH   )rI   rJ   rK   rL   r   rM   r;   rQ   rR   r'   rE   rN   r  rS   rG   r*   r   r  r    s<    J> R R RT r*   r  c                   n    \ rS rSr% \\S'   S
S jrSS jr\R                  S\
4S j5       rS\4S jrS	rg)NonSerializableSetGetItemSourcei  r  r   Nc                 T    SSK Jn  UR                  U R                  5      (       d   eg Nr   )ConstantVariable)	variablesr  
is_literalr  r9   r  s     r   r   -NonSerializableSetGetItemSource.__post_init__  s     /**4::6666r*   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set_getitemr  rl  s   r   r   =NonSerializableSetGetItemSource.reconstruct.<locals>.<lambda>  s    G,,U^^]Kr*   r-  Fr  r8   s    `r   r;   +NonSerializableSetGetItemSource.reconstruct  sU    K	
 			g77

CD21e<=r*   c                 2    S[        U R                  SS9 S3$ )Nz
list({0})[TrB   rC   r  r?   s    r   rE   .NonSerializableSetGetItemSource._name_template  s     htzzdCDAFFr*   c                     g)NFrG   r?   s    r   r  +NonSerializableSetGetItemSource.is_dict_key  s    r*   rG   r   rH   )rI   rJ   rK   rL   r|   rM   r   r;   rQ   rR   r'   rE   rN   r  rS   rG   r*   r   r  r    sA    J7
> G G GT r*   r  c                   `    \ rS rSr% \\S'   S	S jrS
S jr\R                  S\
4S j5       rSrg)DictGetItemSourcei  r  r   Nc                     SSK Jn  [        U R                  [        5      (       d#  UR                  U R                  5      (       d   eg g r  r  r  r   r  r  r  r  s     r   r   DictGetItemSource.__post_init__  C    /JJ*
 
((44	5 54
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	                  [        5       5        g r4   )r   r   r  r   r6   rw   r   r8   s     r   r;   DictGetItemSource.reconstruct  s\    		 djj&))DJJ!!'";";DJJ"GH245r*   c                     [        U R                  [        5      (       a#  S[        U R                  R                  5       S3$ S[        U R                  SS9 S3$ )Nr  rC   TrB   r   r  r  r)   r   r?   s    r   rE    DictGetItemSource._name_template  sL    djj"455HTZZ__56a88HTZZDAB!DDr*   rG   r   rH   rI   rJ   rK   rL   r   rM   r   r;   rQ   rR   r'   rE   rS   rG   r*   r   r  r    s7    
 J5	6 E E Er*   r  c                   `    \ rS rSr% \\S'   S	S jrS
S jr\R                  S\
4S j5       rSrg)DictSubclassGetItemSourcei  r  r   Nc                     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                 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  rl  s   r   r   7DictSubclassGetItemSource.reconstruct.<locals>.<lambda>0      G,,U^^^Lr*   r-  F)	r   r   r   r  r   r6   rw   r   r   r8   s    `r   r;   %DictSubclassGetItemSource.reconstruct+  sv     	L	

 			 djj&))DJJ!!'";";DJJ"GH21e<=r*   c                     [        U R                  [        5      (       a#  S[        U R                  R                  5       S3$ S[        U R                  SS9 S3$ )Nzdict.__getitem__({0}, r   r  TrB   rC   r  r?   s    r   rE   (DictSubclassGetItemSource._name_template>  sL    djj"455-htzz.G-HJJHTZZDAB!DDr*   rG   r   rH   r  rG   r*   r   r  r    s7    
 J5>& E E Er*   r  c                   N    \ rS rSrSrSS jr\R                  S\4S j5       r	Sr
g)	ListGetItemSourceiF  zQ
Same as GetItemSource with reconstruct and name overridden to be list specific.
r   Nc                   ^ 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  rl  s   r   r   /ListGetItemSource.reconstruct.<locals>.<lambda>R  r  r*   >List[slice] is a temporary object and should not have a sourcer-  F)	r   r   r  RuntimeErrorr6   rw   r  r   r   r8   s    `r   r;   ListGetItemSource.reconstructL  st    
 	L	

 			 P  !!'";";DJJ"GH21e<=r*   c                     [        U R                  [        5      (       a   eU R                  (       a  [	        S5      eS[        U R                  SS9 S3$ )Nr  zlist.__getitem__({0}, TrB   r   )r   r  r   r  r  r)   r?   s    r   rE    ListGetItemSource._name_templateb  sR    
 djj&1111P  .htzzd.S-TTUVVr*   rG   rH   )rI   rJ   rK   rL   r   r;   rQ   rR   r'   rE   rS   rG   r*   r   r  r  F  s0    >, 
W 
W 
Wr*   r  c                   J    \ rS rSrSS jr\R                  S\4S j5       rSr	g)TupleIteratorGetItemSourceip  r   Nc                    ^ 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  rl  s   r   r   8TupleIteratorGetItemSource.reconstruct.<locals>.<lambda>t  s    G,,U^^=UVr*   r-  Fr  r8   s    `r   r;   &TupleIteratorGetItemSource.reconstructr  sU    V	
 			g77

CD21e<=r*   c                 2    S[        U R                  SS9 S3$ )Nz___tuple_iterator_getitem({0}, TrB   r   r  r?   s    r   rE   )TupleIteratorGetItemSource._name_templatez  s#     0PT0U/VVWX	
r*   rG   rH   )
rI   rJ   rK   rL   r;   rQ   rR   r'   rE   rS   rG   r*   r   r  r  p  s(    > 
 
 
r*   r  c                   6    \ rS rSrSS jr\S\4S j5       rSrg)NamedTupleFieldsSourcei  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N_fieldsr   r8   s     r   r;   "NamedTupleFieldsSource.reconstruct  r   r*   c                     g)Nz___namedtuple_fields({0})rG   r?   s    r   rE   %NamedTupleFieldsSource._name_template  s    *r*   rG   rH   r   rG   r*   r   r  r    s#    D + + +r*   r  c                   6    \ rS rSrSS jr\S\4S j5       rSrg)DataclassFieldsSourcei  r   Nc                    ^ 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  rl  s   r   r   3DataclassFieldsSource.reconstruct.<locals>.<lambda>  s    G,,U^^=OPr*   r   Frn  r8   s    `r   r;   !DataclassFieldsSource.reconstruct  s8    P	
 			21e<=r*   c                     g)Nz___dataclass_fields({0})rG   r?   s    r   rE   $DataclassFieldsSource._name_template  s    )r*   rG   rH   r   rG   r*   r   r  r    s"    > * * *r*   r  c                   @    \ rS rSrSS jrS	S jr\S\4S j5       rSr	g)

TypeSourcei  r   Nc                 "    U R                   c   eg r4   r   r?   s    r   r   TypeSource.__post_init__  rK  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      $ )Nrj  typerk  rl  s   r   r   (TypeSource.reconstruct.<locals>.<lambda>  s    g&>&>z6&Rr*   r   Frn  r8   s    `r   r;   TypeSource.reconstruct  s4    RS		21e<=r*   c                     g)Nz	type({0})rG   r?   s    r   rE   TypeSource._name_template  s    r*   rG   r   rH   rY  rG   r*   r   r  r    s'    %>
   r*   r  c                   6    \ rS rSrSS jr\S\4S j5       rSrg)OptimizerSourcei  r   Nc                 (    U" U R                   5        g r4   r   r8   s     r   r;   OptimizerSource.reconstruct  r`  r*   c                     gr(  rG   r?   s    r   rE   OptimizerSource._name_template  r*  r*   rG   rH   r   rG   r*   r   r  r    s"       r*   r  c                   b    \ rS rSrSS jr\R                  S\4S j5       r\	S\
4S j5       rSrg)	NNModuleSourcei  r   Nc                 (    U" U R                   5        g r4   r   r8   s     r   r;   NNModuleSource.reconstruct  r`  r*   c                 <    [         U R                  R                     $ r4   r  r?   s    r   r   NNModuleSource.guard_source  r
  r*   c                     gr(  rG   r?   s    r   rE   NNModuleSource._name_template  r*  r*   rG   rH   )rI   rJ   rK   rL   r;   rQ   rR   r
   r   rP   r'   rE   rS   rG   r*   r   r  r    sF     Kk K K   r*   r  c                   @    \ rS rSr\R
                  S\4S j5       rSrg)UnspecializedNNModuleSourcei  r   c                 <    [         U R                  R                     $ r4   )%_GUARD_SOURCE_UNSPECIALIZED_NN_MODULEr   r   r?   s    r   r   (UnspecializedNNModuleSource.guard_source  s    4TYY5K5KLLr*   rG   Nr  rG   r*   r   r&  r&    s$    Mk M Mr*   r&  c                   @    \ rS rSr\R
                  S\4S j5       rSrg)"UnspecializedBuiltinNNModuleSourcei  r   c                 <    [         U R                  R                     $ r4   )-_GUARD_SOURCE_UNSPECIALIZED_BUILTIN_NN_MODULEr   r   r?   s    r   r   /UnspecializedBuiltinNNModuleSource.guard_source  s    <TYY=S=STTr*   rG   Nr  rG   r*   r   r+  r+    s$    Uk U Ur*   r+  c                   @    \ rS rSr\R
                  S\4S j5       rSrg)FSDPNNModuleSourcei  r   c                 <    [         U R                  R                     $ r4   )_GUARD_SOURCE_FSDP_MODULEr   r   r?   s    r   r   FSDPNNModuleSource.guard_source  s    ()?)?@@r*   rG   Nr  rG   r*   r   r0  r0    s$    Ak A Ar*   r0  c                   D    \ rS rSr\S\4S j5       r\S\4S j5       rSr	g)GlobalStateSourcei  r   c                     gNr   rG   r?   s    r   rE    GlobalStateSource._name_template      r*   c                 "    [         R                  $ r4   r   r?   s    r   r   GlobalStateSource.guard_source  r   r*   rG   N
rI   rJ   rK   rL   rP   r'   rE   r
   r   rS   rG   r*   r   r5  r5    s6       "k " "r*   r5  c                   |    \ rS rSr% Sr\\S'   SS jr\R                  S\4S j5       r
SS jr\S\4S	 j5       rS
rg)ImportSourcei  zPoints to an imported module - used instead of GlobalSource
in case the user has overridden the module name in their local namespacemodule_namer   Nc                 V    SSK JnJn  U" U R                  UR                  5      5        g )Nr   )GuardBuilderinstall_guard)guardsrA  rB  r  ID_MATCH)r9   rA  rB  s      r   r   ImportSource.__post_init__  s    7dool&;&;<=r*   c                 "    SU R                    S3$ )Nz__import__('z'))r?  r?   s    r   rE   ImportSource._name_template  s    d../r22r*   c                     UR                  UR                  S5      [        S5      UR                  U R                  5      /5        g )Nr   )r   rw   r   create_import_namer?  r8   s     r   r;   ImportSource.reconstruct  s?    ))!,"1%**4+;+;<	
r*   c                 "    [         R                  $ r4   r   r?   s    r   r   ImportSource.guard_source  r   r*   rG   r   rH   )rI   rJ   rK   rL   r   r'   rM   r   rQ   rR   rE   r;   rP   r
   r   rS   rG   r*   r   r>  r>    sV    P >
 3 3 3
 "k " "r*   r>  c                   |    \ rS rSr% \\S'   \R                  S\4S j5       r	S\4S jr
S
S jr\S\4S j5       rS	rg)TorchFunctionModeStackSourcei  indr   c                 <    S[        U R                  5       5       S3$ )Nz$___get_torch_function_mode_stack_at(r   )r)   
_get_indexr?   s    r   rE   +TorchFunctionModeStackSource._name_template  s    5ht?P6Q5RRSTTr*   c                 D    SSK Jn  UR                  U R                  5      $ )Nr   )TorchFunctionModeStackVariable)variables.torch_functionrT  get_mode_indexrO  )r9   rT  s     r   rQ  'TorchFunctionModeStackSource._get_index  s    L-<<TXXFFr*   Nc                    ^ 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  rl  s   r   r   :TorchFunctionModeStackSource.reconstruct.<locals>.<lambda>  s    G,, Br*   r   F)r   r   rw   rQ  r   r8   s    `r   r;   (TorchFunctionModeStackSource.reconstruct  sQ    	

 	w889JKLM21e<=r*   c                 "    [         R                  $ r4   r   r?   s    r   r   )TorchFunctionModeStackSource.guard_source  r   r*   rG   rH   )rI   rJ   rK   rL   r|   rM   rQ   rR   r'   rE   rQ  r;   rP   r
   r   rS   rG   r*   r   rN  rN    sW    	HU U UGC G
> "k " "r*   rN  c                       \ rS rSr% \\S'   SS jr\S\4S j5       r	\
R                  S\4S j5       rS\S\4S	 jrS
rg)r   i  source_namer   Nc                 V    UR                  UR                  U R                  SS95        g )NFr   )r6   r   r`  r8   s     r   r;   ConstantSource.reconstruct  s&    g889I9Iu8UVr*   c                 "    [         R                  $ r4   )r
   r   r?   s    r   r   ConstantSource.guard_source!  s    ###r*   c                     U R                   $ r4   )r`  r?   s    r   rE   ConstantSource._name_template%  s    r*   r  c                     [         er4   r_   r  s     r   r  ConstantSource.make_guard)  r  r*   rG   rH   )rI   rJ   rK   rL   r'   rM   r;   rP   r
   r   rQ   rR   rE   r   r  rS   rG   r*   r   r   r     s]    W $k $ $      "S "S "r*   r   c                   6    \ rS rSr\S\4S j5       rSS jrSrg)NumpyTensorSourcei-  r   c                     g)Nz___from_numpy({0})rG   r?   s    r   rE    NumpyTensorSource._name_template/  s    #r*   Nc                    ^ 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_tensorrk  rl  s   r   r   /NumpyTensorSource.reconstruct.<locals>.<lambda>4  s    g&>&>w&Tr*   r   Frn  r8   s    `r   r;   NumpyTensorSource.reconstruct3  s4    TU		21e<=r*   rG   rH   )	rI   rJ   rK   rL   rP   r'   rE   r;   rS   rG   r*   r   rj  rj  -  s     $ $ $>r*   rj  c                   ,    \ rS rSr\S\4S j5       rSrg)SubclassAttrListSourcei9  r   c                     g)Nz{0}.__tensor_flatten__()[0]rG   r?   s    r   rE   %SubclassAttrListSource._name_template;  s    ,r*   rG   NrI   rJ   rK   rL   rP   r'   rE   rS   rG   r*   r   rt  rt  9  s    - - -r*   rt  c                   ,    \ rS rSr\S\4S j5       rSrg)FloatTensorSourceiB  r   c                     g)Nz___as_tensor({0})rG   r?   s    r   rE    FloatTensorSource._name_templateD  s    "r*   rG   Nrw  rG   r*   r   ry  ry  B  s    # # #r*   ry  c                   ,    \ rS rSr\S\4S j5       rSrg)CallMethodItemSourceiI  r   c                     g)Nz
{0}.item()rG   r?   s    r   rE   #CallMethodItemSource._name_templateK  s    r*   rG   Nrw  rG   r*   r   r}  r}  I  s      r*   r}  c                   D    \ rS rSr\S\4S j5       r\S\4S j5       rSr	g)ShapeEnvSourceiS  r   c                     gr7  rG   r?   s    r   rE   ShapeEnvSource._name_templateU  r9  r*   c                 "    [         R                  $ r4   )r
   	SHAPE_ENVr?   s    r   r   ShapeEnvSource.guard_sourceY  r  r*   rG   Nr<  rG   r*   r   r  r  S  s6       %k % %r*   r  c                   n    \ rS rSr% \\S'   \R                  S\4S j5       r	S	S jr
\S\4S j5       rSrg)
CurrentStreamSourcei^  r   r   c                     S[        U R                  R                  5       S[        U R                  R                  5       S3$ )Nz$___get_current_stream(torch.device('z', z)))r)   r   r  r  r?   s    r   rE   "CurrentStreamSource._name_templateb  s=    5ht{{?O?O6P5QQTU]^b^i^i^o^oUpTqqsttr*   Nc                   ^ SnTR                  U4S j5        TR                  U4S j5        TR                  TR                  U R                  R                  5      /5        U R                  R
                  b:  US-  nTR                  TR                  U R                  R
                  5      /5        TR                  [        US5      5        TR                  [        SS5      5        g )Nr   c                  D   > T R                  [        R                  S5      $ )Nget_current_streamr  rl  s   r   r   1CurrentStreamSource.reconstruct.<locals>.<lambda>i  s    G,,U^^=QRr*   c                  (   > T R                  SS5      $ )Nro  r   rk  rl  s   r   r   r  k  s    g&>&>w&Qr*   F)r   r   rw   r   r  r  r   )r9   r:   num_argss    ` r   r;   CurrentStreamSource.reconstructf  s    R	
 	QRw889I9IJKL;;(MH!!7#<#<T[[=N=N#O"PQ28UCD21e<=r*   c                 "    [         R                  $ r4   r   r?   s    r   r    CurrentStreamSource.guard_sources  r   r*   rG   rH   )rI   rJ   rK   rL   device_typerM   rQ   rR   r'   rE   r;   rP   r
   r   rS   rG   r*   r   r  r  ^  sJ    u u u> "k " "r*   r  c                   D    \ rS rSr\S\4S j5       r\S\4S j5       rSr	g)BackwardStateSourceix  r   c                     gr7  rG   r?   s    r   rE   "BackwardStateSource._name_templatez  r9  r*   c                 "    [         R                  $ r4   )r
   BACKWARD_STATEr?   s    r   r    BackwardStateSource.guard_source~  s    )))r*   rG   Nr<  rG   r*   r   r  r  x  s6       *k * *r*   r  only_allow_inputr  c                    [        U [        5      (       a  [        U R                  US9$ [        U [        5      (       d  g U(       a  U R
                  (       d  g U R                  $ Nr  )r   r   get_local_source_namer   r-   r0   r/   r   r  s     r   r  r    sK     &-(($V[[CSTTfk**r*   c                    [        XS9S L$ r  )r  r  s     r   is_from_local_sourcer    s     KSWWWr*   c                     [        U 5      S L$ r4   )get_global_source_namer   s    r   is_from_global_sourcer    s    !&)55r*   c                     [        U [        5      (       a  [        U R                  5      $ [        U [        5      (       d  g U R
                  $ r4   )r   r   r  r   r~   r   r   s    r   r  r    s:    &-((%fkk22fl++r*   c                     [        U [        5      (       a  [        U R                  5      $ [        U [        5      =(       a$    U R
                  =(       a    U R                  (       + $ r4   )r   r   is_from_nonlocal_sourcer   r-   r2   r0   r   s    r   r  r    sJ    &-((&v{{336;' 	 ++	 r*   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   r   r   is_from_closure_sourcer   r   s    r   r  r    s1    &-((&-((%fkk22r*   targetc                 f    X:X  a  g[        U [        5      (       a  [        U R                  U5      $ g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   r  r    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   r  r    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   r  r    s2    &899&-((8EEr*   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   rs  r   $is_from_flatten_script_object_sourcer   r   s    r   r  r    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   r  r    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)NTr  r  F)	r   r  r  r   r   r   r  r   is_from_defaultsr   s    r   r  r    s    &.)) 	6,--v{{J//KK"22 	6=))v{{J//KK.0&-((,,r*   c                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ gr   )r   r$  r   is_from_skip_guard_sourcer   r   s    r   r  r  	  s1    &/**&-(((55r*   )F)vr   r   enumrQ   collections.abcr   typingr   r   ro  r   r  torch._guardsr   r   r	   r
   r   r   r   bytecode_transformationr   r   r   r:   r   r>   LOCAL_SPECIALIZED_NN_MODULEr   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-  r2  rN   r   r'   r    r)   r-   rU   rb   rm   r~   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r$  Enumr,  r:  rH  rR  r[  rd  rs  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&  r+  r0  r5  r>  rN  r   rj  rt  ry  r}  r  r  r  	lru_cacher  r  r  r  r  r  r  r  r  r  r  r  r  r  rG   r*   r   <module>r     s  &    $ % '    " {>>@@++[-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 	v 	$ 	&6D= &S &3 3 3# 3 4(B& B )B< 4(
f 
 )
$ 4(P6 P )P 4(B B )B" 4(C6 C )C 4(E& E )E( 4(  ) 4(	0 	 )	 4(0 0 )0* 4(
 
 )
" 4(
 
 )
0 4($] $ )$ 4(M  ) 4(Lf L )L& 4(  ) 4(!M ! )! 4(	0 	0 )	0 4(K
 K )K 4(	Z 	 )	 4(f  )& 4(m  )@TYY @  4(#E= #E )#EL 4(0M 0 )0 4(
= 
 )
 4(	7} 	7 )	7 4(-  )( 4(	' 	' )	' 4(	.m 	. )	. m   4(!] ! )!H 4(!EM !E )!EH 4(  )( 4(m  )4 4(E E )ED 4(%E %E )%EP 4(&W &W )&WR 4(
 
 )
  4(+] + )+ 4(
*M 
* )
* 4(  ) 4(m  ) 4(
] 
 )
 4(M. M )M 4(U)D U )U 4(A A )A 4(" " )" 4("6 " )": 4("6 " )"4 4("V " )"$ 4(> > )> 4(-] - )- 4(# # )# 4(=  ) 4(%V % )% 4("& " )"2 4(*& * )* 05		)-	4Z	 	 EJ X Xd Xt X X 6& 6T 6 6 6D= S4Z   F t   6 d   6 6 d   6 d   6 d   f     D   V    V   2 f   r*   