
    Ph7(                       U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	mZmZ d dlmZ d dlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. 	 d dl/Z0	 d dl2Z3d dl4m5Z6 d dl7m8Z8 d dl2m9Z9 dd	l:m;Z; e0re0e0jx                  e0jz                  e0j|                  fZ?e+ej                  d
f   eAd<   e0e6e0jx                  e6jx                  e0jz                  e6jz                  e0j|                  e6j|                  iZBn	 eC       Z?i ZBd dlDmEZEmFZFmGZG d dlIZId dl3Z3d dlJZ3d dlKZ3d dl3mLZL d dlMmNZN d dlOmPZP d dlQmRZR  ej                  ejH                        ZTe%eUe$eU   f   eAd<   dZVdZWdeW dZX ej                  eZ      Z[i Z\e&eUe(e]   f   eAd<   i Z^e&eUe&eUe]f   f   eAd<    ej                         a`d Zad Zbd acd Zdd Zed afd Zgd ZhddZidd!Zje j                  d"        Zle3j                  e3j                  e3j                  fe3j                  e3j                  e3j                  fe3j                  e3j                  e3j                  fe3j                  e3j                  fe3j                  e3j                  fe3j                  e3j                  fe3j                  e3j                  e3j                  fe3j                  e3j                  e3j                   fe3j                  e3j                  e3j                  fe3j                  e3j
                  fi
Z G d# d$      Z e       Zd% Zd& Zd' Zd( Zd) Zd* Zd+eLj                  fd,Zd- Zd. Zd/ Z G d0 d1      Zd2 Zd3 Zd4 Zd5 Zd6 Zd7 Zd8 Z e	j8                  d9      d:        Zdd;Zd< Zej>                   G d= d>             Zej>                   G d? d@             Z G dA dBe      Z e       e_        dC ZddDdEZdF ZedG        ZdH ZddIZdJ ZdK ZdL Z e	j8                  d      dM        ZdN ZddOZdP Z edQ      dR        ZdS ZdT ZdU ZdV ZdW Z e e       js                               Ze,e.e       eAdX<    e ejv                         js                               Ze,e.e       eAdY<    e e eC                   Ze,e'e       eAdZ<   ej~                  Zej                  Zd[ Zd\ Zd] Zd^ Zd_ Zdd`Zda Zdb Zdc Zdd Zd delmZmZ df Zdg Zdh Zdd did djd d e[j                  fdkZdl Zej6                  dm        Z e       Z ej                  e٫      Ze%e e(e    f   eAdn<    e٫       Ze(do   eAdp<    e       Z G dq dr      Z e	j8                  d      ds        Zdt ZdduZdv Zdw ZddxZ ej                         Zdy Zedz        Zd{ Zd| Zd} Zd~e fdZd Zdej                  fdZde fdZde fdZ G d dej                        ZdefdZde-e3j                  e f   deddde+ee)e   f   fdZddZd Zd Zd ZddgZddgZg dZeez   ez   Z	 	 	 ddZ	 	 	 ddZd Zd Z  G d d      Zd Z G d d      Z G d d      Zd Zd Zd Zd ZdeUdedefdZ	ej>                   G d d             Z
deUde)e
   fdZdej                  dej                  deUfdZd Zd ZdddefdZd Zy# e1$ r dZ0Y w xY w# eH$ r Y w xY w)    N)contextmanager)	lru_cachewraps)Path)AnyCallablecastClassVarCounterDefaultDictDictIteratorListOptionalSetTupleTypeUnion
ValuesView)detect_fake_mode
LazyString   )config.NP_SUPPORTED_MODULES)
FakeTensoris_fakemaybe_get_fake_mode)fx)enable_python_dispatcher)LazyModuleMixin)tree_map_onlycountersz<https://pytorch.org/docs/master/compile/troubleshooting.htmlz6https://pytorch.org/docs/master/compile/nn-module.htmlzSee z& for more information and limitations.compilation_time_metricsframe_phase_timingc                     	 dd l }|j                  | |      S # t        $ r0 dj                  d t        j                  |g|       D              cY S w xY w)Nr   headers
c              3   Z   K   | ]#  }d j                  t        t        |             % yw), N)joinmapstr).0rows     ^C:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/utils.py	<genexpr>ztabulate.<locals>.<genexpr>v   s$      
0PDIIc#sm$0Ps   )+)tabulateImportErrorr,   	itertoolschain)rowsr(   r3   s      r1   r3   r3   p   sZ    
  w 77 
yy 
09	40P
 
 	

s    6AAc                 .     t                fd       }|S )Nc                     t        j                  t        t               dz         }t	        j
                         }|j                           |j                  g| i |}|j                          t        dj                   dt        t               d       t        j                  |      }|j                  |       |j                  d      }	 t        j                  dddd	d
dt!        |      gt        j"                        }t        j$                  dddt!        |      g|j&                         t        dt!        |              |S # t(        $ r t        d       |j+                  t        j,                  j.                        j1                  d       |j+                  t        j,                  j2                        j1                  d       Y |S w xY w)Nz.profilez### Cprofile for z iter z ###z.svg	gprof2dotz-fpstatsz"--node-label=total-time-percentagez!--node-label=self-time-percentagez--node-label=total-time)stdoutdotz-Tsvgz-o)stdinzGenerated SVG from profile at zxFailed to generate SVG from profile -- dumping stats instead.Try installing gprof2dot and dot for a better visualization   )r   __name__nexttimer_countercProfileProfileenableruncalldisableprintr;   Stats
dump_statswith_suffix
subprocessPopenr.   PIPE
check_callr<   FileNotFoundError
sort_statsSortKeyTIMEprint_stats
CUMULATIVE)	argskwargsprofile_pathprofretvalpssvg_pathgprof2dot_processfuncs	           r1   profile_wrapperz)cprofile_wrapper.<locals>.profile_wrapper|   s    DMMtM/B.C8,LLM!d4T4V4!$--tM7J6K4PQ\\$%++F3	E * 0 087-% "! !!s8}5'.. 23x=/BC  ! 	EN MM&..--.::2>MM&..334@@D	Es   A:E BGG)r   )r^   r_   s   ` r1   cprofile_wrapperr`   {   s"    
4[$ $L     c                      t         dz   a y Nr   )
curr_frame ra   r1   increment_framerf      s    aJra   c                  X    t         j                          t        j                          day Nr   )r%   clearr$   rd   re   ra   r1   reset_frame_countrj      s    ""$Jra   c                     t         | z  a y N)op_count)cnts    r1   increment_op_countro      s    OHra   c            	         d} i }t         j                         D ]6  }|j                         D ]!  \  }}| |z  } ||vr|||<   ||xx   |z  cc<   # 8 d}|j                         D ]  \  }}| d| dt        |d       } t	        |       y )Ng        zTIMING: :   )r%   valuesitemsroundrH   )totaltotal_by_keytimingskeytimingoutvalues          r1   print_time_reportr~      s    EL%,,."==?KCVOE,&$*S!S!V+! + / C"((*
UQse1U5!_-. + 
#Jra   c                 &    fd}| r ||       S |S )Nc                 V     t         j                  r S t                fd       }|S )Nc                     j                   }|t        vr	g t        |<   t        j                  j	                  | d      5  t        j
                         } | i |}t        j
                         |z
  }d d d        t        |   j                         rDt        t              }|t        vr	i t        |<   t        |   vsJ d d|        |t        |   <   S # 1 sw Y   ixY w)Nz (dynamo_timed)zDuplicate phase name z for frame )
__qualname__r$   torchprofilerrecord_functiontimeappendr.   rd   r%   )	rV   rW   rz   t0r
time_spent	frame_keyr^   
phase_names	          r1   time_wrapperz>dynamo_timed.<locals>.dynamo_timed_inner.<locals>.time_wrapper   s    ##C2202(-//3%0GHYY[$)&)!YY[2-
 I %S)00<
O	$6646&y1&8&CCN*:,k)MNC<F"9-j9H IHs   4CC&)r   cprofiler   )r^   r   r   s   ` r1   dynamo_timed_innerz(dynamo_timed.<locals>.dynamo_timed_inner   s-    ??K	t	 
	& ra   re   )original_functionr   r   s    ` r1   dynamo_timedr      s    4 !"344ra   r.   Fc                 F   d ffd	}| dk(  r9t         D cg c]  }| |t         |   d       f }}d}|t        |d      z  }|S | d	k(  rKt         j                         D cg c]  } ||d
        }}t        t         j	                               }||fS yc c}w c c}w )a  
    Get metrics about torchdynamo frontend/backend compilation times.

    Accumulates information from functions tagged with `@dynamo_timed`.

    repr='str' returns a printable string for user interaction, and 'csv'
    returns headers, rows which can be logged for output

    aggregate causes values from multiple compilations (e.g. split graphs)
    to be accumulated into one value.  If false, expect more than one value
    per metric.
    c                     | S rl   re   xs    r1   <lambda>zcompile_times.<locals>.<lambda>  s    ra   c                 `    r |t        |             S dj                  t        ||             S )Nr+   )sumr,   r-   )rt   item_fn	aggregates     r1   fmt_fnzcompile_times.<locals>.fmt_fn  s+    3v;''yyWf-..ra   r.   c                 
    | dS )Nz.4fre   r   s    r1   r   zcompile_times.<locals>.<lambda>  s
    3jra   )r   z!TorchDynamo compilation metrics:
)FunctionzRuntimes (s)r'   csvc                 
    | dS )Nz.6fre   r   s    r1   r   zcompile_times.<locals>.<lambda>%  s
    1S'
