
    {Yh                     `   d Z ddlZddlZddlZddlmZmZmZmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZ erddlmZ ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        i
Zej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        i
Zej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        i
Z ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        i
Z!d	 Z" ej#        d
           G d de                      Z$ ej#        d
           G d de                      Z% ej#        d
           G d de                      Z& ej#        d
           G d de                      Z' ej#        d
           G d de                      Z( ej#        d
           G d de
                      Z) ej#        d
           G d de)                      Z* ej#        d
           G d de
                      Z+ ej#        d
           G d de
                      Z, ej#        d
           G d de                      Z- ej#        d
           G d  d!e
                      Z. ej#        d
           G d" d#e+                      Z/ ej#        d
           G d$ d%e+                      Z0 ej#        d
           G d& d'e                      Z1 G d( d)ej2                  Z3 ej#        d
           G d* d+e
                      Z4 ej#        d
           G d, d-e
                      Z5 ej#        d
           G d. d/e
                      Z6 ej#        d
           G d0 d1e
                      Z7 ej#        d
           G d2 d3e
                      Z8 ej#        d
           G d4 d5e
                      Z9 G d6 d7e
          Z: ej#        d
           G d8 d9e
                      Z; ej#        d
           G d: d;e
                      Z< ej#        d
           G d< d=e
                      Z= ej#        d
           G d> d?e
                      Z> ej#        d
           G d@ dAe
                      Z? ej#        d
           G dB dCe<                      Z@ ej#        d
           G dD dEe<                      ZA ej#        d
           G dF dGe
                      ZB ej#        d
           G dH dIe
                      ZC ej#        d
           G dJ dKe
                      ZD ej#        d
           G dL dMe
                      ZE ej#        d
           G dN dOeE                      ZF ej#        d
           G dP dQeF                      ZG ej#        d
           G dR dSeE                      ZH ej#        d
           G dT dUe                      ZI ej#        d
           G dV dWe                      ZJ ej#        d
           G dX dYe                      ZK ej#        d
           G dZ d[e
                      ZL ej#        d
           G d\ d]e
                      ZM ej#        d
           G d^ d_e
                      ZN ej#        d
           G d` dae
                      ZO ej#        d
           G db dce                      ZP ej#        d
           G dd dee                      ZQdfdgdhedieeR         fdjZSdfdgdhefdkZTdhedieUfdlZVdhedieeR         fdmZWdhefdnZXdhedoefdpZYejZ        dhefdq            Z[ejZ        dhefdr            Z\ejZ        dhefds            Z]ejZ        dhefdt            Z^ejZ        dhefdu            Z_ejZ        dhefdv            Z`dS )wa  
This module provides Source classes that track the origins of values in PyTorch Dynamo.
Sources represent where values come from (e.g. local variables, globals, attributes) and
are used for guard generation and code reconstruction during compilation.

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

Sources play a key role in Dynamo's guard system by tracking value origins for
guard generation, and in code reconstruction by providing methods to rebuild
the code needed to recreate values.
    N)AnyOptionalTYPE_CHECKINGUnion)ChainedSourceGuardSourceSource   )utils)create_call_functioncreate_instruction)	PyCodegenc                     t          | t                    rdS 	 |                                 t          j        k    rdS n# t
          $ r Y nw xY wdS NTF)
isinstanceConstantSourceguard_sourcer   CONSTANTNotImplementedErrorsources    f/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/_dynamo/source.pyis_constant_sourcer   c   si    &.)) t  K$8884 9    5s   "> 
A
AT)frozenc                   p    e Zd ZU eed<   dZeed<   dZee	e                  ed<   dZ
eed<   dd	Zd
 Zd ZdS )LocalSource
local_nameFis_inputNdynamismis_derefed_cell_contentscodegenr   c                     | j         r|                    | j                   d S |                    |                    | j                             d S N)r    
load_derefr   append_outputcreate_loadselfr!   s     r   reconstructzLocalSource.reconstruct   sT    ( 	Ht/////!!'"5"5do"F"FGGGGG    c                     t           j        S r#   )r   LOCALr(   s    r   r   zLocalSource.guard_source   s      r*   c                 2    dt          | j                   dS )NzL[])reprr   r-   s    r   namezLocalSource.name   s    ,D)),,,,r*   r!   r   )__name__
__module____qualname__str__annotations__r   boolr   r   	frozensetr    r)   r   r1    r*   r   r   r   o   s         OOO Hd *.Hhy~&---
 &+d***H H H H! ! !- - - - -r*   r   c                   .    e Zd ZU eed<   ddZd Zd ZdS )	SyntheticLocalSourcer   r!   r   c                 `    |                     |                    | j                             d S r#   )r%   r&   r   r'   s     r   r)   z SyntheticLocalSource.reconstruct   s,    g11$/BBCCCCCr*   c                     t           j        S r#   )r   SYNTHETIC_LOCALr-   s    r   r   z!SyntheticLocalSource.guard_source   s    **r*   c                     d| j         dS )NzSYNTHETIC_LOCAL[r/   )r   r-   s    r   r1   zSyntheticLocalSource.name   s    6$/6666r*   Nr2   r3   r4   r5   r6   r7   r)   r   r1   r:   r*   r   r<   r<      sU         OOOD D D D+ + +7 7 7 7 7r*   r<   c                   .    e Zd ZU eed<   d ZddZd ZdS )	RandomValueSourcerandom_call_indexc                     t           j        S r#   )r   RANDOM_VALUEr-   s    r   r   zRandomValueSource.guard_source   s    ''r*   r!   r   c                    |                     |                    |j        j        j                             |                     |                    | j                             |                     t          d                     d S NBINARY_SUBSCR)r%   r&   txoutputrandom_values_varcreate_load_constrD   r   r'   s     r   r)   zRandomValueSource.reconstruct   st    g11'*2C2UVVWWWg778NOOPPP0AABBBBBr*   c                     d| j          S )Nrandom_value_)rD   r-   s    r   r1   zRandomValueSource.name   s    7t5777r*   Nr2   )r3   r4   r5   intr7   r   r)   r1   r:   r*   r   rC   rC      sX         ( ( (C C C C
8 8 8 8 8r*   rC   c                   .    e Zd ZU eed<   ddZd Zd ZdS )	GlobalSourceglobal_namer!   r   c                 d    |                     |                    | j        d                     d S NTaddr%   create_load_globalrS   r'   s     r   r)   zGlobalSource.reconstruct   s2    g889It8TTUUUUUr*   c                     t           j        S r#   r   GLOBALr-   s    r   r   zGlobalSource.guard_source       !!r*   c                 2    dt          | j                   dS )NG[r/   r0   rS   r-   s    r   r1   zGlobalSource.name   s    -D)**----r*   Nr2   rA   r:   r*   r   rR   rR      sX         V V V V" " ". . . . .r*   rR   c                   .    e Zd ZU eed<   ddZd Zd ZdS )	GlobalWeakRefSourcerS   r!   r   c                                            fd                               t          dd                     d S )Nc                  b                                               j        d                    S rU   rX   r!   r(   s   r   <lambda>z1GlobalWeakRefSource.reconstruct.<locals>.<lambda>   s0    G))**4+;*FF  r*   r   Fadd_push_nullextend_outputr   r'   s   ``r   r)   zGlobalWeakRefSource.reconstruct   s\        	
 	
 	

 	21e<<=====r*   c                     t           j        S r#   r[   r-   s    r   r   z GlobalWeakRefSource.guard_source   r]   r*   c                 2    dt          | j                   dS )Nr_   z]()r`   r-   s    r   r1   zGlobalWeakRefSource.name   s    /D)**////r*   Nr2   rA   r:   r*   r   rb   rb      sT         > > > >" " "0 0 0 0 0r*   rb   c                   "    e Zd ZddZd Zd ZdS )WeakRefCallSourcer!   r   c                                            fd                               t          dd                     d S )Nc                  $      j                   S r#   basere   s   r   rf   z/WeakRefCallSource.reconstruct.<locals>.<lambda>   s    ggdi&8&8 r*   r   Frg   r'   s   ``r   r)   zWeakRefCallSource.reconstruct   sJ    8888899921e<<=====r*   c                 4    | j                                         S r#   rq   r   r-   s    r   r   zWeakRefCallSource.guard_source       y%%'''r*   c                 :    | j                                          dS )Nz()rq   r1   r-   s    r   r1   zWeakRefCallSource.name   s    )..""&&&&r*   Nr2   r3   r4   r5   r)   r   r1   r:   r*   r   rm   rm      sF        > > > >( ( (' ' ' ' 'r*   rm   c                       e Zd ZdS )CallFunctionNoArgsSourceNr3   r4   r5   r:   r*   r   ry   ry              Dr*   ry   c                   4    e Zd ZU eed<   d Zd	dZd Zd ZdS )

