
    #h                      U d dl m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Zd dlZd dlZd dlZd dlm Z  d dlm!Z! d dl
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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z;m<Z< d dl=Z=d dl>Z=d dl?Z=d dl@mAc mBZC d d	l=mDZD d d
lEmFZFmGZGmHZHmIZI d dlJmKZK d dlLmMZM d dlNmOZOmPZP d dlQmRZR d dlSmTZTmUZUmVZVmWZW d dlXmYZYmZZZ d dl[m\Z\ d dl]m^Z^ d dl_m`Z`maZa d dlbmcZc 	 d dldZe	 d dlgZ=d dlhmiZj d dlNmkZk d dlgmlZl ddlmmnZn eerpeeeej                  eej                  eej                  fZrdesd<   eeejeej                  ejj                  eej                  ejj                  eej                  ejj                  iZtndZri Ztd dlumvZvmwZwmxZx  e7d      Zze=j                  j                  j                  Z~e=j                  j                  j                  Ze=j                  j                  j                  Z ej                  ejP                        Zdesd<   i Zd esd!<   d"Zd#Zd$e d%Z ej                  e      Zi Zd&esd'<    ej                  e      Zd(esd)<    ej                         Z G d* d+e	j"                        Z G d, d-      Z	 	 	 	 	 	 dd.Zd add/Zdd0Zd add1Zdd2Zdd3Zd4esd5<   dd6Ze 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd8       Ze3ddd9       Ze3	 d	 	 	 	 	 dd:       Zd d!d;Zej>                  dd<       Ze=jB                  e=jD                  e=j                  fe=jF                  e=jH                  e=jJ                  fe=jL                  e=jN                  e=jP                  fe=jR                  e=jT                  fe=jV                  e=jX                  fe=jZ                  e=j\                  fe=j^                  e=j`                  e=jb                  fe=jd                  e=jf                  e=jh                  fe=jj                  e=jl                  e=jn                  fe=jp                  e=jr                  fi
Z G d= d>      Z e       Zd? Zdd@ZdA ZdB Zd"dCZd#dDZd$dEZÐd%dFZdG ZdH Z G dI dJ      Ze3d&dK       Ze3	 	 	 	 	 	 d'dL       Ze3d(dM       ZdN Zej                  dOk\  rIej                  ej                  ej                  ejn                  ej                  ej                  fZdP ZdQ ZdR ZdS ZdT ZdU ZdV ZdW ZdX ZdY ZdZ Zd[ Z e
jD                  d\      d]        Zܐd)d^Zd_ Zސd*d`Zߐd*daZdbZej                   G dc dd             ZdeZ ej                  ef      adgesdh<   d+diZd,djZ	 	 	 	 	 	 	 	 	 	 d-dkZ eMel      Zd.dmZddnZd/doZ G dp dq      Zdadresds<   d0dtZe 	 	 d1	 	 	 	 	 	 	 d2du       Zej                   G dv dw             Z G dx dyeǫ      Z e       e_        dz Zdd{d|Zd} Zd3d~Ze d        Zd ZddZd Zd Zd Z e
jD                  d      d4d       Zd Z d5dZd Z e"d      d        Zeeeeee ed      ej                  e
j                  ej                  e=j                  e=j                  e=j                  e=j                  e=j                   e=j"                  e=j                  j$                  j&                  e=j(                  j*                  hZdesd<    ea       r0d dlZej1                  ej2                  j                         	 d Zd Zd Zd Zd Zd Zd Z  ei jC                               Z"desd<    ei jG                               Z$desd<    e ejJ                         jG                               Z&desd<    e e'd            Z(desd<    e e' e)d                   Z*desd<   e(jV                  Z,e-j\                  Z/d Z0d Z1d Z2e3Z4d6dZ5d Z6d Z7d Z8d Z9d Z:ddZ;d Z<d Z=d"dZ>d"dZ?dZ@d dlAmBZB d ZCd ZDd ZEd ZFdd7dd7dd7d7ej                  d7f	dZHd ZIej@                  d        ZJ eǫ       ZK ej                  eL      ZMdesd<   g ZNdesd<    eǫ       ZO e
jD                  d      d        ZPd ZQd7dZRd ZSd ZTddZU ej                         ZWd ZXe d        ZYd ZZd Z[dÄ Z\d8dĄZ]dń Z^d9dƄZ_d:dǄZ`d;dȄZadd<dɄZb G dʄ de	j"                        Zcd=d̄Zd	 	 	 	 	 	 	 	 d>d̈́Zed΄ Zfdτ ZgddgZhddgZig dԢZjeheiz   ejz   ZkdՄ Zl	 	 	 d?dքZm	 	 	 d?dׄZnd؄ Zodل Zp G dڄ d۫      Zqd܄ Zr G d݄ dޫ      Zs G d߄ d      Ztd Zud Zvd Zwd Zxd Zyd Zzd@dZ{ej                   G d d             Z|dAdZ}dBdZ~d Zd Zd Zd ZdCdZd Zd Zd Zej@                  dDd       Zd Zd Z G d de=j                  j                        ZdEdZd Zd Z G d d      Z e       Zdesd<   d5d Zd Zej@                  d        Zd Zd Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zi Zdesd<   d Zd Z G d d      ZdFdZy# ef$ r dZeY 
w xY w# ey$ r Y 
w xY w(G      )annotationsN)contextmanager)is_dataclass)	lru_cache)MethodWrapperType)AnyCallablecastClassVarCounterDefaultDictDequeDict	GeneratorGenericIterableIteratorKeysViewListOptionaloverloadSetTupleTypeTypeVarUnion
ValuesView)LiteralTypeIs)fx)_instruction_counter_len_torch_function_stack_pop_torch_function_stack_push_on_torch_function_stack)enable_python_dispatcher)MetricsContext)SourceTracingContext)is_sparse_compressed)log_chromium_event_internallog_compilation_eventrecord_chromium_event_internalsignpost_event)_format_graph_codelazy_format_graph_code)_WaitCounter)LazyModuleMixin)
has_tritonhas_triton_package)RemovableHandle)detect_fake_mode
LazyString   )configzTuple[types.ModuleType, ...]NP_SUPPORTED_MODULES )
FakeTensoris_fakemaybe_get_fake_modeTzDefaultDict[str, Counter[str]]countersDict[str, Any]optimus_scuba_logzAhttps://pytorch.org/docs/main/torch.compiler_troubleshooting.htmlz;https://pytorch.org/docs/main/torch.compiler_nn_module.htmlzSee z& for more information and limitations.zDict[str, List[float]]compilation_time_metricsDict[str, float]cumulative_time_spent_nsc                      e Zd ZdZdZdZy)ReInplaceTriggerr8         N)__name__
__module____qualname__AUTO_FUNC_V1AUTO_FUNC_V2
TRITON_OPSr;       P/var/www/html/sandstorm/venv/lib/python3.12/site-packages/torch/_dynamo/utils.pyrG   rG      s    LLJrP   rG   c                      e Zd ZU  ej                  e      Zded<   ed
d       Z	edd       Z
ed        Zed        Zed        Zed        Zy	)ReinplaceCounterszDefaultDict[str, int]_valuesc                X    |dk7  r%| j                   d|j                   xx   |z  cc<   y y Nr   missed_bytes_)rT   name)clstriggerbytess      rQ   add_missed_bytesz"ReinplaceCounters.add_missed_bytes   s-    A:KK-~675@7 rP   c                D    |dk7  r| j                   d| xx   |z  cc<   y y Nr   missed_tensors_)rT   )rY   rZ   counts      rQ   add_missed_opportunitiesz*ReinplaceCounters.add_missed_opportunities   s)    A:KK/'34=4 rP   c                8    | j                   j                          y N)rT   clearrY   s    rQ   rd   zReinplaceCounters.clear   s    rP   c                d    d}t         D ]$  }|| j                  j                  d| d      z  }& |S r^   )rG   rT   getrY   sumrZ   s      rQ   get_total_missedz"ReinplaceCounters.get_total_missed   s=    ' 	CG3;;??_WI#>BBC	C
rP   c                x    d}t         D ].  }|| j                  j                  d|j                   d      z  }0 |S rV   )rG   rT   rg   rX   rh   s      rQ   get_total_missed_bytesz(ReinplaceCounters.get_total_missed_bytes   sA    ' 	FG3;;??]7<<.#A1EEC	F
rP   c                L    | j                   rt        dd| j                          y y )Ninductorreinplace_counters)rT   r-   re   s    rQ   logzReinplaceCounters.log   s!     ;;:';S[[I rP   N)rZ   rG   r[   int)rZ   rG   r`   rq   )rJ   rK   rL   collectionsdefaultdictrq   rT   __annotations__classmethodr\   ra   rd   rj   rl   rp   r;   rP   rQ   rS   rS      s    %<[%<%<S%AG"A A A
 > >       J JrP   rS   c                    	 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     rQ   	<genexpr>ztabulate.<locals>.<genexpr>   s$      
),DIIc#sm$
s   )+)tabulateImportErrorr|   	itertoolschain)rowsrx   r   s      rQ   r   r      sZ    
  w 77 
yy 
09	40P
 
 	

s    6AAc                     t         dz   a y Nr8   )
curr_framer;   rP   rQ   increment_framer      s    aJrP   c                 X    t         j                          t        j                          day Nr   )rE   rd   rC   r   r;   rP   rQ   reset_frame_countr      s    ""$""$JrP   c                    t         | z  a y rc   )op_count)cnts    rQ   increment_op_countr      s    OHrP   c                     i } t         j                         D ]  \  }}|dz  | |<    | j                  dd      | j                  dd      z   | d<   | S )N    eAentire_frame_compiler   entire_backward_compiletotal_wall_time)rE   itemsrg   )total_by_keyphasetimings      rQ   calculate_time_spentr      sl    L1779 +v$slU+ '3&6&6'2A6'7L"# rP   c            	         t               } d}| j                         D ]  \  }}| d| dt        |d       } t        |       y )NzTIMING: :   )r   r   roundprint)r   outkeyvalues       rQ   print_time_reportr     sQ    ')L
C"((* /
UQse1U5!_-./ 
#JrP   r&   _METRICS_CONTEXTc                     t         S rc   )r   r;   rP   rQ   get_metrics_contextr   %  s    rP   Fc           	   #  H  K   ||j                  d      sJ |r|}| }n| }d}| t        vr	g t        | <   i }|r|j                  |       |r|j                  d|i       t               }	t	        j
                         }
|	j                  ||
||       	 t        j                  j                  |  d      5  |r*t        d|        j                         5  d ddd       nd ddd       t	        j
                         }||
z
  }t        |    j                  |dz         |	j                  ||i |
|       |rAt               }|j                         r|j!                  ||dz         t"        |xx   |z  cc<   yy# 1 sw Y   xY w# 1 sw Y   xY w# t	        j
                         }||
z
  }t        |    j                  |dz         |	j                  ||i |
|       |rAt               }|j                         r|j!                  ||dz         t"        |xx   |z  cc<   w w xY ww)a  
    dynamo_timed is a context manager
    By wrapping a function in dynamo_timed, we can get a few things:

    1) Log timings to pt2_compile_events.
    2) Log timings to CompilationMetrics (dynamo_compile).
    3) Chromium events.
    4) Storing a record in compilation_time_metrics
       For example:

        def _foo(...):
            with dynamo_timed("_foo"):
                ...

        Would show up as an entry in our timing dict:
        OrderedDict([('_foo', [0.083690, 0.23949, 3.1425e-05])])
        This is extremely useful for granular debugging.

    Although it is tempting to use dynamo_timed as a decorator, please do not.
    In its decorator form it makes cProfile traces less useful as dynamo_timed
    suddenly becomes a bottleneck for lots of function calls (as only one parent
    pointer is recorded).

    Params:
    - key: key into compile_time_metrics. If phase_name is not provided, this is
      also the event name used for pt2_compile_events logs and chromium events.
    - phase_name: Optional override for the event name.
    - log_pt2_compile_event: Whether to log a pt2 compile event internally.
    - metadata: Extra metadata to put in pt2_compile_events.
    - dynamo_compile_column_us: If provided, updates the specified CompilationMetrics
      field to be logged to dyname_compile column. We expect all columns to be _us;
      therefore, the field name must end with "_us".
    - log_waitcounter: If set, we'll log a waitcounter of the form "pytorch.dynamo_timed.{key}"
    N_usfn_namez (dynamo_timed)zpytorch.dynamo_timed.r     )endswithrC   updateget_chromium_event_loggertimetime_nslog_event_starttorchprofilerrecord_functionr0   guardappendlog_event_endr   in_progress	incrementrE   )r   
phase_namelog_pt2_compile_eventmetadatadynamo_compile_column_uslog_waitcounter
event_namer   event_metadatachromium_logstart_nsend_nstime_spent_nsmetrics_contexts                 rQ   dynamo_timedr   )  s9    Z  +'00777


**(* %Nh'y'23(A(CL||~H  Hn.CB^^++se?,CD 	!$9#"?@FFH   	 ) %,,]S-@A""H.C	
 $13O**,)),mt.C %Z0MA0 $ 	 	 ) %,,]S-@A""H.C	
 $13O**,)),mt.C %Z0MA0 $sP   BH""F 3FE9F$F ,BH"9F	>FF
F BHH"c                     y rc   r;   repr	aggregates     rQ   compile_timesr         rP   c                     y rc   r;   r   s     rQ   r   r          rP   c                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 rc   r;   xs    rQ   <lambda>zcompile_times.<locals>.<lambda>  s     rP   c                `    r |t        |             S dj                  t        ||             S )Nr{   )ri   r|   r}   )valuesitem_fnr   s     rQ   fmt_fnzcompile_times.<locals>.fmt_fn  s+    3v;''yyWf-..rP   r~   c                
    | dS )Nz.4fr;   r   s    rQ   r   zcompile_times.<locals>.<lambda>  s
    3 rP   )r   z!TorchDynamo compilation metrics:
)FunctionzRuntimes (s)rw   csvc                
    | dS )Nz.6fr;   r   s    rQ   r   zcompile_times.<locals>.<lambda>  s
    1S' rP   N)rC   r   r   listkeys)	r   r   r   kr   r   vr   rx   s	    `       rQ   r   r     s      + /
 u} .
 /2<PQR
 
 3x&BCC
	 .446
 123
 
 /4467

