
    #Ki:                        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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  \R8                  \R:                  \R<                  \R>                  \R:                  \R:                  \R>                  \R>                  \R@                  \R@                  \RB                  \RB                  \RD                  \RD                  \RF                  \RF                  \RH                  \RH                  \RJ                  \RJ                  0
r&\R8                  \R@                  \R<                  \RB                  \R@                  \R@                  \RB                  \RB                  \R:                  \R@                  \R>                  \RB                  \RD                  \RD                  \RF                  \RF                  \RH                  \RH                  \RJ                  \RJ                  0
r'\R8                  \RD                  \R<                  \RF                  \R@                  \RD                  \RB                  \RF                  \R:                  \RD                  \R>                  \RF                  \RD                  \RD                  \RF                  \RF                  \RH                  \RH                  \RJ                  \RJ                  0
r(\R8                  \RH                  \R<                  \RJ                  \R:                  \RH                  \R>                  \RJ                  \RH                  \RH                  \RJ                  \RJ                  \R@                  \RH                  \RB                  \RJ                  \RD                  \RH                  \RF                  \RJ                  0
r)S\S\*4S jr+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       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 \5      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+ S,\5      5       r:\" SS9 " S- S.\5      5       r;\" 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\75      5       r?\" SS9 " S7 S8\75      5       r@\" SS9 " S9 S:\5      5       rA\" SS9 " S; S<\5      5       rB " S= S>\R                  5      rD\" SS9 " S? S@\5      5       rE\" SS9 " SA SB\5      5       rF\" SS9 " SC SD\5      5       rG\" SS9 " SE SF\5      5       rH\" SS9 " SG SH\5      5       rI\" SS9 " SI SJ\5      5       rJ\" SS9 " SK SL\5      5       rK " SM SN\5      rL\" SS9 " SO SP\5      5       rM\" SS9 " SQ SR\5      5       rN\" SS9 " SS ST\5      5       rO\" SS9 " SU SV\5      5       rP\" SS9 " SW SX\5      5       rQ\" SS9 " SY SZ\5      5       rR\" SS9 " S[ S\\N5      5       rS\" SS9 " S] S^\N5      5       rT\" SS9 " S_ S`\5      5       rU\" SS9 " Sa Sb\5      5       rV\" SS9 " Sc Sd\5      5       rW\" SS9 " Se Sf\5      5       rX\" SS9 " Sg Sh\5      5       rY\" SS9 " Si Sj\Y5      5       rZ\" SS9 " Sk Sl\Z5      5       r[\" SS9 " Sm Sn\Y5      5       r\\" SS9 " So Sp\5      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       ra\" SS9 " Sy Sz\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\" SS9 " S S\5      5       rg\" SS9 " S S\5      5       rhSS.S\S\*S\\,   4S jjriSS.S\S\*S\*4S jjrjS\S\*4S jrkS\S\\,   4S jrlS\S\*4S jrmS\S\*4S jrnS\S\S\*4S jro\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       ru\R                  S\S\*4S j5       rv\R                  S\S\*4S j5       rwg)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OptionalTYPE_CHECKINGUnion)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    V/var/www/html/dynamic-report/venv/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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)r4   
load_derefr1   append_outputcreate_loadselfcodegens     r   reconstructLocalSource.reconstruct   s:    ((t/!!'"5"5doo"FGr,   c                 "    [         R                  $ r6   )r   LOCALr;   s    r   r   LocalSource.guard_source   s       r,   c                 2    S[        U R                  SS9 S3$ )NzL[Tr$   ]r+   r1   rA   s    r   _name_templateLocalSource._name_template   s    HT__>?qAAr,    r<   r   r   N)__name__
__module____qualname____firstlineno__r)   __annotations__r2   boolr3   r   	frozensetr4   r=   propertyr   r   	functoolscached_propertyrG   __static_attributes__rI   r,   r   r/   r/      sz    O Hd *.Hhy~&-
 &+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   r1   r   Nc                 X    UR                  UR                  U R                  5      5        g r6   r8   r9   r1   r:   s     r   r=   TempLocalSource.reconstruct       g11$//BCr,   c                 "    [         R                  $ r6   )r   
TEMP_LOCALrA   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   rA   s    r   rG   TempLocalSource._name_template   s    !v
 	
r,   rI   rJ   )rK   rL   rM   rN   r)   rO   r=   rR   r   r   rG   rU   rI   r,   r   rW   rW      sE     OD &k & & 
 
 
r,   rW   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   r1   r   Nc                 X    UR                  UR                  U R                  5      5        g r6   rZ   r:   s     r   r=    SyntheticLocalSource.reconstruct   r\   r,   c                 "    [         R                  $ r6   )r   SYNTHETIC_LOCALrA   s    r   r   !SyntheticLocalSource.guard_source   s    ***r,   c                 2    S[        U R                  SS9 S3$ )NzSYNTHETIC_LOCAL[TrD   rE   rF   rA   s    r   rG   #SyntheticLocalSource._name_template   s    !(4??t"L!MQOOr,   rI   rJ   rK   rL   rM   rN   r)   rO   r=   rR   r   r   rS   rT   rG   rU   rI   r,   r   rd   rd      sL    OD +k + + P P Pr,   rd   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                  $ r6   )r   RANDOM_VALUErA   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 r6   )r8   r9   txoutputrandom_values_varcreate_load_constrq   r   r:   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+   rq   rA   s    r   rG    RandomValueSource._name_template   s    x(>(>?@AAr,   rI   rJ   )rK   rL   rM   rN   intrO   rR   r   r   r=   rS   rT   r)   rG   rU   rI   r,   r   ro   ro      sJ    (k ( (6
 B B Br,   ro   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r8   create_load_globalr   r:   s     r   r=   GlobalSource.reconstruct   s&    g889I9It8TUr,   c                 "    [         R                  $ r6   r   GLOBALrA   s    r   r   GlobalSource.guard_source       !!!r,   c                 2    S[        U R                  SS9 S3$ )NG[TrD   rE   r+   r   rA   s    r   rG   GlobalSource._name_template   s    HT--$?@BBr,   rI   rJ   rm   rI   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<   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                  $ r6   r   rA   s    r   r    GlobalWeakRefSource.guard_source  r   r,   c                 2    S[        U R                  SS9 S3$ )Nr   TrD   z]()r   rA   s    r   rG   "GlobalWeakRefSource._name_template  s    HT--$?@DDr,   rI   rJ   rm   rI   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      $ r6   baser   s   r   r   /WeakRefCallSource.reconstruct.<locals>.<lambda>  s    gdii&8r,   r   Fr   r:   s   ``r   r=   WeakRefCallSource.reconstruct  s(    8921e<=r,   c                     g)Nz{0}()rI   rA   s    r   rG    WeakRefCallSource._name_template  s    r,   rI   rJ   	rK   rL   rM   rN   r=   rR   r)   rG   rU   rI   r,   r   r   r     s"    >   r,   r   c                       \ rS rSrSrg)CallFunctionNoArgsSourcei  rI   NrK   rL   rM   rN   rU   rI   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                  ;   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 r6   r   r   create_load_attrsr   r:   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}, TrD   ){0}.)r   isidentifierr+   rA   s    r   rG   AttrSource._name_template,  sG    {{''))$Xdkkd%K$LANN-.//r,   rI   r   NrJ   rK   rL   rM   rN   r)   rO   r   r=   rS   rT   rG   rU   rI   r,   r   r   r     s4    KAF 0 0 0r,   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)GenericAttrSourcei3  r   r   Nc                 :   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__7  r   r,   c                 |    U" U R                   5        UR                  UR                  U R                  5      5        g r6   r   r:   s     r   r=   GenericAttrSource.reconstruct@  r   r,   c                 2    S[        U R                  SS9 S3$ )Nzobject.__getattribute__({0}, TrD   r   r+   r   rA   s    r   rG    GenericAttrSource._name_templateD  s"     .ht{{t.T-UUVW	
r,   rI   r   rJ   r   rI   r,   r   r   r   3  s4    KAF 
 
 
r,   r   c                   6    \ rS rSrSS jr\S\4S j5       rSrg)TypeDictSourceiL  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N__dict__r   r   r   r:   s     r   r=   TypeDictSource.reconstructN  '    		g77
CDr,   c                     g)Nzdict({0}.__dict__)rI   rA   s    r   rG   TypeDictSource._name_templateR  s     $r,   rI   rJ   r   rI   r,   r   r   r   L  s#    E $ $ $r,   r   c                   6    \ rS rSrSS jr\S\4S j5       rSrg)TypeMROSourcei\  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N__mro__r   r:   s     r   r=   TypeMROSource.reconstruct^  '    		g77	BCr,   c                     g)Nz{0}.__mro__rI   rA   s    r   rG   TypeMROSource._name_templateb  s    r,   rI   rJ   r   rI   r,   r   r   r   \  s#    D   r,   r   c                   .    \ rS rSr% Sr\\S'   SS jrSrg)LocalCellSourceig  zw
Conceptually, this class is `LocalSource` for cell objects implicitly
generated by Python (e.g., captured variables).
r1   Nc                 X    UR                  UR                  U R                  5      5        g r6   )r8   create_load_closurer1   r:   s     r   r=   LocalCellSource.reconstructp  s!     	g99$//JKr,   rI   rJ   )	rK   rL   rM   rN   __doc__r)   rO   r=   rU   rI   r,   r   r   r   g  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   r:   s     r   r=   CodeSource.reconstruct}  r   r,   c                     g)Nz{0}.__code__rI   rA   s    r   rG   CodeSource._name_template  s    r,   rI   rJ   r   rI   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   r:   s     r   r=   ClosureSource.reconstruct  s'    		g77FGr,   c                     g)Nz{0}.__closure__rI   rA   s    r   rG   ClosureSource._name_template  s     r,   rI   rJ   r   rI   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 r6   r   r:   s     r   r=   GradSource.reconstruct  r   r,   c                 2    S[        U R                  5       3$ )Nr   r   rA   s    r   rG   GradSource._name_template  s    -.//r,   rI   rJ   )rK   rL   rM   rN   r   r)   rO   r=   rS   rT   rG   rU   rI   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                     $ r6   #_GUARD_SOURCE_SPECIALIZED_NN_MODULEr   r   rA   s    r   r   ParamBufferSource.guard_source      24993I3IJJr,   rI   N	rK   rL   rM   rN   rS   rT   r   r   rU   rI   r,   r   r  r    s$    Kk K Kr,   r  c                       \ rS rSrSrg)UnspecializedParamBufferSourcei  rI   Nr   rI   r,   r   r  r    r   r,   r  c                       \ rS rSr% Sr\\   \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                  $ r6   )r   	EPHEMERALrA   s    r   r   EphemeralSource.guard_source      $$$r,   c                 \    U R                   b  SU R                   -   OSnS[        U5       S3$ )Nz:  z
<ephemeral>)r  r+   )r;   r  s     r   rG   EphemeralSource._name_template  s/    #'99#8tdiibHTN+1--r,   fn.c                     [         er6   ra   r;   r  s     r   
make_guardEphemeralSource.make_guard      !!r,   c                     gNTrI   rA   s    r   is_ephemeralEphemeralSource.is_ephemeral      r,   rI   )rK   rL   rM   rN   r  r   r)   rO   rR   r   r   rS   rT   rG   r   r   r   r  rP   r!  rU   rI   r,   r   r  r    sr    D(3-%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 r6   )r   r=   r:   s     r   r=   SkipGuardSource.reconstruct  s    		g&r,   c                     gNz{0}rI   rA   s    r   rG   SkipGuardSource._name_template      r,   rI   rJ   r   rI   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+   rA   s    r   method_nameTensorProperty.method_name  sL    >&&&^***^222# :htn-=!>??r,   rI   N)
rK   rL   rM   rN   r4  r5  r6  r)   r8  rU   rI   r,   r   r-  r-    s    DFN@S @r,   r-  c                   t    \ rS rSr% \\S'   Sr\\   \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 r6   )r   r<  r-  r6  r=  rA   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   rK   r+   r<  r8  r   s   r   r   2TensorPropertySource.reconstruct.<locals>.<lambda>  s3    G,,%1F1F1H(I'J Kr,   r.  r   F)r   r   r=  r8   ry   r   r   r:   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()[rE   z{0}.stride()[z{0}.storage_offset()r3  )r<  r-  r4  r+   r=  r5  r6  r7  rA   s    r   rG   #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,   rI   r   rJ   )rK   rL   rM   rN   r-  rO   r=  r   r~   r   r=   rS   rT   r)   rG   rU   rI   r,   r   r;  r;    sD    
C#(
 	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 r6   r   rA   s    r   r   IndexedSource.__post_init__      yy$$$r,   c                     [         er6   ra   r:   s     r   r=   IndexedSource.reconstruct  r  r,   c                 4    S[        U R                  5       S3$ )N(z, {0}))r+   r=  rA   s    r   rG   IndexedSource._name_template  s    8DHH%&h//r,   rI   r   rJ   )rK   rL   rM   rN   r~   rO   r   r=   rS   rT   r)   rG   rU   rI   r,   r   rI  rI    s2    	H%" 0 0 0r,   rI  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 r6   r   rA   s    r   r   NegateSource.__post_init__  rL  r,   c                     [         er6   ra   r:   s     r   r=   NegateSource.reconstruct"  r  r,   c                     g)Nz{0}.__neg__()rI   rA   s    r   rG   NegateSource._name_template%  s     r,   rI   r   rJ   
rK   rL   rM   rN   r   r=   rR   r)   rG   rU   rI   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)
ConvertIntSourcei+  r   Nc                 "    U R                   c   eg r6   r   rA   s    r   r   ConvertIntSource.__post_init__-  rL  r,   c                 (    U" U R                   5        g r6   r   r:   s     r   r=   ConvertIntSource.reconstruct0      		r,   c                     g)Nz%cast_symbool_to_symint_guardless({0})rI   rA   s    r   rG   ConvertIntSource._name_template3  s    6r,   rI   r   rJ   rZ  rI   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)DynamicScalarSourcei8  is_intr   Nc                 "    U R                   c   eg r6   r   rA   s    r   r   !DynamicScalarSource.__post_init__<  rL  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~   rC  r<   s   r   r   1DynamicScalarSource.reconstruct.<locals>.<lambda>D  s    g&>&>z5&Qr,   r   Fr   r   r   r   r:   s    `r   r=   DynamicScalarSource.reconstruct?  s6    
 	QR		21e<=r,   c                     g)Nzint({0})rI   rA   s    r   rG   "DynamicScalarSource._name_templateH  s    r,   rI   r   rJ   )rK   rL   rM   rN   rP   rO   r   r=   rR   r)   rG   rU   rI   r,   r   re  re  8  s,    L%>   r,   re  c                   @    \ rS rSrSS jrS	S jr\S\4S j5       rSr	g)