ra   N)r$   r3   rt   listkeys)	reprr   r   kr7   r|   vrt   r(   s	    `       r1   compile_timesr     s      + /
 u} .
- /2<PQR- 	 
 3x&BCC
	 .446
6 1236 	 
 /4467 


s   B#Bc                  D    t         j                  t        dd             y )Nr.   T)r   r   )loginfor   re   ra   r1   dump_compile_timesr   ,  s    HH]67ra   c                        e Zd ZddZd Zd Zy)DuplicateWarningCheckerc                 2    || _         | j                          y rl   )maxsizereset)selfr   s     r1   __init__z DuplicateWarningChecker.__init__@  s    

ra   c                 6    t        j                         | _        y rl   )collectionsOrderedDictsetr   s    r1   r   zDuplicateWarningChecker.resetD  s    **,ra   c                 ^   || j                   v r/| j                   j                  |d       t        j                  syyd | j                   |<   t	        | j                         | j
                  kD  r?| j                   j                  d       t	        | j                         | j
                  kD  r?y)NT)lastF)r   move_to_endr   verboselenr   popitemr   rz   s     r1   addzDuplicateWarningChecker.addG  s    $((?HH  4 0>>
  !DHHSMdhh-$,,.  e , dhh-$,,.ra   N)   )r@   
__module__r   r   r   r   re   ra   r1   r   r   ?  s    -	ra   r   c                  "   t         j                  j                  dd      dk(  } | rWt        j                  j                  t        j                  t        j                  t        j                  d       t               S t        j                         S )NTORCH_COMPILE_DEBUG01T)dynamoaotinductoroutput_code)osenvirongetr   _loggingset_logsloggingDEBUGadd_file_handler
contextlib	ExitStack)compile_debugs    r1   setup_compile_debugr   V  sh    JJNN#8#>#EM==]]	 	  	
  !!!!ra   c                  ,    t         j                          y rl   )graph_break_dup_warning_checkerr   re   ra   r1   reset_graph_break_dup_checkerr   e  s    #))+ra   c                     t         j                  j                  t               d      } t         j                  j	                  |       st        j
                  |        t        j                  t         j                  j                  | d            t        j                  d      j                         t        j                         }|j                  fd       |S )Ntorchdynamoz	debug.logztorch._dynamoc                  &    j                         S rl   removeHandlerlog_file_handlerloggers   r1   r   z"add_file_handler.<locals>.<lambda>s  s    v334DEra   )r   pathr,   get_debug_direxistsmakedirsr   FileHandler	getLogger
addHandlerr   r   callback)log_path	exitstackr   r   s     @@r1   r   r   i  s    ww||MO];H77>>(#
H**277<<++NO/F
&'$$&IEFra   c                  B   t        j                         } t        j                  xt	        j
                  t        j                        t        j                  j                  j                         D ](  j                         | j                  fd       * | S | S )Nc                  &    j                         S rl   r   r   s   r1   r   z setup_log_file.<locals>.<lambda>}  s    v';';<L'Mra   )r   r   r   log_file_namer   r   r   r   	_internalget_loggersr   r   )r   r   r   s    @@r1   setup_log_filer   w  s}    $$&I'"..v/C/CDnn..::<F./MN = ra   c                 |    t                d|j                   dt        |       j                   d|j                   dS )Nz/error_recordings/_z.rec)r   co_nametyper@   co_firstlineno)exccodes     r1   gen_record_file_namer     sB    o aS	""#1T%8%8$9? ?ra   c                    	 t         j                  j                  |       rt        j	                  d|        y t        j
                  t         j                  j                  |       d       t        | d      5 }|j                  |       d d d        y # 1 sw Y   y xY w# t        $ r t        j                  d|        Y y w xY w)Nz9Unable to write execution record %s; file already exists.T)exist_okwbz#Unable to write execution record %s)r   r   r   r   warningr   dirnameopendump	Exception	exception)filenameexec_recordfs      r1   write_record_to_filer    s    
G77>>(#KKKX KK1DAh%  # &%% G;XFGs5   5B A B 8B
B BB B C Cgc                 T    d}| j                   D ]  }d|j                  v s|dz  } |S )Nr   callr   )nodesop)r  cns      r1   count_callsr    s0    	AWWQTT>FA  Hra   c                     | S rl   re   r   s    r1   identityr    s    Hra   c                 :    	 t        |        y# t        $ r Y yw xY w)NTF)hash	TypeErrorr   s    r1   hashabler    s#    Q s    	c                       y rl   re   rV   rW   s     r1   nothingr    s    ra   c                   <    e Zd ZdZd Zd Zd
dZd Zd Zd Z	d	 Z
y)ExactWeakKeyDictionaryz\Similar to weakref.WeakKeyDictionary, but use `is`/`id` rather than `==` to compare equalityc                 @    t               | _        t               | _        y rl   )dictrt   refsr   s    r1   r   zExactWeakKeyDictionary.__init__  s    fF	ra   c                 2    | j                   t        |         S rl   )rt   idr   s     r1   __getitem__z"ExactWeakKeyDictionary.__getitem__  s    {{2c7##ra   Nc                 L    | j                   j                  t        |      |      S rl   )rt   r   r  )r   rz   defaults      r1   r   zExactWeakKeyDictionary.get  s    {{r#w00ra   c                 0    t        |      | j                  v S rl   )r  rt   r   s     r1   __contains__z#ExactWeakKeyDictionary.__contains__  s    #w$++%%ra   c                      t        |       j                  vr't        j                  | fd       j                  <   | j                  <   y )Nc                 &    j                        S rl   )
_remove_id)refidxr   s    r1   r   z4ExactWeakKeyDictionary.__setitem__.<locals>.<lambda>  s    $//#:Nra   )r  r  weakrefr$  rt   )r   rz   r}   r%  s   `  @r1   __setitem__z"ExactWeakKeyDictionary.__setitem__  s?    gdii$[[.NODIIcN Cra   c                 r    || j                   v r| j                   |= || j                  v r| j                  |= y y rl   )rt   r  )r   r%  s     r1   r#  z!ExactWeakKeyDictionary._remove_id  s6    $++C $))		# ra   c                 l    | j                   j                          | j                  j                          y rl   )r  ri   rt   r   s    r1   ri   zExactWeakKeyDictionary.clear  s     		ra   rl   )r@   r   r   __doc__r   r  r   r   r'  r#  ri   re   ra   r1   r  r    s(    f$1&!ra   r  c                 l    t        |t        t        t        f      rt	        |       |v S t	        |       |u S )zisinstance() without subclasses)
isinstancetupler   r   r   )objallowed_typess     r1   istyper0    s1    -%s!34CyM))9%%ra   c                 ^    t        | t        j                        xs | t        j                  u S rl   )r,  typing_FinalGenericr}   s    r1   	is_typingr6    s#     eV]]+Fu/FFra   c                    t         syt        | t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  f      S NF)
npr0  int8int16int32int64uint8uint16uint32uint64r5  s    r1   is_numpy_int_typerB    sU    GGHHHHHHHHIIIIII		
 ra   c                     t         syt        | t         j                  t         j                  t         j                  f      S r8  )r9  r0  float16float32float64r5  s    r1   is_numpy_float_typerG    s2    JJJJJJ	
 ra   c                 D    t         syt        | t         j                        S r8  )r9  r0  ndarrayr5  s    r1   is_numpy_ndarrayrJ    s    %$$ra   c                     t         j                  t         j                  j                  gt        j
                  }|t         j                  j                  fz   }t        | |      S )zCheck of obj is a tensor)	r   Tensornn	Parameterr   traceable_tensor_subclasses_subclassesr   r0  )r.  tensor_lists     r1   istensorrR  
  sW     	 
	+	+K
 !2!2!=!= ??K#{##ra   c                 "    t        | t              S rl   )r,  r!   )mods    r1   is_lazy_modulerU    s    c?++ra   r   c                      t        |   y rl   )rH   )rV   s    r1   
print_oncerW    s	    	4Lra   c                 |    | fd}|j                   t        |j                         dk(  sJ |j                   d   S )zNSome black magic to create a cell object that usually only exists in a closurec                       S rl   re   r   s   r1   r  zmake_cell.<locals>.f"  s    ra   r   r   )__closure__r   )valr  r   s     @r1   	make_cellr\    s>    A ==$Q]]);q)@@@==ra   c                 0   	 t        d | D              }|j                         D ci c]  \  }}||j                          }}}||fS c c}}w # t        $ r=}ddlm} ddlm}  |d ||   d |t        |j                                       |d }~ww xY w)Nc              3   <   K   | ]  }|j                           y wrl   )as_proxyr/   args     r1   r2   z$proxy_args_kwargs.<locals>.<genexpr>+  s     :Tc3<<>T   r   unimplemented)typestrzcall_function args: rq   )
r-  ru   r_  NotImplementedErrorr   rd  variables.basere  r   rt   )	rV   rW   
proxy_argsrz   ra  proxy_kwargserd  re  s	            r1   proxy_args_kwargsrk  )  s    
:T::
<BLLNKNSS\\^+NK<'' L &+"7D>"2!GT&--/=R4S3TU
		s(   %A A	A 	A 	B8BBc                       e Zd ZU eed<   eed<   eed<   eed<   eed<   eed<   ee   ed<   ee   ed<   ee   ed	<   ee   ed
<   ee   ed<   ee   ed<   ee   ed<   ee   ed<   ee   ed<   y)CompilationMetricsr   r   co_filenamer   
cache_sizeaccumulated_cache_sizeguard_countgraph_op_countgraph_node_countgraph_input_countentire_frame_compile_time_sbackend_compile_time_sfail_reasonnon_compliant_opscompliant_custom_opsN)	r@   r   r   r.   __annotations__intr   floatr   re   ra   r1   rm  rm  7  s}    NLO#SM!sm#}$!)%0$UO+#3xc("ra   rm  c                   F    e Zd ZU dZeeef   ed<   eed<   d Ze	d        Z
y)CleanupHookz,Remove a global variable when hook is calledscopenamec                 d    t         xj                  dz  c_        | j                  | j                  = y rc   )CleanupManagercountr  r  )r   rV   s     r1   __call__zCleanupHook.__call__Q  s#    !JJtyy!ra   c                 b    || vsJ t         xj                  dz  c_        || |<   t        | |      S rc   )r  r  r~  )r  r  r[  s      r1   createzCleanupHook.createU  s7    5   !d5$''ra   N)r@   r   r   r*  r   r.   r   rz  r  staticmethodr  re   ra   r1   r~  r~  J  s1    6S>
I" ( (ra   r~  c                   4     e Zd ZU dZed    ed<    fdZ xZS )r  r   instancec                 Z    | j                   |   D ]	  } |         t        | 	  |       y rl   )rt   superr#  )r   r%  hook	__class__s      r1   r#  zCleanupManager._remove_ida  s(    KK$DF %3ra   )r@   r   r   r  r
   rz  r#  __classcell__)r  s   @r1   r  r  ]  s    E'((   ra   r  c                     | j                         j                  | j                        }| j                  r+| j                  | j                  j                         |_        |S )z!Clone the tensor and its gradient)clonerequires_grad_requires_gradis_leafgrad)r   ys     r1   clone_tensorr  j  sB    		  1AyyQVV'Hra   dtypec          	      L   t        |       r| S fd}t        j                         5  | j                  j                  dk(  r ||       cddd       S t        d t        | j                         | j                               D              }| j                  rt        j                  |dz   f|       }n3t        j                  |dz   xs | j                  | j                        }| j                         |j                         z
  dz  | j                         z  }|j                  | j                         | j                         |       	 |j!                  | j#                                | j$                  r|j'                  | j(                         | j$                  r(| j*                  t-        | j*                        |_        t1        | d      r| j2                  j5                         |_        |cddd       S # t.        $ r  ||       cY cddd       S w xY w# 1 sw Y   yxY w)	zcopy while preserving stridesc                 >   t        j                  |       }| j                  r|j                  | j                         | j                  r(| j
                  t        | j
                        |_        t        | d      r| j                  j                         |_        |S )Nr  _dynamo_dynamic_indices)
