
    Phu:                        d dl Z d dlZd dlZd dl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 ddlmZ 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.                  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&                  iZd Zd	 Zd
ed   f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# G d dejH                        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/ d0e.             Z/ ej:                  d       G d1 d2e.             Z0 ej:                  d       G d3 d4e
             Z1 ej:                  d       G d5 d6e
             Z2 ej:                  d       G d7 d8e             Z3 ej:                  d       G d9 d:e
             Z4dd;d
e
fd<Z5y)=    N)AnyOptionalUnion)ChainedSourceGuardSourceSource   )utils)create_call_functioncreate_instruction)	enum_reprc                     t        | t              ry	 | j                         t        j                  k(  ry	 y# t
        $ r Y yw xY w)NTF)
isinstanceConstantSourceguard_sourcer   CONSTANTNotImplementedErrorsources    _C:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/source.pyis_constant_sourcer   (   sO    &.) K$8$88 9
   s   !7 	AAc                     | j                         t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  fv S N)r   r   LOCALGLOBALLOCAL_NN_MODULEGLOBAL_NN_MODULELOCAL_FSDP_MODULEGLOBAL_FSDP_MODULEr   s    r   is_input_sourcer    4   sS     ##$$%%&&%      r   )GetItemSourceODictGetItemSourcec                    | j                   j                  |      }t        | j                  t              r,|j                  | j                  j                  |             |S |rBt        | t              sJ |j                  |j                  | j                                      |S |j                  |j                  | j                               |S r   )
basereconstructr   indexr   extendr"   appendcreate_load_constunpack_slice)r   codegenindex_is_sliceinstrss       r   reconstruct_getitemr/   ?   s     [[$$W-F&,,'fll..w78 M fm444MM'33F4G4G4IJK M MM'33FLLABMr!   T)frozenc                   8    e Zd ZU eed<   dZeed<   d Zd Zd Z	y)LocalSource
local_nameFcell_or_freevarc                 :    |j                  | j                        gS r   )create_loadr3   selfr,   s     r   r&   zLocalSource.reconstructU   s    ##DOO455r!   c                 "    t         j                  S r   )r   r   r8   s    r   r   zLocalSource.guard_sourceX   s       r!   c                 4    dt        | j                         dS )NzL[])reprr3   r:   s    r   namezLocalSource.name[   s    D)*!,,r!   N)
__name__
__module____qualname__str__annotations__r4   boolr&   r   r>    r!   r   r2   r2   P   s     O!OT!6!-r!   r2   c                   *    e Zd ZU eed<   d Zd Zd Zy)RandomValueSourcerandom_call_indexc                 "    t         j                  S r   )r   RANDOM_VALUEr:   s    r   r   zRandomValueSource.guard_sourcec   s    '''r!   c                     |j                  |j                  j                  j                        |j	                  | j
                        t        d      gS NBINARY_SUBSCR)r6   txoutputrandom_values_varr*   rH   r   r7   s     r   r&   zRandomValueSource.reconstructf   sF    

 1 1 C CD%%d&<&<=/
 	
r!   c                      d| j                    S )Nrandom_value_)rH   r:   s    r   r>   zRandomValueSource.namem   s    t55677r!   N)r?   r@   rA   intrC   r   r&   r>   rE   r!   r   rG   rG   _   s    (
8r!   rG   c                   *    e Zd ZU eed<   d Zd Zd Zy)GlobalSourceglobal_namec                 @    |j                  | j                  dd      gS )NFTadd)create_load_globalrV   r7   s     r   r&   zGlobalSource.reconstructu   s#    **4+;+;U*MNNr!   c                 "    t         j                  S r   r   r   r:   s    r   r   zGlobalSource.guard_sourcex       !!!r!   c                 4    dt        | j                         dS )NG[r<   r=   rV   r:   s    r   r>   zGlobalSource.name{   s    D))*+1--r!   Nr?   r@   rA   rB   rC   r&   r   r>   rE   r!   r   rU   rU   q   s    O".r!   rU   c                   *    e Zd ZU eed<   d Zd Zd Zy)GlobalWeakRefSourcerV   c                 X    |j                  | j                  dd      gt        dd      S )NTrX   r   F)rZ   rV   r   r7   s     r   r&   zGlobalWeakRefSource.reconstruct   s6    &&t'7'74&H
!!U+
 	