AttrSourcememberc                 J   | j         s
J d            d| j        v r| j                            d          }t                              | dt          | j         d                    |d d                                        t                              | d|d                    d S d S Nz9Can't construct an AttrSource without a valid base source.rq   r~   rq   r~   splitobject__setattr__r}   joinr(   member_partss     r   __post_init__zAttrSource.__post_init__       yUUUUUU$+;,,S11LfjCHH\#2#=N4O4OPP   tX|B/?@@@@@ r*   r!   r   c                      || j                    |                    |                    | j                             d S r#   rq   ri   create_load_attrsr~   r'   s     r   r)   zAttrSource.reconstruct   >    	g77DDEEEEEr*   c                 4    | j                                         S r#   rs   r-   s    r   r   zAttrSource.guard_source   rt   r*   c                     | j                                         s%d| j                                         d| j         dS | j                                         d| j          S )Nzgetattr(, )r   )r~   isidentifierrq   r1   r-   s    r   r1   zAttrSource.name   sb    {'')) 	CBdinn..BB$+BBBB)..""22T[222r*   Nr2   	r3   r4   r5   r6   r7   r   r)   r   r1   r:   r*   r   r}   r}      sg         KKKA A AF F F F( ( (3 3 3 3 3r*   r}   c                   4    e Zd ZU eed<   d Zd	dZd Zd ZdS )
GenericAttrSourcer~   c                 J   | j         s
J d            d| j        v r| j                            d          }t                              | dt          | j         d                    |d d                                        t                              | d|d                    d S d S r   r   r   s     r   r   zGenericAttrSource.__post_init__   r   r*   r!   r   c                      || j                    |                    |                    | j                             d S r#   r   r'   s     r   r)   zGenericAttrSource.reconstruct  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zGenericAttrSource.guard_source  rt   r*   c                 L    d| j                                          d| j        dS )Nzobject.__getattribute__(r   r   rq   r1   r~   r-   s    r   r1   zGenericAttrSource.name  s)    N$)..*:*:NNdkNNNNr*   Nr2   r   r:   r*   r   r   r      sl         KKKA A AF F F F( ( (O O O O Or*   r   c                   &    e Zd ZU dZeed<   ddZdS )LocalCellSourcez
    Conceptually, this class is `LocalSource` for cell objects implicitly
    generated by Python (e.g., captured variables).
    r   r!   r   c                 `    |                     |                    | j                             d S r#   )r%   create_load_closurer   r'   s     r   r)   zLocalCellSource.reconstruct  s.     	g99$/JJKKKKKr*   Nr2   )r3   r4   r5   __doc__r6   r7   r)   r:   r*   r   r   r     sE          
 OOOL L L L L Lr*   r   c                   2    e Zd ZU dZeed<   d	dZd Zd ZdS )

GradSourcegradr~   r!   r   c                      || j                    |                    |                    | j                             d S r#   r   r'   s     r   r)   zGradSource.reconstruct*  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zGradSource.guard_source.  rt   r*   c                 H    | j                                          d| j         S )Nr   r   r-   s    r   r1   zGradSource.name1  s$    )..""22T[222r*   Nr2   )	r3   r4   r5   r~   r6   r7   r)   r   r1   r:   r*   r   r   r   &  s\         FCF F F F( ( (3 3 3 3 3r*   r   c                       e Zd Zd ZdS )ParamBufferSourcec                 J    t           | j                                                 S r#   #_GUARD_SOURCE_SPECIALIZED_NN_MODULErq   r   r-   s    r   r   zParamBufferSource.guard_source7      2493I3I3K3KLLr*   Nr3   r4   r5   r   r:   r*   r   r   r   5  s(        M M M M Mr*   r   c                       e Zd ZdS )UnspecializedParamBufferSourceNrz   r:   r*   r   r   r   <  r{   r*   r   c                   B    e Zd ZU dZee         ed<   d Zd Zd Z	d Z
dS )EphemeralSourceNdescc                     t           j        S r#   )r   	EPHEMERALr-   s    r   r   zEphemeralSource.guard_sourceN      $$r*   c                 0    d| j         
d| j         z   nd dS )Nz
<ephemeralz:  >)r   r-   s    r   r1   zEphemeralSource.nameQ  s&    P	0ED49,,2PPPPr*   c                     t           r#   r   r(   fns     r   
make_guardzEphemeralSource.make_guardT      !!r*   c                     dS NTr:   r-   s    r   is_ephemeralzEphemeralSource.is_ephemeralW      tr*   )r3   r4   r5   r   r   r6   r7   r   r1   r   r   r:   r*   r   r   r   J  si         D(3-% % %Q Q Q" " "    r*   r   c                        e Zd ZdZdZdZd ZdS )TensorPropertyr   r
      c                 f    | t           j        u rdS | t           j        u rdS | t           j        u rdS d S )Nsizestridestorage_offset)r   SIZESTRIDESTORAGE_OFFSETr-   s    r   method_namezTensorProperty.method_name`  sD    >&&&6^***8^222## 32r*   N)r3   r4   r5   r   r   r   r   r:   r*   r   r   r   [  s2        DFN$ $ $ $ $r*   r   c                   N    e Zd ZU eed<   dZee         ed<   d Zd