s   B#Bc                 D    t         j                  t        dd             y )Nr~   Tr   )rp   infor   r;   rP   rQ   dump_compile_timesr     s    HH]67rP   c                  $    e Zd ZdddZd ZddZy)DuplicateWarningCheckerc                2    || _         | j                          y rc   )maxsizereset)selfr   s     rQ   __init__z DuplicateWarningChecker.__init__  s    

rP   c                6    t        j                         | _        y rc   )rr   OrderedDictsetr   s    rQ   r   zDuplicateWarningChecker.reset  s    **,rP   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_endr9   verboselenr   popitemr   r   s     rQ   addzDuplicateWarningChecker.add  s    $((?HH  4 0>>
  !DHHSMdhh-$,,.  e , dhh-$,,.rP   N)   )r   rq   returnNone)r   z!Union[str, Tuple[object, object]]r   bool)rJ   rK   rL   r   r   r   r;   rP   rQ   r   r     s    -	rP   r   c                     t         j                  j                  dd      dk(  } | r
t               S t	        j
                         S )NTORCH_COMPILE_DEBUG01)osenvironrg   add_file_handler
contextlib	ExitStack)compile_debugs    rQ   setup_compile_debugr    s7    JJNN#8#>#EM!!!!rP   c                 ,    t         j                          y rc   )graph_break_dup_warning_checkerr   r;   rP   rQ   reset_graph_break_dup_checkerr    s    #))+rP   c                    t         j                  j                  t               d      } t        j                  | d       t        j                  t         j                  j                  | d            t        j                  d      j                         t        j                         }|j                  fd       |S )NtorchdynamoTexist_okz	debug.logztorch._dynamoc                 &    j                         S rc   removeHandlerlog_file_handlerloggers   rQ   r   z"add_file_handler.<locals>.<lambda>  s    v334DE rP   )r   pathr|   get_debug_dirmakedirsloggingFileHandler	getLogger
addHandlerr  r  callback)log_path	exitstackr  r  s     @@rQ   r  r    s    ww||MO];HKK4(**277<<++NO/F
&'$$&IEFrP   c                 B   t        j                         } t        j                  xt	        j
                  t        j                        t        j                  j                  j                         D ](  j                         | j                  fd       * | S | S )Nc                 &    j                         S rc   r  r  s   rQ   r   z setup_log_file.<locals>.<lambda>  s    v';';<L'M rP   )r  r  r9   log_file_namer  r  r   _logging	_internalget_loggersr  r  )r  r  r  s    @@rQ   setup_log_filer#     s    $$&I'"..v/C/CDnn..::< 	OF./MN	O rP   c                |    t                d|j                   dt        |       j                   d|j                   dS )Nz/error_recordings/_z.rec)r  co_nametyperJ   co_firstlineno)exccodes     rQ   gen_record_file_namer+    sB    o aS	""#1T%8%8$9? ?rP   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.Tr  wbz#Unable to write execution record %s)r   r  existsrp   warningr  dirnameopendump	Exception	exception)filenameexec_recordfs      rQ   write_record_to_filer8    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c                T    d}| j                   D ]  }d|j                  v s|dz  } |S )Nr   callr8   )nodesop)gcns      rQ   count_callsr@    s5    	AWW QTT>FA HrP   c                    | S rc   r;   r   s    rQ   identityrB  '  s    HrP   c                N    	 t        |        y# t        $ r Y yt        $ r Y yw xY w)NTF)hash	TypeError
ValueErrorr   s    rQ   hashablerG  +  s.    Q  s    	$$$c                      y rc   r;   argskwargss     rQ   nothingrL  6  s    rP   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                     i | _         i | _        y rc   r   refsr   s    rQ   r   zExactWeakKeyDictionary.__init__=  s    	rP   c                2    | j                   t        |         S rc   )r   idr   s     rQ   __getitem__z"ExactWeakKeyDictionary.__getitem__A  s    {{2c7##rP   Nc                L    | j                   j                  t        |      |      S rc   )r   rg   rS  )r   r   defaults      rQ   rg   zExactWeakKeyDictionary.getD  s    {{r#w00rP   c                0    t        |      | j                  v S rc   )rS  r   r   s     rQ   __contains__z#ExactWeakKeyDictionary.__contains__G  s    #w$++%%rP   c                     t        |       j                  vr't        j                  | fd       j                  <   | j                  <   y )Nc                &    j                        S rc   )
_remove_id)refidxr   s    rQ   r   z4ExactWeakKeyDictionary.__setitem__.<locals>.<lambda>M  s    $//#:N rP   )rS  rQ  weakrefr\  r   )r   r   r   r]  s   `  @rQ   __setitem__z"ExactWeakKeyDictionary.__setitem__J  s?    gdii$[[.NODIIcN CrP   c                r    || j                   v r| j                   |= || j                  v r| j                  |= y y rc   rP  )r   r]  s     rQ   r[  z!ExactWeakKeyDictionary._remove_idP  s6    $++C $))		# rP   c                l    | j                   j                          | j                  j                          y rc   )rQ  rd   r   r   s    rQ   rd   zExactWeakKeyDictionary.clearV  s     		rP   rc   )rJ   rK   rL   __doc__r   rT  rg   rX  r_  r[  rd   r;   rP   rQ   rN  rN  :  s(    f$1&!rP   rN  c                     y rc   r;   objallowed_typess     rQ   istyperg  [  r   rP   c                     y rc   r;   rd  s     rQ   rg  rg  `  r   rP   c                     y rc   r;   rd  s     rQ   rg  rg  g  r   rP   c                l    t        |t        t        t        f      rt	        |       |v S t	        |       |u S )zisinstance() without subclasses)
isinstancetupler   r   r'  rd  s     rQ   rg  rg  l  s1    -%s!34CyM))9%%rP   rI      c                    t         j                  dk\  rt        | t              ryt        | t        j
                        xs | t        j                  u S )Nrm  T)sysversion_infork  _builtin_final_typing_classestyping_Finalr   r   s    rQ   	is_typingrv    s>     7"z%9V'WeV]]+Fu/FFrP   c                   t         syt        | t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  f      S NF)
nprg  int8int16int32int64uint8uint16uint32uint64ru  s    rQ   is_numpy_int_typer    sU    GGHHHHHHHHIIIIII		
 rP   c                    t         syt        | t         j                  t         j                  t         j                  f      S rx  )ry  rg  float16float32float64ru  s    rQ   is_numpy_float_typer    s2    JJJJJJ	
 rP   c                x    t        | t        j                        xr t        t	        j
                  | d            S )N__wrapped__)rk  	functools_lru_cache_wrapperis_functioninspectgetattr_staticru  s    rQ   is_lru_cache_wrapped_functionr    s4    eY99: {um4@ rP   c                    t        |       xs> t        | t        j                  j                  t        j                  j
                  f      S rc   )r  rk  r   _opsOpOverloadPacket
OpOverloadru  s    rQ   is_function_or_wrapperr    s9    u 

++UZZ-B-BC" rP   c                    t        | t        j                  t        j                  t        j                  t        j
                  f      S rc   )rk  typesFunctionTypeBuiltinFunctionTypeMethodDescriptorTypeWrapperDescriptorTyperu  s    rQ   r  r    s;    %%&&''		
 rP   c                    t        | t        j                  t        j                  t        j                  t        j
                  t        j                  f      S rc   )rk  r  GetSetDescriptorTyper  r  MemberDescriptorTyper   ru  s    rQ   is_wrapper_or_member_descriptorr    sF     &&&&''&&##	
 rP   c                    t        |       d   S r   ) unwrap_with_attr_name_if_wrapper)fns    rQ   unwrap_if_wrapperr    s    +B/22rP   c                    t        |       r4t        j                  | dd      rt        j                  | d|       } d}| |fS d }| |fS )N_torchdynamo_inlineF)r  r  r  )r  	attr_names     rQ   r  r    sT     2711"6KUS##B(=rB)	 y= 	y=rP   c                D    t         syt        | t         j                        S rx  )ry  rg  ndarrayru  s    rQ   is_numpy_ndarrayr    s    %$$rP   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	Parameterr9   traceable_tensor_subclasses_subclassesr<   rg  )re  tensor_lists     rQ   istensorr    sW     	% 
	+	+%K
 !2!2!=!= ??K#{##rP   c                "    t        | t              S rc   )rk  r1   )mods    rQ   is_lazy_moduler    s    c?++rP   r   c                     t        |   y rc   )r   rJ  s    rQ   
print_oncer    s	    	4LrP   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 rc   r;   r   s   rQ   r7  zmake_cell.<locals>.f  s    rP   r8   r   )__closure__r   )valr7  r   s     @rQ   	make_cellr    s>    A ==$Q]]);q)@@@==rP   c                <   	 t        d | D              }|j                         D ci c]  \  }}||j                          }}}||fS c c}}w # t        $ rC}ddlm} ddlm}  |d ||   d |t        |j                                 |       Y d }~y d }~ww xY w)Nc              3  <   K   | ]  }|j                           y wrc   )as_proxyr   args     rQ   r   z$proxy_args_kwargs.<locals>.<genexpr>  s     :c3<<>:   r8   unimplemented)typestrzcall_function args: r   from_exc)
rl  r   r  NotImplementedErrorr)  r  variables.baser  r   r   )	rJ  rK  
proxy_argsr   r  proxy_kwargser  r  s	            rQ   proxy_args_kwargsr    s    
:T::
<BLLNKSS\\^+KK<'' L 
&+"7D>"2!GT&--/=R4S3TU	
 	
	
s(   %A A	A 	A 	B9BBc                &    | d S t        | dz        S Nr   rq   r   s    rQ   	to_int_msr    s    94/#a$h-/rP   c                &    | d S t        | dz        S )Ni@B r  r  s    rQ   	to_int_usr  #  s    944#a)m"44rP   rI   c                     e Zd ZU dZded<   dZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded <   dZded!<   dZded"<   dZ ded#<   dZ!ded$<   dZ"ded%<   dZ#ded&<   dZ$ded'<   dZ%ded(<   dZ&ded)<   dZ'ded*<   dZ(ded+<   dZ)ded,<   dZ*ded-<   dZ+ded.<   dZ,ded/<   dZ-ded0<   dZ.ded1<   dZ/ded2<   dZ0ded3<   dZ1ded4<   dZ2ded5<   dZ3ded6<   dZ4ded7<   dZ5ded8<   dZ6ded9<   dZ7ded:<   dZ8ded;<   dZ9ded<<   dZ:ded=<   dZ;ded><   e<Z=d?ed@<   dZ>dedA<   dZ?dedB<   dZ@dedC<   dZAdedD<   dZBdedE<   dZCdedF<   dZDdedG<   dZEdedH<   dZFdedI<   dZGdJedK<   y)LCompilationMetricsNOptional[str]
compile_id	frame_keyr&  co_filenameOptional[int]r(  
cache_sizeaccumulated_cache_sizeguard_countshape_env_guard_countgraph_op_countgraph_node_countgraph_input_countOptional[float]
start_timeentire_frame_compile_time_sbackend_compile_time_sinductor_compile_time_scode_gen_time_s	fail_typefail_reasonfail_user_frame_filenamefail_user_frame_linenozOptional[Set[str]]non_compliant_opscompliant_custom_opsrestart_reasonsdynamo_time_before_restart_szOptional[bool]has_guarded_coderemote_cache_time_saved_sstructured_logging_overhead_sconfig_suppress_errors config_inline_inbuilt_nn_modulesspecialize_floatdynamo_config
is_forwardnum_triton_bundles!remote_fx_graph_cache_get_time_ms!remote_fx_graph_cache_put_time_msstart_time_usduration_us!dynamo_cumulative_compile_time_us'aot_autograd_cumulative_compile_time_us#inductor_cumulative_compile_time_us,inductor_code_gen_cumulative_compile_time_ustriton_compile_time_usruntime_cudagraphify_time_usruntime_triton_autotune_time_us%dynamo_compile_time_before_restart_uscuda_synchronize_time_us distributed_ephemeral_timeout_usstructured_logging_overhead_us!remote_fx_graph_cache_get_time_us!remote_fx_graph_cache_put_time_us#backward_cumulative_compile_time_usend_time_uspre_grad_pass_time_uspost_grad_pass_time_usjoint_graph_pass_time_usrq   log_format_versioninductor_configremote_cache_version"inductor_fx_remote_cache_hit_count#inductor_fx_remote_cache_miss_count%inductor_fx_remote_cache_backend_type!inductor_fx_remote_cache_hit_keys"inductor_fx_remote_cache_miss_keyscuda_versiontriton_versionzOptional[dict[str, bool]]feature_usage)HrJ   rK   rL   r  rt   r  r&  r  r(  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r	  r
  r  r  r  r  LOG_FORMAT_VERSIONr  r  r  r  r  r  r  r  r  r  r  r;   rP   rQ   r  r  ,  s    $J$#I}#!G]!!%K%$(NM( $J$,0M0!%K%+/=/$(NM(&*m*'+}+"&J&377.2O2/3_3'+O_+#I}#!%K%.2m2,0M0,0)0/3,3*.O'.48 /8 (,n+15559!?9-1N17;$n;'+n+#'M='!%J%(,,7;%};7;%};#'M='!%K%7;%};=A+]A9='=BF0-F,0M026 -659#]9;?)=?.2m26:$m:48"M87;%};7;%};9='=!%K%+/=/,0M0.2m200%)O])*.-.8<&<9='=;?)=?7;%};8<&<"&L-&$(NM(/3M,3rP   r  @   maxlenzDeque[CompilationMetrics]_compilation_metricsc                   t               }|j                         }|sy |j                  || j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                  | j$                  t'        | j$                        nd | j(                  t'        | j(                        nd | j*                  t'        | j*                        nd | j,                  | j.                  | j0                         y )N)r   r  r&  r  r(  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r   get_topadd_event_datar  r&  r  r(  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  )r>  event_loggerr   s      rQ   #add_compilation_metrics_to_chromiumr#  ~  s%   ,.L%%'J++		MM''<< 77MM55''++--++MM!"!;!; 77 * q223!!- "!"8"89( Q../%&%C%C++oo;   rP   c                 *    G d dt         j                        } d}t               }d}t        j                  j
                  r(t        j                  j
                  j                         nd}|	 |j                         D ][  \  }}t        |t              rt        j                  ||      r|j                  |       t        |t              sNt        |      ||<   ] |D ]  }||=  t        j                  || d      }|S |S # t        $ r d}Y |S w xY w)zN
    Method to parse and scrub uninteresting configs from inductor config
    c                       e Zd Z fdZ xZS )A_scrubbed_inductor_config_for_logging.<locals>.TypeSafeSerializerc                B    	 t         |   |      S # t        $ r Y yw xY w)NzValue is not JSON serializable)superrV  r3  )r   o	__class__s     rQ   rV  zI_scrubbed_inductor_config_for_logging.<locals>.TypeSafeSerializer.default  s)    8wq)) 878s    	)rJ   rK   rL   rV  __classcell__r*  s   @rQ   TypeSafeSerializerr&    s    	8 	8rP   r-  zV((^TYPE_CHECKING$)|(.*_progress$)|(.*TESTING.*)|(.*(rocm|halide).*)|(^trace\..*)|(^_))NT)rY   skipkeysz(Inductor Config is not JSON serializable)jsonJSONEncoderr   r   	_inductorr9   get_config_copyr   rk  r~   researchr   r   dumpsr3  )r-  configs_to_scrub_rekeys_to_scrubinductor_conf_strinductor_config_copyr   r  s          rQ   %_scrubbed_inductor_config_for_loggingr:    s   8T-- 8 tEM49OO4J4J..0PT  '	K0668 :S!#s+ryy9Lc/R!%%c*c3'04S	(-: % .(-. !%

