
    Ph)              	         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mZ d dlmZ d dlmZ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 d dl m!Z! d dl"Z"d dl#Z"d dl$m%c m&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/m0Z0 d dl1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9 ddl:m;Z; ddl<m=Z=m>Z> ddl?m@Z@ erd dlAmBZBmCZCmDZDmEZEmFZF nl eGe"j                  j                  j                        D ]C  ZKeKj                  d      r eMe"j                  j                  j                  eK       eN       eK<   E ddlOmPZPmQZQmRZRmSZSm%Z% ddlTmTZT ddlUmVZVmWZWmXZX ddlYmZZZ ddlm[Z[m\Z\ ddl%m]Z]  ej                  e_      Z`d dlambZb d dlcmdZd  e%j                         Zfej                  Zhd dliZi G d de      Zjejj                  Zl e
j                         Zn e
j                         Zpd  Zqd! Zrej                  dSd"       Zt ej                  e;       e e eev            d#      hZw	 	 	 	 dTd$Zx G d% d&e"j                  j                        Z{d' Z|d( Z}d) Z~ e
j                         Ze G d* d+             Zd, Zej                  	 	 	 	 	 	 dUd-       ZdVd.ZdWd/Z G d0 d1      Z G d2 d3e      Z G d4 d5e      Z G d6 d7e      Zd8 ZdXd9Zehddd:d;f	 dXd<Zd= Z G d> d?ej                        Zd@ ZdA Z	 dYd;ddd;dd:dBdCZ e!dDd:      dE        Z G dF dGe"jt                  j$                  j&                        Z G dH dIe      ZdJ ZdK Zd;d;ddLdd;d:d;dM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dZdNZ e@dd      d;ddd:dOdPZ G dQ dR      Zy)[    )annotationsN)	dataclass)Enum)dirnamejoin)
AnyCallableDictList
NamedTupleOptionalSetTupleTYPE_CHECKINGUnion)patch)_guards)fake_tensor)
Constraint)make_fxmaybe_disable_fake_tensor_mode)ConstraintViolationError
DimDynamicStatelessSymbolicContext)_PyTreeCodeGen_PyTreeInfo)DistributedDataParallel   )GraphModule   )
CompilerFnlookup_backend)Hooks)
reset_codeset_eval_frameset_guard_error_hook	skip_codeunsupported__)configconvert_frameexternal_utils	skipfilesutils)code_context)CondOpArgsMismatchError	UserErrorUserErrorTypeinstall_generation_tagging_init)
CacheEntryDynamoCallback)compile_times)enable_python_dispatcher)_disable_current_modesc                      e Zd ZdZy)Unsetr   N)__name__
__module____qualname__token     cC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/eval_frame.pyr;   r;   Y   s    ErA   r;   c                     t        t        d      sdt        _        t        t        d      sd t        _        t        t        d      si t        _        y y )N$skip_backend_check_for_run_only_modeFcurrent_backendcached_backends)hasattrguarded_backend_cacherD   rE   rF   r@   rA   rB   !_maybe_init_guarded_backend_cacherI   c   sF    (*PQEJB(*;<04-(*;<02- =rA   c                     t                dt        _        d t        _        t        j                  } | j                         D ]  }t        |d      s|j                          ! | j                          i t        _        y )NFreset)	rI   rH   rD   rE   rF   valuesrG   rK   clear)rF   backends     rB   _reset_guarded_backend_cacherO   l   sb    %'AF>,0)+;;O"))+7G$MMO , ,.)rA   c              #    K   t                | du r,	 t        j                  }dt        _        d  |t        _        y t        |       }dd} ||      }	 |  ||       y # t        _        w xY w#  ||       w xY ww)NFTc                t    t         j                  }| t         _        | t         j                  t        |       <   |S N)rH   rE   rF   id)rN   prev_backends     rB   _set_current_backendz3backend_cache_wrapper.<locals>._set_current_backend   s1    0@@L4;!1AH!11"W+>rA   )rN   r!   )rI   rH   rD   innermost_fn)callback	prev_skiprN   rU   rT   s        rB   backend_cache_wrapperrY   x   s     %' 5	S-RRIIM!FJIR!Fx(	  ,G4	/M . JS!F !.s3   A?A" #A?A2 	A?"A//A?2
A<<A?z+onnx/_internal/fx/dynamo_graph_extractor.pyc                    t        |       r| j                  } t        j                  j                  j
                  j                  |       }g }| |j                  |       |j                  }| |S )zh
    Given a code object or a callable object, retrieve the cache entries
     stored in this code.
    )	callable__code__torch_C_dynamo
eval_frame_debug_get_cache_entry_listappendnext)code
cache_head
cache_lists      rB   ra   ra      sf     ~}}!!,,HHNJJ

 *%__
 
  rA   c                  b     e Zd ZU dZded<   ded<   d fdZd Zd Zd	 Zd
 Z	d Z
 fdZ xZS )OptimizedModulezx
    Wraps the original nn.Module object and later patches its
    forward method to optimized self.forward method.
    Callable[..., Any]_torchdynamo_orig_callablezCallable[[], Any]get_compiler_configc                ^    t         |           || _        || _        | j	                          y rR   )super__init__	_orig_mod
dynamo_ctx_initialize)selfmodrp   	__class__s      rB   rn   zOptimizedModule.__init__   s(    $rA   c                   t        | j                  j                  t        j                        r]t        j                  | j                  j                        r4| j                  t        j                  | j                              | _        n*| j                  | j                  j                        | _        t        | j                  d      r#| j                  | _        | j                  | _        y y N_initialize_hook)
isinstancero   forwardtypes
MethodTyper-   checkrp   r,   wrap_inline__call__rG   _forward_call_lazy_checkrr   s    rB   rq   zOptimizedModule._initialize   s    dnn,,e.>.>?IOONN""E
  ??>+E+Ednn+UVDL  ??4>>+B+BCDL4>>#56 LLDM00DL 7rA   c                x    t        | j                        }|j                  dd        |j                  dd        |S )Nry   r~   )dict__dict__poprr   states     rB   __getstate__zOptimizedModule.__getstate__   s1    T]]#		)T"		*d#rA   c                2    || _         | j                          y rR   )r   rq   r   s     rB   __setstate__zOptimizedModule.__setstate__   s    rA   c                V    |dk(  r| j                   d   S t        | j                  |      S )Nro   )_modulesgetattrro   )rr   names     rB   __getattr__zOptimizedModule.__getattr__   s*    ;==--t~~t,,rA   c                    t        | j                  d      r'| j                  j                  | j                  ||        | j                  |i |S rv   )rG   ro   _infer_parametersr   )rr   argskwargss      rB   r   z OptimizedModule._call_lazy_check   sC    4>>#56
 NN,,T^^T6Jt}}d-f--rA   c                    | j                   j                         }|t        |          D cg c]	  }||vs| c}z   S c c}w rR   )ro   __dir__rm   )rr   orig_mod_attrsattrrt   s      rB   r   zOptimizedModule.__dir__   sM    //1"W_.!