dZ	d Z
d	 ZdS )TensorPropertySourcepropNidxc                 f    | j         J | j        t          j        u r| j        J d S | j        J d S r#   )rq   r   r   r   r   r-   s    r   r   z"TensorPropertySource.__post_init__n  sH    y$$$95558#####8'''''r*   r!   r   c                                           fd             j                    j        -                                         j                                                 t           j        dndd                     d S )Nc                  x                          t          j        dj                                                   S )Ncall_)load_import_fromr   r3   r   r   re   s   r   rf   z2TensorPropertySource.reconstruct.<locals>.<lambda>w  s5    G,, A	(=(=(?(? A A  r*   r   r
   F)rh   rq   r   r%   rM   ri   r   r'   s   ``r   r)   z TensorPropertySource.reconstructu  s        	
 	
 	

 		8!!'";";DH"E"EFFF dh&:5II	
 	
 	
 	
 	
r*   c                 4    | j                                         S r#   rs   r-   s    r   r   z!TensorPropertySource.guard_source  rt   r*   c                 |   | j         t          j        u r$| j                                         d| j         dS | j         t          j        u r$| j                                         d| j         dS | j         t          j        u r%| j        J | j                                         dS t          d| j                    )Nz.size()[r/   z
.stride()[z.storage_offset()z
unhandled )	r   r   r   rq   r1   r   r   r   AssertionErrorr-   s    r   r1   zTensorPropertySource.name  s    9+++inn&&;;;;;;Y.///inn&&==$(====Y.7778###inn&&9999 !9di!9!9:::r*   r2   )r3   r4   r5   r   r7   r   r   rP   r   r)   r   r1   r:   r*   r   r   r   i  sw         
C#( ( (
 
 
 