r   r  r  r  r  r  clone_inputhasattrr  copy)r   r  r  s     r1   torch_clonez clone_input.<locals>.torch_cloney  sr    KKN99Q__-99+ u5AF1/0()(A(A(F(F(HA%ra   xlaNc              3   2   K   | ]  \  }}|d z
  |z    yw)r   Nre   )r/   shapestrides      r1   r2   zclone_input.<locals>.<genexpr>  s"      
6O]UFUQY& 6O       )r  devicer  r  )r   r   no_gradr  r   r   zipsizer  is_quantizedempty_quantizedemptyr  data_ptrelement_sizeas_strided_copy_r  r  r  r  r  r  RuntimeErrorr  r  r  )r   r  r  needed_sizeresultcache_line_offsets    `    r1   r  r  r  s    qz 
88==E!q> 

  
69!&&(AHHJ6O
 
 >>**K",<+>BF[[b (8F ZZ\FOO--3^^ 	1668QXXZ1BC
	"LL#yy%%aoo6yyQVV/)!&&> 1/0-.-F-F-K-K-MF*? 
0  	" q>!9 
0	"1 
s7   !HC6H
A:G:,H:HHHHH#c                    t        |       t        u r|t        |       }|j                         D ]\  \  }}t        |t              rt        |      ||<   %t        |t        j                        sJ t        |             t        |      ||<   ^ |S t        |       }t        t        |            D ]1  }t        ||   t        j                        s!t        ||         ||<   3 |S rl   )r   r  ru   r,  r-  clone_inputsr   rL  r  r   ranger   )example_inputsresrz   r}   is        r1   r  r    s    Nt#>"))+JC%''.C!%6CUC6&u-C & 

~
C3s8_c!fell+ Q(CF  Jra   c               #     K   t         j                  j                  j                         5  t        j                  t         j
                  j                               } t         j                  j                         r1t        j                  t         j                  j                               }d d d        	 d  t         j                  j                  j                         5  t         j
                  j                          t         j                  j                         rt         j                  j                         d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w# t         j                  j                  j                         5  t         j
                  j                          t         j                  j                         rt         j                  j                         d d d        w # 1 sw Y   w xY wxY wwrl   )
r   utils_python_dispatch_disable_current_modesr  randomget_rng_statecudais_availableset_rng_state)	rng_statecuda_rng_states     r1   preserve_rng_stater    s*    		%	%	<	<	>KK : : <=	::""$"[[)A)A)CDN 
?9[[))@@BLL&&y1zz&&(

((8 CB 
?	> CBU[[))@@BLL&&y1zz&&(

((8 CBBsg   )G=BE,G=5E 9(G=!AE>	G=EG=EG=)G:AG.%	G:.G73G::G=c                 
   t        | t        j                  j                  j                  t        j                  j
                  j                  t        j                  j                  t        j                  j                  f      S rl   )	r,  r   jit_traceTopLevelTracedModule_scriptRecursiveScriptModuleScriptFunctionScriptModule)model0s    r1   is_jit_modelr    sW    II11II33II$$II""		
 ra   c                 6   t        |       r| S 	 t        j                  j                  | |      S # t        $ r` 	 t        j                  j                  |       cY S # t        $ r1 |rt        j                  d       nt        j                  d       Y Y y w xY ww xY w)Nz	jit errorz0Both torch.jit.trace and torch.jit.script failed)	r  r   r  tracer   scriptr   r   error)modelr  r   s      r1   torchscriptr    s    E	Nyyun55 N	N99##E** 	Nk*		LM	NNs,   / 	BAB6BBBBc                 X    	 t        j                  |       S # t        t        f$ r Y y w xY wrl   )inspectgetfiler  OSErrorr.  s    r1   r  r    s-    s##w s    ))c                 *    t        t        |             S )LTest if an object is a namedtuple or a torch.return_types.* quasi-namedtuple)is_namedtuple_clsr   r  s    r1   is_namedtupler    s    T#Y''ra   c                     	 t        | t              rMt        | dg       xs dg}t        | dd      }|dk(  xs' |d   t        u xr t        | d      xr t        | d      S 	 y# t        $ r Y yw xY w)	r  	__bases__Nr   torch.return_typesr   _make_fieldsF)
issubclassr-  getattrr  r  )clsbasesmodules      r1   r  r    s    c5!Cb1;dVES,5F11 aE!Wgc7&;WY@W "   s   AA! !	A-,A-c                    | t         u rg dS t        | t              sJ t        | d      r| j                  S t
        j                   G d d             }| j                  dk(  sJ  | t        |t        | j                                    }dg| j                  z  }t        |      D ];  }|d   dk7  st        t        ||      |      s#||t        ||      j                  <   = |S )	zIGet the fields of a namedtuple or a torch.return_types.* quasi-namedtuple)startstopstepr  c                       e Zd ZU eed<   y)!namedtuple_fields.<locals>.MarkerindexNr@   r   r   r{  rz  re   ra   r1   Markerr  
  s    
ra   r  r  Nr   r   )slicer  r-  r  r  dataclasses	dataclassr   r-   r  n_fieldsdirr,  r  r  )r  r  r.  fieldsr  s        r1   namedtuple_fieldsr    s     e|((c5!!!sI{{   >>1111
c&%-.
/C#'&3<<"7FC7c>jd);VD/3F73%++,  Mra   c           	      B   t        j                         5  t        j                  t         j                  j	                               t         j
                  j                         r1t        j                  t         j
                  j	                               g t        j                  | j                         | j                               D ]3  }j                  ||j                  t        j                  |      f       5 	 d d d        fd}|S # 1 sw Y   xY w)Nc                  j   t        j                         5  t         j                  j                         t         j                  j                         rt         j                  j                         D ]'  \  } }}| j                  |k7  s| j                  |       ) 	 d d d        y # 1 sw Y   y xY wrl   )r   r  r  r  r  r  _versionr  )paramversionoriginal_valuer  r  saved_states      r1   restorez"checkpoint_params.<locals>.restore!  ss    ]]_LL&&y1zz&&(

((82=.w>>W,KK/ 3>	 __s   A5B)B))B2)r   r  r  r  r  r  r  r5   r6   
parametersbuffersr   r  )gmr  r  r  r  r   s      @@@r1   checkpoint_paramsr    s    	KK : : <=	::""$"[[)A)A)CDN__R]]_bjjlCEu~~u{{57IJK D 
0 N# 
s   C+DDc                 v   t         j                  j                         rt         j                  j                  }nt        } |        t        j                          t        j                  d       t        j                         }t        |      D ]  } | | } |         t        j                         }||z
  fS )Ni9  )r   r  r  synchronizer  gccollectmanual_seedr   perf_counterr  )r  r  timesr  r   r   r  t1s           r1   timedr  -  s    zz jj,,MJJL	d				B5\'  
			B27?ra   c           	      l    t        d t        j                  || j                  d            D              S )Nc              3   4   K   | ]  }|j                     y wrl   )is_cudar/   r   s     r1   r2   z check_is_cuda.<locals>.<genexpr>?  s     W"VQqyy"Vs   T)allr5   r6   r  )r  r  s     r1   check_is_cudar  >  s(    W)//."--PTBU"VWWWra   r  c                     | dkD  sJ t        |       D cg c]  }d| 	 }}t        |dd  |d d z         }t        ddj                  |       ddj                  |       d      }d|  d	|_        |S c c}w )
Nr   r   zlambda ,z: ()rot__helper)r  reversedevalr,   r@   )r
  r  varsrotatedfns        r1   rot_n_helperr   B  s    q5L5"1X&XasGXD&tBCy49,-G	's388G+<*=Q?	@B7#BKI	 's   A4c                    t        | t        t        f      rt        t	        t
        |             S t        | t        j                  t        f      xso t        | t        j                  t        t        t        t        t         t        d       t"        t        t              t$        j&                  t$        j(                  f      S rl   )r0  r-  	frozensetr  r-   is_safe_constantr,  enumEnumr   typesCodeTyper{  r|  boolr.   bytesr  r   r  r  )r   s    r1   r#  r#  L  s    a%#$3'+,,a$))T*+ v	NNJJLLKK	