.T$n2LD.!
 
 	
 !
s
   	A A )rs   ztorch.nn.Module)r<   r=   r>   __doc____annotations__rn   rq   r   r   r   r   r   __classcell__rt   s   @rB   rh   rh      s>    
 !32**1"-
.
 
rA   rh   c                H   t        | t        j                        rt        |        yt	        | d      rt        | j
                         yt	        t        | dd      d      r t        | j                  j
                         yddlm	}  |        t        j                  d|        y)zA
    Make sure f.__code__ is not cached to force a recompile
    r\   ry   Nr    rK   z#could not determine __code__ for %s)rx   rz   CodeTyper$   rG   r\   r   ry    rK   logwarning)frK   s     rB   remove_from_cacher      sk     !U^^$1	J	1::	It,j	9199%%&91=rA   c                      y rR   r@   r@   rA   rB   nothingr     s    rA   c                n    | }t        |d      r&|j                  }t        |      sJ t        |d      r&|S )z
    In case of nesting of _TorchDynamoContext calls, find the innermost
    function. TorchDynamo caches on fn.__code__ object, so its necessary to find
    the innermost function to pass on the optimize, run, disable etc.
    rj   )rG   rj   r[   )fnunaltered_fns     rB   rV   rV     sB     L
, <
=#>>%%% , <
= rA   c                  "    e Zd ZU ded<   ded<   y)ConfigAndHashzDict[str, Any]r*   byteshashNr<   r=   r>   r   r@   rA   rB   r   r     s    
KrA   r   c                 R    t        t        d      sd t        _        d t        _        y y )Nsaved_config_and_hash)rG   config_cacher   nopythonr@   rA   rB    _maybe_init_guarded_config_cacher     s"    <!89-1* $ :rA   c              #    K   t                d}	 | rit        j                  Yt        j                  J d}|t        _        |t        _        t        j                  d|j                  j                                nt        j                  d       d  |rSt        j                  dt        j                  j                  j                                d t        _        d t        _        y y # |rSt        j                  dt        j                  j                  j                                d t        _        d t        _        w w xY ww)NFTz)Setting top-level compile config hash: %sz-Ignoring inner dynamo compile config and hashz+Unsetting top-level compile config hash: %s)r   r   r   r   r   debugr   hex)	first_ctxr   r   is_top_levels       rB   restore_guarded_dynamo_configr   $  s     %&L);;C((000L1FL.$,L!II;%**..0
 IIEFII=2277;;= 26L.$(L! <II=2277;;= 26L.$(L! s   EBC* AE*AEEc                Z    | i }n| rddi}nddd}t        t        j                  |       S )Nassume_static_by_defaultFT)automatic_dynamic_shapesr   )r   r*    get_config_and_hash_with_updates)dynamicupdatess     rB   _get_config_and_hashr   B  s:    	-u5/4RVW&AA'JKKrA   c                     t                t        j                  t        j                  j                  S t	        j
                         S rR   )r   r   r   r   r*   get_hashr@   rA   rB   "get_saved_else_current_config_hashr   L  s3    $&))511666  rA   c                  P     e Zd Zeeedfddddd	 d
 fdZd Zd Zd Zd	 Z	 xZ