( ( (	; 	; 	; 	; 	;r*   r   c                   4    e Zd ZU eed<   d Zd	dZd Zd ZdS )
IndexedSourcer   c                     | j         J d S r#   rp   r-   s    r   r   zIndexedSource.__post_init__      y$$$$$r*   r!   r   c                     t           r#   r   r'   s     r   r)   zIndexedSource.reconstruct  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zIndexedSource.guard_source  rt   r*   c                 L    d| j          d| j                                         dS )N(r   r   )r   rq   r1   r-   s    r   r1   zIndexedSource.name  s)    24822ty~~//2222r*   Nr2   )	r3   r4   r5   rP   r7   r   r)   r   r1   r:   r*   r   r   r     s`         	HHH% % %" " " "( ( (3 3 3 3 3r*   r   c                   (    e Zd Zd ZddZd Zd ZdS )	NegateSourcec                     | j         J d S r#   rp   r-   s    r   r   zNegateSource.__post_init__  r   r*   r!   r   c                     t           r#   r   r'   s     r   r)   zNegateSource.reconstruct  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zNegateSource.guard_source  rt   r*   c                 :    | j                                          dS )Nz
.__neg__()rv   r-   s    r   r1   zNegateSource.name  s    )..""....r*   Nr2   r3   r4   r5   r   r)   r   r1   r:   r*   r   r   r     sU        % % %" " " "( ( (/ / / / /r*   r   c                   (    e Zd Zd ZddZd Zd ZdS )	ConvertIntSourcec                     | j         J d S r#   rp   r-   s    r   r   zConvertIntSource.__post_init__  r   r*   r!   r   c                 &     || j                    d S r#   rp   r'   s     r   r)   zConvertIntSource.reconstruct      	r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zConvertIntSource.guard_source  rt   r*   c                 <    d| j                                          dS )Nz!cast_symbool_to_symint_guardless(r   rv   r-   s    r   r1   zConvertIntSource.name  s    F49>>3C3CFFFFr*   Nr2   r   r:   r*   r   r   r     sZ        % % %   ( ( (G G G G Gr*   r   c                   (    e Zd Zd ZddZd Zd ZdS )	FlattenScriptObjectSourcec                     | j         J d S r#   rp   r-   s    r   r   z'FlattenScriptObjectSource.__post_init__  r   r*   r!   r   c                 &     || j                    d S r#   rp   r'   s     r   r)   z%FlattenScriptObjectSource.reconstruct  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   z&FlattenScriptObjectSource.guard_source  rt   r*   c                 :    | j                                          dS )Nz.__obj_flatten__()rv   r-   s    r   r1   zFlattenScriptObjectSource.name  s    )..""6666r*   Nr2   r   r:   r*   r   r   r     sU        % % %   ( ( (7 7 7 7 7r*   r   c                   (    e Zd Zd ZddZd Zd ZdS )	ScriptObjectQualifiedNameSourcec                     | j         J d S r#   rp   r-   s    r   r   z-ScriptObjectQualifiedNameSource.__post_init__  r   r*   r!   r   c                 &     || j                    d S r#   rp   r'   s     r   r)   z+ScriptObjectQualifiedNameSource.reconstruct  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   z,ScriptObjectQualifiedNameSource.guard_source  rt   r*   c                 :    | j                                          dS )Nz._type().qualified_name()rv   r-   s    r   r1   z$ScriptObjectQualifiedNameSource.name  s    )..""====r*   Nr2   r   r:   r*   r   r   r     sU        % % %   ( ( (> > > > >r*   r   c                   "    e Zd ZddZd Zd ZdS )AttrProxySourcer!   r   c                 &     || j                    d S r#   rp   r'   s     r   r)   zAttrProxySource.reconstruct  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zAttrProxySource.guard_source  rt   r*   c                 :    | j                                          dS )Nz.get_base()rv   r-   s    r   r1   zAttrProxySource.name  s    )..""////r*   Nr2   rw   r:   r*   r   r   r     sF           ( ( (0 0 0 0 0r*   r   c                       e Zd ZU eeef         ed<   dZeed<    e	j
        ddd          Z
eed<    e	j
        ddd          Zeed<   d Zdd
Zd Zd ZdS )DefaultsSourceidx_keyFis_kw)initr0   comparefield_namec           
      2   | j         s
J d            | j        rt          | j        t                    sJ t
                              | dd           t
                              | d| j                                          d| j         d| j         d           d S t          | j        t                    sJ t
                              | dd           t
                              | d| j                                          d| j         d	| j         d
           d S )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__[r/   )
rq   r  r   r  r6   r   r   r1   r  rP   r-   s    r   r   zDefaultsSource.__post_init__  s6   y 	
 	
k	
 	
 	
 : 	dlC00000tW.>???g$).."2"2SSTZSS4<SSS     dlC00000tWn===g$).."2"2QQTZQQ$,QQQ    r*   r!   r   c                     || j                    |                    |                    | j                             |                    |                    | j                             |                    t          d                     d S rH   )rq   ri   r   r  r%   rM   r  r   r'   s     r   r)   zDefaultsSource.reconstruct  s    	g77
CCDDDg77EEFFF0AABBBBBr*   c                 4    | j                                         S r#   rs   r-   s    r   r   zDefaultsSource.guard_source	  rt   r*   c                     | j         S r#   )r	  r-   s    r   r1   zDefaultsSource.name  s
    zr*   Nr2   )r3   r4   r5   r   rP   r6   r7   r  r8   dataclassesr  r	  r   r)   r   r1   r:   r*   r   r  r    s         38_E4""E5IIIE3III""E5IIIE3III  "C C C C( ( (    r*   r  c                   R     e Zd ZU eed<   dZeed<    fdZddZd Z	d	 Z
d
 Z xZS )GetItemSourceindexFindex_is_slicec                    | j         J t          | j        t                    r]t	                                          d| j                                                   t	                                          dd           d S d S )Nr  r  T)rq   r   r  slicesuperr   