FlattenScriptObjectSourceiM  r   Nc                 "    U R                   c   eg r6   r   rA   s    r   r   'FlattenScriptObjectSource.__post_init__O  rL  r,   c                 (    U" U R                   5        g r6   r   r:   s     r   r=   %FlattenScriptObjectSource.reconstructR  ra  r,   c                     g)Nz{0}.__obj_flatten__()rI   rA   s    r   rG   (FlattenScriptObjectSource._name_templateU  s    &r,   rI   r   rJ   rZ  rI   r,   r   rt  rt  M  s'    % ' ' 'r,   rt  c                   @    \ rS rSrSS jrS	S jr\S\4S j5       rSr	g)
ScriptObjectQualifiedNameSourceiZ  r   Nc                 "    U R                   c   eg r6   r   rA   s    r   r   -ScriptObjectQualifiedNameSource.__post_init__\  rL  r,   c                 (    U" U R                   5        g r6   r   r:   s     r   r=   +ScriptObjectQualifiedNameSource.reconstruct_  ra  r,   c                     g)Nz{0}._type().qualified_name()rI   rA   s    r   rG   .ScriptObjectQualifiedNameSource._name_templateb  s    -r,   rI   r   rJ   rZ  rI   r,   r   r|  r|  Z  s'    % . . .r,   r|  c                   6    \ rS rSrSS jr\S\4S j5       rSrg)AttrProxySourceig  r   Nc                 (    U" U R                   5        g r6   r   r:   s     r   r=   AttrProxySource.reconstructh  ra  r,   c                     g)Nz{0}.get_base()rI   rA   s    r   rG   AttrProxySource._name_templatek  s    r,   rI   rJ   r   rI   r,   r   r  r  g  s"          r,   r  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S
 jrSS jr\R                   S\4S j5       rSrg	)DefaultsSourceip  idx_keyFis_kw)initr(   comparefield_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__[rE   )
r   r  r   r  r)   r   r   r+   r  r~   rA   s    r   r   DefaultsSource.__post_init__w  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 r6   )r   r   r   r  r8   ry   r  r   r:   s     r   r=   DefaultsSource.reconstruct  sZ    		g77