0 ra   c                     ddl m}m} t        | |      r| j	                         S t        | |      r| j                         S | S )Nr   )ConstantVariableSymNodeVariable)	variablesr+  r,  r,  evaluate_expras_python_constant)ra  r+  r,  s      r1   guard_if_dynr0  a  s?    <#'
   ""	C)	*%%''Jra   c                 j    t        d t        j                  | |j                               D              S )Nc              3   <   K   | ]  }|j                           y wrl   )is_python_constantr  s     r1   r2   z&check_constant_args.<locals>.<genexpr>q  s     V/U!q##%/Urb  )r  r5   r6   rt   r  s     r1   check_constant_argsr4  p  s$    VytV]]_/UVVVra   c                     ddl m} ddlm} d}t	        j
                  | |j                               D ]$  }t        ||      r|dz  }t        |||f      s y& |dkD  S )Nr   )r+  )UnspecializedPythonVariabler   F)variables.constantr+  variables.tensorr6  r5   r6   rt   r,  )rV   rW   r+  r6  unspec_countr   s         r1   check_unspec_python_argsr:  t  sa    4=L__T6==?3a45ALA ;=MNO 4 !ra   c                 |    ddl m t        fdt        j                  | |j                               D              S )Nr   )NumpyNdarrayVariablec              3   6   K   | ]  }t        |        y wrl   )r,  )r/   r   r<  s     r1   r2   z+check_numpy_ndarray_args.<locals>.<genexpr>  s!      7A 	1*+7s   )r8  r<  anyr5   r6   rt   )rV   rW   r<  s     @r1   check_numpy_ndarray_argsr?    s1    6 v}}7  ra   dict_valuesodict_valuestuple_iteratorc                 n    t        |       }t        j                  j                  j	                  |       |S rl   )
object_newr   rM  Moduler   )r  r.  s     r1   nn_module_newrF    s&    
S/C	HHOOS!Jra   c                 L    t        j                  t        j                  | d      S rc   )	functoolsreduceoperatormul)its    r1   productrM    s    HLL"a00ra   c                 >    | j                         \  }\  }}|||z      S rl   )
__reduce__)rL  r  r   r.  r  s        r1   tuple_iterator_getitemrP    s%    }}Avuuu}ra   c                 j    | j                   j                  }| j                  }|rdnd}| d| d| }|S )NLGz["z"].)r  r@   r  )r}   localr  r[  r  
local_names         r1   	enum_reprrV    sA     ??##D
**CCcE7"TF#cU+Jra   c                     | j                         j                  j                  j                  d      }t	        |      sddlm}  |d       |S )Nexample_valuer   rc  z:Cannot check Tensor object identity without its fake value)r_  nodemetar   r   r   rd  )vtfake_tensorrd  s      r1   _get_fake_tensorr]    s>    ++-$$))--o>K;&RSra   c                 
   ddl m}m}m}m} j                         r%t        fd| D              }|j                  |      S d}	|rt        |      rd}	t              d }
| D ]  }|	r.t        ||      st        |      u s |j                  d      c S  |t        j                        j                  ||gi       }|
|}
a |t        j                        j                  |||
gi       }
 |
|j                  d      }
|
S )Nr   )BuiltinVariabler+  TensorVariableVariableTrackerc              3      K   | ]7  }|j                         xr! |j                         j                         k(   9 y wrl   )r3  r/  )r/   r   searchs     r1   r2   z iter_contains.<locals>.<genexpr>  sJ      
    " F$$&&*C*C*EEF   =A FT)r-  r_  r+  r`  ra  r3  r>  r  r,  r]  rJ  eqcall_functionor_)ru   rc  txcheck_tensor_identityr_  r+  r`  ra  found_constmust_check_tensor_idfoundr   checks    `           r1   iter_containsrn    s       " 
 
 

  &&{33 FN!C#!&)'+E!^,-a00+22488#HKK0>>rAv;PRSE}'5CC  } ''.Lra   c                     | j                         D ch c]B  }t        |t        j                  j                  t        j
                  f      s8t        |      D c}S c c}w rl   )r   r,  r   rM  rN  rL  r  r}   r   s     r1   dict_param_key_idsrq    sI    zz|#!z!ehh6H6H%,,5W'X1|  s   9AAc                     | j                         D ch c]9  }t        |t        j                  j                  t        j
                  f      r8|; c}S c c}w rl   )r   r,  r   rM  rN  rL  rp  s     r1   dict_const_keysrs    sE    ::<az!ehh6H6H%,,5W'X<  s   9AAc                    t        d | D              rS| D ch c]4  }t        |t        j                        rt	        ||      n
t        |      6 c} j                  dd      }|S | }|S c c}w )Nc              3   P   K   | ]  }t        |t        j                           y wrl   )r,  r$  r%  )r/   r   s     r1   r2   z'dict_const_keys_repr.<locals>.<genexpr>  s     
8Z:a#Zs   $&)rT  ' )r>  r,  r$  r%  rV  r   replace)
const_keysrT  r   const_keys_strs       r1   dict_const_keys_reprr{    s    

8Z
88 kuujtef:a;Si7Y]^_Y``jtuw  A  A

  '> vs   9A+c                     dt        |        S )N__dict_key_)r  )rz   s    r1   global_key_namer~    s    C	""ra   )FakeTensorModeUnsupportedFakeTensorExceptionc                     	  |        S # t         $ r9}ddlm} d|j                   d}t        j                  |        ||      |d }~ww xY w)Nr   rc  zUnsupported: z with fake tensor propagation.)r  r   rd  reasonr   r   )r  rj  rd  msgs       r1   wrap_fake_exceptionr    sM    (t) (&ahhZ'EFCC a'(s   	 	A4AAc                      t         j                  j                  j                  |      5  t	         fd      cd d d        S # 1 sw Y   y xY w)Nc                  .    t        j                         S rl   )r  deepcopyr  s   r1   r   z)deepcopy_to_fake_tensor.<locals>.<lambda>  s    4==+=ra   )r   rP  r\  FakeCopyModer  )r.  	fake_modes   ` r1   deepcopy_to_fake_tensorr    s2    				&	&	3	3I	>"#=> 
?	>	>s   AAc                 ~    t        j                  t        j                  t        j                  | |z
                    S )z+
    Calculate root mean squared error
    )r   sqrtmeansquare)r$  r  s     r1   rmser    s)     ::ejjcCi!89::ra   g-C6?Tc
                    	  t         t        t        t        j                  j
                  t        j                  f      rt        t        t        f      sJ dt                dt                      t               t              k7  r	 	d       yt               t              k(  xr% t        	fdt               D              S t         t              rt        t              sJ t         j                               t        j                               k(  s;J dt         j                                dt        j                                       t         j                               D ]+  }
t         |
   |
   |
   		
      r" 	d
|
        y yt         t        j                   t"        f      rt         t        j$                  j&                        rJ t        t        j$                  j&                        rJ d fd fD        \    j(                  r.j(                  sJ  j+                          j+                         t        t        j                         sJ dt                dt                      r j,                  j,                  k7  r 	d j,                  j,                         y j,                  t        j.                  k(  reryt        j0                   j3                  t        j4                        j3                  t        j4                              }|s 	d       |S r j7                         j3                  t        j8                         j7                         j3                  t        j8                        t        j0                   d      ryt        j                  j:                  j=                   dd      }|dk  r@t>        jA                  d|jC                         jE                         jG                                |dk\  S s j3                  j,                         t        j0                         ryj,                  t        jH                  k(  rtK               jG                         }tM        jN                  |      rt>        jA                  d       tK              jG                         }j,                  t        jP                  k(  rdnd}jS                         dk  s; jT                  dk(  r' jV                  d    jV                  d   cxk(  rdk(  sn dk\  rd}|||z  d z  z   k  }|s 	d!||jY                                |S ry 	d"       yt         tZ        t\        t        d      t.        t        j^                  f      r ry k(  }|s 	d#t                       |S ta               stc               rSr&ta              stc              s jG                          t               t              u xr  k(  }|s
 	d$        |S te               rSt               t              u xr; t        t        jf                         t        jf                        		
      S t               jh                  d%v rMt               t              u sJ t        	 f
d& jj                  j                         D              S tm        d't               jh                         )(z-Check correctness to see if ref and res matchNztype mismatch rq   zLength mismatchFc              3   P   K   | ]  \  }}}t        |||
	 
        yw))	log_errorN)same)r/   aibi	fp64_reficos_similarity	equal_nanexact_dtypeignore_non_fpr  relax_numpy_equalitytols       r1   r2   zsame.<locals>.<genexpr>,  sL      ,
 &=!B	 $#  &=s   #&zkeys mismatch z == r  r  r  r  r  r  r  zAccuracy failed for key name %sTc                 d    t        | t        j                        r| S t        j                  |       S rl   )r,  r   rL  tensorts    r1   	to_tensorzsame.<locals>.to_tensorV  s"    "1ell31HaHra   c              3   .   K   | ]  } |        y wrl   re   )r/   r[  r  s     r1   r2   zsame.<locals>.<genexpr>Y  s     M8Lin8Ls   zdtype mismatch %s, %sr  )atolrtolr  z+Accuracy failed: uint8 tensor did not matchr   gư>)dimepsgGz?zSimilarity score=%sz=Found nan in reference. Consider running in higher precision.g      @g       @i     r  r   g{Gz?g      $@z4RMSE (res-fp64): %.5f, (ref-fp64): %.5f and shape=%sz+Accuracy failed: allclose not within tol=%szAccuracy failed (%s): %s != %sz!Accuracy failed (numpy): %s != %s)MaskedLMOutputSeq2SeqLMOutput!CausalLMOutputWithCrossAttentionsLongformerMaskedLMOutput	InstancesSquashedNormalBoxesNormalTanhTransformFooVariablec              3      
K   | ]7  }t        t        |      t        
|      t        |      	 
       9 yw)r  N)r  r  )r/   rz   r  r  r  fp64_refr  r  r$  r  r  r  s     r1   r2   zsame.<locals>.<genexpr>  sZ      
 + S!S!#&-#'%9+#  +rd  zunsupported type: )7r,  r   r-  r   rM  ParameterListSizer   r   r  r  r  r   r   sortedr  rL  r|  rP  r   	is_sparseto_denser  r(  allclosetor>  flattenrE  