__reduce__)r(   	__class__s    r   r   zGetItemSource.__post_init__  sx    y$$$dj%(( 	8GG)>)>)@)@AAAGG 0$77777	8 	8r*   r!   r   c                 H    || j                    | j        r;|                    |                    |                                                      n-|                    |                    | j                             |                    t          d                     d S rH   )rq   r  r%   rM   unpack_slicer  r   r'   s     r   r)   zGetItemSource.reconstruct  s    	 	I!!'";";D<M<M<O<O"P"PQQQQ!!'";";DJ"G"GHHH0AABBBBBr*   c                 4    | j                                         S r#   rs   r-   s    r   r   zGetItemSource.guard_source$  rt   r*   c                 2    | j         sJ | j        \  }} || S r#   )r  r  )r(   slice_class
slice_argss      r   r  zGetItemSource.unpack_slice'  s*    """""&*Z{J''r*   c                     t          | j        t                    rJ | j        r1| j                                         d|                                 dS | j                                         d| j        dS Nr  r/   )r   r  r	   r  rq   r1   r  r-   s    r   r1   zGetItemSource.name,  s{     dj&11111 	9inn&&AA):):)<)<AAAAinn&&888888r*   r2   )r3   r4   r5   r   r7   r  r8   r   r)   r   r  r1   __classcell__)r  s   @r   r  r    s         JJJ ND   8 8 8 8 8C C C C( ( (( ( (
9 9 9 9 9 9 9r*   r  c                   4    e Zd ZU eed<   d Zd	dZd Zd ZdS )
ConstDictKeySourcer  c                 4    | j                                         S r#   rs   r-   s    r   r   zConstDictKeySource.guard_source;  rt   r*   r!   r   c                                          fd            | j                                                           | j                                                 t          dd                     d S )Nc                  D                          t          j        d          S )Ndict_keys_getitemr   r   r3   r!   s   r   rf   z0ConstDictKeySource.reconstruct.<locals>.<lambda>@  s    G,,U^=PQQ r*   r   Frh   rq   r%   rM   r  ri   r   r'   s    `r   r)   zConstDictKeySource.reconstruct>  s    QQQQ	
 	
 	
 		g77
CCDDD21e<<=====r*   c                 L    d| j                                          d| j        dS )Nzlist(dict.keys(z))[r/   rq   r1   r  r-   s    r   r1   zConstDictKeySource.nameF  s)    E!1!1EEdjEEEEr*   c                     dS r   r:   r-   s    r   is_dict_keyzConstDictKeySource.is_dict_keyJ  r   r*   Nr2   )	r3   r4   r5   r   r7   r   r)   r1   r0  r:   r*   r   r%  r%  7  sc         JJJ( ( (> > > >F F F    r*   r%  c                   4    e Zd ZU eed<   d Zd Zd	dZd ZdS )
DictGetItemSourcer  c                     ddl m} t          | j        t                    s|                    | j                  sJ d S d S Nr
   )ConstantVariable	variablesr5  r   r  r%  
is_literalr(   r5  s     r   r   zDictGetItemSource.__post_init__V  d    //////J*
 
 	5((44	5 	5 	5 	5 	5 	5 	5r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zDictGetItemSource.guard_source]  rt   r*   r!   r   c                     || j                    t          | j        t                    r || j                   n-|                    |                    | j                             |                    t          d                     d S rH   )rq   r   r  r	   r%   rM   r   r'   s     r   r)   zDictGetItemSource.reconstruct`  s    	 dj&)) 	IGDJ!!'";";DJ"G"GHHH0AABBBBBr*   c                     t          | j        t                    r6| j                                         d| j                                         dS | j                                         d| j        dS r"  r   r  r%  rq   r1   r-   s    r   r1   zDictGetItemSource.namek  sk    dj"455 	9inn&&==):):====inn&&888888r*   Nr2   	r3   r4   r5   r   r7   r   r   r)   r1   r:   r*   r   r2  r2  O  sf         
 JJJ5 5 5( ( (	C 	C 	C 	C9 9 9 9 9r*   r2  c                   4    e Zd ZU eed<   d Zd Zd	dZd ZdS )
DictSubclassGetItemSourcer  c                     ddl m} t          | j        t                    s|                    | j                  sJ d S d S r4  r6  r9  s     r   r   z'DictSubclassGetItemSource.__post_init__{  r:  r*   c                 4    | j                                         S r#   rs   r-   s    r   r   z&DictSubclassGetItemSource.guard_source  rt   r*   r!   r   c                 N                        fd            | j                   t          | j        t                    r | j                   n-                                        | j                                                 t          dd                     d S )Nc                  D                          t          j        d          S )Ndict_getitemr*  r+  s   r   rf   z7DictSubclassGetItemSource.reconstruct.<locals>.<lambda>      G,,U^^LL r*   r   F)	rh   rq   r   r  r	   r%   rM   ri   r   r'   s    `r   r)   z%DictSubclassGetItemSource.reconstruct  s     	LLLL	
 	
 	

 		 dj&)) 	IGDJ!!'";";DJ"G"GHHH21e<<=====r*   c                     t          | j        t                    r7d| j                                         d| j                                         dS | j                                         d| j        dS )Nzdict.__getitem__(r   r   r  r/   r>  r-   s    r   r1   zDictSubclassGetItemSource.name  sm    dj"455 	9Oty~~'7'7OO4:??;L;LOOOOinn&&888888r*   Nr2   r?  r:   r*   r   rA  rA  t  sb         
 JJJ5 5 5( ( (> > > >&9 9 9 9 9r*   rA  c                        e Zd ZdZddZd ZdS )ListGetItemSourcezY
    Same as GetItemSource with reconstruct and name overridden to be list specific.
    r!   r   c                 $                        fd            | j                   | j        rt          d                                                  | j                                                 t          dd                     d S )Nc                  D                          t          j        d          S )Nlist_getitemr*  r+  s   r   rf   z/ListGetItemSource.reconstruct.<locals>.<lambda>  rG  r*   >List[slice] is a temporary object and should not have a sourcer   F)	rh   rq   r  RuntimeErrorr%   rM   r  ri   r   r'   s    `r   r)   zListGetItemSource.reconstruct  s    
 	LLLL	
 	
 	

 		  	IP   !!'";";DJ"G"GHHH21e<<=====r*   c                     t          | j        t                    rJ | j        rt	          d          d| j                                         d| j        dS )NrN  zlist.__getitem__(r   r   )r   r  r	   r  rO  rq   r1   r-   s    r   r1   zListGetItemSource.name  sg     dj&11111 	KP   Kty~~'7'7JJ4:JJJJr*   Nr2   )r3   r4   r5   r   r)   r1   r:   r*   r   rJ  rJ    sF         > > > >,