$*<t!   	K J	Ks   /AD 2D DDc                *   fd}fd}dfd}t         j                  j                         }t         j                  j                  j                         r1	 ddlm}	m}
 |
}|	j                         }t        |      j                  }nd }d }t        t         j                  j                  j!                               | dz  |dz  || z
  dz  |r|j"                  nd |rt        |      nd t%        |      t'               t         j(                  j*                  t-               rt.        j0                  nd |d       |d	      ||d
}| dz   |d       |d       |d       |d       |d       |d       |d      |d	}t3        di i ||t4        j7                         j8                  rd}nd}t         j                  j;                  |fdd       t=               t>        j@                  rtC               y y # t        $ r d }d }Y w xY w)Nc                :    j                  | d       }||dz  S d S )Ng    .Arg   fieldmetricmetricss     rQ   us_to_sz+record_compilation_metrics.<locals>.us_to_s  s'    UD)%1v|;t;rP   c                :    j                  | d       }||dz  S d S r  r=  r>  s     rQ   us_to_msz,record_compilation_metrics.<locals>.us_to_ms  s'    UD)!'!3v~==rP   c                    ddj                  | d       }|y | = t        |t              st        |t              sy dj	                  fd|D              S )Nc                N    	 t        |       S # t        $ r t        d       cY S w xY wrc   )r~   r3  )items    rQ   safe_strzPrecord_compilation_metrics.<locals>._convert_collection_to_str.<locals>.safe_str  s*    !4y  !4y !s   
 $$,c              3  .   K   | ]  } |        y wrc   r;   )r   rG  rH  s     rQ   r   zQrecord_compilation_metrics.<locals>._convert_collection_to_str.<locals>.<genexpr>  s     :4:   )rG  r   r   r~   )rg   rk  r   r   r|   )r?  r@  rH  rA  s     @rQ   _convert_collection_to_strz>record_compilation_metrics.<locals>._convert_collection_to_str  sV    	! UD)> EN&#&z&$/Gxx:6:::rP   r   )FbRemoteFxGraphCacheREMOTE_CACHE_VERSIONr    r  r  )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r  r  r	  )	r  r  r  r  r  r  r  r  r  compilation_metricsbwd_compilation_metricsc            	         t        j                        j                         D  ci c]#  \  } }| t        |t              rt        |      n|% c}} S c c}} w rc   )dataclassesasdictr   rk  r   r   )r   r   rP  s     rQ   r   z,record_compilation_metrics.<locals>.<lambda>2  sM    #**+>?EEG
1 *Q,tAw!3
  
s   (AF)record_logging_overhead)r?  r~   r   r  r;   )"r   r   get_structured_logging_overheadr1  utils should_use_remote_fx_graph_cachetorch._inductor.fb.remote_cacherM  rN  get_remote_backendr'  rJ   ModuleNotFoundErrorr~   _guardsCompileContextcurrent_compile_idrL   r  r:  versioncudar2   triton__version__r  r  r   r  trace_structuredr#  r9   log_compilation_metricsr+   )start_time_nsend_time_nsrA  exc_type	exc_valuerB  rD  rL  r  rM  rN  r  backendr  common_metricslegacy_metricsrX   rP  s     `              @rQ   record_compilation_metricsrl    s*   <>;" %*NN$R$R$T!==?	9
 $8 *==?G48M4J4J1
 15-# %--66IIKL&$."d*#m3<.6X**D)2s9~*34Q*R@B**0:&,,"-G/.
 /I0/
 !51V%N0 $c)'./R'S")*S"T#*+P#Q"#QR%,-O%P-5/.
 .6/.
 *GN  - 
9^
9~
9
9  34%%$(	NN##	
 !& $  ((;< %%12 &Q # 	9#' 481	9s   /H HH)on_exitc                    t        t              | kD  r't        j                          t        t              | kD  r't        j                  t        |       }|ay )Nr  )r   r  popleftrr   deque)new_size	new_deques     rQ   set_compilation_metrics_limitrs  I  sE    
"
#h
.$$& "
#h
.!!"6xHI$rP   c                 ,    t         j                          y rc   )r  rd   r;   rP   rQ   clear_compilation_metricsru  Q  s     rP   c                      t        t              S rc   )r   r  r;   rP   rQ   get_compilation_metricsrw  V  s    $%%rP   c                      e Zd ZdZddZddZd ZddZd ZddZ		 	 	 	 ddZ
	 d	 	 	 	 	 	 	 	 	 dd	Zdd
Z	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 	 	 ddZy)ChromiumEventLoggera  Logs chromium events to structured logs. tlparse will concatenate these into a perfetto UI link.

    See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.yr4qxyxotyw for
    a specification of the Chromium Event JSON format.
    c                    t        | j                  d      r| j                  j                  S g | j                  _        | j                  j                  S )z]
        The main event stack, with every chromium event.
        Logged to tlparse.
        stack)hasattrtlsr{  r   s    rQ   	get_stackzChromiumEventLogger.get_stacka  s9    
 488W%88>>!DHHN88>>!rP   c                4    | j                         }|r|d   S dS )zG
        Get the top event name or None if the stack is empty.
        N)r~  )r   r{  s     rQ   r   zChromiumEventLogger.get_topl  s!      !uRy+t+rP   c                    t        | j                  d      r| j                  j                  S g | j                  _        | j                  j                  S )zq
        A smaller subset of the main stack that gets used to log
        PT2 Compile Events internally.
        pt2_compile_substack)r|  r}  r  r   s    rQ   get_pt2_compile_substackz,ChromiumEventLogger.get_pt2_compile_substacks  s?    
 4883488000,.DHH)88000rP   c                |    t        | j                  d      si | j                  _        | j                  j                  S )N