functionalcosine_similarityr   r   cpudetachitemrF  r  mathisnanbfloat16numelndimr  r  r.   r{  r  rB  rG  rJ  	as_tensorr@   __dict__r  )r$  r  r  r  r  r  r  r  r  r  r   r   score	ref_error	res_error
multiplierpasses_testr  s   ``````````       @r1   r  r    s?    #eUXX%;%;UZZHI#e}-WS	{!DQTI;/WW-s8s3x'(3x3s8# 
 ,
 ,
 &)c8%<,
 )
 	
 
C	#t$$$388:#HHJ#
 
 	CC
O,DSXXZ0AB	C 
 
#AFFQK#1' +)="/' ;Q?! $" 	C%,,.	/c5#4#4#?#?@@@c5#4#4#?#?@@@	I Nc88LMS(==== =,,.C,,.C#u||,VtCyk4PS9+.VV,yyCII%1399ciiHyyEJJ& NNFFF-FFF-' KL++-""5==1C++-""5==1C~~c3SsdK HH''99#st9TEt|1599;3E3E3G3L3L3NOD= ffSYY' ~~c3SsiP ~~. 3/446	::i(KKW !3/446	 %(II$?SS
 NN$t+A#))B-399R=*MA*Mh
 "%J'J,BS4Z,OP"N!!
	 #"CSI	C#sDJellC	D3J6S	3L	3	#6s#;c"&9#&>((*C#Y$s)#5#*93D	#	S	T#Y& 
DOOC OOC )#!5'-
 	
 
c		   
 CyDI%%% 
 
 ||((*
 
 	
  /S	0B0B/CDEEra   c                 ~    | j                   j                  d      d   }d| j                   d| d| j                   dS )N/r  rv  z' (rr   r  )rn  splitr   r   )r   short_filenames     r1   format_func_infor    sD    %%++C04Nt||nC/q1D1D0EQGGra   c               #     K   t         j                  } t        j                  t         _        t         j                  }t        j                  t         _        	 d  | t         _        |t         _        y # | t         _        |t         _        w xY wwrl   )r   cache_size_limitsysr   accumulated_cache_size_limit)priorprior_acc_limits     r1   disable_cache_limitr    s_     ##E!kkF99O*-++F'>"'.=+ #(.=+s   ABA1 B1B		Bguard_failuresz-torch._dynamo.output_graph.GraphCompileReasongraph_break_reasonsc                   b    e Zd ZdZd Zdej                  j                  fdZd Z	d Z
d Zd Zy	)
CompileProfilerzUtility for profiling how and what dynamo would compile.

    Can be used for
     * diagnosing recompilation issues
     * determining an appropriate compile cache limit
     * (TODO)confirming which functions got compiled/skipped
    c                 6    d| _         d| _        t        | _        y rh   )frame_countrm   r  backend_ctx_ctorr   s    r1   r   zCompileProfiler.__init__  s     3ra   r  c                     | xj                   dz  c_         |j                  j                  D ]&  }d|j                  v s| xj                  dz  c_        ( |j
                  S )Nr   r  )r  graphr  r  rm   forward)r   r  r  rY  s       r1   r  zCompileProfiler.__call__   sK    AHHNND " # zzra   c                     | S rl   re   r   s    r1   	__enter__zCompileProfiler.__enter__(  s    ra   c                      y rl   re   )r   typr[  	tracebacks       r1   __exit__zCompileProfiler.__exit__+  s    ra   c                     dt         iS )Nr  )r  r   s    r1   get_metricszCompileProfiler.get_metrics.  s     .11ra   c                 J  	 | j                         }|d   fdfd}D cg c]  }t        |       |       ||      g c}	d }	fd}t        j                  d      }| |       xs dz  }|t        j                  d      z  }| |       xs d	z  }|S c c}w )
Nr  c                      t        |          S rl   r   )r   gfs    r1   num_recompilesz.CompileProfiler.report.<locals>.num_recompiles5  s    r$x= ra   c                 d    dj                  |    D cg c]  }t        |       c}      S c c}w )Nr)   )r,   r.   )r   r   r  s     r1   recompile_reasonsz1CompileProfiler.report.<locals>.recompile_reasons8  s,    99bh7hc!fh7887s   -c                  t    dt         v r+t         d   } t        | D cg c]	  }|| |   g c}ddg      S y c c}w )Ngraph_breakzGraph Break ReasonCountr'   )r#   r3   )graph_breaksr  s     r1   graph_break_reportz2CompileProfiler.report.<locals>.graph_break_report@  sP    ('69EF#c<,-F17;  ) Gs   5c                      t              rJt        D  cg c]
  }  |        c}       }t        g d      }|t        j                  d| d      z   S y c c} w )N)r   
RecompileszRecompile Reasonsr'   zC

                    Set torch._dynamo.config.cache_size_limit to z/ to avoid being cache limited.
                )r   maxr3   textwrapdedent)r   max_recompilesrecomp_tabler  r  summarized_gfs      r1   recompilation_reportz4CompileProfiler.report.<locals>.recompilation_reportH  sq    2w!$r%JrtnT&:r%J!K'!K  $hooBBPAQ R'   %Js   Aa  
            Torchdynamo Profiler Report
            ===========================

            Graph Breaks
            ------------
            Graph breaks happen when torchdynamo encounters code it can't safely trace.
            If you want to find out why breaks are happening, check below for each break reason
            You may gain additional insight by passing `fullgraph=True` to torch.compile,
            to stop at the first break.

        zNo graph breaks detected.a+  

            Recompilation
            -------------
            These subgraphs were recompiled more than once due to guard failures
            Guard failures indicate some condition assumed to be static by the tracer changed,
            making it unsafe to reuse the compiled program.

        zNo recompilation detected.
)r  r  r  r  )
r   metricsr  r   r  r  reportr  r  r  s
          @@@r1   r  zCompileProfiler.report1  s    ""$%&	!	9
 
 d#^D%9;LT;RS

		 
 	$&E*EE(//

 
	
 	&(J,JJm
s   !B N)r@   r   r   r*  r   r   r   GraphModuler  r  r  r  r  re   ra   r1   r  r    s7    4
588// 2@ra   r  c                     dt         j                   j                         j                  d      z   dz   t        t	        j
                               z   }t        j                  j                  | |      S )Nrun_z%Y_%m_%d_%H_%M_%S_%fz-pid_)datetimenowstrftimer.   r   getpidr   r,   )root_dirdir_names     r1   _get_debug_dirr  u  sf     	





!
*
*+A
B	C 	 biik
		  77<<(++ra   c                  8    t         j                  } t        |       S rl   )r   debug_dir_rootr  )
debug_roots    r1   r   r     s    &&J*%%ra   c                     d| j                   v r't        | j                   d         r| j                   d   S |rddlm}  |d       y y )NrX  r   rc  z9`FakeTensor` example value was required but not available)rZ  r   torch._dynamo.excrd  )rY  requiredrd  s      r1   extract_fake_example_valuer    s?    $))#		/0J(Kyy))	3QRra   c                 8    t        |       |j                  u sJ | S rl   )r   r  )rj  rh  s     r1   ensure_graph_faker    s    q!R\\111Hra   c                     dt         j                  j                  fd}t         j                  j                  j	                  ||      }t        t         j                  t        j                  t        |       |      S )Nr
  c                      | j                   d   S )NrX  )rZ  )r
  s    r1   visitz)get_fake_values_from_nodes.<locals>.visit  s    vvo&&ra   rh  )
r   r   NoderY  map_argr"   rL  rH  partialr  )rh  r  r  args_kwargss       r1   get_fake_values_from_nodesr     sX    ' ' ((--''u5Ki''(9bA; ra   c           	          ddl m} ddlm}m}m}m}m}  j                  }	d j                  v r't         j                  d         r j                  d   S t         j                   j                  f      \  d|	dk(  r^t              dkD  rPt        d   t         j"                  j$                        r)t'        d   j(                        ft+        dd       z   |	dk(  rbj,                  j.                   j0                     t3              rt5        d	      rj7                         t'        j(                        	 j(                  5  t9               5  t;         fd
      }
ddd       ddd       |s4t]        t         j^                  ta        jb                  td              
      }