K 
K 
K 
K 
Kr*   rJ  c                       e Zd ZddZd ZdS )TupleIteratorGetItemSourcer!   r   c                                          fd            | j                                                           | j                                                 t          dd                     d S )Nc                  D                          t          j        d          S )Ntuple_iterator_getitemr*  r+  s   r   rf   z8TupleIteratorGetItemSource.reconstruct.<locals>.<lambda>  s    G,,U^=UVV r*   r   Fr,  r'   s    `r   r)   z&TupleIteratorGetItemSource.reconstruct  s    VVVV	
 	
 	
 		g77
CCDDD21e<<=====r*   c                 L    d| j                                          d| j        dS )Nz___tuple_iterator_getitem(r   r   r.  r-   s    r   r1   zTupleIteratorGetItemSource.name  s)    ODINN,<,<OO
OOOOr*   Nr2   )r3   r4   r5   r)   r1   r:   r*   r   rR  rR    s<        > > > >P P P P Pr*   rR  c                   "    e Zd ZddZd Zd ZdS )DataclassFieldsSourcer!   r   c                                          fd            | j                                       t          dd                     d S )Nc                  D                          t          j        d          S )Ndataclass_fieldsr*  r+  s   r   rf   z3DataclassFieldsSource.reconstruct.<locals>.<lambda>  s    G,,U^=OPP r*   r
   Frh   rq   ri   r   r'   s    `r   r)   z!DataclassFieldsSource.reconstruct  s`    PPPP	
 	
 	
 		21e<<=====r*   c                 4    | j                                         S r#   rs   r-   s    r   r   z"DataclassFieldsSource.guard_source  rt   r*   c                 <    d| j                                          dS )Nz___dataclass_fields(r   rv   r-   s    r   r1   zDataclassFieldsSource.name  s    9dinn&6&69999r*   Nr2   rw   r:   r*   r   rX  rX    sF        > > > >( ( (: : : : :r*   rX  c                   (    e Zd Zd ZddZd Zd ZdS )	
TypeSourcec                     | j         J d S r#   rp   r-   s    r   r   zTypeSource.__post_init__  r   r*   r!   r   c                                          fd            | j                                       t          dd                     d S )Nc                  0                          dd          S )Nbuiltinstyper   r+  s   r   rf   z(TypeSource.reconstruct.<locals>.<lambda>  s    g&>&>z6&R&R r*   r
   Fr\  r'   s    `r   r)   zTypeSource.reconstruct  sX    RRRRSSS	21e<<=====r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zTypeSource.guard_source  rt   r*   c                 <    d| j                                          dS )Nztype(r   rv   r-   s    r   r1   zTypeSource.name  s    *ty~~''****r*   Nr2   r   r:   r*   r   r`  r`    sU        % % %> > > >