CDg77EF245r,   c                     U R                   $ r6   )r  rA   s    r   rG   DefaultsSource._name_template  s    zzr,   rI   r   rJ   )rK   rL   rM   rN   r   r~   r)   rO   r  rP   dataclassesr  r  r   r=   rS   rT   rG   rU   rI   r,   r   r  r  p  sw    38_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__)r;   	__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 r6   )r   r  r8   ry   unpack_slicer  r   r:   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 $ r6   )r  r  )r;   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}[TrD   rE   )r   r  r   r  r+   r  rA   s    r   rG   GetItemSource._name_template  s_    
 djj&1111HT%6%6%8TJK1MMHTZZDAB!DDr,   rI   r   rJ   )rK   rL   rM   rN   r   rO   r  rP   r   r=   r  r  rS   rT   r)   rG   rU   __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rC  r   rK   rm  s   r   r   0ConstDictKeySource.reconstruct.<locals>.<lambda>  s    G,,U^^=PQr,   r.  Fr   r   r8   ry   r  r   r   r:   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}))[TrD   rE   r+   r  rA   s    r   rG   !ConstDictKeySource._name_template  s     )$**)N(OqQQr,   c                     gr   rI   rA   s    r   is_dict_keyConstDictKeySource.is_dict_key  r#  r,   rI   rJ   )rK   rL   rM   rN   r   rO   r=   rS   rT   r)   rG   rP   r  rU   rI   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  r;   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  rm  s   r   r   =NonSerializableSetGetItemSource.reconstruct.<locals>.<lambda>  s    G,,U^^]Kr,   r.  Fr  r:   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})[TrD   rE   r  rA   s    r   rG   .NonSerializableSetGetItemSource._name_template  s     htzzdCDAFFr,   c                     g)NFrI   rA   s    r   r  +NonSerializableSetGetItemSource.is_dict_key  s    r,   rI   r   rJ   )rK   rL   rM   rN   r~   rO   r   r=   rS   rT   r)   rG   rP   r  rU   rI   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 r6   )r   r   r  r   r8   ry   r   r:   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  rE   TrD   r   r  r  r+   r!   rA   s    r   rG    DictGetItemSource._name_template  sL    djj"455HTZZ__56a88HTZZDAB!DDr,   rI   r   rJ   rK   rL   rM   rN   r   rO   r   r=   rS   rT   r)   rG   rU   rI   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  rm  s   r   r   7DictSubclassGetItemSource.reconstruct.<locals>.<lambda>       G,,U^^^Lr,   r.  F)	r   r   r   r  r   r8   ry   r   r   r:   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  TrD   rE   r  rA   s    r   rG   (DictSubclassGetItemSource._name_template.  sL    djj"455-htzz.G-HJJHTZZDAB!DDr,   rI   r   rJ   r  rI   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)	ListGetItemSourcei6  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  rm  s   r   r   /ListGetItemSource.reconstruct.<locals>.<lambda>B  r  r,   >List[slice] is a temporary object and should not have a sourcer.  F)	r   r   r  RuntimeErrorr8   ry   r  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                  SS9 S3$ )Nr  zlist.__getitem__({0}, TrD   r   )r   r  r   r  r  r+   rA   s    r   rG    ListGetItemSource._name_templateR  sR    
 djj&1111P  .htzzd.S-TTUVVr,   rI   rJ   )rK   rL   rM   rN   r   r=   rS   rT   r)   rG   rU   rI   r,   r   r  r  6  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)TupleIteratorGetItemSourcei`  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  rm  s   r   r   8TupleIteratorGetItemSource.reconstruct.<locals>.<lambda>d  s    G,,U^^=UVr,   r.  Fr  r:   s    `r   r=   &TupleIteratorGetItemSource.reconstructb  sU    V	
 			g77