r!   c                 "    t         j                  S r   r\   r:   s    r   r   z GlobalWeakRefSource.guard_source   r]   r!   c                 4    dt        | j                         dS )Nr_   z]()r`   r:   s    r   r>   zGlobalWeakRefSource.name   s    D))*+3//r!   Nra   rE   r!   r   rc   rc      s    
"0r!   rc   c                   0    e Zd ZU eed<   d Zd Zd Zd Zy)
AttrSourcememberc                 ,   | j                   sJ d       d| j                  v rs| j                  j                  d      }t        j	                  | dt        | j                   dj                  |d d                    t        j	                  | d|d          y y )Nz9Can't construct an AttrSource without a valid base source.r%   ri   )r%   ri   splitobject__setattr__rh   join)r8   member_partss     r   __post_init__zAttrSource.__post_init__   s    yyUUUy$++;;,,S1LfjCHH\#2=N4OP tX|B/?@ r!   c                 p    | j                   j                  |      |j                  | j                        z   S r   )r%   r&   create_load_attrsri   r7   s     r   r&   zAttrSource.reconstruct   s+    yy$$W-0I0I$++0VVVr!   c                 6    | j                   j                         S r   r%   r   r:   s    r   r   zAttrSource.guard_source       yy%%''r!   c                     | j                   j                         s+d| j                  j                          d| j                   dS | j                  j                          d| j                    S )Nzgetattr(, )rk   )ri   isidentifierr%   r>   r:   s    r   r>   zAttrSource.name   sX    {{'')diinn./r$++BB)).."#1T[[M22r!   N)	r?   r@   rA   rB   rC   rr   r&   r   r>   rE   r!   r   rh   rh      s    KAW(3r!   rh   c                       e Zd Zd Zy)ParamBufferSourcec                 D    t         | j                  j                            S r   _GUARD_SOURCE_NN_MODULEr%   r   r:   s    r   r   zParamBufferSource.guard_source       &tyy'='='?@@r!   Nr?   r@   rA   r   rE   r!   r   r}   r}      s    Ar!   r}   c                       e Zd ZdZdZdZd Zy)TensorPropertyr   r	      c                 v    | t         j                  u ry| t         j                  u ry| t         j                  u ryy )Nsizestridestorage_offset)r   SIZESTRIDESTORAGE_OFFSETr:   s    r   method_namezTensorProperty.method_name   s:    >&&&^***^222# 3r!   N)r?   r@   rA   r   r   r   r   rE   r!   r   r   r      s    DFN$r!   r   c                   D    e Zd ZU eed<   dZee   ed<   d Zd Z	d Z
d Zy)TensorPropertySourcepropNidxc                     | j                   J | j                  t        j                  u r| j                  J y | j                  J y r   )r%   r   r   r   r   r:   s    r   rr   z"TensorPropertySource.__post_init__   sD    yy$$$9955588###88'''r!   c                 P   g | j                   j                  |      |j                  | j                  j	                               }| j
                  *|j                  |j                  | j
                               |j                  t        | j
                  dndd             |S )Nr	   r   T)