S # 1 sw Y   IxY w# 1 sw Y   MxY w# |$ r  t<        $ r}|}|j>                  |j>                  }t        |t         j@                  jB                  jD                        r |d|jF                          nt        |t         j@                  jB                  jH                        r |d|jF                          nt        |t         j@                  jB                  jJ                        r |d|jF                   d       n}t        |t         jL                  jN                  jP                  jR                        r ||jT                  d| d      t        ||      r! ||jT                  |j                  d         | |tW        |            jY                  |jZ                        dd}~ww xY w)az  
    Run the computation represented by `node` using fake tensors and return the result.

    allow_non_graph_fake: whether to allow the return result to be:
        1. non-fake or 2. fake that is not created by this instance of Dynamo.
        If `True`, you must be prepared to deal with such return values, ideally
        by further wrapping them as this graph's fakes.
    r   )ValueRangeErrorr   )TorchRuntimeErrorrd  Unsupported	UserErrorUserErrorTyperX  Ncall_methodcall_module_initialize_hookc                  6    t        j                         S rl   )run_nodeoutput)rV   rW   nnmodulerY  rh  s   r1   r   z get_fake_value.<locals>.<lambda>  s    D$Ira   zdata dependent operator: zdynamic shape operator: zunsupported operator: z (see https://docs.google.com/document/d/1GgvOe7C8_NVOMLOCwDaYV1mXXyHMXY7ExoewHqooxrs/edit#heading=h.64r4npvq0w0 for how to fix)a  Tried to use data-dependent value in the subsequent computation. This can happen when we encounter unbounded dynamic value that is unknown during tracing time.  You will need to explicitly give hint to the compiler. Please take a look at constrain_as_value OR constrain_as_size APIs.  constrain_as_size_example)	case_namer  )3torch.utils._sympy.value_rangesr"  r   r#  rd  r$  r%  r&  r  rZ  r   r   rV   rW   r   r,  r   rM  rE  r  r  r-  r,  
nn_modulestargetrU  r  _infer_parametersr    r  r  	__cause__rP  r\  DataDependentOutputExceptionr^   DynamicOutputShapeExceptionUnsupportedOperatorExceptionr   experimentalsymbolic_shapesGuardOnDataDependentSymNodeCONSTRAINT_VIOLATIONr.   with_traceback__traceback__r"   rL  rH  r  r  )rY  rh  allow_non_graph_faker"  r#  rd  r$  r%  r&  r  ret_valrj  causer   rV   rW   r-  s   ``            @@@r1   get_fake_valuerA    s    @  
B $))#		/0J(Kyy))-b499dkk2JKLD&H	]s4y1}DGUXX__1U'Q>@5ab?R	]99''4(#:L(M
 &&x6 +8R\\B)R\\35)IG 6\T  LL)++,="Ew
 N] 65\\   "R ;;"KKE5$$00MM
 5ejj\BC5$$00LL
 4UZZLAB5$$00MM
 ( 5# #
 588((88TT
 22B CHJ 6  /M>>q	JPQQA'66qGTQE"RsI   G G$F?7G?G ?G	GGG M;&FM66M;c                  $    t        t        dd       S )Nr}   )r  _current_nodere   ra   r1   get_current_noderD    s    ='400ra   c              #   v   K   t               }| t        _        	 d  |t        _        y # |t        _        w xY wwrl   )rD  rC  r}   )rY  olds     r1   set_current_noderG    s.     

CM"!cs   9) 969c                 "   |j                   }t        |      5  	 |dk(  r |j                  |i |cddd       S |dk(  r+ t        |d   |j                        |dd i |cddd       S |dk(  r|J  ||i |cddd       S |dk(  r$| j	                  |j                        cddd       S |dk(  r(d	|j
                  v sJ |j
                  d	   cddd       S 	 ddd       t        |      # t        $ r+}dd
lm}  |d| d|j                   d| d| d	      |d}~wt        $ rO}d| d|j                   d| d| d	}t        |t        |      z         j                  |j                        |d}~ww xY w# 1 sw Y   t        |      xY w)a  
    Runs a given node, with the given args and kwargs.

    Behavior is dictated by a node's op.

    run_node is useful for extracting real values out of nodes.
    See get_real_value for more info on common usage.

    Note: The tracer arg is only used for 'get_attr' ops
    Note: The nnmodule arg is only used for 'call_module' ops

    Nodes that are not call_function, call_method, call_module, or get_attr will
    raise an AssertionError.
    rf  Nr'  r   r   r(  get_attrplaceholderrX  rc  zrunning rq   z(*z, **r  zFailed running z):
)r  rG  r2  r  get_submodulerZ  rf  r   rd  r   r  r.   r<  r=  AssertionError)	tracerrY  rV   rW   r-  r  rj  rd  fn_strs	            r1   r+  r+    s    
B	$		W_$"t{{D3F3 
 	 }$4wtAw4d12hI&I 
 	 }$+++00 
 	 z!++DKK8 
 	 }$&$))333yy1 
 	 % 
 4 
 # 	*2$a}BtfDB  	W&rd!DKK=4&VHDQFvA/>>qOUVV	W- 
 4 
sL   E;C.&C.*C.C.-#C..	E87&DE8)A
E33E88E;;Fc                 ,   ddl m} j                  }| |v r||    S | j                  }t        j
                  j                  j                  | j                  | j                  ffd      \  }}|dk(  rMj                  j                  | j                     }t        |      st        j                  |      }n ||i | nd}	 t!        | |||      }||| <   |S # t"        $ r0}	 |t%        |	            j'                  |	j(                        dd}	~	ww xY w)z
    Run the actual computation represented by `node` and return the result.
    This will execute any dependent nodes in the graph as well.
    r   )r#  c                     t        |       S rl   )get_real_value)r
  rM  s    r1   r   z get_real_value.<locals>.<lambda>K  s    .F+ra   r(  N)r   r#  real_value_cacher  r   r   rY  r  rV   rW   output_graphr1  r2  rU  r  r  r+  r  r.   r<  r=  )
rY  rM  r#  cacher  rV   rW   	nn_module
real_valuerj  s
    `        r1   rQ  rQ  =  s   
 '##Eu}T{	B88==((	DKK +LD&
 
]''224;;?	i(i0I t&v&	RfdD&)D
 d   RA'66qGTQRs   C 	D#+DDc                 X   ddl m fd}| j                         D ]<  \  }}t        |t        j
                  j                        s+J d| d ||               | j                         D ]<  \  }}t        |t        j
                  j                        s+J d| d ||               y )Nr   )FakeTensorConfigc                 b    j                   r"dd l}d|j                  | j                         S y)Nr   z"FAKE TENSOR CREATION TRACEBACK: 
 zNEnable TORCH_FAKE_TENSOR_DEBUG=1 to get creation stack traces on fake tensors.)debugr  format_list_debug_trace)r  r  rX  s     r1   stack_or_hintz7assert_no_fake_params_or_buffers.<locals>.stack_or_hintd  s/    !!89N9Nq~~9^8_``cra   zUnexpected fake buffer rq   zUnexpected fake param )torch._subclasses.fake_tensorrX  named_buffersr,  r   rP  r   named_parameters)r  r]  r  bufferr  rX  s        @r1    assert_no_fake_params_or_buffersrb  a  s    >d ((*fE%%00
 	D$TF!M&,A+BC	D 
 + **,e5$$//
 	B#D6=+?*@A	B 
 -ra   r.  c                 8    | j                    d| j                   S )z9
    Returns the fully qualified name of the object.
    .)r   r   r  s    r1   fqnre  v  s!     nnQs//011ra   c                 R    t         j                  j                  j                  r| S |S rl   )r   _dynamor   assume_static_by_default)count1count2s     r1   ifdynstaticdefaultrk  }  s    }}44ra   rT  c           
      8   t        t        j                  t        j                  j	                  t        t        | j                                          D ]D  }|j                  d      s|d   dk7  st        j                  | j                   d|dd         F y)z@
    Ensure all the files in a given submodule are imported
    z.pyr   r   rd  N)r  r   listdirr   r   r	   r.   __file__endswith	importlibimport_moduler@   )rT  r   s     r1   import_submodulers    sq     2::bggood36M&NOPU#s(:##s||nAhsm_$EF Qra   r}   c                     	 t        t        j                  t        |       d      t        j
                        ry	 y# t        $ r Y yw xY w)N__getattribute__TF)r,  r  getattr_staticr   r&  FunctionTypeAttributeErrorr5  s    r1   object_has_getattributery    sS    ""4;0BC
 	
   s   7< 	AAc                     	 t        j                  t        |       d      }|t        j
                  j                  j                  u rd }|S # t        $ r d }Y 7w xY w)N__getattr__)r  rv  r   rx  r   rM  rE  r{  )r}   
getattr_fns     r1   get_custom_getattrr}    sV    ++DKG
 UXX__000
  
s   A AAc                       e Zd ZdZdZdZy)TensorStaticReason   r  rs   N)r@   r   r   	PARAMETER
NOT_TENSORNN_MODULE_PROPERTYre   ra   r1   r  r    s    IJra   r  r  c                     | t         j                  k(  ry| t         j                  k(  ry| t         j                  k(  ryt	        d|        )Nz>mark_dynamic on parameter, parameters are always static today.z2mark_dynamic on a non tensor, how did this happen?z4tensor is static because it is nn module associated.zIllegal reason )r  r  r  r  rL  )r  s    r1   tensor_static_reason_to_messager    sJ    #---O#...C#666E
?6(3
44ra   r  	is_tensorguard_sourceztorch._guards.GuardSourcereturnc                    |j                         r"t        j                  rdt        j                  fS t        |       t        j                  j                  u r"t        j                  rdt        j                  fS |sdt        j                  fS y)a@  
    Given a tensor, source, and is_tensor flag, determine if a shape should be static.

    Args:
    tensor - the real tensor to evaluate, parameters force a static shape.
    is_tensor - internal dynamo check, essentially "is_tensor": target_cls is TensorVariable,
    tensors not in a TensorVariable for whatever reason are forced static.

    Returns a tuple, where the first element is the bool of whether or not this tensor should have a static shape.
    The second element is a TensorStaticReason, useful for passing to tensor_static_reason_to_message if needed.
    T)FN)is_nn_moduler   &force_nn_module_property_static_shapesr  r  r   r   rM  rN  force_parameter_static_shapesr  r  )r  r  r  s      r1   tensor_always_has_static_shaper    sr        "v'T'T'::::F|uxx)))f.R.R'1111'2222ra   c                 4      fdt        fd      S )Nc                        d  S S )Nrq   re   )maybe_idr  s   r1   format_namez+lazy_format_graph_code.<locals>.format_name  s    V1XJ''Kra   c                      t        d          dj                  j                  j                  j	                  d            S )Nz===== z =====
F)print_output)_format_graph_coder  __code__rn  print_readable)r  r  s   r1   r   z(lazy_format_graph_code.<locals>.<lambda>  s=    "[]O8,JJ++51
ra   r   )r  r  r  r  s   ```@r1   lazy_format_graph_coder    s     	
 ra   c                     d|  d| d| dS )NzTRACED GRAPH
 rq   r)   re   )r  r   	graph_strs      r1   r  r    s    TF!H:Qyk<<ra   c                 (      fd}t        |      S )Nc                     	 ddl m }  j                  j
                  D cg c];  }|j                  |j                  |j                  |j                  |j                  g= }} | |g d      }t        j                  j                  j                  |      S # t        $ r dt        t                    z   cY S w xY wc c}w )Nr   )r3   zkTabulate module missing, please install tabulate to log the graph in tabular format, logging code instead:
)opcoder  r2  rV   rW   r'   )r3   r4   r.   r  r  r  r  r  r2  rV   rW   r  r  r  rn  )r3   r
  
node_specsr  fn_namer  s       r1   innerz(lazy_format_graph_tabular.<locals>.inner  s    	) AC
@N1QTT166188QVVQXX6 	 
  N
	 "'2::+>+>+J+JIVV  	~,Wb9:;	