CD21e<=r,   c                 2    S[        U R                  SS9 S3$ )Nz___tuple_iterator_getitem({0}, TrD   r   r  rA   s    r   rG   )TupleIteratorGetItemSource._name_templatej  s#     0PT0U/VVWX	
r,   rI   rJ   )
rK   rL   rM   rN   r=   rS   rT   r)   rG   rU   rI   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)NamedTupleFieldsSourceiq  r   Nc                 h    U" U R                   5        UR                  UR                  S5      5        g )N_fieldsr   r:   s     r   r=   "NamedTupleFieldsSource.reconstructs  r   r,   c                     g)Nz___namedtuple_fields({0})rI   rA   s    r   rG   %NamedTupleFieldsSource._name_templatew      *r,   rI   rJ   r   rI   r,   r   r  r  q  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  rm  s   r   r   3DataclassFieldsSource.reconstruct.<locals>.<lambda>  s    G,,U^^=OPr,   r   Fro  r:   s    `r   r=   !DataclassFieldsSource.reconstruct~  s8    P	
 			21e<=r,   c                     g)Nz___dataclass_fields({0})rI   rA   s    r   rG   $DataclassFieldsSource._name_template  s    )r,   rI   rJ   r   rI   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 r6   r   rA   s    r   r   TypeSource.__post_init__  rL  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      $ )Nrk  typerl  rm  s   r   r   (TypeSource.reconstruct.<locals>.<lambda>  s    g&>&>z6&Rr,   r   Fro  r:   s    `r   r=   TypeSource.reconstruct  s4    RS		21e<=r,   c                     g)Nz	type({0})rI   rA   s    r   rG   TypeSource._name_template  s    r,   rI   r   rJ   rZ  rI   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 r6   r   r:   s     r   r=   OptimizerSource.reconstruct  ra  r,   c                     gr)  rI   rA   s    r   rG   OptimizerSource._name_template  r+  r,   rI   rJ   r   rI   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 r6   r   r:   s     r   r=   NNModuleSource.reconstruct  ra  r,   c                 <    [         U R                  R                     $ r6   r  rA   s    r   r   NNModuleSource.guard_source  r
  r,   c                     gr)  rI   rA   s    r   rG   NNModuleSource._name_template  r+  r,   rI   rJ   )rK   rL   rM   rN   r=   rS   rT   r   r   rR   r)   rG   rU   rI   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                     $ r6   )%_GUARD_SOURCE_UNSPECIALIZED_NN_MODULEr   r   rA   s    r   r   (UnspecializedNNModuleSource.guard_source  s    4TYY5K5KLLr,   rI   Nr  rI   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                     $ r6   )-_GUARD_SOURCE_UNSPECIALIZED_BUILTIN_NN_MODULEr   r   rA   s    r   r   /UnspecializedBuiltinNNModuleSource.guard_source  s    <TYY=S=STTr,   rI   Nr  rI   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                     $ r6   )_GUARD_SOURCE_FSDP_MODULEr   r   rA   s    r   r   FSDPNNModuleSource.guard_source  s    ()?)?@@r,   rI   Nr  rI   r,   r   r3  r3    s$    Ak A Ar,   r3  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  rI   rA   s    r   rG    GlobalStateSource._name_template      r,   c                 "    [         R                  $ r6   r   rA   s    r   r   GlobalStateSource.guard_source  r   r,   rI   N