r%   r&   create_load_attrr   r   r   r)   r*   r(   r   )r8   r,   instructionss      r   r&   z TensorPropertySource.reconstruct   s    
YY""7+
$$TYY%:%:%<=
 88 9 9$(( CD dhh&:4H	
 r!   c                 6    | j                   j                         S r   rv   r:   s    r   r   z!TensorPropertySource.guard_source   rw   r!   c                    | j                   t        j                  u r*| j                  j	                          d| j
                   dS | j                   t        j                  u r*| j                  j	                          d| j
                   dS | j                   t        j                  u r+| j
                  J | j                  j	                          dS t        d| j                          )Nz.size()[r<   z
.stride()[z.storage_offset()z
unhandled )	r   r   r   r%   r>   r   r   r   AssertionErrorr:   s    r   r>   zTensorPropertySource.name   s    99+++iinn&'xz;;YY.///iinn&'z$((1==YY.77788###iinn&''899 :dii[!9::r!   )r?   r@   rA   r   rC   r   r   rS   rr   r&   r   r>   rE   r!   r   r   r      s*    
C#(
(	;r!   r   c                   $    e Zd Zd Zd Zd Zd Zy)NegateSourcec                      | j                   J y r   r%   r:   s    r   rr   zNegateSource.__post_init__       yy$$$r!   c                     t               r   r   r7   s     r   r&   zNegateSource.reconstruct       !##r!   c                 6    | j                   j                         S r   rv   r:   s    r   r   zNegateSource.guard_source   rw   r!   c                 <    | j                   j                          dS )Nz
.__neg__()r%   r>   r:   s    r   r>   zNegateSource.name   s    )).."#:..r!   Nr?   r@   rA   rr   r&   r   r>   rE   r!   r   r   r      s    %$(/r!   r   c                   $    e Zd Zd Zd Zd Zd Zy)ConvertIntSourcec                      | j                   J y r   r   r:   s    r   rr   zConvertIntSource.__post_init__   r   r!   c                 8    | j                   j                  |      S r   r%   r&   r7   s     r   r&   zConvertIntSource.reconstruct       yy$$W--r!   c                 6    | j                   j                         S r   rv   r:   s    r   r   zConvertIntSource.guard_source   rw   r!   c                 >    d| j                   j                          dS )Nz!cast_symbool_to_symint_guardless(rz   r   r:   s    r   r>   zConvertIntSource.name   s    2499>>3C2DAFFr!   Nr   rE   r!   r   r   r      s    %.(Gr!   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 Zd	 Zd
 Zy)DefaultsSourceidx_keyFis_kw)initr=   comparefield_namec           
      @   | j                   sJ d       | j                  rt        | j                  t              sJ t
        j                  | dd       t
        j                  | d| j                   j                          d| j                   d| j                   d       y t        | j                  t              sJ t
        j                  | dd       t
        j                  | d| j                   j                          d| j                   d	| j                   d
       y )Nz]Base must be a valid source in order to properly track and guard this Defaults to its origin.r   __kwdefaults__r   rk   z['z']__defaults__[r<   )
r%   r   r   r   rB   rn   ro   r>   r   rS   r:   s    r   rr   zDefaultsSource.__post_init__
  s    II	kj	k::dllC000tW.>?g$)).."2!31TZZL4<<.PRS dllC000tWn=g$)).."2!31TZZL$,,qQr!   c                     | j                   j                  |      }|j                  |j                  | j                               |j                  |j                  | j                        t        d      g       |S rL   )r%   r&   r(   rt   r   r*   r   r   )r8   r,   r.   s      r   r&   zDefaultsSource.reconstruct  sc    &&w/g//

;<))$,,7"?3	
 r!   c                 6    | j                   j                         S r   rv   r:   s    r   r   zDefaultsSource.guard_source&  rw   r!   c                     | j                   S r   )r   r:   s    r   r>   zDefaultsSource.name)  s    zzr!   N)r?   r@   rA   r   rS   rB   rC   r   rD   dataclassesr   r   rr   r&   r   r>   rE   r!   r   r   r     sd    38_E4"""E5IE3I"""E5IE3I"	(r!   r   c                   P     e Zd ZU eed<   dZeed<    fdZd Zd Z	d Z
d Z xZS )	r"   r'   Fr-   c                     | j                   J t        | j                  t              r9t        |   d| j                  j                                t        |   dd       y y )Nr'   r-   T)r%   r   r'   slicesuperro   
__reduce__)r8   	__class__s    r   rr   zGetItemSource.__post_init__2  sR    yy$$$djj%(G)>)>)@AG 0$7 )r!   c                 L    g t        | || j                        t        d      S )Nr-   rM   )r/   r-   r   r7   s     r   r&   zGetItemSource.reconstruct9  s0    
 wt?R?RS
/
 	