s   B A C!B>=B>r   )r  r  r  s   `` r1   lazy_format_graph_tabularr    s    W" era   c                 f    |  d| d| d| dt        j                  |      j                          d
S )Nrq   z line z 
r)   )disBytecode)prefixr  r   line_nor   s        r1   format_bytecoder    s;    XQtfAhZvgYc#,,t:L:P:P:R9SSUVVra   _forward_pre_hooks_forward_hooks_backward_pre_hooks_backward_hooks)_state_dict_pre_hooks_state_dict_hooks_load_state_dict_pre_hooks_load_state_dict_post_hooksc                 z   t         j                  j                  j                  j                  }	 g }| xr | xr | }|s|r|j                  t               |s|r|j                  t               |r|j                  t               g }|D ],  }t        | |g       }	|	D ]  }
|	|
   }|j                  |        . |S rl   )r   _Crg  
eval_frame
reset_codeextendforward_hook_namesbackward_hook_namesstate_dict_hook_namesr  r   )rT  check_forward_hookscheck_backward_hookscheck_state_dict_hooksr  hook_dicts_to_checkcheck_all_hooks	all_hookshook_dict_namehooks	hook_namer  s               r1   nn_module_get_all_hooksr    s     !!,,77J  	'$$	'&& 
 o""#56""#67""#89I-^R0I#DT"  . ra   c                 6    t        | |||      }t        |      S )zL
    Helper function to check if a module has any hooks attached to it.
    )r  r  r  )r  r(  )rT  r  r  r  r  s        r1   nnmodule_has_hooksr  '  s&     $/15	E ;ra   c                    t        | t        j                        rt        | j                        S t        | t
        j                        r| j                  d      S t        | t        t        f      r t        |       d | D              S | S )z0Convert tensor and tnp.ndarray to numpy.ndarray.T)forcec              3   2   K   | ]  }t        |        y wrl   )to_numpy_helperr/   r.  s     r1   r2   z"to_numpy_helper.<locals>.<genexpr>@       A5C?3/5r  )r,  tnprI  r  r  r   rL  numpyr-  r   r   r5  s    r1   r  r  9  sh    %%u||,,	E5<<	({{{&&	EE4=	)tE{A5AAAra   c                    t         J t        | t         j                        rt        j                  |       S t        | t
        j                        r| j                  S t        | t        t        f      r t        |       d | D              S | S )zeConvert tnp.ndarray to tensor, leave other types intact. If a list/tuple, loop through it to convert.c              3   2   K   | ]  }t        |        y wrl   )numpy_to_tensorr  s     r1   r2   z"numpy_to_tensor.<locals>.<genexpr>M  r  r  )
r9  r,  rI  r   r  r  r  r-  r   r   r5  s    r1   r  r  E  sk    >>%$u%%%%||	EE4=	)tE{A5AAAra   c                       e Zd Zd Zd Zd Zy)numpy_to_tensor_wrapperc                 N    || _         d| j                   j                  z   | _        y Nwrapped_r  r@   )r   r  s     r1   r   z numpy_to_tensor_wrapper.__init__S  s    "TVV__4ra   c                 6    d| j                   j                   dS )Nz<Wrapped function <original >>r  r   s    r1   __repr__z numpy_to_tensor_wrapper.__repr__W  s    -dffoo->bAAra   c                 <     | j                   |i |}t        |      S rl   )r  r  r   rV   rW   r|   s       r1   r  z numpy_to_tensor_wrapper.__call__Z  s"    dffd%f%s##ra   N)r@   r   r   r   r  r  re   ra   r1   r  r  R  s    5B$ra   r  c                     t        | t        j                        rt        | |      }t	        |      S t        | t
        j                        r*t        t        j                  |       |      }t	        |      S y rl   )r,  r  rI  r  r  r   rL  )r.  r  r|   s      r1   numpy_attr_wrapperr  _  sZ    #s{{#c4 s##	C	&ckk#&-s## 
'ra   c                   (    e Zd ZdZdefdZd Zd Zy)numpy_method_wrapperzgConvert obj from torch.Tensor to tnp.ndarray and call method. Then convert result back to torch.Tensor.methodc                 :    || _         d| j                   z   | _        y r  )r  r@   )r   r  s     r1   r   znumpy_method_wrapper.__init__k  s    "T[[0ra   c                 "    d| j                    dS )Nz<Wrapped method <original r  )r  r   s    r1   r  znumpy_method_wrapper.__repr__o  s    +DKK=;;ra   c                     |d   }t        |t        j                        rt        j                  |      }t        || j                        } ||dd  i |}t        |      S Nr   r   )r,  r   rL  r  rI  r  r  r  )r   rV   rW   r.  method_callabler|   s         r1   r  znumpy_method_wrapper.__call__r  sW    1gc5<<(++c"C!#t{{3tABx262s##ra   N)r@   r   r   r*  r.   r   r  r  re   ra   r1   r  r  h  s    q1s 1<$ra   r  c                   2    e Zd ZdZdedef   fdZd Zd Zy)numpy_operator_wrapperzQImplements dunder methods for tnp.ndarray via functions from the operator libraryr  .c                 :    || _         d|j                   | _        y r  )r  r@   )r   r  s     r1   r   znumpy_operator_wrapper.__init__~  s    "2;;-0ra   c                 "    d| j                    dS )Nz<Wrapped operator <original r  )r@   r   s    r1   r  znumpy_operator_wrapper.__repr__  s    -dmm_B??ra   c                 P    |rJ d |D        } | j                   | }t        |      S )Nc              3   ~   K   | ]5  }t        |t        j                        rt        j                  |      n| 7 y wrl   )r,  r   rL  r  rI  r`  s     r1   r2   z2numpy_operator_wrapper.__call__.<locals>.<genexpr>  s0      
RV3
3 =CKK3FRVs   ;=)r  r  r  s       r1   r  znumpy_operator_wrapper.__call__  s5    z
RV
 dggtns##ra   N)	r@   r   r   r*  r   r   r   r  r  re   ra   r1   r  r  {  s%    [18CH- 1@$ra   r  c                    t        | t              s| S | j                  r| j                         D cg c]W  }t        |t        j
                        r9|j                  j                  j                  |j                  j                        n|Y }}| j                         D cg c]W  }t        |t        j
                        r9|j                  j                  j                  |j                  j                        n|Y }}n | j                         }| j                         }t	        j                  ||| j                  | j                  | j                        }|j                          |S c c}w c c}w )N)r  r  r  )r,  r   _has_symbolic_sizes_stridesr  r   SymIntrY  	shape_env	size_hintexprr  empty_stridedr  r  r  zero_)r   sr  r  r  s        r1   defaker    s;   a$ 	$$
 VVX	
  !U\\* FF&&qvv{{3 	 	 
 XXZ	
   !U\\* FF&&qvv{{3  	 	 
 vvxggxxoo	A GGIH/

s   AE*!AE/c                 N    dd l }| |j                  j                  j                  u S rh   )torch.utils.checkpointr  
checkpoint)r.  r   s     r1   is_utils_checkpointr    s     !%++((3333ra   c                      dd l mc m} ddlm} |j
                  }t        j                  j                  j                  r|j                  } |j                  |fi | S )Nr   r   ) TorchHigherOrderOperatorVariable)torch._higher_order_ops.wrap_higher_order_opswrapvariables.higher_order_opsr  tag_activation_checkpointr   