rK   rL   rM   rN   rR   r)   rG   r   r   rU   rI   r,   r   r8  r8    s6       "k " "r,   r8  c                   v   ^  \ rS rSrSrS\S\SS4U 4S jjr\S\4S j5       r	SS	 jr
\S\4S
 j5       rSrU =r$ )TorchSourcei  zPoints to the actual `torch` module - used instead of GlobalSource
in case the user has overridden `torch` in their local namespaceargskwargsr   Nc                 x   > [         TU ]  " U0 UD6  SSKJnJn  U" U R                  UR                  5      5        g Nr   )GuardBuilderinstall_guardr  __init__guardsrF  rG  r  ID_MATCHr;   rB  rC  rF  rG  r  s        r   rI  TorchSource.__init__  /    $)&)7dool&;&;<=r,   c                     g)Nz__import__('torch')rI   rA   s    r   rG   TorchSource._name_template  s    $r,   c                 z    UR                  UR                  S5      [        S5      UR                  S5      /5        g )Nr   torchr   ry   r   create_import_namer:   s     r   r=   TorchSource.reconstruct  s9    ))!,"1%**73	
r,   c                 "    [         R                  $ r6   r   rA   s    r   r   TorchSource.guard_source  r   r,   rI   rJ   rK   rL   rM   rN   r   r   rI  rR   r)   rG   r=   r   r   rU   r  r  s   @r   rA  rA    s^    H>c >S >T > % % %
 "k " "r,   rA  c                   v   ^  \ rS rSrSrS\S\SS4U 4S jjr\S\4S j5       r	SS	 jr