event_data)r|  r}  r  r   s    rQ   get_event_dataz"ChromiumEventLogger.get_event_data~  s,    txx."$DHHxx"""rP   c                    t        j                         | _        t        t	        j
                               | _        t        j                  d| j                         y )Nz*ChromiumEventLogger initialized with id %s)		threadinglocalr}  r~   uuiduuid4id_rp   r   r   s    rQ   r   zChromiumEventLogger.__init__  s9    ??$ tzz|$ 	=txxHrP   c                P    || j                         vry | j                  |fi | y)zd
        Same as add_event_data, but will silently not log if the event isn't in the stack.
        N)r~  r!  )r   r   rK  s      rQ   try_add_event_dataz&ChromiumEventLogger.try_add_event_data  s+     T^^--J1&1rP   c                    || j                         vr)t        dt        |       d| j                          d      | j                         }||vri ||<   ||   j	                  |       y)zz
        Adds additional metadata info to an in-progress event
        This metadata is recorded in the END event
        zEvent z not in zq. Cannot add metadata to events that aren't in progress. Please make sure the event has started and hasn't ended.N)r~  RuntimeErrorr   r  r   )r   r   rK  r  s       rQ   r!  z"ChromiumEventLogger.add_event_data  s}     T^^--j)*(4>>3C2D EK K 
 ((*
Z'%'Jz":%%f-rP   c                @   t        t        j                  j                  j	                               }||d<   | j                  ||d|       | j                         j                  |        | j                  |fi | |r | j                         j                  |       yy)z
        Logs the start of a single event.
        :param str event_name Name of event to appear in trace
        :param time_ns Timestamp in nanoseconds
        :param metadata: Any extra metadata associated with this event
        r  BN)
r~   r   r\  r]  r^  _log_timed_eventr~  r   r!  r  )r   r   r   r   r   r  s         rQ   r   z#ChromiumEventLogger.log_event_start  s     55HHJK
!+		
 	
+J3(3 ))+22:> !rP   c                    | j                         }| j                         }|j                          |j                          | j                         }|j                          y rc   )r~  r  rd   r  )r   r{  substackr  s       rQ   r   zChromiumEventLogger.reset  sK      002((*
rP   c                   t        t        j                  j                  j	                               }||d<   | j                         }|v r	|   }|= ni }|j                  |       | j                  |d|      }	fd}
| j                         }|vrt        j                  d       y |
|       |r@| j                         } |
|       t        |	|| j                  |       |j                          |j                          y)aA  
        Logs the end of a single event. This function should only be
        called after log_event_start with the same event_name.
        :param event_name: Name of event to appear in trace
        :param time_ns: Timestamp in nanoseconds
        :param metadata: Any extra metadata associated with this event
        r  Ec                t    | d   k7  r/t         j                  d       | j                          | d   k7  r.y y )Nr  z>ChromiumEventLogger: Detected overlapping events, fixing stack)rp   r/  pop)r{  r   s    rQ   	pop_stackz4ChromiumEventLogger.log_event_end.<locals>.pop_stack  s9    b	) T 		 b	)rP   z7ChromiumEventLogger: Start event not in stack, ignoringN)r~   r   r\  r]  r^  r  r   r  r~  rp   r/  r  r*   r  r  )r   r   r   r   re  r   r  all_event_datar   eventr  event_stackr  s    `           rQ   r   z!ChromiumEventLogger.log_event_end  s    55HHJK
!+ ,,.'+J7Nz*Nh'%%	
	 nn& [( KKQR+ #'#@#@#B *+'+TXX} !$$& 	rP   Nc                    ||dz  ||ddddt         j                  j                  dfddd       t               S )	za
        Logs a timed event in chromium format. See log_event_start, log_event_end, etc.
        r   r   r   )rX   tsrJ  phcattidpidchromium_eventc                      S rc   r;   r  s   rQ   r   z6ChromiumEventLogger._log_timed_event.<locals>.<lambda>(      u rP   F
payload_fnsuppress_contextexpect_trace_id)r   r   rc  r,   )r   r   r   r   r   r  s        @rQ   r  z$ChromiumEventLogger._log_timed_event  sY     D.!	
 	''$"!	 	( 	
 	'u-rP   c           	     4   |i }t        t        j                  j                  j	                               }||d<   ||dz  |ddddddt        j
                  j                  d	fd
dd       |r't        | j                         | j                  |       yy)aZ  
        Log an instant event with no associated duration.
        :param str event_name: Name of event to appear in trace
        :param int time_ns Timestamp in nanoseconds
        :param Optional[Dict[str, Any]] metadata: Any extra metadata associated with this event
        :param str cname optional color for the arrow in the trace
        Nr  r   ir   r   p)rX   r  rJ  r  r  r  r  sr  c                      S rc   r;   r  s   rQ   r   z7ChromiumEventLogger.log_instant_event.<locals>.<lambda>O  r  rP   FTr  )
r~   r   r\  r]  r^  r   rc  r*   r  r  )r   r   r   r   r   r  r  s         @rQ   log_instant_eventz%ChromiumEventLogger.log_instant_event/  s     H55HHJK
!+D.!

 	''$" 	 	( 	
 !'t446' !rP   )r   z	List[str]r   r  )r   rA   )r   r~   r   r   F)
r   r~   r   rq   r   rA   r   r   r   r   r   r   )r   r~   r   rq   r   rA   re  rq   r   r   r   r   rc   )
r   r~   r   rq   r   r~   r   Optional[Dict[str, Any]]r   rA   rx  )
r   r~   r   rq   r   r  r   r   r   r   )rJ   rK   rL   rb  r~  r   r  r  r   r  r!  r   r   r   r  r  r;   rP   rQ   ry  ry  Z  s;   	",	1#
I2.. 
	.2 ',?? ? !	?
  $? 
?6CC C !	C
 C  $C 
CT .2  	
 + 
B .2&+(( ( +	(  $( 
(rP   ry  zOptional[ChromiumEventLogger]CHROMIUM_EVENT_LOGc                 .    t         
t               a t         S rc   )r  ry  r;   rP   rQ   r   r   ]  s    !02rP   c           	   #  D  K   t               }|r|j                          t        j                         }|j	                  | |i |       	 d |j                  | t        j                         i ||       y# |j                  | t        j                         i ||       w xY ww)z
    Context manager that creates a chromium start and end event. Chromium event
    logging is integrated with dynamo_timed, so you probably want to use that
    instead. Use this context manager only if you want to avoid dynamo_timed.
    N)r   r   r   r   r   r   )r   reset_event_logr   chromium_event_logchromium_start_times        rQ   chromium_event_timedr  d  s      34  ",,.&&
		
((LLN!	
((LLN!	
s   AB A4 (B 4)BB c                  <    e Zd ZU dZded<   ded<   d Zed        Zy)	CleanupHookz,Remove a global variable when hook is calledrA   scoper~   rX   c                p    t         t         xj                  dz  c_        | j                  | j                  = y r   )CleanupManagerr`   r  rX   r   rJ  s     rQ   __call__zCleanupHook.__call__  s)    %  A% JJtyy!rP   c                b    || vsJ t         xj                  dz  c_        || |<   t        | |      S r   )r  r`   r  )r  rX   r  s      rQ   createzCleanupHook.create  s7    5   !d5$''rP   N)rJ   rK   rL   rb  rt   r  staticmethodr  r;   rP   rQ   r  r    s)    6
I" ( (rP   r  c                  .     e Zd ZU dZded<    fdZ xZS )r  r   zClassVar[CleanupManager]instancec                Z    | j                   |   D ]	  } |         t        | 	  |       y rc   )r   r(  r[  )r   r]  hookr*  s      rQ   r[  zCleanupManager._remove_id  s-    KK$ 	DF	3rP   )rJ   rK   rL   r`   rt   r[  r+  r,  s   @rQ   r  r    s    E&&   rP   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     rQ   clone_tensorr    sB    		  1AyyQVV'HrP   dtypec          	        t        |       r| S fd}t        j                         5  | j                  j                  dk(  r ||       cddd       S | j
                  t        j                  u rbt        j                   || j                                || j                               | j                  | j                               cddd       S t        |       r| j
                  t        j                  t        j                  hv r!| j                         }| j!                         }n | j#                         }| j%                         }t        j&                   ||       ||       || j)                               | j                  | j
                        cddd       S t+        d t-        | j/                         | j1                               D              }| j2                  rt        j4                  |dz   f|       }n3t        j6                  |dz   xs | j8                  | j                        }| j;                         |j;                         z
  dz  | j=                         z  }|j?                  | j/                         | j1                         |       	 |jA                  | jC                                | jD                  r|jG                  | jH                         | jD                  r(| jJ                  tM        | jJ                  	      |_%        tQ        | d
      r| jR                  jU                         |_)        |cddd       S # tN        $ 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_inputr|  r  copy)r   r  r  s     rQ   torch_clonez clone_input.<locals>.torch_clone  sr    KKN99Q__-99+ u5AF1/0()(A(A(F(F(HA%rP   xlaN)is_coalesced)layoutc              3  2   K   | ]  \  }}|d z
  |z    yw)r8   Nr;   )r   shapestrides      rQ   r   zclone_input.<locals>.<genexpr>  s"      
%2UFUQY& 
       )r  devicer  r  )+r=   r   no_gradr  r'  r  
sparse_coosparse_coo_tensor_indicesrT   r  r  r)   
sparse_csr
sparse_bsrcrow_indicescol_indicesccol_indicesrow_indicessparse_compressed_tensorr   ri   zipsizer  is_quantizedempty_quantizedemptyr  data_ptrelement_sizeas_strided_copy_r  r  r  r  r  r  r  r|  r  r  )r   r  r  compressed_indicesplain_indicesneeded_sizeresultcache_line_offsets    `      rQ   r  r    s    qz 
 688==E!q>6 6 88u'''**AJJL)AIIK(^^-	6 6 "!$xxE,,e.>.>??%&^^%5" !%&^^%5" !11./M*AHHJ'xx)6 68  
69!&&(AHHJ6O
 
 >>**K",<+>BF[[b (8F ZZ\FOO--3^^ 	1668QXXZ1BC
	"LL#yy%%aoo6yyQVV/)!&&> 1/0-.-F-F-K-K-MF*m6 6^  	" q>!g6 6^	"_6 6sE   !M'A4M'CM' C6M'A:M,M'M$M'#M$$M''M0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 rc   )r'  dictr   rk  rl  clone_inputsr   r  r  r   ranger   )example_inputsresr   r   r  s        rQ   r  r    s    Nt#>"))+ 	.JC%''.C!%6CUC6&u-C	. 

~
C3s8_ )c!fell+ Q(CF) JrP   c                    	 | j                          y # t        $ r7}ddlm} t	        j
                  ddt        |             } |d|       |d }~ww xY w)Nr8   )	SkipFramez\(.*rO  z(torch.compile cannot be run in context: )r  r  r)  r  r3  subr   )r  r  r  functorch_subclass_names       rQ   skip_frame_if_in_functorch_moder    sX    	 " #%&&"d3i"@67N6OP
	s    	A2AAc               #    K   t         j                  j                  } t         j                  j                  j
                  } |       5   |        5  t        j                  t         j                  j                               }t        |       t         j                  j                         r1t        j                  t         j                  j                               }d d d        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   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rc   )r   _C_DisableFuncTorchrW  _python_dispatch_disable_current_modesr  randomget_rng_stater  r`  is_availableset_rng_state)disable_functorchdisable_current_modes	rng_statecuda_rng_states       rQ   preserve_rng_stater    s    22!KK88OO		  E"3"5 EKK : : <=	'	2::""$"[[)A)A)CDN	E E
9[[))@@B 	9LL&&y1zz&&(

((8	9 	9E E E E	9 	9U[[))@@B 	9LL&&y1zz&&(

((8	9 	9 	9s   AIFBE?F$I-F# 1(IAF6	I?F	FFIF I#)H>AH2)	H>2H;7H>>Ic                
   t        | t        j                  j                  j                  t        j                  j
                  j                  t        j                  j                  t        j                  j                  f      S rc   )	rk  r   jit_traceTopLevelTracedModule_scriptRecursiveScriptModuleScriptFunctionScriptModule)model0s    rQ   is_jit_modelr  +  sW    II11II33II$$II""		
 rP   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  tracer3  scriptrp   r4  error)modelr  r   s      rQ   torchscriptr%  7  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rc   )r  getfilerE  OSErrorre  s    rQ   r'  r'  I  s-    s##w s    ))c                *    t        t        |             S )zLTest if an object is a namedtuple or a torch.return_types.* quasi-namedtuple)is_namedtuple_clsr'  r)  s    rQ   is_namedtupler,  P  s    T#Y''rP   c                H    	 t         t              rt         dd      }|dv ryt        t         dd      t              rTt	        t         dd            r>t        d  j
                  D              }|t        fk(  ry|rt         fd|D              ryy	# t        $ r Y y	w xY w)
zhTest if an object is a namedtuple or a (torch.return_types|torch.autograd.forward_ad).* quasi-namedtuplerK   N)torch.return_typesztorch.autograd.forward_adT_fields_makec              3  2   K   | ]  }|t         us|  y wrc   )r   )r   ts     rQ   r   z$is_namedtuple_cls.<locals>.<genexpr>`  s     KA!7:JaKs   c              3  h   K   | ])  }t        |      xr j                  |j                  u  + y wrc   )r+  __new__)r   r2  rY   s     rQ   r   z$is_namedtuple_cls.<locals>.<genexpr>d  s:      ! 	 *!, 5KK19945!s   /2F)
issubclassrl  getattrrk  callable	__bases__anyrE  )rY   modulebasess   `  rQ   r+  r+  U  s    c5!S,5FLL'#y$7?HWd+E KKKUH$S ! #!      s   !B AB =B 	B! B!c                   | t         u ryt        | t              sJ t        | d      r| j                  S t
        j                   G d d             }| j                  dk(  sJ  | t        |t        | j                                    }i }t        |      D ];  }|d   dk7  st        t        ||      |      s#t        ||      j                  ||<   = t        |      | j                  k(  sJ t        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 ded<   y)!namedtuple_fields.<locals>.Markerrq   indexNrJ   rK   rL   rt   r;   rP   rQ   MarkerrA  ~  s    
rP   rD  r.  r   r%  )r   )slicer5  rl  r|  r/  rS  	dataclassrK   r}   r   n_fieldsdirrk  r6  rB  r   sortedrg   )rY   rD  re  fieldsrX   s        rQ   namedtuple_fieldsrK  s  s     e|(c5!!!sI{{   >>1111
c&%-.
/CFC 47c>jd);VD"3-33F4L4 v;#,,&&&FJJ/00rP   c           	     6   t        j                         5  t        j                  t         j                  j	                               t         j
                  j                         r1t        j                  t         j
                  j	                               t        j                  | j                         | j                               D cg c]$  }||j                  t        j                  |      f& c}d d d        fd}|S c c}w # 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rc   )r   r  r  r  r`  r  _versionr  )paramr_  original_valuer  r  saved_states      rQ   restorez"checkpoint_params.<locals>.restore  s    ]]_ 	0LL&&y1zz&&(

((82= 0.w>>W,KK/0		0 	0 	0s   A5B)B))B2)r   r  r  r  r  r`  r  r   r   
parametersbuffersrN  )gmrO  rR  r  r  rQ  s      @@@rQ   checkpoint_paramsrV    s    	 
KK : : <=	::""$"[[)A)A)CDN #"**,G
 ENNEKK$67
	
0 N
	
 
s   B5D)D
6D
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  synchronizerL  gccollectmanual_seedr   perf_counterr   )r$  r  timesrX  t0r%  r  t1s           rQ   timedr`    s    zz jj,,MJJL	d				B5\ ' 
			B27?rP   c           	     l    t        d t        j                  || j                  d            D              S )Nc              3  4   K   | ]  }|j                     y wrc   )is_cudar   r   s     rQ   r   z check_is_cuda.<locals>.<genexpr>  s     WQqyyWs   T)allr   r   rS  )rU  r  s     rQ   check_is_cudarf    s(    W)//."--PTBU"VWWWrP   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 )
Nr8   r   r  zlambda rI  z: ()rot__helper)r   reversedevalr|   rJ   )r?  r  varsrotatedr  s        rQ   rot_n_helperro    s    q5L5"1X&asG&D&tBCy49,-G	's388G+<*=Q?	@B7#BKI	 's   A4z	Set[type]common_constant_typesc                    t        | t        t        f      rt        t	        t
        |             S t        | t        j                  t        t        j                  f      xs t        | t        t        hz        S rc   )rg  rl  	frozensetre  r}   is_safe_constantrk  enumEnumr'  r   Sizerp  rE  r  s    rQ   rs  rs    s[    a%#$3'+,,a$))T5::67 6	'< rP   c                l    ddl m}m} t        | |      r|j	                  | j                               S | S )Nr8   )ConstantVariableSymNodeVariable)	variablesrx  ry  rk  r  evaluate_expr)r  rx  ry  s      rQ   specialize_symnoder|    s0    < #'&&s'8'8':;;JrP   c                `    ddl m} t        |       } t        | |      r| j	                         S | S )Nr8   rx  )rz  rx  r|  rk  as_python_constant)r  rx  s     rQ   guard_if_dynr    s.    +
S
!C#'(%%''JrP   c                j    t        d t        j                  | |j                               D              S )Nc              3  <   K   | ]  }|j                           y wrc   )is_python_constantrd  s     rQ   r   z&check_constant_args.<locals>.<genexpr>  s     V!q##%Vr  )re  r   r   r   rI  s     rQ   check_constant_argsr    s$    VytV]]_/UVVVrP   c                    ddl m} ddlm} d}t	        j
                  | |j                               D ]"  }t        ||      r|dz  }t        ||      r" y |dkD  S )Nr8   r~  UnspecializedPythonVariabler   F)variables.constantrx  variables.tensorr  r   r   r   rk  )rJ  rK  rx  r  unspec_countr   s         rQ   check_unspec_python_argsr    s]    4=L__T6==?3 a45ALA/0	
 !rP   c                    ddl m} t        j                  | |j	                               D ]!  }|j                         rt        ||      r! y y)Nr8   r  FT)r  r  r   r   r   r  rk  )rJ  rK  r  r   s       rQ   check_unspec_or_constant_argsr    sE     >__T6==?3 $$&*Q8S*T rP   c                |    ddl m t        fdt        j                  | |j                               D              S )Nr8   )NumpyNdarrayVariablec              3  6   K   | ]  }t        |        y wrc   )rk  )r   r   r  s     rQ   r   z+check_numpy_ndarray_args.<locals>.<genexpr>"  s!       	1*+s   )r  r  r9  r   r   r   )rJ  rK  r  s     @rQ   check_numpy_ndarray_argsr    s1    6 v}}7  rP   zType[KeysView[Any]]	dict_keyszType[ValuesView[Any]]dict_valuesodict_valueszType[Iterator[Any]]tuple_iteratorrange_iteratorc                n    t        |       }t        j                  j                  j	                  |       |S rc   )
object_newr   r  Moduler   )rY   re  s     rQ   nn_module_newr  1  s&    
S/C	HHOOS!JrP   c                L    t        j                  t        j                  | d      S r   )r  reduceoperatormul)its    rQ   productr  7  s    HLL"a00rP   c                >    | j                         \  }\  }}|||z      S rc   )
__reduce__)r  rB  r%  re  r=  s        rQ   tuple_iterator_getitemr  ;  s%    }}Avuuu}rP   c                    | j                         \  }\  }}|j                  |xs dz   }|j                  }|j                  }|||fS r   )r  r=  r>  r?  )
range_iterr%  	range_obj	maybe_idxr=  r>  r?  s          rQ   normalize_range_iterr  C  sL    !+!6!6!8A|	Y OOy~A.E>>D>>D4rP   c                $    | j                  |      S rc   )as_subclass)r2  rY   s     rQ   to_subclassr  M  s    ==rP   c                Z    t        t        j                  t        |       ||dz               S r   )nextr   isliceiter)dr?  s     rQ   dict_keys_getitemr  Q  s$    	  a!QU344rP   c                j    | j                   j                  }| j                  }|rdnd}| d| d| }|S )NLGz["z"].)r*  rJ   rX   )r   r  rX   r  r  
local_names         rQ   	enum_reprr  U  sA     ??##D
**CCcE7"TF#cU+JrP   c                    || j                   d<   t        j                         j                  j                  }t
        j                  j                  j                  j                  ||      x}r|| j                   d<   y y )Nexample_valueunbacked_bindings)
metar(   rg   	fake_mode	shape_envr   r    experimentalsymbolic_shapescompute_unbacked_bindings)noder  r  symbol_to_paths       rQ   set_example_valuer  _  sq     "/DIIo""$..88I..>>XX= ~  *8		%&rP   c                    | j                         j                  j                  j                  d      }t	        |      sddlm}  |d       |S )Nr  r8   r  z:Cannot check Tensor object identity without its fake value)r  r  r  rg   r=   r)  r  )vtfake_tensorr  s      rQ   _get_fake_tensorr  n  s>    ++-$$))--o>K;&RSrP   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 )Nr8   )BuiltinVariablerx  TensorVariableVariableTrackerc              3     K   | ]7  }|j                         xr! |j                         j                         k(   9 y wrc   )r  r  )r   r   r4  s     rQ   r   z iter_contains.<locals>.<genexpr>  sJ      
    " F$$&&*C*C*EEF
s   =A FT)rz  r  rx  r  r  r  r9  r  rk  r  r  eqcall_functionor_)r   r4  txcheck_tensor_identityr  rx  r  r  found_constmust_check_tensor_idfoundr   checks    `           rQ   iter_containsr  w  s       " 
 
 

  &&{33 FN!C#!&)'+E !^,-a00+22488#HKK0>>rAv;PRSE}'5CC } ''.LrP   c                t    t        | t        j                  t        j                  j                  t
        f      S )z4Returns whether it indexes dictionaries using its id)rk  r   r  r  r  r   )r   s    rQ   	key_is_idr    s#    a%,,9JKLLrP   c                t    | j                         D cg c]  }t        |      rt        |      n| c}S c c}w rc   )r   r  rS  )r   r   s     rQ   	key_to_idr    s+    27**,?QYq\BqEq(???s   5c                  ddl m} t        | t        t        f      r\dj                  fd| D              }t        | t              rd| dS t        | t              sJ t        |       dk(  rd| dS d| d	S t        | t        j                        rt        | 
      j                  dd      S  ||       r| j                  S t        | t              rd } ||       S | S )Nr8   )is_builtin_callablerI  c              3  8   K   | ]  }t        |         ywr  N
const_reprr   r  r  s     rQ   r   zconst_repr.<locals>.<genexpr>  s     DQj%88D   [](z,)rh  r  'rO  c                x    | j                   }|j                  }|dk(  r|j                  S |dz   |j                  z   S )Nbuiltins.)r*  rK   rL   )r)  klassr:  s      rQ   fullnamezconst_repr.<locals>.fullname  s?    KKE%%F#)))C<%"4"444rP   )trace_rulesr  rk  r   rl  r|   r   rt  ru  r  replacerJ   r'  )r   r  r  
elems_reprr  s    `   rQ   r  r    s    0!dE]#XXD!DD
azl!$$a'''1v{:,b)):,a((	Atyy	! %(00b99	Q	zz	At		5 {rP   c               H    dj                  fd| D              }d|z   dz   S )NrI  c              3  8   K   | ]  }t        |         ywr  r  r  s     rQ   r   z!dict_keys_repr.<locals>.<genexpr>  s     Gq
1E22Gr  r  r  )r|   )
const_keysr  keys_strs    ` rQ   dict_keys_reprr    s&    xxGJGGH>CrP   
__dict_key)UnsupportedFakeTensorExceptionc                P    | dt        |       d| j                  j                   S )Nr%  _c)rS  outputr  )r  rootre  s      rQ   get_safe_global_namer    s*     V1RWIR		 4 4566rP   c                    	  |        S # t         $ r?}ddlm} d|j                   d}t        j                  |        |||       Y d }~y d }~ww xY w)Nr8   r  zUnsupported: z with fake tensor propagation.r  )r  r)  r  reasonrp   r/  )r  r  r  msgs       rQ   wrap_fake_exceptionr    sM    't) '&ahhZ'EFCcA&&'s   	 	A5A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 rc   )r  deepcopyr)  s   rQ   r   z)deepcopy_to_fake_tensor.<locals>.<lambda>  s    4==+= rP   )r   r  r  FakeCopyModer  )re  r  s   ` rQ   deepcopy_to_fake_tensorr    s;    				&	&	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     rQ   rmser    s)     ::ejjcCi!89::rP   g-C6?Tc                   	
  t         t        t        t        j                  t
        j                  j                  t
        j                  f      rt        t        t        t        j                  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               j                  dk(  r4t         j                  j                  j                  	
      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"              rIt        t"              sJ t#               t#              k(  sJ dt#                d
t#                      yt         t
        j(                  t*        f      r!t         t
        j,                  j.                        rJ t        t
        j,                  j.                        rJ d fd fD        \    j0                  r.j0                  sJ  j3                          j3                         t        t
        j(                        sJ dt                dt                      r j4                  j4                  k7  r 	d j4                  j4                         y j4                  t
        j6                  k(  reryt        j8                   j;                  t
        j<                        j;                  t
        j<                              }|s 	d       |S r j?                         j;                  t
        j@                         j?                         j;                  t
        j@                        t        j8                   d      ryt
        j                  jB                  jE                   dd      }|dk  r@tF        jI                  d|jK                         jM                         jO                                |dk\  S s j;                  j4                         t        j8                         ryj4                  t
        jP                  k(  r@d}jS                         jU                         sqjS                         jU                         sS jS                         jU                         r5t        j8                  j;                  j4                        ||      rytW               jO                         }tY        jR                  |      rtF        jI                  d       tW              jO                         }j4                  t
        jZ                  t
        j\                  fv rdnd}
rj_                         dk  rdk\  rd}nm
rj_                         d k  rdk\  rd!}nPj_                         d"k  s; j`                  d#k(  r' jb                  d$    jb                  d%   cxk(  rd&k(  sn d'k\  rd}|||z  dz  z   k  }|s\rZtY        jR                  |      rEtY        jR                  |      r0t
        jd                  jf                  jh                  jj                  sd}|s' 	d(||jm                         j4                  |
       |S ry 	d)       yt         tn        tp        t        d      t6        t
        jr                  f      r ry k(  }|s 	d*t                       |S tu               stw               rSr&tu              stw              s jO                          t               t              u xr  k(  }|s
 	d+        |S ty               rTt               t              u xr< t        t        jz                         t        jz                        	
      S t               j                  d,v rNt               t              u sJ t        	 
fd- j|                  j%                         D              S t        d.t               j                         )/z-Check correctness to see if ref and res matchNztype mismatch r   zLength mismatchFc              3  R   K   | ]  \  }}}t        |||
	          yw)	log_error(use_larger_multiplier_for_smaller_tensorN)same)r   aibi	fp64_reficos_similarity	equal_nanexact_dtypeignore_non_fpr  relax_numpy_equalitytolr  s       rQ   r   zsame.<locals>.<genexpr>  sL      ,
 "B	 $#9a ,
s   $'QuestionAnsweringModelOutputr  zkeys mismatch z == r  r  r  r  r  r  r  r  zAccuracy failed for key name %sTzelements mismatch c                d    t        | t        j                        r| S t        j                  |       S rc   )rk  r   r  tensorr2  s    rQ   	to_tensorzsame.<locals>.to_tensorP  s"    "1ell31HaHrP   c              3  .   K   | ]  } |        y wrc   r;   )r   r  r  s     rQ   r   zsame.<locals>.<genexpr>S  s     MinMrK  zdtype mismatch %s, %sr  )atolrtolr  z+Accuracy failed: uint8 tensor did not matchr   gư>)dimepsgGz?zSimilarity score=%sg{Gz?z=Found nan in reference. Consider running in higher precision.g      @g       @
   g      $@i  g      @r      r  r8   g{Gz?zRMSE (res-fp64): %.5f, (ref-fp64): %.5f and shape=%s. res.dtype: %s, multiplier: %f, tol: %f, use_larger_multiplier_for_smaller_tensor: %dz+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   | ]8  }t        t        |      t        
|      t        |      	        : yw)r  N)r  r6  )r   r   r  r  r  fp64_refr  r  r\  r  r  r  r  s     rQ   r   zsame.<locals>.<genexpr>	  s[      
  S!S!#&-#'%9+#9a 
s   >Azunsupported type: )@rk  r   rl  rr   rp  r   r  ParameterListrv  r'  r   re  r  rJ   r  lossr  r   r   rI  r  floatr  r<   	is_sparseto_denser  r   allclosetor~  flattenr  
functionalcosine_similarityrp   r/  cpudetachrG  r  isnanr9  r  mathr  bfloat16numelndimr  r1  r9   cppinject_relu_bug_TESTING_ONLYr  r~   rq   r  r  r  r  	as_tensor__dict__r  )r\  r  r2  r  r  r  r  r  r  r  r  r   rscore	loose_tol	ref_error	res_error
multiplierpasses_testr  s   ```````````        @rQ   r  r    s
    dE;,,ehh.D.DejjQ ${001
 	4DI;aS	{3	4 
 s8s3x'(3x3s8# 
 ,
 ,
 &)c8%<,
 )
 	
  
c		=	= HHHHMM 5]
 	
 
C	#t$$$388:#HHJ#
 
 	CC
O,DSXXZ0AB	C 
 
# 	AFFQK#1' +)="/'=e ;Q?#	$ 	C	#s###3x3s8#R'9#c(4Cz%RR#	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 ~~. %	 (,,.IIKOO-		) #))4&&"+   3/446	::i(KKW !3/446	 99(GGCS  <NN$*sh!%J=NN$+x!$JNN$t+A#))B-399R=*MA*Mh
 "%J'J,BS4Z,OP#!

9-

9- "OO2266SS"&K"I!!
		"@
 #"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'5]-
 	
 
c		   
 CyDI%%% 
 
 ||((*
 
 	
" /S	0B0B/CDEErP   c                ~    | j                   j                  d      d   }d| j                   d| d| j                   dS )N/r  r  z' (r   rh  )r  splitr&  r(  )r*  short_filenames     rQ   format_func_inforS  	  sD    %%++C04Nt||nC/q1D1D0EQGGrP   c               #    K   t         j                  } t        j                  t         _        t         j                  }t        j                  t         _        	 d  | t         _        |t         _        y # | t         _        |t         _        w xY wwrc   )r9   cache_size_limitrp  r   accumulated_cache_size_limit)priorprior_acc_limits     rQ   disable_cache_limitrY  	  s_     ##E!kkF99O*-++F'>"'.=+ #(.=+s   ABA1 B1B		BzDefaultDict[Any, List[Any]]guard_failuresz3List[torch._dynamo.output_graph.GraphCompileReason]graph_break_reasonsc                    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     rQ   _get_debug_dirrd  ;	  sf     	





!
*
*+A
B	C 	 biik
		  77<<(++rP   c                 8    t         j                  } t        |       S rc   )r9   debug_dir_rootrd  )
debug_roots    rQ   r  r  G	  s    &&J*%%rP   c                    d| j                   v r't        | j                   d         r| j                   d   S |rddlm}  |d       y y )Nr  r   r  z9`FakeTensor` example value was required but not available)r  r=   torch._dynamo.excr  )r  requiredr  s      rQ   extract_fake_example_valuerk  L	  s?    $))#		/0J(Kyy))	3QRrP   c                8    t        |       |j                  u sJ | S rc   )r>   r  )r  r  s     rQ   ensure_graph_fakerm  W	  s    q!R\\111HrP   c                h     d fd}t         j                  j                  j                  ||      S )Nc                    | j                   dk(  rd| j                  vrt        |       S | j                  d   }s&t        |t        j
                        rt        |      S |S )Nr  r  )r<  r  get_fake_valuerk  r   r  rm  )r?  r   allow_non_graph_faker  s     rQ   visitz)get_fake_values_from_nodes.<locals>.visit]	  s\    44?"aff'D "!R)=>>ff_%#
3(E$S"--
rP   )r?  ztorch.fx.Node)r   r    r  map_arg)r  r;  rq  rr  s   ` ` rQ   get_fake_values_from_nodesrt  \	  s%    	 88==  ..rP   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(                         j8                  d
v st;        d D              rt+        d D              	 j(                  5  t=               5  t?         fd      }
ddd       ddd       |s>tu        jv                  t         jx                  t{        j|                  t~               
      }
S # 1 sw Y   SxY w# 1 sw Y   WxY w# |$ r  t@        $ r}|}|jB                  |jB                  }t        |t         jD                  jF                  jH                        r |d|jJ                   d       nt        |t         jD                  jF                  jL                        rTt         jN                  jP                  jR                  s |d|jJ                   d       n |d|jJ                   d       nt        |t         jD                  jF                  jT                        r|jJ                  }	d}t        |	t         jV                  jX                        r[t         jZ                  j]                  |	j^                  j8                  |	j^                  j`                        }||\  }}d| d| d| d} |d|jJ                   d| d       nt        |t         jb                  jd                  jf                  jh                        r ||jj                  tm        |      d      t        ||      r! ||jj                  |j                  d         |t        |tn              r%dtm        |      v r |d j0                   d|         |tm        |            jq                  |jr                        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   )ValueRangeErrorr8   )TorchRuntimeErrorr  Unsupported	UserErrorUserErrorTyper  Ncall_methodcall_module_initialize_hook)interpolate
is_integerwrapped_gradientc              3  <   K   | ]  }t        |t                y wrc   )rk  complex)r   as     rQ   r   z!get_fake_value.<locals>.<genexpr>	  s      M#$
1gMr  c              3     K   | ]A  }t        |t        j                        r!|j                  j                  t        |      n| C y wrc   )rk  r   SymFloatr  hintr5  r  s     rQ   r   z!get_fake_value.<locals>.<genexpr>	  sC      
  #u~~.388==3L #J
s   AA	c                 6    t        j                         S rc   )run_noder  )rJ  rK  nnmoduler  r  s   rQ   r   z get_fake_value.<locals>.<lambda>	  s    D$I rP   zdata dependent operator: zC; to enable, set torch._dynamo.config.capture_scalar_outputs = Truezdynamic shape operator: zM; to enable, set torch._dynamo.config.capture_dynamic_output_shape_ops = Truezm; Operator does not have a meta kernel that supports dynamic output shapes, please report an issue to PyTorchrO  z:It's possible that the support was implemented in module `z` and you may need to `import z`(z), otherwise zunsupported operator: z (z~see https://docs.google.com/document/d/1GgvOe7C8_NVOMLOCwDaYV1mXXyHMXY7ExoewHqooxrs/edit#heading=h.64r4npvq0w0 for how to fix)constrain_as_size_example)	case_nameargumentz
TypeError z: )r  )@torch.utils._sympy.value_rangesrv  r)  rw  r  rx  ry  rz  r<  r  r=   rt  rJ  rK  r   rk  r   r  r  r  r  rl  r  
nn_modulestargetr  r|  _infer_parametersrX   r9  r%   r  r  	__cause__r  r  DataDependentOutputExceptionfuncDynamicOutputShapeException_dynamor9    capture_dynamic_output_shape_opsUnsupportedOperatorExceptionr  r  r	  _dispatch_pystub_schemaoverload_namer    r  r  GuardOnDataDependentSymNodeCONSTRAINT_VIOLATIONr~   rE  with_traceback__traceback__pytreetree_map_onlyr  r  partialrm  )r  r  rq  rv  rw  r  rx  ry  rz  r<  ret_valr  causeimport_suggestionmaybe_pystubr:  ctxr%  rJ  rK  r  s   ``                @@@rQ   rp  rp  k	  sU    @  
B $))#		/0J(Kyy))-
TYY$&:LD& H	]s4y1}DGUXX__1U'Q>@5ab?R	]99''4(#:L(M
 &&x6 +8R\\ByyEE M(,M J  
 	
 
CR\\ 	35 	)IG	 	H    LL)++,="Ew
 NQ	 	 	 	   <R ;;"KKE5$$00MM
 +EJJ< 8T T 5$$00LL
 ==''HH.uzzl ;b b
 .uzzl ;8 8
 5$$00MM
 B ""ejj334$xx88JJOORZZ%=%=   +".KFC##)(*H Q5/ &
 (B7H6I J# #
 588((88TT
 22E
5 
 /M>>q	JPQQy)jCJ.FJt{{m2eW=>A'66qGTQy<RsI    H HG<*H2H <H	HHH S#JR==Sc                 $    t        t        dd       S )Nr   )r6  _current_noder;   rP   rQ   get_current_noder  	  s    ='400rP   c              #  v   K   t               }| t        _        	 d  |t        _        y # |t        _        w xY wwrc   )r  r  r   )r  olds     rQ   set_current_noder  	  s.     

CM"!cs   9) 969c                   j                   t              5  fd}	 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                  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        t        f$ r }ddl	m
}  | ||      |       Y d}~=d}~wt        $ r0}t         ||            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.
    c           	     N    d dj                    d d d	t        |       z   S )NzFailed running r   z(*z, **z):
)r  r~   )r  rJ  rK  r  r<  s    rQ   make_error_messagez$run_node.<locals>.make_error_message
  s4    $RD$++bd6($ORUVWRXXXrP   r  Nr{  r   r8   r|  get_attrplaceholderr  r  r  )r<  r  r  r6  output_graphget_submoduler  r  r  r)  r  r3  r  r  r  AssertionError)	tracerr  rJ  rK  r  r  r  r  r<  s	    ```    @rQ   r  r  
  s    
B	$	 	Y	_$"t{{D3F3  }$4wtAw4d12hI&I  }$+++00  z!**88E  }$&$))333yy1#  %: 
 $%CD 	=*,Q/!<< 	1!45DD	1: 
sX   	E-D&D6D)D#D0E-E*D.)E-.E*:+E%%E**E--F c                   ddl m} j                  }| |v r||    S | j                  }t        j
                  j                  j                  | j                  | j                  ffd      \  }}|dk(  r'd| j                  v r| j                  d   j                  S |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.
    r8   )rw  c                    t        |       S rc   )get_real_value)r?  r  s    rQ   r   z get_real_value.<locals>.<lambda>A
  s    .F+ rP   r  graphargr|  N)r)  rw  real_value_cacher<  r   r    r  rs  rJ  rK  r  exampler  r  r  r  r  r  r  r  r~   r  r  )
r  r  rw  cacher<  rJ  rK  	nn_module
real_valuer  s
    `        rQ   r  r  3
  s/   
 '##Eu}T{	B88==((	DKK +LD&
 
]zTYY6yy$,,,	]''224;;?	i(i0I t&v&	RfdD&)D
 d   RA'66qGTQRs   0D 	D?+D::D?c                    ddl mm} fd}| j                         D ]   \  }} ||      sJ d| d ||               | j	                         D ]   \  }} ||      sJ d| d ||               y )Nr   )FakeTensorConfigr=   c                d    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.)debug	tracebackformat_list_debug_trace)r2  r  r  s     rQ   stack_or_hintz7assert_no_fake_params_or_buffers.<locals>.stack_or_hint]
  s2    !!89N9N9Nq~~9^8_``crP   zUnexpected fake buffer r   zUnexpected fake param )torch._subclasses.fake_tensorr  r=   named_buffersnamed_parameters)rU  r=   r  rX   bufferrO  r  s         @rQ    assert_no_fake_params_or_buffersr  Z
  s    Gd ((* Df
 	D$TF!M&,A+BC	D 
D **, Be
 	B#D6=+?*@A	B 
BrP   c                8    | j                    d| j                   S )z9
    Returns the fully qualified name of the object.
    r  )rK   rL   r)  s    rQ   fqnr  o
  s!     nnQs//011rP   c                R    t         j                  j                  j                  r| S |S rc   )r   r  r9   assume_static_by_default)count1count2s     rQ   ifdynstaticdefaultr  v
  s    }}44rP   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%  r  N)rI  r   listdirr  r0  r
   r~   __file__r   	importlibimport_modulerJ   )r  r5  s     rQ   import_submoduler  }
  sw     2::bggood36M&NOP GU#s(:##s||nAhsm_$EFGrP   c                *    t        t        |             S rc   )class_has_getattributer'  ru  s    rQ   object_has_getattributer  
  s    !$u+..rP   c                    	 t        t        j                  | d      t        j                        ry	 y# t
        $ r Y yw xY w)N__getattribute__TF)rk  r  r  r  r  AttributeErrorre   s    rQ   r  r  
  sO    ""3(:;
 	
   s   .3 	??c                    	 t        j                  t        |       d      }|r(|t        j
                  j                  j                  u rd }|S # t        $ r d }Y 9w xY w)N__getattr__)r  r  r'  r  r   r  r  r  )r   ignore_nn_module_getattr
getattr_fns      rQ   get_custom_getattrr  
  sX    ++DKG
  J%((//2M2M$M
  
s   A AAc                      e Zd ZdZdZdZy)TensorStaticReasonrH   r$  r   N)rJ   rK   rL   	PARAMETER
NOT_TENSORNN_MODULE_PROPERTYr;   rP   rQ   r  r  
  s    IJrP   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  r  )r  s    rQ   tensor_static_reason_to_messager  
  sJ    #---O#...C#666E
?6(3
44rP   c                   ddl m} |j                         j                         s|j                         j	                         r"t
        j                  rdt        j                  fS t        |       t        j                  j                  u s ||      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.
    r8   ))is_from_unspecialized_param_buffer_sourceT)FN)sourcer  guard_sourceis_specialized_nn_module"is_unspecialized_builtin_nn_moduler9   &force_nn_module_property_static_shapesr  r  r'  r   r  r  force_parameter_static_shapesr  r  )r  	is_tensortensor_sourcer  s       rQ   tensor_always_has_static_shaper  
  s      B 	""$==?%%'JJL

7
7':::: 	V***4]C

.
.'1111'2222rP   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   )r   zkTabulate module missing, please install tabulate to log the graph in tabular format, logging code instead:
)opcoderX   r  rJ  rK  rw   )r   r   r~   r/   graphr;  r<  rX   r  rJ  rK  r.   forward__code__r  )r   r?  
node_specs	graph_strr   rU  s       rQ   innerz(lazy_format_graph_tabular.<locals>.inner
  s    	) AC
;<QTT166188QVVQXX6

 
  N
	 "'2::+>+>+J+JIVV  	~,Wb9:;	
s   B A C!B>=B>r6   )r   rU  r  s   `` rQ   lazy_format_graph_tabularr   
  s    W" erP   c                f    |  d| d| d| dt        j                  |      j                          d
S )Nr   z line z 
ry   )disBytecode)prefixrX   r5  line_nor*  s        rQ   format_bytecoder  
  s;    XQtfAhZvgYc#,,t:L:P:P:R9SSUVVrP   _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                     t        t        j                  j                  j                  j
                        xs7 t        t        j                  j                  j                  j                        S rc   )r   r   r  modulesr:  _global_backward_hooks_global_backward_pre_hooksr;   rP   rQ   nn_module_has_global_hooksr  
  sM     uxx&&==> #::C rP   c                   g }| xr | xr | }|s|r|j                  t               |s|r|j                  t               |r|j                  t               g }|D ],  }t	        | |g       }|D ]  }	||	   }
|j                  |
        . |S )z
    Sometimes its useful to differentiate between types of hooks such as forward/backward/pre
    hooks executed during module.__call__, and state_dict hooks which are executed separately.
    )extendforward_hook_namesbackward_hook_namesstate_dict_hook_namesr6  r   )r  check_forward_hookscheck_backward_hookscheck_state_dict_hookshook_dicts_to_checkcheck_all_hooks	all_hookshook_dict_namehooks	hook_namer  s              rQ   nn_module_get_all_hooksr"  
  s      	'$$	'&& 
 o""#56""#67""#89I- #^R0 	#I#DT"	## rP   c                6    t        | |||      }t        |      S )zL
    Helper function to check if a module has any hooks attached to it.
    )r  r  r  )r"  r   )r  r  r  r  r   s        rQ   nnmodule_has_hooksr$     s&     $/15	E ;rP   c                2   t        |       r| S 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rc   )to_numpy_helperr   re  s     rQ   r   z"to_numpy_helper.<locals>.<genexpr>;       AC?3/Ar  )r=   rk  tnpr  r(  r  r   r  numpyrl  r   r'  ru  s    rQ   r(  r(  2  st    u~%%u||,,	E5<<	({{{&&	EE4=	)tE{A5AAArP   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rc   )numpy_to_tensorr)  s     rQ   r   z"numpy_to_tensor.<locals>.<genexpr>H  r*  r  )
ry  rk  r  r   rF  r+  r  rl  r   r'  ru  s    rQ   r/  r/  @  sk    >>%$u%%%%||	EE4=	)tE{A5AAArP   c                       e Zd Zd ZddZd Zy)numpy_to_tensor_wrapperc                N    || _         d| j                   j                  z   | _        y Nwrapped_r7  rJ   )r   r7  s     rQ   r   z numpy_to_tensor_wrapper.__init__N  s    "TVV__4rP   c                6    d| j                   j                   dS )Nz<Wrapped function <original >>r5  r   s    rQ   __repr__z numpy_to_tensor_wrapper.__repr__R  s    -dffoo->bAArP   c                <     | j                   |i |}t        |      S rc   )r7  r/  r   rJ  rK  r   s       rQ   r  z numpy_to_tensor_wrapper.__call__U  s"    dffd%f%s##rP   Nr   r~   )rJ   rK   rL   r   r8  r  r;   rP   rQ   r1  r1  M  s    5B$rP   r1  c                    t        | t        j                        rt        | |      }t	        |      S t        | t
        j                        r*t        t        j                  |       |      }t	        |      S y rc   )rk  r+  r  r6  r/  r   r  )re  rX   r   s      rQ   numpy_attr_wrapperr=  Z  sZ    #s{{#c4 s##	C	&ckk#&-s## 
'rP   c                  &    e Zd ZdZddZd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.c                :    || _         d| j                   z   | _        y r3  )methodrJ   )r   rA  s     rQ   r   znumpy_method_wrapper.__init__f  s    "T[[0rP   c                "    d| j                    dS )Nz<Wrapped method <original r7  )rA  r   s    rQ   r8  znumpy_method_wrapper.__repr__j  s    +DKK=;;rP   c                    |d   }t        |t        j                        rt        j                  |      }t        || j                        } ||dd  i |}t        |      S Nr   r8   )rk  r   r  r+  r  r6  rA  r/  )r   rJ  rK  re  method_callabler   s         rQ   r  znumpy_method_wrapper.__call__m  sW    1gc5<<(++c"C!#t{{3tABx262s##rP   N)rA  r~   r;  rJ   rK   rL   rb  r   r8  r  r;   rP   rQ   r?  r?  c  s    q1<$rP   r?  c                  &    e Zd ZdZddZddZd Zy)numpy_operator_wrapperzQImplements dunder methods for tnp.ndarray via functions from the operator libraryc                :    || _         d|j                   | _        y r3  )r<  rJ   )r   r<  s     rQ   r   znumpy_operator_wrapper.__init__y  s    "2;;-0rP   c                "    d| j                    dS )Nz<Wrapped operator <original r7  )rJ   r   s    rQ   r8  znumpy_operator_wrapper.__repr__}  s    -dmm_B??rP   c                P    |rJ d |D        } | j                   | }t        |      S )Nc              3  ~   K   | ]5  }t        |t        j                        rt        j                  |      n| 7 y wrc   )rk  r   r  r+  r  r  s     rQ   r   z2numpy_operator_wrapper.__call__.<locals>.<genexpr>  s0      
KN
3 =CKK3F
s   ;=)r<  r/  r:  s       rQ   r  znumpy_operator_wrapper.__call__  s5    z
RV
 dggtns##rP   N)r<  zCallable[..., Any]r;  rF  r;   rP   rQ   rH  rH  v  s    [1@$rP   rH  c                B   t        | t              s| S | j                  rg }| j                         D ]v  }t        |t        j
                        rI|j                  |j                  j                  j                  |j                  j                               f|j                  |       x g }| j                         D ]v  }t        |t        j
                        rI|j                  |j                  j                  j                  |j                  j                               f|j                  |       x n | j                         }| j                         }t	        j                  ||| j                  | j                  | j                        }|j!                          |S )N)r  r  r  )rk  r<   _has_symbolic_sizes_stridesr  r   SymIntr   r  r  	size_hintexprr  empty_stridedr  r  r  zero_)r   r  r  r  r  s        rQ   defakerT    s*   a$ 	$$ 	A!U\\*AFF,,66qvv{{CDA		
  	!A!U\\*aff..88EFa 		! vvxggxxoo	A GGIHrP   c                N    dd l }| |j                  j                  j                  u S r   )torch.utils.checkpointrW  
checkpoint)re  r   s     rQ   is_utils_checkpointrX    s     !%++((3333rP   c                    ddl m} | |u S )Nr   )invoke_subgraph_placeholder)'torch._higher_order_ops.invoke_subgraphrZ  )re  rZ  s     rQ   is_invoke_subgraphr\    s    S---rP   c                 d    ddl m}  |j                  t        j                  j
                  fi | S )Nr8    TorchHigherOrderOperatorVariable)variables.higher_order_opsr_  maker   _higher_order_opsinvoke_subgraph)optionsr_  s     rQ   build_invoke_subgraph_variablere    s2    L0+00//
 rP   c                     dd l mc m} ddlm} |j
                  }t        j                  j                  j                  r|j                  } |j                  |fi | S )Nr   r8   r^  )torch._higher_order_ops.wraprb  wrapr`  r_  tag_activation_checkpointr   
_functorchr9   functionalize_rng_opswrap_activation_checkpointra  )rd  higher_order_opsr_  activation_checkpoint_ops       rQ   build_checkpoint_variablero    s_    ;;L
 	22  44#3#N#N 0+00 
 rP   c                Z    ddl m}  |       }| dk(  r	 |S | dk(  r|rt               }|S d}|S )Nr8   )is_dynamo_supportedr=  r`  F)
eval_framerq  r2   )device_typerq  compile_supporteds      rQ   is_compile_supportedru    sL    /+-e
 	 
	#4&L  "rP   c                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-8Nr  )errors)encoder   decode)r~   offsetas_utf8s      rQ   _fix_offsetr|    s4     jj!Gww&&wy&ABBrP   c                  6    e Zd ZU ded<   ded<   ded<   ded<   y)_Anchorsrq   left_end_linenoleft_end_offsetright_start_linenoright_start_offsetNrC  r;   rP   rQ   r~  r~    s     rP   r~  c                   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
    )rI      r   Nz(
z
)r8   ry   c                "    t        |    |      S rc   )r|  )linenorz  liness     rQ   	normalizez-_extract_anchors_from_expr.<locals>.normalize  s    5=&11rP   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 rD  r   )r  colr  s     rQ   next_valid_charz3_extract_anchors_from_expr.<locals>.next_valid_char  sy    s5z!cSv-?&?CaKF s5z!cSv-?&? E
"sSv-?'???s{rP   c                p    |dz  } | |      \  } }| t              k  r|t        |          k  sJ | |fS r   r  r  r  r  r  s     rQ   r   z-_extract_anchors_from_expr.<locals>.increment!  sH    q%fc2E
"sSv-?'???s{rP   c                t    d}| dz  }  | |      \  } }| t              k  r|t        |          k  sJ | |fS rD  r  r  s     rQ   nextlinez,_extract_anchors_from_expr.<locals>.nextline(  sM    !%fc2E
"sSv-?'???s{rP   rH   z)\#z\#r  r  )rp  rq  astparseSyntaxErrorr   bodyrQ  rk  Exprr   BinOpr
   rq   left
end_linenoend_col_offsetisspacer~  	SubscriptCallr  )segmentr  treer  r   r  	statementrQ  
cur_linenocur_colch	right_colleft_linenoleft_colright_linenor  r  s                  @@rQ   _extract_anchors_from_exprr    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c                   t         j                  dk\  rt        j                  | j                  |j
                  j                  | j                  |j
                  j                  |j
                  j                  |j
                  j                        }t        j                  |g      d   }dj                  |j                         dd       }t        |j
                  j                  |j
                  j                  dz         D cg c]0  }t        j                   | j                  |      j#                         2 }}t%        j&                  dj                  |            j                         }t)        |d         t)        |d         z
  }|d   d| }t%        j*                  t%        j&                  |      |      }|S |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)        |j1                               z
  }|j/                  d|z  d	t)        |      |z
  z  z           ||d| z  }t)        |      t)        |j1                               z
  }|j/                  d|z  d	||z
  z  z          d}	 t3        |      }|!|D cg c]  }|j7                  d	d
       }}n%|D cg c]  }t9        |       }}|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 c c}w # t4        $ 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 in < 3.13 since `format_frame_summary` in
    Python's `traceback` module doesn't handle multi-line expressions
    (and their anchor extraction code is not completely correct).
    )rI      )r  colno	end_colnor   ry   r8   NrO  r   ~^)!rp  rq  r  FrameSummaryr  	positionsr  r&  r  
col_offsetr  r  r|   
splitlinesr   	linecachegetlinerstriptextwrapdedentr   indentr|  r   lstripr  r  r  r   r  r  r  r  )r*  instframe_summaryr  r  
orig_linesorig_lines_dedent
indent_lenr  
first_linestart_offset
end_offsetr  markers	last_lineline
num_spacesanchorsmarkermutable_markersr  r  s                         rQ   get_instruction_source_311r  s  s    7"!..NN!!LL~~00..++nn33
 &&7:6,,.qr23   5 5t~~7P7PST7TU
 d..7>>@

 
 %OODIIj,ABMMOA'#.?.B*CC
A{
+!8&A>>%%%~~$ ""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Q 	NF$$T%5%5v>EEGDtd{"GTS%77JNN3+cSY5K.LLM	N 	9[j))^c)*:*:*<&==
sZ'#j1H*IIJ"&G,W5
 :AB6>>#s+BB HO+OVDL+O+O ""a'##|3#%%*&&,6& CL) 	7FS!89: 7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7	7" 2AAv2776?AAF3w<  $d..0E0E0IJQQS	
 	'!*t##$ MI
r  
 C ,P4 Bs*   5Y%Y* 0Y:Y?Z*	Y76Y7c                R    t        | t        j                        rt        | dd       S y )N_dynamo_static_input_type)rk  r   r  r6  r  s    rQ   get_static_address_typer    s#    !U\\"q5t<<rP   c                   t         j                  j                  j                  t         j                  j                  t         j
                  t         j                  j
                  f}t         j                  j                  j                  t         j                  j                  t         j                  t         j                  j                  f}| g ||v S rc   )	r   r	  r   	get_statedefault_generatorr  r`  	set_stater  )r   getterssetterss      rQ   is_rng_state_getter_or_setterr    s     	$$))

  G 	$$))

  	G (g((((rP   c                    t        | t        j                        xrA | j                  dk(  xr0 | j                  j
                  t        j                  j                  u S )N__get__)	rk  r  r   rJ   __self____objclass__r   r	  _TensorBaseru  s    rQ   is_tensor_base_attr_getterr    sK    5%112 	@NNi'	@NN''588+?+??rP   c                    t        | d      S )N__torch_function__)r|  ru  s    rQ   is_torch_function_objectr    s    5.//rP   c                    ddl m} ddlm} | j	                         s&t        | d      rKt        | j                         d      r1t        | |      ryt        | |      xr t        | j                  d      S y)Nr   )UserDefinedObjectVariable)TensorWithTFOverrideVariable
peek_valuer  TF)	torch._dynamo.variablesr  &torch._dynamo.variables.torch_functionr  is_realizedr|  r  rk  r   )r  r  r  s      rQ   has_torch_functionr    sg    AS 
~~L!gbmmo?S&Tb67"78 
WHH*>
 	
 rP   c                    d }d }t         j                  j                  j                         x}r)| |j                  v r|j                  |    }|j
                  }|j                  | d||      S )NF)static_shapessymbolic_contextr  )r   r\  r(   try_gettensor_to_contextr  from_tensor)r2  r  r  r  tracing_contexts        rQ   to_fake_tensorr  5  sw    F--66>>@@@111.@@C%33F  	1A& !  rP   c                    t        |        xrW t        |        xrI t        |       xr< t        | d      xr. t        | j                  d      xr | j                  j
                  S )N__dataclass_params__frozen)r  r  r   r|  r  r  ru  s    rQ   is_frozen_dataclassr  C  sn    #E** 	.&u--	.	. E12	. E..9		.
 &&--rP   c                d    |D ]  }t        | |      st        | |      c S  t        |  d|       )zX
    Return the first available attribute or throw an exception if none is present.
    z% does not has any of the attributes: )r|  r6  r  )re  attrsattrs      rQ   get_first_attrr  N  sC      &33%%& C5 EeWM
NNrP   c              #     K   | sd  y fd}t         j                  j                  j                  |      5 }| d d d        y # 1 sw Y   y xY ww)Nc                <    d }t        j                  | |      S )Nc                    t         j                  j                  j                  d   dxx   dz  cc<   t         j                  j                  | |      S )Ncompiled_autogradcompilesr8   )r   r  rW  r@   r1  compile)gm_example_inputs_s     rQ   inner_compilerzKmaybe_enable_compiled_autograd.<locals>.compiler_fn.<locals>.inner_compiler`  s@    ##,,-@A*MQRRM..sODDrP   )ri  	fullgraphdynamic)r   r  )rU  r  r  r  s     rQ   compiler_fnz3maybe_enable_compiled_autograd.<locals>.compiler_fn_  s%    E ==Ni rP   )r   r  r  _enable)should_enabler  r  r  r  s    ``  rQ   maybe_enable_compiled_autogradr  Y  sG     	 ]],,44[A 	SI	 	 	s   7AA	 	A	AAc                 @     G d dt               } t         |              S )Nc                      e Zd Zy)*invalid_removeable_handle.<locals>.InvalidN)rJ   rK   rL   r;   rP   rQ   Invalidr  n  s    rP   r  )r  r4   )r  s    rQ   invalid_removeable_handler  l  s    $  79%%rP   c                
   t        | t        j                  j                        s| S t        | t        j                  j
                        r| S | j                  j                  | j                        }| j                  |_        |S rc   )	rk  r   r  r  r    GraphModuler*  r4  rG  )r  proxys     rQ   nn_module_proxyr  x  sZ    c588??+
#uxx++,
MM!!#--0E\\ENLrP   c                  $     e Zd Z fdZd Z xZS )	GmWrapperc                >    t         |           || _        || _        y rc   )r(  r   rU  unflatten_fn)r   rU  r  r*  s      rQ   r   zGmWrapper.__init__  s    (rP   c                T    t        |      } | j                  | j                  |       S rc   )r   rU  r  r  s     rQ   r  zGmWrapper.forward  s'    t*tww))$/00rP   )rJ   rK   rL   r   r  r+  r,  s   @rQ   r  r    s    )
1rP   r  c                  	
 t        | j                  j                        D cg c]2  \  }}|j                  dk(  r|j                  j                  dd      r|4 c}}t        j                  j                  j                  rMdgk(  sJ t        |d   t              sJ t        |d         	d 	fd} |t        | |       |            
n`t        j                  |      \  }}t!        j"                  t        j$                  |      } |t        | |      |      
t        j&                  
fd}|S c c}}w )	z
    Mutate inputs so that they are flat and wrap gm such that it
    accepts those inputs.  This is needed for graphs that take
    bumpy inputs.
    r  	steal_argFr   c                *    | d   t        | dd        z   S rD  )r   r  s    rQ   
flatten_fnz(flatten_graph_inputs.<locals>.flatten_fn  s    7T$qr(^++rP   c                    | d  g| d  S rc   r;   )	flat_argsboxed_inputs_counts    rQ   r  z*flatten_graph_inputs.<locals>.unflatten_fn  s#    112TY?Q?R5STTrP   )treespecc                 X     |       }D ]  }| |   j                            |      S rc   )rd   )rJ  r  r  compiled_fnr  inputs_idx_to_clears      rQ   wrapperz%flatten_graph_inputs.<locals>.wrapper  s8    t$	 % 	AGMMO	 9%%rP   )	enumerater  r;  r<  r  rg   r   r  r  in_compiled_autograd_regionrk  r   r   r  r  tree_flattenr  r  tree_unflattenarg_tree_leaves)rU  inputs
compile_gmr  r  r  flat_inputsspecr  r  r  r  r  s            @@@@rQ   flatten_graph_inputsr&    s    !0At77m#		k5(I 	
 }}&&BB #qc)))&)T*** ^	,	U !2|!<j>PQ #//7T (()>)>N 2|!<kJ++
& NMs   7D<c                    t        | t        j                  j                        rt	        | d      sg S | j
                  j                  dg       S )Nr  locals_to_steal)rk  r   r    r	  r|  r  rg   )maybe_gms    rQ   get_locals_to_stealr*    s<    h 4 45WXv=V	==.33rP   c                "    || j                   d<   y )Nr(  )r  )rU  r(  s     rQ   set_locals_to_stealr,    s    !0BGGrP   c                      e Zd Zd ZddZy)Litc                    || _         y rc   r  )r   r  s     rQ   r   zLit.__init__  s	    rP   c                    | j                   S rc   r0  r   s    rQ   r8  zLit.__repr__  s    vvrP   Nr;  )rJ   rK   rL   r   r8  r;   rP   rQ   r.  r.    s    rP   r.  zSet[str]warn_once_cachec                t    | t         v ry t         j                  |        t        j                  | |dz          y )Nr8   )
stacklevel)r2  r   warningswarn)r  r4  s     rQ   	warn_oncer7    s/     oMM#*q.1rP   c                P    t        j                  d      }|j                  d|       S )Nz\x1B[@-_][0-?]*[ -/]*[@-~]rO  )r3  r  r  )textansi_escapes     rQ   strip_color_from_stringr;    s"    **:;K??2t$$rP   c               #    K   	 t         j                  j                  j                  d      } d  t         j                  j                  j                  |        y # t         j                  j                  j                          w xY ww)NT)r   r	  	_autograd _saved_tensors_hooks_set_tracing)rW  s    rQ   +_disable_saved_tensors_hooks_during_tracingr?    sY     C""CCDI;;EB;;EBs   B	-A *B	+BB	c                 x    t         j                  j                  j                  xr t        j                          S rc   )r   r1  r9   freezingis_grad_enabledr;   rP   rQ   is_parameter_freezingrC    s)    ??!!**J53H3H3J/JJrP   c                 `    t        t                     D  cg c]  } t        |        c} S c c} w rc   )r   r"    get_torch_function_mode_stack_atr  s    rQ   get_torch_function_mode_stackrG    s.    5:;T;V5W01(+  s   +c                h    | t               k  r| dk\  sJ t        j                  j                  |       S r   )r"   r   r	  _get_function_stack_at)inds    rQ   rE  rE    s/    *,,9988**3//rP   c                l    t        t                     D ]  }t                 | D ]  }t        |        y rc   )r   r"   r#   r$   )r{  r  modes      rQ   set_torch_function_mode_stackrM    s9    ,./ $!#$  ,%d+,rP   c                 H    t        t                     D ]  } t                 y rc   )r   r"   r#   rF  s    rQ   clear_torch_function_mode_stackrO    s     ,./ $!#$rP   c                     t                y rc   )
breakpointr  s    rQ   _breakpoint_for_c_dynamorR    s    LrP   c                    | j                   }t        j                  |      }t        |j                        dk7  rddlm}  |d      |j                  | j                  k7  rddlm}  |d      y )NrH   r8   )InternalTorchDynamoErrorz[Tensor subclass method __metadata_guard__ must take exactly two subclass metadata argumentsz?Tensor subclass method __metadata_guard__ must be a classmethod)	__metadata_guard__r  	signaturer   rS  r)  rT  r  r*  )r   r  sigrT  s       rQ   verify_guard_fn_signaturerX    sk    		!	!B


B
C
3>>a1&i
 	
 
{{eoo%1&M
 	
 &rP   c                   | j                   t        j                   t        j                  j                   fv xr | j                  t        j                  t        j                  j                  fv xrn | j
                  t        j
                  t        j                  j
                  fv xr6 | j                  t        j                  t        j                  j                  fv S rc   )r   r  rr   r   r   r   __iter__)user_clss    rQ   #does_not_override_dict_iter_methodsr\     s    4::{'>'>'D'DEE 	SOO[-D-D-K-KLL	SMMdii)@)@)E)EFF	S $--1H1H1Q1Q!RR	rP   c                `    t         j                  j                  d      d        } || |      S )NT	recursivec                $    | j                  |      S rc   )r  r   r  s     rQ   r  zcall_size.<locals>.fn.  s    vvayrP   r   r  disabler   r  r  s      rQ   	call_sizere  -  s3    
]]T* + a8OrP   c                `    t         j                  j                  d      d        } || |      S )NTr^  c                $    | j                  |      S rc   )r  ra  s     rQ   r  zcall_stride.<locals>.fn6  s    xx{rP   rb  rd  s      rQ   call_striderh  5  s3    
]]T* + a8OrP   c                ^    t         j                  j                  d      d        } ||       S )NTr^  c                "    | j                         S rc   )storage_offsetr   s    rQ   r  zcall_storage_offset.<locals>.fn>  s    !!rP   rb  )r   r  s     rQ   call_storage_offsetrl  =  s1    
]]T*" +" a5LrP   c                    ddg}|D ci c]4  }|| j                   v s|t        j                  | j                   |         6 }}|S c c}w )Nr  tag)rG  r  )r2  KEYS_TO_COPYr   tensor_dicts       rQ   _extract_tensor_dictrq  G  sZ    #L 4@,/3!**CTTYYqzz#''K  	s
   A%Az(Dict[int, weakref.ReferenceType[object]]user_obj_id_to_weakrefc                2    t        |           }|J d       |S )NzUser object is no longer alive)rr  )obj_idre  s     rQ   get_user_object_from_idru  Z  s$    
 
(
*C?<<<?JrP   c                R    t        |       }t        j                  |       t        |<   y rc   )rS  r^  r\  rr  )re  rt  s     rQ   store_user_object_weakrefrw  `  s    WF%,[[%56"rP   c                      e Zd ZU dZded<   dZded<   dZedd       Zedd       Z	edd       Z
edd	       Zeed
               Zy)CompileTimeInstructionCounterr   rq   _counterr  _idc                ~    | j                   dz   | _         | j                   dk(  rt        j                         | _        y y r   )_depthr!   r=  r{  re   s    rQ   r=  z#CompileTimeInstructionCounter.startj  s1    ZZ!^
::?*002CG rP   c                    | j                   dz
  | _         | j                   dk(  r:| xj                  t        j                  | j                        z  c_        d| _        y y )Nr8   r   r  )r}  rz  r!   endr{  re   s    rQ   r  z!CompileTimeInstructionCounter.endp  sF    ZZ!^
::?LL044SWW==LCG rP   c                    d| _         y r   rz  re   s    rQ   rd   z#CompileTimeInstructionCounter.clearw  s	    rP   c                    | j                   S rc   r  re   s    rQ   r   z#CompileTimeInstructionCounter.value{  s    ||rP   c              #     K   	 t         j                  r| j                          d  t         j                  r| j                          y y # t         j                  r| j                          w w xY wwrc   )r9   %record_compile_time_instruction_countr=  r  re   s    rQ   recordz$CompileTimeInstructionCounter.record  sN     	;;		;;	 <v;;	 <s   A0$A
 "A0
#A--A0Nr  )r   rq   )rJ   rK   rL   rz  rt   r{  r}  ru   r=  r  rd   r   r   r  r;   rP   rQ   ry  ry  e  s    HcCMF3 3
         rP   ry  c                l    t               j                         rt               j                  d| |       yy)zQ
    Records whether we are using a feature
    Generally a feature is a JK.
    r  N)r   r   set_key_value)featureusages     rQ   set_feature_user    s-     ((*++OWeL +rP   )r   z3Union[List[Tuple[str, object]], List[List[object]]]rx   z!Union[Tuple[str, ...], List[str]]r   r~   r  )r   rq   r   r   )r   rD   )r   r&   )NFNNF)r   r~   r   r  r   r   r   zOptional[Dict[str, object]]r   r  r   r   r   Generator[Any, None, None]r  )r   zLiteral['str']r   r   r   r~   )r   zLiteral['csv']r   r   r   zTuple[List[str], List[object]])r~   F)r   r   r;  )r5  r~   r   r   )r=  zfx.Graphr   rq   )r   r?   r   r?   )re  objectrf  zType[T]r   	TypeIs[T])re  r  rf  z)Tuple[Type[List[T]], Type[Tuple[T, ...]]]r   r  )re  r  rf  zIterable[type]r   r   rc   )r   r  r   r  )r>  r  r   r   r  )
re  rq   rf  rq   rA  rA   rg  zOptional[Type[BaseException]]rh  zOptional[BaseException])rq  rq   r   r   )r   zList[CompilationMetrics])r   ry  )FF)r   r~   r  r   r   r   r   r  )r  ztorch.Tensor)r   zTuple[str, ...])r8   )r   zTuple[int, int, int])T)re  r   )r  ztypes.ModuleType)r   r   )rY   r'  )r   r   r  r   )r  r  )r  zUnion[torch.Tensor, Any]r  r   r  r'   r   z)Tuple[bool, Optional[TensorStaticReason]])FFF)r~   r~   rz  rq   r   rq   )r  r~   r   zOptional[_Anchors])r*  ztypes.CodeTyper  zdis.Instructionr   r~   )r  z,torch._dynamo.variables.base.VariableTrackerr   r   )TT)rU  ztorch.fx.GraphModule)r  r~   r  r   (  
__future__r   atexitrr   r  r  rS  r^  r  rt  r  rY  r  r  r   r/  r  r  r@  r  r   r3  rp  r  r  r   r  r  rs  r  r5  r^  r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   r   r   torch._functorch.config%torch.fx.experimental.symbolic_shapestorch.utils._pytreerW  _pytreer  r    torch._Cr!   r"   r#   r$   torch._dispatch.pythonr%   torch._dynamo.metrics_contextr&   torch._guardsr'   r(   torch._subclasses.meta_utilsr)   torch._utils_internalr*   r+   r,   r-   torch.fx._utilsr.   r/   torch.monitorr0   torch.nn.modules.lazyr1   torch.utils._tritonr2   r3   torch.utils.hooksr4   r,  ry  r[  torch._loggingtorch._numpy_numpyr+  r5   r7   rO  r9   fftlinalgr  r:   rt   NP_TO_TNP_MODULEr  r<   r=   r>   r   r?   r  r  r  unpatched_nn_module_getattrr  unpatched_nn_module_call
_call_implunpatched_nn_module_call_implrs   r@   rB   troubleshooting_urlnnmodule_doc_urlnnmodule_doc_url_msgr  rJ   rp   rC   r5  rE   r`   timer_counterru  rG   rS   r   r   r   r   r   r   r   r   r   r   r   registerr   FloatTensorr  DoubleTensorr  double
HalfTensorr  halfBFloat16TensorrA  
ByteTensorr~  
CharTensorrz  
LongTensorr}  long	IntTensorr|  rq   ShortTensorr{  short
BoolTensorr   tensortype_to_dtyper   r  r  r  r  r#  r+  r8  r@  rB  rG  rL  rN  rg  rq  ParamSpecArgsParamSpecKwargs	ParamSpecTypeVarTupleTypeAliasTyperr  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rF  r  !DEFAULT_COMPILATION_METRICS_LIMITrp  r  r#  r:  rl  r   rs  ru  rw  ry  r  r   r  r  r  r  r  r  r  r  r  r  r%  r'  r,  r+  rK  rV  r`  rf  ro  r  r~   r[   r'  Ellipsisr*  NotImplementedCodeTyper  r  memory_formatr  finfoiinfo	attention
SDPBackendr`  _CudaDevicePropertiesrp  ra  r   languagers  r|  r  r  r  r  r  r   r  r   r  r   r  r  r  r   r  __length_hint__tuple_iterator_lenr  r4  r  r  r  r  r  	iter_nextr  r  r  r  r  r  r  r  r  r  r  GLOBAL_KEY_PREFIXtorch._subclassesr  r  r  r  r  r#  r  rS  rY  orig_code_mapr   rZ  r[  seen_code_maprd  r  rk  rm  rt  rp  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  all_hook_namesr  r"  r$  r(  r/  r1  r=  r?  rH  rT  rX  r\  re  ro  ru  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&  r*  r,  r.  r   r2  r7  r;  r?  rC  rG  rE  rM  rO  rR  rX  r\  re  rh  rl  rq  rr  ru  rw  ry  r  r;   rP   rQ   <module>r     s%   "       
   	         	 	 
          % $  #     0 .   , $ $   < 8 0 =  G & 1 > -	.) 
FFIIII	>
: 	
 FFCGGIIszzIIszz	
  "VV
 CL#hhoo99  88??33  % : : +B;+B+B;CVCV+W
( W$& > &G  Q .//UV g! 46 0 5
 .E[-D-DU-K * K	!tyy %J %JP

=
.
 	
 
   > !    !%"',0.2!^B	^B ^B  	^B
 *^B ,^B ^B  ^B ^BB 
 
 
,1
%)# 
"J 8 8
 
u{{3	5	u}}ejj1	5>>+	u{{n	uzzm	u{{EJJ/	OOekk599-	U[[1	uzzm  ( #:"; ",
	?
G	 B 
 
 
	 I 
 
 
& w 	%!G&	$3%$, T 
05   F4 F4 F4R %' ! 3D+2C2C,3 / 
#L&Ru3u3u3 u3 ,	u3
 'u3r "*DE %!
&} }@ 59 1 8  ""'


  
  	
 
@ ( ( (( +   )*  ! GT&
 9 9"	$(
< Q1 12,"X 2  		J	NN	LL	KK		LL	KK	KK	HH!!	JJ$$'$ y , foo334W
 "&bggi	 0%)"))+%6" 6&*+B;+B+B+D+K+K+M&N# N&*48n# 4&*4a>&:# :#33 ^^
1
 	58&RM
@B 
 !  = <7'?
; ii-2`FF	H
 
> 
> '( /Fk.E.Ed.K+ K LN H M '( T, ,&

/CL  	!1 " ".b$NB*2G/	 5$  /	D*W +,<= ,.?@   $&99<QQ  	F  	$

$ 
$$$ $&$ $(@4.&
"	C   vrAH)"04
O  $&1 1,^41   E !	2% C CK0
,$
"
  DF @ E6
# #LM[q  	B>  		s%    o Bo% o"!o"%o.-o.