S )_TorchDynamoContextFNT)r   compiler_configsave_configr   c                  t         
|           t        |      s|du s|J || _        t        | _        || _        || _        || _        || _	        || _
        |xr || _        |	| _        | j                  r| j                           |        y NF)rm   rn   r[   rW   unsetprioron_enterextra_ctx_ctorr   r   r   r   r   save_and_hash_config)rr   rW   r   backend_ctx_ctorpatch_fnr   r   r   r   r   rt   s             rB   rn   z_TorchDynamoContext.__init__U  s     	!X%6(:JJJ(038
 .".&49 %%'
rA   c                    t        | j                        | _        t        j	                  d| j                  j
                  j                                y )NzBSaving dynamo config and hash for new compiled object(s). Hash: %s)r   r   r   r   r   r   r   r   s    rB   r   z(_TorchDynamoContext.save_and_hash_configq  s:    %9$,,%G"		P&&++//1	
rA   c                   t         j                  rt        d      | j                          t	        | j
                        | _        t        | j
                        | _        | j                  j                          | j                         | _        | j                  j                          | j                  rKt        | j                  | j                  | j                         | _        | j"                  j                          y y )Nztorch._dynamo.optimize(...) is used with a context manager. Please refer to https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html to use torch._dynamo.optimize(...) as an annotation/decorator. )r*   raise_on_ctx_manager_usageRuntimeErrorr   r%   rW   r   rY   backend_cache_manager	__enter__r   backend_ctxr   r   r   r   r   dynamo_config_ctxr   s    rB   r   z_TorchDynamoContext.__enter__y  s    ,,R 
 	#DMM2
%:4==%I""",,...0""$%B : :DMM&D" "",,.	 rA   c                2   | j                   t        usJ t        | j                          t        | _         | j                  r| j                  j                  |||       | j                  j                  |||       | j                  j                  |||       y rR   )r   r   r%   r   r   __exit__r   r   )rr   exc_typeexc_valexc_tbs       rB   r   z_TorchDynamoContext.__exit__  sx    zz&&&tzz"
""++HgvF!!(GV<""++HgvFrA   c                   	  fd}t              t        t        j                  j                        r,t        j                  j                  j                        d<   t        t        j                  j                        r6}t        |       }|j                  |_        t        |d      rJ ||_        |S t              sJ 	 t!        j"                        }|t'        j(                        r,t+        dd      dvr|t,        vrt/        j0                         j2                   j4                  	 j6                  t9        j:                        	 fd       }t         t<              rd|_        n|_         |_        t        |d      rJ ||_        d	vr=t        d
      stC        tE        jF                  d            dtH        j                  <   |S # t$        $ r d }Y w xY w)Nc                      j                   S rR   )r   r   s   rB   rk   z9_TorchDynamoContext.__call__.<locals>.get_compiler_config  s    '''rA   orig_graphmodulerk   r<   r   )
_call_impl_wrapped_call_implc                    t        
t              sKt        j                  j                  j                         r#t        j                  rt        d       | i |S t        j                  j                         r#t        j                  rt        d       | i |S  	        t              }t        
j                        }|j                                  }|j                          
j                   r;t#        
j$                  
j&                  
j(                        }|j                          	  | i |t        |       
j                   rj+                  d d d        |j+                  d d d        |j+                  d d d        S # t        |       
j                   rj+                  d d d        |j+                  d d d        |j+                  d d d        w xY w)NzvDetected that you are using FX to symbolically trace a dynamo-optimized function. This is not supported at the moment.zsDetected that you are using FX to torch.jit.trace a dynamo-optimized function. This is not supported at the moment.)rx   DisableContextr]   fx_symbolic_traceis_fx_tracingr*   error_on_nested_fx_tracer   jit
is_tracingerror_on_nested_jit_tracer%   rY   rW   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   rW   r   r   rr   s         rB   _fnz)_TorchDynamoContext.__call__.<locals>._fn  s    t^4HH,,::<22&\ 
 t.v..yy##%33&\ 
 t.v..J"8,E$9$--$H!!++-*,K!!#$ANND$>$>%! "++-A4*6*u%##%..tT4@$$T46%..tT4@	 u%##%..tT4@$$T46%..tT4@s   4F AGTr   r\   a  

                        torch._dynamo.optimize is called on a non function object.
                        If this is a callable class, please wrap the relevant code into a function and optimize the
                        wrapper function.

                        >> class CallableClass:
                        >>     def __init__(self):
                        >>         super().__init__()
                        >>         self.relu = torch.nn.ReLU()
                        >>
                        >>     def __call__(self, x):
                        >>         return self.relu(torch.sin(x))
                        >>
                        >>     def print_hello(self):
                        >>         print("Hello world")
                        >>
                        >> mod = CallableClass()

                        If you want to optimize the __call__ function and other code, wrap that up in a function

                        >> def wrapper_fn(x):
                        >>     y = mod(x)
                        >>     return y.sum()

                        and then optimize the wrapper_fn

                        >> opt_wrapper_fn = torch._dynamo.optimize(wrapper_fn)
                        )%rV   rx   r]   r   r   r/   get_contextry   r\   nnModulerh   rj   rG   rk   r[   inspectgetsourcefile	TypeErrorr-   r|   r   DONT_WRAP_FILESr,   r}   rW   r   r   	functoolswrapsr   _torchdynamo_disable_torchdynamo_inliner   textwrapdedentalways_optimize_code_objects)
rr   r   rk   rs   new_modfilenamer   r   rW   r   s
   ``     @@@rB   r~   z_TorchDynamoContext.__call__  s   	( " b%((../ QSL$$RZZ%8%89:LM b%((//*C%c40G 25G. w(=>>>*=G'N||	,,R0H !4J+3WW/  ++B/B====..		(	A 
(	AV dN+'+C$&(C# *,& 3 5666"5 =(2z*"OO   B 9=(5
c  	H	s   G) )G87G8rW   r6   )r<   r=   r>   r   null_contextrn   r   r   r   r~   r   r   s   @rB   r   r   T  sG     %  8
/&GQrA   r   c                  .     e Zd Z	 dddddd fdZ xZS )OptimizeContextFNT)r   r   r   r   c               X    d }t         	|   |||t        j                  |||||	       y )Nc                     t                y rR   r3   r@   rA   rB   r   z*OptimizeContext.__init__.<locals>.on_enter6  s    +-rA   )	rW   r   r   r   r   r   r   r   r   )rm   rn   TorchPatcherr   )
rr   rW   r   r   r   r   r   r   r   rt   s
            rB   rn   zOptimizeContext.__init__+  s=    	. 	-!''+# 	 
	
rA   )Fr<   r=   r>   rn   r   r   s   @rB   r   r   *  s%    
 	
 
 
rA   r   c                       e Zd Z fdZ xZS )RunOnlyContextc                .    d }t         |   d|       y )Nc                 r    t         j                  j                  j                  xj                  dz  c_        y )Nr    )r]   r_   mutation_guardGenerationTracker
generationr@   rA   rB   r   z)RunOnlyContext.__init__.<locals>.on_enterI  s#    MM((::EEJErA   F)rW   r   rm   rn   )rr   r   rt   s     rB   rn   zRunOnlyContext.__init__G  s    	K 	%(;rA   r  r   s   @rB   r  r  F  s    < <rA   r  c                       e Zd Z fdZ xZS )r   c                &    t         |   d        y )N)rW   r  )rr   rt   s    rB   rn   zDisableContext.__init__P  s    $'rA   r  r   s   @rB   r   r   O  s    ( (rA   r   c                    t         j                  dk  ryt        j                  |       D ]"  }|j                  dk(  s|j
                  dz  c S  t        d      )N)      r   RESUMEr   z$RESUME instruction not found in code)sysversion_infodisget_instructionsopnameoffsetr   )rd   insts     rB   first_real_inst_idxr  T  sQ    
'!$$T*;;(";;!## + =
>>rA   c                T     t        j                          fd       } |_        |S )Nc                p   |J t        j                  | j                        }| j                  t	        | j                        k\  s|st
        j                  rt        j                  t        j                        r| j                  t	        | j                        k\  rdn"t        j                  | j                        rdnd}|rt
        j                  r@t        j                  d| j                  j                  || j                  j                         y | j                  j                  dk(  r| j                  j                  dk(  ry t
        j                  rt!        j"                         }|rmt$        5  ddlm}  ||j*                  	j,                  	      }t/        	d
      sJ d       	j1                  |j2                        } || |
|      cd d d        S t$        5  t5               5   	| |
|      cd d d        cd d d        S # 1 sw Y   8xY w# 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)Nztraced frame alreadyzin skipfileszdynamo tracing is disabledz#skipping: %s (reason: %s, file: %s)z<string>__new__r   )DDPOptimizer)bucket_bytes_capbackend_compile_fn_clone_with_backendzJDDPOptimizer only supports callback fns that know how to clone themselves.)r-   r|   f_codef_lastir  r*   disabler   isEnabledForloggingDEBUGverboser   co_nameco_filenameoptimize_ddpr   _get_active_ddp_modulecompile_lock"torch._dynamo.backends.distributedr  r  rj   rG   r   
compile_fnr9   )framecache_entryframe_stateis_skipfileskip_reason
ddp_moduler  ddp_optimizerhijacked_callbackrW   hookss            rB   catch_errorsz*catch_errors_wrapper.<locals>.catch_errors^  s   &&&ooell3 MM0>>~~. }}(;ELL(II + !u||4 (5  #fnnII=,,#00	 <<##z1ell6J6Ji6W0GGIJ!O$0)3)D)D+3+N+N%M # "7 dcd  )1(D(D%00)% -UKT "\ 13E;{C 43\\ "\ 43\\\s1   5AH"H,-H8	H,HH 	H,,H5)r   r   rj   )rW   r7  r8  s   `` rB   catch_errors_wrapperr9  ]  s1    __X0D 0Dd /7L+rA   TFc           	     :    t        t        | |      |d||||      S )NT)r   r   r   r   r   r   )r   r9  )r.  r7  r   r   r   r   r   s          rB   _optimize_catch_errorsr;    s-     Z/)' rA   c                    ddl m} t        | d      r| j                  }nt	        | t
              r| }nd }t        |       }  || |      S )Nr    )wrap_backend_debugcompiler_name)repro.after_dynamor=  rG   r>  rx   strr"   )compiler_fnr=  compiler_strs      rB   get_compiler_fnrC    sE    6{O,"00	K	%" -Kk<88rA   c                      e Zd Zd Zy)_NullDecoratorc                     t        |      sJ |S rR   )r[   )rr   r   s     rB   r~   z_NullDecorator.__call__  s    ||	rA   N)r<   r=   r>   r~   r@   rA   rB   rE  rE    s    rA   rE  c                 |    t         j                  dk(  rt        d      t         j                  dk\  rt        d      y )Nwin32z+Windows not yet supported for torch.compile)r     z0Python 3.12+ not yet supported for torch.compile)r  platformr   r  r@   rA   rB   check_if_dynamo_supportedrK    s9    
||wHII
7"MNN #rA   c                 8    	 t                y# t        $ r Y yw xY w)NTF)rK  	Exceptionr@   rA   rB   is_dynamo_supportedrN    s"    !# s   
 	)r   guard_export_fnguard_fail_fnr#  r   r   c                  t                t        ||      }t        j                  j	                  d       |s#t
        j                  j                  dd      dk(  r
t               S t        |       } t        | dt              }|rt        | |||      S t        t        j                  | |      ||||t        | d	      r| j!                               S d
      S )an  
    The main entrypoint of TorchDynamo.  Do graph capture and call
    backend() to optimize extracted graphs.

    Args:
        backend: One of the two things:
            - Either, a function/callable taking a torch.fx.GraphModule and
            example_inputs and returning a python callable that runs the
            graph faster.
            One can also provide additional context for the backend, like
            torch.jit.fuser("fuser2"), by setting the backend_ctx_ctor attribute.
            See AOTAutogradMemoryEfficientFusionWithContext for the usage.
            - Or, a string backend name in `torch._dynamo.list_backends()`
        nopython: If True, graph breaks will be errors and there will
            be a single whole-program graph.
        disable: If True, turn this decorator into a no-op
        dynamic: If True, upfront compile as dynamic a kernel as possible.  If False,
            disable all dynamic shapes support (always specialize).  If None, automatically
            detect when sizes vary and generate dynamic kernels upon recompile.
        save_config: If True, recompiling this function will first restore the dynamo config
            at the time when `optimize` was first called, for the duration of the compilation
            process.
    Example Usage::

        @torch._dynamo.optimize()
        def toy_example(a, b):
            ...
    rO  rP  ztorch._dynamo.optimizeTORCHDYNAMO_DISABLEr   1r   )r   r7  r   )r7  rk   N)r   r   r   )rK  r#   r]   r^   _log_api_usage_onceosenvirongetrE  rC  r   r   optimize_assertr;  r+   rG   rk   )	rN   r   rO  rP  r#  r   r   r7  r   s	            rB   optimizerZ    s    L  /OE	HH  !9:"**..!6;sBg&G w(:LI#	
 	
 "##G59712  335	 	 	 	rA   z&torch._dynamo.symbolic_convert.explainc                T      fd}|s|rt        j                  d        ||i |S |S )Nc            
     ,   ddl m}  |        g g dg g 	 	 dfd}fd} t        |d|            } || i | t              }i }D ]  }|j                  d   }	||t        |	      <   ! d	}
t        |j                               D ]P  \  }}d	j                  t        j                  |j                              }|dz    d
|j                   d| d}|
|z  }
R |dz
  }t        d      } |        ddlm}  ||||      S )Nr    r   r   c                L    ddl m}  ||       \  } | j                  S )Nr    )_explain_graph_detail)backends.debuggingr^  ry   )gmexample_inputsr^  break_reasonsgraphsop_countops_per_graphs      rB   "dynamo_graph_accumulating_compilerzBexplain.<locals>.inner.<locals>.dynamo_graph_accumulating_compiler#  s:     B BWFHm]B>B- ::rA   c                (    j                  |        y rR   )extendguards
out_guardss    rB   guard_export_printz2explain.<locals>.inner.<locals>.guard_export_print3  s    f%rA   F)r   rO  r   z
. Reason: z
   User Stack: 
r@  )repr)ExplainOutputr`  torch.fx.GraphModule)r   rK   rZ  len
user_stackro  	enumeraterL   r   	tracebackformat_listreasonr7   r_  rp  )r   r   rK   rf  rl  opt_fgraph_countdeduped_reasonsrx  innermost_frameformatted_listidxbreak_reasonformatted_stackmsggraph_break_countcompile_timerp  rb  rc  rd  re  rk  r   s                     @@@@@rB   innerzexplain.<locals>.inner  s]   -/#%-/*,
	$	 	 	&
..
 	 	tv&k #F$//3O5;OD12 $
 !*?+A+A+C!DC ggi&;&;L<S<S&TUO1WIZ(;(;'<<MoM^^`aCc!N "E
 (!O$%0 	5	
 		
rA   zexplain(f, *args, **kwargs) is deprecated, use explain(f)(*args, **kwargs) instead.  If you don't migrate, we may break your explain call in the future if your user defined kwargs conflict with future kwargs added to explain(f).warningswarn)r   
extra_argsextra_kwargsr  s   `   rB   explainr    s9    G
R \?	

 j1L11rA   c                  X     e Zd Z	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZd Z fdZ fdZ xZS )FlattenInputOutputSignaturec                J    t            |       t        |      t        |      k(  sJ t        |      D 	ci c]  \  }}	|	||    }
}}	g  _        t        dt        |            D ]  }t            d| di       }||
v r|
|   |j                  j                  d<   n|t        ||   t        j                        r|j                  ||   t        t        t        ||   j                              D cg c])  }|||   v rt        j                   nt        j"                  + c}d gt        ||   j                        z              |j                  j                  d<    j                  j%                  |         fd|D         _        | _        y c c}	}w c c}w )Nr   argr@   val)dynamic_sizesconstraint_sizes)symbolic_contextc              3  <   K   | ]  }j                   |     y wrR   )new_args).0irr   s     rB   	<genexpr>z7FlattenInputOutputSignature.__init__.<locals>.<genexpr>  s     X7W!T]]1-7Ws   )rm   rn   rs  ru  r  rangeplaceholdernodemetarx   r]   Tensorfrom_tensorr   shaper   DYNAMICSTATICrb   old_args_gen!matched_output_elements_positions)rr   m	flat_args matched_input_elements_positionsr  example_fake_inputsflat_args_dynamic_dims	fake_modeixr  matched_input_elements_to_faker  r  drt   s   `             rB   rn   z$FlattenInputOutputSignature.__init__l  s    	)*c)n<<< %%EF*
FC $R((F 	' *

 q#i.)A'%A3iR8C22'Ea'He$ (Z	!ell-S+4+@+@!!)A
 */s9Q<3E3E/F)G	+ *HA $%(>q(A#A !+ 2 2%/%6%6!7 *H	+ /3Vc)A,:L:L6M-M* ,A ,CHHMM%( MM  %+ *, Y7WX1R.;*
$+s   F7.F c                   t        | j                        }d| j                  j                  v r0| j                  j                  d   |j                  j                  d<   d| j                  j                  v r0| j                  j                  d   |j                  j                  d<   d| j                  j                  v r0| j                  j                  d   |j                  j                  d<   |S )Nr  tensor_dictexample_value)rc   r  current_noder  r  )rr   targetr   r   r  s        rB   r  z'FlattenInputOutputSignature.placeholder  s    4$$%D%%***#'#4#4#9#9%#@CHHMM% D--222+/+<+<+A+A-+PCHHMM-(d//444-1->->-C-CO-TCHHMM/*
rA   c                    |d   }g || j                   }| j                  D cg c]  }||   	 }}t        |   ||fi       S c c}w )Nr   )r  r  rm   output)	rr   r  r   r   dynamo_result_flatlookupr  new_result_flatrt   s	           rB   r  z"FlattenInputOutputSignature.output  s]    !!W6%66.2.T.TU.T6!9.TUw~f&8"== Vs   Ac                   || _         t        | 	  |      }d| j                   j                  v r0| j                   j                  d   |j                  j                  d<   d| j                   j                  v r0| j                   j                  d   |j                  j                  d<   | j                   j
                  dk7  rD|j                  j                  t        | j                   d|j                  j                               |S )Nr  r  r  r   )	r  rm   run_noder  r  op_renamer   r   )rr   nresult_proxyrt   s      rB   r  z$FlattenInputOutputSignature.run_node  s    w'*D%%***,0,=,=,B,B5,IL""5)d//4446:6G6G6L6L7L""?3 8+%%))6<3D3D3I3IJ rA   rR   )r  rr  r  z
Tuple[Any]r  	List[int]r  r  r  zList[torch.Tensor]r  zList[Set[int]]r  z$Optional[fake_tensor.FakeTensorMode])r<   r=   r>   rn   r  r  r  r   r   s   @rB   r  r  k  sn     ;?*S*S *S +4	*S
 ,5*S 0*S !/*S 8*SX> rA   r  c                  "    e Zd ZU ded<   ded<   y)ExportResultrr  graph_module_guards.GuardsSetrj  Nr   r@   rA   rB   r  r    s    &&rA   r  c                   g }| j                   j                  D ]  }|j                  dk(  st        |d      sJ |j                  }| j
                  j                  |      }|Kt        |      dkD  sJ d }|D ]  }t        |      dk(  r|} n ||j                          d}n]dj                  t        j                  |            }d}	t        |      dkD  rdt        |      dz
   d}	|j                          d	| |	 }|j                  |        |r,t        t        j                  d
dj                  |      z         y )Nr  _dynamo_sourcer   z, a closed over free variabler   r    z(elided z more accesses)z, accessed at:
a  Cannot export model which references tensors that are neither buffers/parameters/constants nor are direct inputs.  For each tensor, if you'd like this tensor to be an explicit input, add it as a dummy argument to the top-level model definition you are exporting; if you would like its value to be embedded as an exported constant, wrap its access in a function marked with @assume_constant_result.

z

)graphnodesr  rG   r  _source_to_user_stacksrX  rs  r   r   rv  rw  rb   r1   r2   INVALID_INPUT)
r  input_errorsr  sourceuser_stacksstacksr  tbextras
             rB   check_signature_rewritabler    s\   L!!77m#4!1222((F66::6BK"{#a''' E q6Q;	 !
 }'DEWWY2259:{#a'&s;'7'9&:/JE'7tE7C$3 "6 ''E kk,'(	
 		
 rA   c
           	        t        j                  ||      \  }
}t        j                  t        j                  t        j
                  t        j                  ffdfd} |d|id|i      }t        j                  |      \  }}|J  |t        |      |dd|i      }t        ||||||	|      j                         }d	d}t        t         || |
|      ||            |j                  _        |j                          |S )
Nc                    t        |       S rR   )rx   )r  supported_typess    rB   is_supported_typez,rewrite_signature.<locals>.is_supported_type  s    #//rA   c                   dj                  | j                         D cg c]?  \  }}|dz   dj                  |D cg c]  }t        t        |             c}      z   dz   A c}}}      }| j	                         D cg c]  }|D ]  }|  }}}g }i }t        |      D ]  \  }	}|	|t        |      <    |j                         D ]  \  }
}t        |      D ]r  \  }	} |      rMt        |      |v r|j                  |t        |                9t        |
 d|	dz    dt        |       d|       t        |
 d|	dz    d	| d
         |S c c}w c c}}}w c c}}w )Nz or z of types: (z, )z #r    z
, of type z, is not among z is z., but only the following types are supported: )	r   itemsr@  typerL   ru  rS   rb   AssertionError)sources
candidatesdescvalsr  source_typessource_valsmatched_elements_positionsdict_of_source_valsr  candidate_desccandidate_valsr  r  s               rB   produce_matchingz+rewrite_signature.<locals>.produce_matching  s   {{ #*--/
 #2JD$	  !))t<tSc^t<=>  #2
 (/~~'7H'7t4Cs4s'7H%'" ,FAs+,3( - /9.>.>.@*NN#N33$S)#w"55299:MbQTg:VW,-.b1ZS	{/ZfYgh  ))*"QqSEcU ;>>M=NP  4 /A *)5 = Is   EEEEEoriginal inputszgraph-captured input)r  r  )zgraph-captured outputsr  zoriginal outputc                   dd} ||       }|j                   d t        |       }t        |      t        |j                         kD  rU|j                  J d       |t        dt        |      t        |      z
        D cg c]  }|j                   d|  c}z  }ndt        |      t        |j                         k  rC|j                   t        |      t        |j                  xs g         D ]  }||v rJ d|         |t        |j                               z  }|j                  D ]%  }|j                  xs i }	||v r||	v rJ d|         |S c c}w )Nc           	     h   t        | j                  j                               }|D cg c]5  }|j                  t        j
                  j                  k(  r|j                  7 }}|D cg c]6  }|j                  t        j
                  j                  k(  s+|j                  8 }}t        d |D        d       }t        d |D        d       }t        d |D              }|D ci c]f  }|j                  t        j
                  j                  k(  r=|j                  t        j
                  j                  ur|j                  |j                  h }}i }	| j                  rd| j                  i}	|D ]  }
|
j                  |	|
j                  <    t	        j                  |||||||	      S c c}w c c}w c c}w )Nc              3     K   | ]8  }|j                   t        j                  j                  k(  s+|j                   : y wrR   )kindr   	ParameterVAR_POSITIONALr   r  ps     rB   r  z^rewrite_signature.<locals>.argument_names.<locals>.signature_to_fullargspec.<locals>.<genexpr>F  s,     VA166W5F5F5U5U+U
   ,A A c              3     K   | ]8  }|j                   t        j                  j                  k(  s+|j                   : y wrR   )r  r   r  VAR_KEYWORDr   r  s     rB   r  z^rewrite_signature.<locals>.argument_names.<locals>.signature_to_fullargspec.<locals>.<genexpr>J  s,     SA166W5F5F5R5R+Rr  c              3     K   | ]]  }|j                   t        j                  j                  k(  r4|j                  t        j                  j
                  ur|j                   _ y wrR   )r  r   r  POSITIONAL_OR_KEYWORDdefaultemptyr  s     rB   r  z^rewrite_signature.<locals>.argument_names.<locals>.signature_to_fullargspec.<locals>.<genexpr>N  sL      A66W..DDDIIW%6%6%<%<< 		s   A#A%return)list
parametersrL   r  r   r  r  r   KEYWORD_ONLYrc   tupler  r  return_annotation
annotationFullArgSpec)sigparamsr  r   
kwonlyargsvarargsvarkwdefaultskwonlydefaultsr   	parameters              rB   signature_to_fullargspeczKrewrite_signature.<locals>.argument_names.<locals>.signature_to_fullargspec9  s   #..//12F  A66W..DDD    !' &1!&&G4E4E4R4R*R   VVG SSE
   H  A66W..;;;IIW%6%6%<%<< 		!   K$$')>)>?#	.7.B.BINN+ $ &&guh
NK I
$s   :F%(,F*F*!A+F/zMore arguments than expectedr   _zMissing argument zMissing keyword only argument )r  zinspect.Signature)	r   rs  r  r  r   r  keysr  r  )
f_sigr   r   r  fullargspec
input_strsr  unprovided_arg
kwonly_argr  s
             rB   argument_namesz)rewrite_signature.<locals>.argument_names8  s~   *	X /u5 !%%kD	2
t9s;++,, &&2R4RR2q#d)c*o"=>>A &&'q,> J Y[--.. #."2"2D	S!5!5!;<<# &/U3D^DT1UU/# 	d6;;=))
 &00J(77=2Nf$
n(D=/
|<=D 1 5s   =E)r  z	List[str])pytreetree_unflattenr]   r  SymIntSymFloatSymBooltree_flattenr  r  	transformr   r   r  _codegen	recompile)r  r  r  r  in_specr  graph_captured_inputgraph_captured_outputdynamo_traced_resultr  	orig_argsorig_kwargsr  r  flat_results_tracedout_spec_tracedr  	new_graphr  r  r  s                      @@rB   rewrite_signaturer    s$    $229gFI{||U\\5>>5==QO0*B (8"I.*,@A($
 ,2+>+>?S+T( ,,,(8&*+@&A(
 &':;)% ,() ik Pd  .5)[9	
 IOO rA   symbolic)
aten_graphpre_dispatchdecomposition_tabletracing_modeconstraintsr   same_signaturedisable_constraint_solverc          	     |    | |f	d}|	s|
rt        j                  d        ||	i |
S |S )aL  
    Export an input function f to a format that can be executed outside of PyTorch using the FX graph.

    Args:
        f (callable): A PyTorch function to be exported.

        aten_graph (bool): If True, exports a graph with ATen operators.
        If False, exports a graph with Python operators. Default is False.

        pre_dispatch (bool): If True, exports a graph with ATen operators,
        but before any logic in the PyTorch dispatcher has run.
        This can be useful if you want to apply further transformations on a graph before running it
        through autograd, autocast, or any other functionalities that are integrated into the dispatcher.
        This flag is only valid if aten_graph=True is set.
        Default is False.

        decomposition_table (dict): A dictionary that maps operators to their decomposition functions.
        Required if aten_graph or tracing_mode is specified. Default is None.

        tracing_mode (str): If "symbolic", turn on dynamic shapes support. Default is "symbolic".

        same_signature (bool): If True, rewrite the returned graph's signature to be the same as f.

        disable_constraint_solver (bool): Whether the dim constraint solver must be disabled.

    Returns:
        A function that given args and kwargs, returns a tuple of (graph, guards)
        Graph: An FX graph representing the execution of the input PyTorch function with the provided arguments and options.
        Guards: The guards we accumulated during tracing f above

    Raises:
        AssertionError: If decomposition_table is specified without setting aten_graph=True,
        or if graph breaks during tracing in export.

        AssertionError: If Dynamo input and output is not consistent with traced input/output.

    Note - this headerdoc was authored by ChatGPT, with slight modifications by the author.
    c                 	  	  "}!}t                t        j                  j                  d       %	#sJ d       'r	#sJ d       t	        |      }t        |t        j                  j                        r|j                  n|}t        j                  |      }d d  d d d d fd}g 	 	 d fd}t        j                  | |f      \  }}	t        |       d }
)dk7  rd}t        j                  d|ddd	      5   t!        |t#        |d 
      d$      |      }	  || i |}d d d        t        |       &s0t'        dd       x} |j(                  x}t+        j,                  |      s|j/                          |j1                          |j3                         }|j5                  ||
|      }|
r|
j6                  d   |z   f|
_        n$|rt%        |      }
nt8        j;                  d|       |j<                  j?                         D ]]  }t        |t@        jB                        st%        djE                  tG        jH                  |jJ                  |                d| d      }
_ |
r|
J d       tM        d      sJ  J d       J (rtO               D cg c]  }jQ                  |       }}#rڈfd}tS               5  tU               5  5  	  tW        |%dd'd      | 	 d d d        d d d        d d d        jb                  jd                  D ]u  }|jf                  dk(  st        t'        |jh                        t        jj                        sBjQ                  t'        |jh                        d      |jl                  d<   w (rT|D cg c]3  }$xs dD ch c]!  }|jo                         |u s|jp                  # c}5 }}}ts        |||	||
      $r$D cg c]  }|jt                   c}ng jl                  d<   tw               S # t$        $ r}|}
Y d }~d }~ww xY w# 1 sw Y   xY wc c}w # tX        $ r*}t[        t\        j^                  ta        |      d      d }~ww xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY wc c}w c c}}w c c}w )!Nztorch._dynamo.exportzaSpecifying a decomposition_table table or tracing mode is illegal without setting aten_graph=Truez7pre_dispatch=True can only be used when aten_graph=Truec                    J d       | y )Nz3whole graph export entails exactly one guard exportr@   ri  s    rB   rl  z1export.<locals>.inner.<locals>.guard_export_print  s"     "EDE"JrA   c                Z    J d       | t        j                         |fd}|S )Nz\Tried to emit a second graph during export. Tracing through 'f' must produce a single graph.c                 h   | 
J t        
j                  d            }t        
j                  d            }t        j                  |       t        j                  |       n	}|5  t               5  i t        |      t        |      }t               }|j                         D ]  \  }}|j                  |d      ||<    t        j                  |j                  |       }t        j                  j                  
||      d d d        d d d        S # 1 sw Y   xY w# 1 sw Y   S xY w)NF)remove_duplicateTstatic_shapes)r   named_parametersnamed_buffersr   detect_fake_moder8   r  r  r  tree_mapr]   funcfunctional_call)graph_inputsr/  r0  ambient_fake_modeparams_and_buffersfake_params_buffersr   valuefake_graph_inputsr  r  r  graph_captured_results            rB   result_capturing_wrapperzhexport.<locals>.inner.<locals>.dynamo_normalization_capturing_compiler.<locals>.result_capturing_wrapper  sH    (4$(((#'(>(>PU(>(V#W  $U%8%8%%8%P Q //=I ,,\:" " '(@(B*/0*}-*& +/&''9'?'?'Ae4E4Q4Q! 5R 5+D1 (B
 )/)55|)% -2JJ,F,F24E-) )C&& -,' )C(B&& -,s%   ,D'7BD	D'D$	 D''D1)r   r1  )r`  inner_example_inputsr<  ra  r  r  r  r;  s      rB   'dynamo_normalization_capturing_compilerzFexport.<locals>.inner.<locals>.dynamo_normalization_capturing_compiler  sD    
 nmnE  002I1N#-J ,+rA   r  TF)specialize_intr   r    capture_dynamic_output_shape_opscapture_scalar_outputsrR  )r7  exportexport_constraints	shape_envr   z#Summary of dimension constraints:%sr   zk
It appears that you're trying to set a constraint on a value which we evaluated to have a static value of z1. Scroll up to see where this constraint was set.zZFailed to produce a graph during tracing. Tracing through 'f' must produce a single graph.r  z'Failed to produce guards during tracingc                     t         j                  j                  j                         5  t        j                  j	                        j
                  |  cd d d        S # 1 sw Y   y xY wrR   )r]   r   rv  preserve_node_metaInterpreterrun)r   r  s    rB   graph_with_interpreterz5export.<locals>.inner.<locals>.graph_with_interpretery  sB    XX''::< 88//6::DA =<<s   +AA(real)r"  r#  _allow_non_fake_inputsr!  _allow_fake_constantcond_operands)	case_nameget_attrr-  r  r@   input_shape_constraints)rj  r  rq  )<rK  r]   r^   rU  rV   rx   r   r   ry   r   	signaturer  r  r   r*   r   rY  r#   r   r   dim_constraintsr-   r|   solve remove_redundant_dynamic_resultsforced_specializationsprettify_resultsr   r   infovar_to_ranger  sympyIntegerr   rv  rw  var_to_stackrG   r  r  r   r8   r   r0   r1   r2   DYNAMIC_CONTROL_FLOWr@  r  r  r  r  r  r  w_tensordimr  serializable_specr  )*r   r   r   r   call_to_inspectoriginal_signaturerl  r>  r  r  constraint_violation_errorry  result_tracederD  rR  rU  r  ktr  rI  r  xcr  
constraintra  r  r  r  r;  rk  _assume_static_by_default_fr   r$  r"  r&  r!  r%  r#  s*                              @@@@@@rB   r  zexport.<locals>.inner  s!   #< !#$$%;<*srsXXX:O'1!UXX__'E!))1$..?
#DH		  7	,$7	, 7	,v $00$@	7!%)":%'+$\\%=%*-1#'
O7$6"& #. E/ %t 6v 6%
* 	! *%idCCP$-$=$==JOOO4!!#<<>%4%K%K%M"!22"$>@VC *.33A6<3*/ *1I#1N.HH= ++002a/1I779#8#89O9OPQ9R#STU VNNOS QJJ2. 3 &,, 	hg	hu6777%P'PP%$$$ &u- BPPAy44Q7PB 013K3MG.,?%+/3%1-2 +,E  4N1( ))77j(ZE4;;/. (1'<'<t{{34 (= (DIIe$	 *  #&"A "-!2!2I!21qzz|q7H!2I" # & &"#$%&E  =HHKjZ))KH 	

,- E:..e , /-.*/'
 
R Q( / #%::A"1  	 4N3M11< J&$ Is   !Q%P/,QR*"R%R'Q<RR*)R<6R7R7R<>S/	Q8Q :Q QQQ	R	#%R	R	RRRR'	"R**R47R<zexport(f, *args, **kwargs) is deprecated, use export(f)(*args, **kwargs) instead.  If you don't migrate, we may break your export call in the future if your user defined kwargs conflict with future kwargs added to export(f).r  )r   r   r!  r"  r#  r$  r   r%  r&  r  r  r  rj  rk  s    ````` ``   @@rB   rB  rB    sN    l 
B 8c/ c/J \>	

 j1L11rA   )r7  rB  rC  r   r   c                   t        |       } t        | dt              }t        t	        j
                  | ||      ||||d      S )zF
    The same as `torch._dynamo.optimize(backend, nopython=True)`
    r   )rB  rC  T)r   r   r   )rC  r   r   r;  r+   convert_frame_assert)rN   r7  rB  rC  r   r   r   s          rB   rY  rY    sT     g&G w(:LI!**F7I	
 		 	rA   c                  V    e Zd Ze ej
                  d      d               Zed        Zy)r  Nc                 X   ddl m}   | t        j                  j                        t        j                  _         | t        j                  j
                        t        j                  _         | t        j                  j                        t        j                  _         | t        j                  j                  j                  j                        t        j                  j                  j                  _        t        j                  j                  j                  d       ddlm}m}m}m}m}m}m}m}m}	m}
m}m}m} |||||||||	|
|||h}||	|h}|D ]  }|j6                  j9                  d      d   }d| }d	| }t;        ||      r!||v rt=        || | t?        ||                   t;        ||      set=        || | t?        ||                    t        j                  j@                  jC                         D cg c]=  }tE        jF                  |      r&tI        |t        j                  jJ                        r|? }}t        j                  jL                  t        j                  jN                  t        j                  jP                  h}|D ]  }||v r | |jR                        |_)        t;        |d
      r | |jT                        |_*        t?        |jR                  dd      }|r t?        |jR                  dd       }|r||_)        d|jR                  _+         y c c}w )Nr    )r#  Fr   )adadeltaadagradadamadamaxadamwasgdlbfgsnadamradamrmsproprpropsgdsparse_adam.rm  _multi_tensor__fused__init_grouphooked__wrapped__T),
decoratorsr#  r]   r   tracetrace_module_get_trace_graphr   r   TracerdistributionsDistributionset_default_validate_argsoptimrp  rq  rr  rs  rt  ru  rv  rw  rx  ry  rz  r{  r|  r<   splitrG   setattrr   r   rL   r   isclass
issubclass	Optimizer
SparseAdamRAdamLBFGSstepr  r  )r#  rp  rq  rr  rs  rt  ru  rv  rw  rx  ry  rz  r{  r|  optimizer_modules!disabled_multi_tensor_opt_modulesopt_modopt_namemulti_tensor_fn_namefused_fn_nameoptoptimizer_classesexcluded_optimizer_classesr  unwrapped_steps                            rB   r   zTorchPatcher.patch  s    	(!%))//2		!()?)?!@		%,UYY-G-G%H		"07HH$$++111
  ''- 	((BB5I	
 	
 	
 	
" 
" -
) )G''--c226H%3H:#> %hZ0M!56@@(GG-ABC w.]GGG]4S,T )* {{++224
4s#
38M8M(N 4 	 
 KK""KKKK&
"
 %C00"388,sM*")#//":
 SXXx7F!(=$!G!-CH #CHHO# %
s   AL'c                      fd}|S )Nc                 L    t        j                  dt        d        | i |S )Nignoreztorch.distributed)categorymodule)r  filterwarningsUserWarning)r   r   r   s     rB   inner_fnzBTorchPatcher.suppress_torch_distributed_warnings.<locals>.inner_fnF  s+    ##;7J t&v&&rA   r@   )r   r  s   ` rB   #suppress_torch_distributed_warningsz0TorchPatcher.suppress_torch_distributed_warningsD  s    	' rA   )r<   r=   r>   staticmethodr   	lru_cacher   r  r@   rA   rB   r  r    s@    Yd#  d#L  rA   r  r   )rd   z)Union[types.CodeType, Callable[..., Any]]r  zList[CacheEntry])r   boolr   r   r   r  rR   )r  r   )r7  r#   )inductor)r   ri   r   r  r!  r  r"  z9Optional[Dict[torch._ops.OpOverload, Callable[..., Any]]]r#  r@  r$  zOptional[List[Constraint]]r   r  r%  r  r&  r  r  zCallable[..., ExportResult])
__future__r   
contextlibr  r   r   r%  rV  r  r   	threadingrv  rz   r  dataclassesr   enumr   os.pathr   r   typingr   r	   r
   r   r   r   r   r   r   r   unittest.mockr   r]   torch.fxtorch.utils._pytreer.   _pytreer  torch.utils.checkpointr   torch._subclassesr   torch.exportr   "torch.fx.experimental.proxy_tensorr   r   %torch.fx.experimental.symbolic_shapesr   r   r   torch.fx.graphr   r   torch.nn.parallel.distributedr   r   r   backends.registryr!   r"   r7  r#   torch._C._dynamo.eval_framer$   r%   r&   r'   r(   dirr^   r_   r`   r   
startswithr   globalsr   r*   r+   r,   r-   r/   excr0   r1   r2   r  r4   r5   r6   r7   	getLoggerr<   r   torch._dispatch.pythonr8   torch.utils._python_dispatchr9   ExactWeakKeyDictionaryr   nullcontextr   rY  r;   r?   r   RLockr,  localrH   rI   rO   contextmanagerrY   r   __file__r   ra   r   r   rh   r   r   rV   r   r   r   r   r   r   r   r   r  r   r  r9  r;  rC  rE  rK  rN  rZ  r  interpreterTransformerr  r  r  r  rB  rY  r  r@   rA   rB   <module>r     s   #  
    	 
      !  !       $ $   ) # V 
 7 A  9   EHH$$//0??4 !%(("2"2"="=tD	$ 1
 F E & B B ; -  g! ; ?;u;;= %% D  	y '	) 3	/ / /B G+&"	#%RS
3"=
ehhoo =
@>"	
 y    
% )),9)EI) ):L!S Sl
) 
8<( <(( (
?5v "(
9Z++ O F FT /6R 7RjJ%(("6"6"B"B JZ: '
Ti^  	".2%*&+ff f 	f
f f ,f #f f  $f !fX	 d
:q qrA   