\S\4S
 j5       rSrU =r$ )CollectionsSourcei  zPoints to the actual `collections` module - used instead of GlobalSource
in case the user has overridden `collections` in their local namespacerB  rC  r   Nc                 x   > [         TU ]  " U0 UD6  SSKJnJn  U" U R                  UR                  5      5        g rE  rH  rL  s        r   rI  CollectionsSource.__init__  rN  r,   c                     g)Nz__import__('collections')rI   rA   s    r   rG    CollectionsSource._name_template  r  r,   c                 z    UR                  UR                  S5      [        S5      UR                  S5      /5        g )Nr   collectionsrS  r:   s     r   r=   CollectionsSource.reconstruct  s9    ))!,"1%**=9	
r,   c                 "    [         R                  $ r6   r   rA   s    r   r   CollectionsSource.guard_source  r   r,   rI   rJ   rX  r  s   @r   rZ  rZ    s^    N>c >S >T > + + +
 "k " "r,   rZ  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_indexrA   s    r   rG   +TorchFunctionModeStackSource._name_template  s    5ht?P6Q5RRSTTr,   c                 D    SSK Jn  UR                  U R                  5      $ )Nr   )TorchFunctionModeStackVariable)variables.torch_functionrk  get_mode_indexrf  )r;   rk  s     r   rh  '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  rm  s   r   r   :TorchFunctionModeStackSource.reconstruct.<locals>.<lambda>  s    G,, Br,   r   F)r   r   ry   rh  r   r:   s    `r   r=   (TorchFunctionModeStackSource.reconstruct  sQ    	

 	w889JKLM21e<=r,   c                 "    [         R                  $ r6   r   rA   s    r   r   )TorchFunctionModeStackSource.guard_source!  r   r,   rI   rJ   )rK   rL   rM   rN   r~   rO   rS   rT   r)   rG   rh  r=   rR   r   r   rU   rI   r,   r   re  re    sW    	HU U UGC G