r!   c                 6    | j                   j                         S r   rv   r:   s    r   r   zGetItemSource.guard_source?  rw   r!   c                 F    | j                   sJ | j                  \  }} || S r   )r-   r'   )r8   slice_class
slice_argss      r   r+   zGetItemSource.unpack_sliceB  s*    """""&**ZJ''r!   c                 V   t        | j                  t              r8| j                  j	                          d| j                  j	                          dS | j
                  r.| j                  j	                          d| j                         dS t        | j                  t        j                        rP| j                  j	                          dt        | j                  | j                         j                                dS | j                  j	                          d| j                  dS )Nr   r<   )r   r'   r   r%   r>   r-   r+   enumEnumr   r   is_localr:   s    r   r>   zGetItemSource.nameG  s    djj&)iinn&'q):(;1==""))..*+1T->->-@,C1EEDJJ		2))..*+1Ytzz4CTCTCVC_C_Ca-b,ccdee))..*+1TZZN!<<r!   )r?   r@   rA   r   rC   r-   rD   rr   r&   r   r+   r>   __classcell__)r   s   @r   r"   r"   -  s+    J ND 8
((
	=r!   r"   c                       e Zd Zd Zd Zy)TupleIteratorGetItemSourcec                     |j                  t        j                  d       g | j                  j	                  |      |j                  | j                        t        dd      S )Ntuple_iterator_getitemr   T)load_import_fromr
   r?   r%   r&   r*   r'   r   r7   s     r   r&   z&TupleIteratorGetItemSource.reconstructU  s`      1IJ
YY""7+
%%djj1
 "!T*
 	
r!   c                 X    d| j                   j                          d| j                  dS )Nz___tuple_iterator_getitem(ry   rz   )r%   r>   r'   r:   s    r   r>   zTupleIteratorGetItemSource.name]  s'    +DIINN,<+=R

~QOOr!   N)r?   r@   rA   r&   r>   rE   r!   r   r   r   S  s    
Pr!   r   c                   $    e Zd Zd Zd Zd Zd Zy)
TypeSourcec                      | j                   J y r   r   r:   s    r   rr   zTypeSource.__post_init__c  r   r!   c                 v    |j                  dd       | j                  j                  |      t        dd      z   S )Nbuiltinstyper	   Tr   r%   r&   r   r7   s     r   r&   zTypeSource.reconstructf  s4      V4yy$$W-0DQ0MMMr!   c                 6    | j                   j                         S r   rv   r:   s    r   r   zTypeSource.guard_sourcej  rw   r!   c                 >    d| j                   j                          dS )Nztype(rz   r   r:   s    r   r>   zTypeSource.namem  s    tyy~~'(**r!   Nr   rE   r!   r   r   r   a  s    %N(+r!   r   c                   0    e Zd ZU eed<   d Zd Zd Zd Zy)r#   r'   c                      | j                   J y r   r   r:   s    r   rr   z ODictGetItemSource.__post_init__u  r   r!   c                     |j                  t        j                  j                        gt	        | |d      t        dd      S )NFr   r   T)_create_load_constcollectionsOrderedDict__getitem__r/   r   r7   s     r   r&   zODictGetItemSource.reconstructx  sH    &&{'>'>'J'JK
 wuE
 "!T*
 	
r!   c                 6    | j                   j                         S r   rv   r:   s    r   r   zODictGetItemSource.guard_source  rw   r!   c                    t        | j                  t              rQd| j                  j                   d| j                  j                   }d| j
                  j                          d| dS t        | j                  t              r9d| j
                  j                          d| j                  j                          dS d| j
                  j                          d| j                  dS )Nz__load_module("z").z___odict_getitem(ry   rz   )r   r'   r   r@   rA   r%   r>   r   )r8   reps     r   r>   zODictGetItemSource.name  s    djj$'#DJJ$9$9#:#djj>U>U=VWC&tyy~~'7&83%qAA

F+&tyy~~'7&84::??;L:MQOO&tyy~~'7&84::.JJr!   N)	r?   r@   rA   r   rC   rr   r&   r   r>   rE   r!   r   r#   r#   q  s    J%
(Kr!   r#   c                       e Zd Zd Zd Zd Zy)NNModuleSourcec                 8    | j                   j                  |      S r   r   r7   s     r   r&   zNNModuleSource.reconstruct  r   r!   c                 D    t         | j                  j                            S r   r   r:   s    r   r   zNNModuleSource.guard_source  r   r!   c                 6    | j                   j                         S r   r   r:   s    r   r>   zNNModuleSource.name  s    yy~~r!   N)r?   r@   rA   r&   r   r>   rE   r!   r   r   r     s    .A r!   r   c                       e Zd Zd Zy)NotNNModuleSourcec                 D    t         | j                  j                            S r   )_GUARD_SOURCE_NOT_NN_MODULEr%   r   r:   s    r   r   zNotNNModuleSource.guard_source  s    *499+A+A+CDDr!   Nr   rE   r!   r   r   r     s    Er!   r   c                       e Zd Zd Zy)FSDPNNModuleSourcec                 D    t         | j                  j                            S r   )_GUARD_SOURCE_FSDP_MODULEr%   r   r:   s    r   r   zFSDPNNModuleSource.guard_source  s    ()?)?)ABBr!   Nr   rE   r!   r   r   r     s    Cr!   r   c                       e Zd Zd Zd Zy)GlobalStateSourcec                      yN rE   r:   s    r   r>   zGlobalStateSource.name      r!   c                 "    t         j                  S r   r\   r:   s    r   r   zGlobalStateSource.guard_source  r]   r!   Nr?   r@   rA   r>   r   rE   r!   r   r   r     s    "r!   r   c                   0    e Zd ZU eed<   d Zd Zd Zd Zy)r   source_namec                 @    |j                  | j                  dd      gS )NFrX   )rZ   r   r7   s     r   r&   zConstantSource.reconstruct  s#    **4+;+;U*NOOr!   c                 "    t         j                  S r   )r   r   r:   s    r   r   zConstantSource.guard_source  s    ###r!   c                     | j                   S r   )r   r:   s    r   r>   zConstantSource.name  s    r!   c                     t               r   r   )r8   fns     r   
make_guardzConstantSource.make_guard  r   r!   N)	r?   r@   rA   rB   rC   r&   r   r>   r  rE   r!   r   r   r     s    P$ $r!   r   c                   $    e Zd ZdefdZd Zd Zy)NumpyTensorSourcereturnc                 >    d| j                   j                          dS )Nz___from_numpy(rz   r   r:   s    r   r>   zNumpyTensorSource.name  s    		 0133r!   c                 6    | j                   j                         S r   rv   r:   s    r   r   zNumpyTensorSource.guard_source  rw   r!   c                 v    |j                  dd       | j                  j                  |      t        dd      z   S )Ntorch	as_tensorr	   Tr   r7   s     r   r&   zNumpyTensorSource.reconstruct  s4      +6yy$$W-0DQ0MMMr!   N)r?   r@   rA   rB   r>   r   r&   rE   r!   r   r  r    s    4c 4(Nr!   r  c                       e Zd Zd Zd Zy)ShapeEnvSourcec                      yr   rE   r:   s    r   r>   zShapeEnvSource.name  r   r!   c                 "    t         j                  S r   )r   	SHAPE_ENVr:   s    r   r   zShapeEnvSource.guard_source  s    $$$r!   Nr   rE   r!   r   r  r    s    %r!   r  allow_cell_or_freevarc                    t        | t              rt        | j                  |      S t        | t              sy|s| j
                  ryy)Nr  FT)r   r   is_from_local_sourcer%   r2   r4   )r   r  s     r   r  r    sC    &-(#KK/D
 	
 fk* V%;%;r!   )6r   r   r   typingr   r   r   torch._guardsr   r   r   r   r
   bytecode_transformationr   r   r   r   r   r   r   r   r   r   r   r   r   r    r/   	dataclassr2   rG   rU   rc   rh   r}   r   r   r   r   r   r   r"   r   r   r#   r   r   r   r   r   r  r  r  rE   r!   r   <module>r     s      ' ' < <  M 
 {2244!<!<  +">">	  {4466!>!>  +"@"@!!;#@#@""K$B$B  {((**!2!2  +"4"4!!;#4#4""K$6$6 	78" d#-& - $- d#8 8 $8" d#
.6 
. $
. d#0& 0 $0  d#3 3 $30 d#A
 A $A
$TYY $ d##;= #; $#;L d#/= / $/ d#G} G $G d#&] & $&R d#"=M "= $"=J d#
P 
P $
P d#+ + $+ d#K K $K4 d# ]   $  d#E E $E
 d#C C $C
 d#" " $" d#$V $ $$  d#	N 	N $	N d#%V % $% CG 	 	r!   