( ( (+ + + + +r*   r`  c                   "    e Zd ZddZd Zd ZdS )OptimizerSourcer!   r   c                 &     || j                    d S r#   rp   r'   s     r   r)   zOptimizerSource.reconstruct  r   r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zOptimizerSource.guard_source  rt   r*   c                 4    | j                                         S r#   rv   r-   s    r   r1   zOptimizerSource.name      y~~r*   Nr2   rw   r:   r*   r   rj  rj    sF           ( ( (         r*   rj  c                   "    e Zd ZddZd Zd ZdS )NNModuleSourcer!   r   c                 &     || j                    d S r#   rp   r'   s     r   r)   zNNModuleSource.reconstruct  r   r*   c                 J    t           | j                                                 S r#   r   r-   s    r   r   zNNModuleSource.guard_source  r   r*   c                 4    | j                                         S r#   rv   r-   s    r   r1   zNNModuleSource.name  rn  r*   Nr2   rw   r:   r*   r   rp  rp    sI           M M M         r*   rp  c                       e Zd Zd ZdS )UnspecializedNNModuleSourcec                 J    t           | j                                                 S r#   )%_GUARD_SOURCE_UNSPECIALIZED_NN_MODULErq   r   r-   s    r   r   z(UnspecializedNNModuleSource.guard_source  s    4TY5K5K5M5MNNr*   Nr   r:   r*   r   ru  ru    s(        O O O O Or*   ru  c                       e Zd Zd ZdS )"UnspecializedBuiltinNNModuleSourcec                 J    t           | j                                                 S r#   )-_GUARD_SOURCE_UNSPECIALIZED_BUILTIN_NN_MODULErq   r   r-   s    r   r   z/UnspecializedBuiltinNNModuleSource.guard_source  s    <TY=S=S=U=UVVr*   Nr   r:   r*   r   ry  ry    s(        W W W W Wr*   ry  c                       e Zd Zd ZdS )FSDPNNModuleSourcec                 J    t           | j                                                 S r#   )_GUARD_SOURCE_FSDP_MODULErq   r   r-   s    r   r   zFSDPNNModuleSource.guard_source  s    ()?)?)A)ABBr*   Nr   r:   r*   r   r}  r}    s(        C C C C Cr*   r}  c                       e Zd Zd Zd ZdS )GlobalStateSourcec                     dS Nr   r:   r-   s    r   r1   zGlobalStateSource.name#      rr*   c                     t           j        S r#   r[   r-   s    r   r   zGlobalStateSource.guard_source&  r]   r*   Nr3   r4   r5   r1   r   r:   r*   r   r  r  !  s2          " " " " "r*   r  c                   4    e Zd ZU eed<   d Zd Zd	dZd ZdS )
TorchFunctionModeStackSourceindc                 2    d|                                   dS )Nz$___get_torch_function_mode_stack_at(r   )
_get_indexr-   s    r   r1   z!TorchFunctionModeStackSource.name.  s    Jdoo6G6GJJJJr*   c                 B    ddl m} |                    | j                  S )Nr
   )TorchFunctionModeStackVariable)variables.torch_functionr  get_mode_indexr  )r(   r  s     r   r  z'TorchFunctionModeStackSource._get_index1  s*    LLLLLL-<<TXFFFr*   r!   r   c                                          fd                                                   |                                           g                               t	          dd                     d S )Nc                  D                          t          j        d          S )N get_torch_function_mode_stack_atr*  r+  s   r   rf   z:TorchFunctionModeStackSource.reconstruct.<locals>.<lambda>8  s    G,, B  r*   r
   F)rh   ri   rM   r  r   r'   s    `r   r)   z(TorchFunctionModeStackSource.reconstruct6  s       	
 	
 	

 	w889J9JKKLMMM21e<<=====r*   c                     t           j        S r#   r[   r-   s    r   r   z)TorchFunctionModeStackSource.guard_source?  r]   r*   Nr2   )	r3   r4   r5   rP   r7   r1   r  r)   r   r:   r*   r   r  r  *  sf         	HHHK K KG G G
> > > >" " " " "r*   r  c                   4    e Zd ZU eed<   d	dZd Zd Zd ZdS )
r   source_namer!   r   c                 d    |                     |                    | j        d                     d S )NFrV   )r%   rY   r  r'   s     r   r)   zConstantSource.reconstructG  s2    g889Iu8UUVVVVVr*   c                     t           j        S r#   )r   r   r-   s    r   r   zConstantSource.guard_sourceJ  s    ##r*   c                     | j         S r#   )r  r-   s    r   r1   zConstantSource.nameM  s    r*   c                     t           r#   r   r   s     r   r   zConstantSource.make_guardP  r   r*   Nr2   )	r3   r4   r5   r6   r7   r)   r   r1   r   r:   r*   r   r   r   C  sg         W W W W$ $ $     " " " " "r*   r   c                   (    e Zd ZdefdZd ZddZdS )	NumpyTensorSourcereturnc                 <    d| j                                          dS )Nz___from_numpy(r   rv   r-   s    r   r1   zNumpyTensorSource.nameV  s    3	 0 03333r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zNumpyTensorSource.guard_sourceY  rt   r*   r!   r   c                                          fd            | j                                       t          dd                     d S )Nc                  0                          dd          S )Ntorch	as_tensorrf  r+  s   r   rf   z/NumpyTensorSource.reconstruct.<locals>.<lambda>]  s    g&>&>w&T&T r*   r
   Fr\  r'   s    `r   r)   zNumpyTensorSource.reconstruct\  sX    TTTTUUU	21e<<=====r*   Nr2   )r3   r4   r5   r6   r1   r   r)   r:   r*   r   r  r  T  sR        4c 4 4 4 4( ( (> > > > > >r*   r  c                        e Zd ZdefdZd ZdS )SubclassAttrListSourcer  c                 :    | j                                          dS )Nz.__tensor_flatten__()[0]rv   r-   s    r   r1   zSubclassAttrListSource.named  s    )..""<<<<r*   c                 4    | j                                         S r#   rs   r-   s    r   r   z#SubclassAttrListSource.guard_sourceg  rt   r*   Nr3   r4   r5   r6   r1   r   r:   r*   r   r  r  b  s>        =c = = = =( ( ( ( (r*   r  c                        e Zd ZdefdZd ZdS )FloatTensorSourcer  c                 <    d| j                                          dS )Nz___as_tensor(r   rv   r-   s    r   r1   zFloatTensorSource.nameo  s    2ty~~//2222r*   c                 4    | j                                         S r#   rs   r-   s    r   r   zFloatTensorSource.guard_sourcer  rt   r*   Nr  r:   r*   r   r  r  m  s>        3c 3 3 3 3( ( ( ( (r*   r  c                        e Zd ZdefdZd ZdS )CallMethodItemSourcer  c                 :    | j                                          dS )Nz.item()rv   r-   s    r   r1   zCallMethodItemSource.namex  s    )..""++++r*   c                 4    | j                                         S r#   rs   r-   s    r   r   z!CallMethodItemSource.guard_source{  rt   r*   Nr  r:   r*   r   r  r  v  s>        ,c , , , ,( ( ( ( (r*   r  c                       e Zd Zd Zd ZdS )ShapeEnvSourcec                     dS r  r:   r-   s    r   r1   zShapeEnvSource.name  r  r*   c                     t           j        S r#   )r   	SHAPE_ENVr-   s    r   r   zShapeEnvSource.guard_source  r   r*   Nr  r:   r*   r   r  r    s2          % % % % %r*   r  c                       e Zd Zd Zd ZdS )BackwardStateSourcec                     dS r  r:   r-   s    r   r1   zBackwardStateSource.name  r  r*   c                     t           j        S r#   )r   BACKWARD_STATEr-   s    r   r   z BackwardStateSource.guard_source  s    ))r*   Nr  r:   r*   r   r  r    s2          * * * * *r*   r  Fonly_allow_inputr   r  c                    t          | t                    rt          | j        |          S t          | t                    sd S |r	| j        sd S | j        S Nr  )r   r   get_local_source_namerq   r   r   r   r   r  s     r   r  r    sa    &-(( U$V[CSTTTTfk** t  tr*   c                (    t          | |          d uS r  )r  r  s     r   is_from_local_sourcer    s     :JKKKSWWWr*   c                 $    t          |           d uS r#   )get_global_source_namer   s    r   is_from_global_sourcer    s    !&))55r*   c                     t          | t                    rt          | j                  S t          | t                    sd S | j        S r#   )r   r   r  rq   rR   rS   r   s    r   r  r    sD    &-(( 3%fk222fl++ tr*   c                     t          | t                    rt          | j                  S t          | t                    o| j        o| j         S r#   )r   r   is_from_nonlocal_sourcerq   r   r    r   r   s    r   r  r    sN    &-(( 4&v{3336;'' 	 +	 r*   targetc                 b    t          | t                    rt          | j        |          S | |k    S r#   )r   r   is_from_sourcerq   )r   r  s     r   r  r    s1    &-(( 3fk6222Vr*   c                     t          | t                    rdS t          | t                    rt          | j                  S dS r   )r   ru  r   &is_from_unspecialized_nn_module_sourcerq   r   s    r   r  r    sB    &566 t&-(( C5fkBBB5r*   c                     t          | t                    rdS t          | t                    rt          | j                  S dS r   )r   ry  r   .is_from_unspecialized_builtin_nn_module_sourcerq   r   s    r   r  r    sB    &<== t&-(( K=fkJJJ5r*   c                     t          | t                    rdS t          | t                    rt          | j                  S dS r   )r   r   r   )is_from_unspecialized_param_buffer_sourcerq   r   s    r   r  r    sB    &899 t&-(( F8EEE5r*   c                     t          | t                    rdS t          | t                    rt          | j                  S dS r   )r   r   r   $is_from_flatten_script_object_sourcerq   r   s    r   r  r    sC    &344 At	FM	*	* A3FK@@@5r*   c                     t          | t                    rdS t          | t                    rt          | j                  S dS r   )r   rj  r   is_from_optimizer_sourcerq   r   s    r   r  r    s@    &/** t&-(( 5'4445r*   c                    t          | t                    rdS t          | t                    r,t          | j        t                    r| j        j        dk    rdS t          | t                    r,t          | j        t                    r| j        j        dk    rdS t          | t                    rt          | j                  S dS )NTr  r  F)	r   r  r2  rq   r}   r~   r  r   is_from_defaultsr   s    r   r  r    s    &.)) t 	6,--v{J// K"222t 	6=))v{J// K.00t&-(( -,,,5r*   )ar   r  enum	functoolstypingr   r   r   r   torch._guardsr   r   r	   r   r   bytecode_transformationr   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   rw  r{  r  r   	dataclassr   r<   rC   rR   rb   rm   ry   r}   r   r   r   r   r   r   Enumr   r   r   r   r   r   r   r   r  r  r%  r2  rA  rJ  rR  rX  r`  rj  rp  ru  ry  r}  r  r  r   r  r  r  r  r  r  r6   r  r  r8   r  r  r  r  	lru_cacher  r  r  r  r  r  r:   r*   r   <module>r     s6   &          6 6 6 6 6 6 6 6 6 6 6 6 < < < < < < < < < <       M M M M M M M M  #"""""" {>@+[-T,k.V-{/X.0Z5{7h68j!;#@"K$B' #  {@B-{/X.0Z+[-V,k.X5{7h68j!;#@"K$B) %" {HJ-{/`.0b+[-^,k.`5{7h68j!;#@"K$B1 - {46+[-J,k.L!;#@"K$B-{/L.0N5{7T68V 	 	 	 d###- - - - -& - - $#-8 d###
7 
7 
7 
7 
76 
7 
7 $#
7 d###8 8 8 8 8 8 8 $#8 d###
. 
. 
. 
. 
.6 
. 
. $#
. d###0 0 0 0 0& 0 0 $#0$ d###	' 	' 	' 	' 	' 	' 	' $#	' d###	 	 	 	 	0 	 	 $#	 d###3 3 3 3 3 3 3 $#32 d###O O O O O O O $#O. d###L L L L Lf L L $#L, d###3 3 3 3 3 3 3 $#3 d###M M M M M
 M M $#M d###	 	 	 	 	Z 	 	 $#	 d###    f   $# $ $ $ $ $TY $ $ $ d###%; %; %; %; %;= %; %; $#%;P d###3 3 3 3 3M 3 3 $#3  d###/ / / / /= / / $#/ d###G G G G G} G G $#G d###7 7 7 7 7 7 7 $#7 d###> > > > >m > > $#>0 0 0 0 0m 0 0 0 d###! ! ! ! !] ! ! $#!H d####9 #9 #9 #9 #9M #9 #9 $##9L d###       $#. d###9 9 9 9 9 9 9 $#9H d###'9 '9 '9 '9 '9 '9 '9 $#'9T d###%K %K %K %K %K %K %K $#%KP d###
P 
P 
P 
P 
P 
P 
P $#
P d###: : : : :M : : $#: d###+ + + + + + + $#+  d###         m     $#  d###         ]     $#  d###O O O O O. O O $#O
 d###W W W W W)D W W $#W
 d###C C C C C C C $#C
 d###" " " " " " " $#" d###" " " " "6 " " $#"0 d###" " " " "V " " $#"  d###
> 
> 
> 
> 
> 
> 
> $#
> d###( ( ( ( (] ( ( $#( d###( ( ( ( ( ( ( $#( d###( ( ( ( (= ( ( $#( d###% % % % %V % % $#% d###* * * * *& * * $#* ?D   & QT     >C X X X X X X X6& 6T 6 6 6 66 hsm    F    6 6     6     6     f          V     V      r*   