> "k " "r,   re  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   )r8   r   rw  r:   s     r   r=   ConstantSource.reconstruct*  s&    g889I9Iu8UVr,   c                 "    [         R                  $ r6   )r   r   rA   s    r   r   ConstantSource.guard_source-  s    ###r,   c                     U R                   $ r6   )rw  rA   s    r   rG   ConstantSource._name_template1  s    r,   r  c                     [         er6   ra   r  s     r   r  ConstantSource.make_guard5  r  r,   rI   rJ   )rK   rL   rM   rN   r)   rO   r=   rR   r   r   rS   rT   rG   r   r  rU   rI   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)NumpyTensorSourcei9  r   c                     g)Nz___from_numpy({0})rI   rA   s    r   rG    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      $ )NrR  	as_tensorrl  rm  s   r   r   /NumpyTensorSource.reconstruct.<locals>.<lambda>@  s    g&>&>w&Tr,   r   Fro  r:   s    `r   r=   NumpyTensorSource.reconstruct?  s4    TU		21e<=r,   rI   rJ   )	rK   rL   rM   rN   rR   r)   rG   r=   rU   rI   r,   r   r  r  9  s     $ $ $>r,   r  c                   ,    \ rS rSr\S\4S j5       rSrg)SubclassAttrListSourceiE  r   c                     g)Nz{0}.__tensor_flatten__()[0]rI   rA   s    r   rG   %SubclassAttrListSource._name_templateG  s    ,r,   rI   NrK   rL   rM   rN   rR   r)   rG   rU   rI   r,   r   r  r  E  s    - - -r,   r  c                   ,    \ rS rSr\S\4S j5       rSrg)FloatTensorSourceiN  r   c                     g)Nz___as_tensor({0})rI   rA   s    r   rG    FloatTensorSource._name_templateP  s    "r,   rI   Nr  rI   r,   r   r  r  N  s    # # #r,   r  c                   ,    \ rS rSr\S\4S j5       rSrg)CallMethodItemSourceiU  r   c                     g)Nz
{0}.item()rI   rA   s    r   rG   #CallMethodItemSource._name_templateW  s    r,   rI   Nr  rI   r,   r   r  r  U  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)ShapeEnvSourcei_  r   c                     gr:  rI   rA   s    r   rG   ShapeEnvSource._name_templatea  r<  r,   c                 "    [         R                  $ r6   )r   	SHAPE_ENVrA   s    r   r   ShapeEnvSource.guard_sourcee  r  r,   rI   Nr?  rI   r,   r   r  r  _  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)
CurrentStreamSourceij  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  rA   s    r   rG   "CurrentStreamSource._name_templaten  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  rm  s   r   r   1CurrentStreamSource.reconstruct.<locals>.<lambda>u  s    G,,U^^=QRr,   c                  (   > T R                  SS5      $ )NrR  r   rl  rm  s   r   r   r  w  s    g&>&>w&Qr,   F)r   r   ry   r   r  r  r   )r;   r<   num_argss    ` r   r=   CurrentStreamSource.reconstructr  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                  $ r6   r   rA   s    r   r    CurrentStreamSource.guard_source  r   r,   rI   rJ   )rK   rL   rM   rN   device_typerO   rS   rT   r)   rG   r=   rR   r   r   rU   rI   r,   r   r  r  j  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)BackwardStateSourcei  r   c                     gr:  rI   rA   s    r   rG   "BackwardStateSource._name_template  r<  r,   c                 "    [         R                  $ r6   )r   BACKWARD_STATErA   s    r   r    BackwardStateSource.guard_source  s    )))r,   rI   Nr?  rI   r,   r   r  r    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/   r2   r1   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$ r6   )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
                  $ r6   )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                  (       + $ r6   )r   r	   is_from_nonlocal_sourcer   r/   r4   r2   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                 `    [        U [        5      (       a  [        U R                  U5      $ X:H  $ r6   )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   rt  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)xr   r  enumrS   collections.abcr   typingr   r   r   r   rR  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+  r0  r5  rP   r   r)   r"   r+   r/   rW   rd   ro   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r%  Enumr-  r;  rI  rS  r\  re  rt  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r)  r.  r3  r8  rA  rZ  re  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  	lru_cacher  r  r  r  r  r  r  rI   r,   r   <module>r     sW  &    $ 6 6 '    " {>>@@++[-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 	$ 	&8F#3 & &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(
 
 )
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("& " )"8 4(" " )"8 4("6 " )"4 4("V " )"$ 4(> > )> 4(-] - )- 4(# # )# 4(=  ) 4(%V % )% 4("& " )"2 4(*& * )* 16		)-	c]	 FK X Xd Xt X6& 6T 66 hsm F t 6 d 6 6 d  6 d   6 d   f     D   V    V   2 f   r,   