_functorchr   functionalize_rng_opswrap_activation_checkpointmake)optionshigher_order_opsr  activation_checkpoint_ops       r1   build_checkpoint_variabler    s_    ;;L
 	22  44#3#N#N 0+00 
 ra   c                 `    ddl m}  |       }| dk(  r	 |S | dk(  r|rddlm}  |       }|S d}|S )Nr   )is_dynamo_supportedr  r  r   )
has_tritonF)r  r  torch.utils._tritonr  )device_typer  compile_supportedr  s       r1   is_compile_supportedr    sO    /+-e  
	#42&L  "ra   offsetc                 b    | j                  d      }t        |d| j                  dd            S )z
    Convert byte offset `offset` of `str` into character offset.
    Byte offset is used for 3.11+ instruction column data.
    Takes things like unicode characters into consideration.

    Unchanged from CPython implementation.
    zutf-8Nrx  )errors)encoder   decode)r.   r  as_utf8s      r1   _fix_offsetr    s4     jj!Gww&&wy&ABBra   c                   6    e Zd ZU eed<   eed<   eed<   eed<   y)_Anchorsleft_end_linenoleft_end_offsetright_start_linenoright_start_offsetNr  re   ra   r1   r  r    s     ra   r  segmentc                    t         j                  dk\  sJ ddl}	 |j                  d| z   dz         }t        |j                        dk7  ry| j                  d      fd}fd	fd
}fd}|j                  d   }t        ||j                        r|j                  }t        ||j                        rt        t        |j                  j                        dz
  } |||j                  j                         }	 ||	      \  }}	|   |	   x}
j#                         s|
dv r;|
dv r |||	      \  }}	n |||	      \  }}	|   |	   x}
j#                         r6|
dv r;|	dz   }|t        |         k  r!|   |   x}
j#                         s	|
dvr|dz  }t%        ||	||      S t        ||j&                        rt        t        |j                  j                        dz
  } |||j                  j                         } ||      \  }}|   |   dk7  r |||      \  }}|   |   dk7  rt        t        |j                        dz
  } |||j                         }t%        ||||      S t        ||j(                        rt        t        |j*                  j                        dz
  } |||j*                  j                         } ||      \  }}|   |   dk7  r |||      \  }}|   |   dk7  rt        t        |j                        dz
  } |||j                         }t%        ||||      S y# t        $ r Y yw xY w)a  
    Given source code `segment` corresponding to a bytecode
    instruction, determine:
        - for binary ops, the location of the binary op
        - for indexing, the location of the brackets.
    `segment` is expected to be a valid Python expression
    )      r   Nz(
z
)r   r)   c                 "    t        |    |      S rl   )r  )linenor  liness     r1   	normalizez-_extract_anchors_from_expr.<locals>.normalize  s    5=&11ra   c                     | t              k  r8|t        |          k\  r'd}| dz  } | t              k  r|t        |          k\  r'| t              k  r|t        |          k  sJ | |fS r  r  )r  colr   s     r1   next_valid_charz3_extract_anchors_from_expr.<locals>.next_valid_char  sy    s5z!cSv-?&?CaKF s5z!cSv-?&? E
"sSv-?'???s{ra   c                 p    |dz  } | |      \  } }| t              k  r|t        |          k  sJ | |fS rc   r  r  r#  r   r$  s     r1   	incrementz-_extract_anchors_from_expr.<locals>.increment  sH    q%fc2E
"sSv-?'???s{ra   c                 t    d}| dz  }  | |      \  } }| t              k  r|t        |          k  sJ | |fS r  r  r&  s     r1   nextlinez,_extract_anchors_from_expr.<locals>.nextline  sM    !%fc2E
"sSv-?'???s{ra   r  z)\#z\#[()r  version_infoastparseSyntaxErrorr   bodyr  r,  Exprr}   BinOpr	   r{  left
end_linenoend_col_offsetisspacer  	SubscriptCallr^   )r  r-  treer!  r'  r)  	statementr  
cur_linenocur_colch	right_colleft_linenoleft_colright_linenor   r$  s                  @@r1   _extract_anchors_from_exprrB    sQ    w&&& yy501 499~MM$E2
 		!I)SXX&dCII& c499#7#781<J
DII,D,DEG"1*g"FJ z*7332<<>",;*2:w*G'J*3J*H'J	 z*7332<<>",  !ICj 122$Z0;;DDFeOQ	 JYGGcmm, sDJJ$9$9:Q>K djj.G.GHH$3K$J!K$X.#5(1+x(H%X $X.#5  T__59L!,0C0CDIK<KKchh'
 sDII$8$89A=K dii.F.FGH$3K$J!K$X.#5(1+x(H%X $X.#5  T__59L!,0C0CDIK<KKK  s   L7 7	MMr   instc                 	   |j                   J |j                   j                  yt        j                  | j                  |j                   j                        j                         }|j                   j                  |S |j                   j                  |j                   j                  |S t        ||j                   j                        }d}d}g }|j                   j                  |j                   j                  k(  rDt        ||j                   j                        }||| }|j                  d|z  d||z
  z  z          n||d dz   }|j                  d|z  dt        |      |z
  z  z          t        j                  | j                  |j                   j                        j                         }t        ||j                   j                        }t        |j                   j                  dz   |j                   j                        D ]  }t        j                  | j                  |      j                         }	||	dz   z  }t        |	      t        |	j                               z
  }
|j                  d|
z  dt        |	      |
z
  z  z           ||d| z  }t        |      t        |j                               z
  }
|j                  d|
z  d||
z
  z  z          d}	 t        |      }|!|D cg c]  }|j!                  dd       }}n%|D cg c]  }t#        |       }}|j$                  dk(  r|xj&                  |z  c_        |j(                  dk(  r|xj*                  |z  c_        t        t        |            D ]  }t        t        ||               D ]t  }||j$                  k  r||j$                  k(  r||j&                  k  r2||j(                  k(  r||j*                  k\  rQ||j(                  kD  ra||   |   dk(  smd||   |<   v  |D cg c]  }dj-                  |       }}d}t        t        |            D ]X  }|t        j                  | j                  |j                   j                  |z         j                         dz   z  }|||   dz   z  }Z |S # t        $ r Y w xY wc c}w c c}w c c}w )	a  
    Python 3.11+ only. Returns lines of source code (from code object `code`)
    corresponding to `inst`'s location data, and underlines relevant code to `inst`.

    Example: CALL on `g`:
    f(g(
      ^^
        h(x)))
        ^^^^^

    We need our own implementation since `format_frame_summary` in
    Python's `traceback` module doesn't handle multi-line expressions
    (and their anchor extraction code is not completely correct).
    Nrw  rq   ~r)   r   ^r   )	positionsr  	linecachegetlinern  rstripr4  
col_offsetr5  r  r   r   r  lstriprB  rL  rx  r   r  r  r  r  r,   )r   rC  
first_linestart_offset
end_offsetr  markers	last_liner  line
num_spacesanchorsmarkermutable_markersr#  r  r  s                    r1   get_instruction_source_311rW  j  sw    >>%%%~~$ ""4#3#3T^^5J5JKRRTJ~~  (~~  (DNN,I,I,Q z4>>+D+DEL JGG ~~  DNN$9$99 T^^-J-JK
\*5s\)C:3L,MMN\]+d2s\)C3z?\3Q,RRS%%dnn77

&( 	 !DNN,I,IJ
DNN11A5t~~7P7PQF$$T%5%5v>EEGDtd{"GTS%77JNN3+cSY5K.LLM R 	9[j))^c)*:*:*<&==
sZ'#j1H*IIJ"&G,W5
 :AB'6>>#s+'B HO+OwVDLw+O ""a'##|3#%%*&&,6& CL)FS!89:G333W444w?V?V9Vg888w999G666"6*3/3636OF+C0 ; *" 2AAv2776?AF3w< d..0E0E0IJQQS	
 	'!*t## ! MW  
 C ,P4 Bs$   R% 0R5R:R?%	R21R2c                 R    t        | t        j                        rt        | dd       S y )N_dynamo_static_input_type)r,  r   rL  r  r  s    r1   get_static_address_typerZ    s#    !U\\"q5t<<ra   c                     t        | t        j                        xrA | j                  dk(  xr0 | j                  j
                  t        j                  j                  u S )N__get__)	r,  r&  MethodWrapperTyper@   __self____objclass__r   r  _TensorBaser5  s    r1   is_tensor_base_attr_getterra    sK    5%112 	@NNi'	@NN''588+?+??ra   r[  z,torch._dynamo.variables.base.VariableTrackerc                 ~    ddl m} ddlm} t	        | |      xs$ t	        | |      xr t        | j                  d      S )Nr   )UserDefinedObjectVariable)TensorWithTFOverrideVariable__torch_function__)torch._dynamo.variablesrc  &torch._dynamo.variables.torch_functionrd  r,  r  r}   )r[  rc  rd  s      r1   has_torch_functionrh    s<    ASb67 201 	4BHH23ra   c                     d }d }t         j                  j                  j                         x}r)| |j                  v r|j                  |    }|j
                  }|j                  | d||      S )NF)static_shapessymbolic_contextsource)r   _guardsTracingContexttry_gettensor_to_contexttensor_sourcefrom_tensor)r  r  rk  rl  tracing_contexts        r1   to_fake_tensorrt    sw    F--66>>@@@111.@@C%33F  	1A& !  ra   )NN)r.   Frl   )F)r   )T)FFF(  atexitr   r   r  rC   r  r  r  r$  rH  r  r  r5   rH  r   r  rJ  r   r;   rL   r  r  	threadingr   r&  r2  r&  r   r   r   pathlibr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r  r9  ModuleNotFoundErrortorch._loggingr   torch._numpy_numpyr  torch._guardsr   r   rw  r   fftlinalgr  r   
ModuleTyperz  NP_TO_TNP_MODULEr-  r^  r   r   r   r4   rq  torch._functorch.config%torch.fx.experimental.symbolic_shapesr   torch._dispatch.pythonr    torch.nn.modules.lazyr!   torch.utils._pytreer"   defaultdictr#   r.   troubleshooting_urlnnmodule_doc_urlnnmodule_doc_url_msgr   r@   r   r$   r|  r%   r  rB   r3   r`   rd   rf   rj   rm   ro   r~   r   r   registerr   FloatTensorrE  DoubleTensorrF  double
HalfTensorrD  halfBFloat16Tensorr  
ByteTensorr>  
CharTensorr:  
LongTensorr=  long	IntTensorr<  r{  ShortTensorr;  short
BoolTensorr(  tensortype_to_dtyper   r   r   r   r   r   r   r  Graphr  r  r  r  r  r0  r6  rB  rG  rJ  rR  rU  rW  r\  rk  r  rm  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r#  r0  r4  r:  r?  r   r  rt   r@  r   rA  iterrB  __length_hint__tuple_iterator_lenobject__new__rD  rF  rM  rP  rV  r]  rn  rq  rs  r{  r~  torch._subclassesr  r  r  r  r  r  r  r  r  orig_code_mapr   r  r  seen_code_mapr  r  r   r  r  r   rA  rT  rC  rD  rG  r+  rQ  rb  re  rk  rs  ry  r}  r%  r  r  rL  r  r  r  r  r  r  r  r  all_hook_namesr  r  r  r  r  r  r  r  r  r  r  r  r  r  rB  r'  InstructionrW  rZ  ra  rh  rt  re   ra   r1   <module>r     s          
   	       	   
       % &     &	.) 
FFIIII	>
eE$4$4c$9: 	
 FFCGGIIszzIIszz	
  %wVV    ,  ; 1 - ,C;+B+B;CVCV+W+c73<'
( WT K .//UV g! 46 $sDK/0 5 35 Dd3:../ 4	!
(V 
  H@!H 8 8
 
u{{3	5	u}}ejj1	5>>+	u{{n	uzzm	u{{EJJ/	OOekk599-	U[[1	uzzm  ( #:"; ",	?
G288 	 B&	G&%$, T  # # #$ ( ( ($ +   )*  ! 0f& 9 9	$(
 Q 0*"X 2 *W  &*$&--/%:T*S/" :&*+B;+B+B+D+K+K+M&Nd:c?# N&*4=&9Xc]# 9#33 ^^
1
&R	#(?
; iiVFrH
 
> 
> '( /Fk.E.Ed.KCcN+ K NRV TIJ S '(_ _F T, ,&

[|  	!1 " "+\!HB*2S 2G%** G	3 	c  5,> 5%,,#$ . 4,--.	2 =*W +,<= ,.?@   $&99<QQ
  	H  	$	

$ 
$$$ $&$ $(@4$&	CS 	C# 	C# 	C   v v0B vriU^^ i3?? is iXI d 
yE  	B<  		s%   %\= *B0] =]]]]