
    3j_t                       S SK Jr   S SKrS SKrS SKrS SKrS SKrS SKJrJ	r	  S SK
Jr  S SKJr  S SKJrJrJrJrJr  S SKJrJrJr  S SKrS SKJr  S	S
KJr  S	SKJr  \(       a$  S SKrS SK J!r!  S SKJ"r"  S	SK#J$r$  S	SK%J&r&  S	SKJ'r'J(r(  SzS jr)\RT                  " \+5      r,\RZ                  R]                  \+S5      r/ " S S\05      r1 " S S\15      r2 " S S\15      r3 " S S\15      r4 " S S\45      r5 " S S\45      r6 " S S \45      r7 " S! S"\45      r8 " S# S$\45      r9 " S% S&\45      r: " S' S(\15      r; " S) S*\15      r< " S+ S,\15      r= " S- S.\15      r> " S/ S0\15      r? " S1 S2\?5      r@ " S3 S4\15      rA " S5 S6\15      rB " S7 S8\15      rC " S9 S:\15      rD " S; S<\15      rE " S= S>\	5      rF " S? S@\15      rG " SA SB\15      rH " SC SD\15      rI " SE SF\15      rJ " SG SH\K5      rL " SI SJ\15      rM " SK SL\15      rN " SM SN\N5      rO " SO SP\N5      rP " SQ SR\P5      rQ " SS ST\P5      rR " SU SV\N5      rS " SW SX\N5      rT " SY SZ\N5      rU " S[ S\\N5      rV " S] S^\N5      rW\X\O\Y\P\Z\Q\[\S\\\R\]\T\0\U\^\V\_\W0	r`S{S_ jraSSS`.         S|Sa jjrbS}Sb jrcS~Sc jrd\R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  4rl              SSd jrm          SSe jrn\" S	Sf9SSg j5       roSSh jrp\q" 5       rr\rSiSiSj.               SSk jjrs " Sl Sm5      rtSSn jruSSSo jjrv      SSp jrwSSq jrx S     SSr jjrySSs jrzSSt jr{SSu jr|  S         SSv jjr}SSw jr~SSx jr  S         SSy jjrg)    )annotationsN)autoEnum)	lru_cache)Path)extract_stack
format_excformat_listFrameSummaryStackSummary)AnyNoReturnTYPE_CHECKING)get_file_path_2   )config)counters)VariableTracker)	CompileId)DynamoTracerOutput)InstructionTranslatorBase)DynamoFrameTypeFrameExecStrategyc                ,    SU R                  SS5      -   $ )NzhFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#_-)replace)	case_names    K/home/wildlama/miniconda3/lib/python3.13/site-packages/torch/_dynamo/exc.pyexportdb_error_messager    :   s"    	I


C
%	&    graph_breaksc                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )TorchDynamoExceptionF   a  Base exception class for all TorchDynamo-specific exceptions.

Attributes:
    _torch_dynamo_tracer_output: Optional tracer output attached to the exception
    frame_exec_strategy: Optional frame execution strategy to control how convert_frame
        should handle this exception. When set, convert_frame will use this strategy
        instead of the default behavior. This allows exceptions to signal specific
        execution strategies (e.g., SKIP, RUN_ONLY) without requiring separate
        exception types for control flow.
c                B   > [         TU ]  " U0 UD6  S U l        S U l        g N)super__init___torch_dynamo_tracer_outputframe_exec_strategy)selfargskwargs	__class__s      r   r)   TorchDynamoException.__init__R   s%    $)&)FJ(=A r!   )r*   r+   )r-   r   r.   r   returnNone)__name__
__module____qualname____firstlineno____doc__r)   __static_attributes____classcell__r/   s   @r   r$   r$   F   s    	B Br!   r$   c                      \ rS rSrSrg)InternalTorchDynamoErrorX    Nr3   r4   r5   r6   r8   r>   r!   r   r<   r<   X       r!   r<   c                      \ rS rSrSrg)ResumePrologueTracingError\   r>   Nr?   r>   r!   r   rB   rB   \   r@   r!   rB   c                  @   ^  \ rS rSr% S\S'   SS.SU 4S jjjrSrU =r$ )RestartAnalysis`   
str | Nonerestart_reasonN)rH   c               ,   > Xl         [        TU ]  " U6   g r'   )rH   r(   r)   )r,   rH   r-   r/   s      r   r)   RestartAnalysis.__init__c   s    ,$r!   )r-   r   rH   rG   r1   r2   r3   r4   r5   r6   __annotations__r)   r8   r9   r:   s   @r   rE   rE   `   s    @D      r!   rE   c                      \ rS rSrSrg)SpeculationRestartAnalysish   r>   Nr?   r>   r!   r   rN   rN   h   r@   r!   rN   c                      \ rS rSrSrSrg)AutogradGradRestartAnalysisl   zRaised when autograd.grad consumed grad_fns that are returned.

On restart, autograd.grad will graph break instead of being traced.
r>   Nr3   r4   r5   r6   r7   r8   r>   r!   r   rQ   rQ   l   s    r!   rQ   c                      \ rS rSrSrSrg)RequiresGradRestartAnalysiss   zRaised when a source-less requires_grad_() intermediate leaks as output.

On restart, requires_grad_() will graph break instead of being traced,
preserving partial acceleration for code before the call.
r>   NrS   r>   r!   r   rU   rU   s   s    r!   rU   c                      \ rS rSrSrg)UnspecializeRestartAnalysis{   r>   Nr?   r>   r!   r   rX   rX   {   r@   r!   rX   c                      \ rS rSrSrg) CompileCollectiveRestartAnalysis   r>   Nr?   r>   r!   r   r[   r[      r@   r!   r[   c                      \ rS rSrSrg)TensorifyScalarRestartAnalysis   r>   Nr?   r>   r!   r   r^   r^      r@   r!   r^   c                      \ rS rSrSrg)	SkipFrame   r>   Nr?   r>   r!   r   ra   ra      r@   r!   ra   c                  0   ^  \ rS rSrSSU 4S jjjrSrU =r$ )TorchRuntimeError   c                   > [         TU ]  U5        Xl        Ub  UU l        g [        R                  R
                  R                  5       U l        g r'   r(   r)   msgtorch_guardsTracingContextr   
real_stackr,   rh   rl   r/   s      r   r)   TorchRuntimeError.__init__   H     %  	 --;;= 	r!   rh   rl   r'   rh   strrl   StackSummary | Noner1   r2   r3   r4   r5   r6   r)   r8   r9   r:   s   @r   rd   rd          
 
r!   rd   c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )InvalidBackend   c                .   > [         TU ]  SU< S35        g )NzInvalid backend: z=, see `torch._dynamo.list_backends()` for available backends.)r(   r)   )r,   namer/   s     r   r)   InvalidBackend.__init__   s    x'de	
r!   r>   )rz   rr   r1   r2   rt   r:   s   @r   rw   rw      s    
 
r!   rw   c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )ResetRequired   c                L   > [         TU ]  [        R                  " S5      5        g )Nz
                Must call `torch._dynamo.reset()` before changing backends.  Detected two calls to
                `torch.compile()` with a different backend compiler arguments.
                )r(   r)   textwrapdedent)r,   r/   s    r   r)   ResetRequired.__init__   s!    OO	
r!   r>   r1   r2   rt   r:   s   @r   r}   r}      s    
 
r!   r}   c                  F   ^  \ rS rSr        SU 4S jjrSS jrSrU =r$ )ShortenTraceback   c               2   > [         TU ]  " U0 UD6  Xl        g r'   )r(   r)   first_useful_frame)r,   r   r-   r.   r/   s       r   r)   ShortenTraceback.__init__   s     	$)&)"4r!   c                   U R                   nU R                  b  Ub  [        R                  (       a  U $ UR                  U R                  La1  UR
                  nUc   S5       eUR                  U R                  La  M1  U R                  U5      $ )Nz#internal error, please report a bug)__traceback__r   r   verbosetb_frametb_nextwith_traceback)r,   tbs     r   remove_dynamo_frames%ShortenTraceback.remove_dynamo_frames   sz    ""*bjFNNKkk!8!88B>H#HH> kk!8!88 ""2&&r!   r   )r-   r   r   types.FrameType | Noner.   r   r1   r2   )r1   ztyping.Self)r3   r4   r5   r6   r)   r   r8   r9   r:   s   @r   r   r      s2    55.D5PS5	5' 'r!   r   c                  <   ^  \ rS rSr        SU 4S jjrSrU =r$ )BackendCompilerFailed   c                   > [        USS5      U l        X l        SU R                  < S[        U5      R                   SU 3n[
        TU ]  XCS9  g )Nr3   ?zbackend=z	 raised:
z: r   )getattrbackend_nameinner_exceptiontyper3   r(   r)   )r,   
backend_fnr   r   rh   r/   s        r   r)   BackendCompilerFailed.__init__   sZ     $J
C@.**-Z_8M8V8V7WWYZiYjkDr!   )r   r   )r   r   r   	Exceptionr   r   r1   r2   rt   r:   s   @r   r   r      s9    	E	E #	E 3		E
 
	E 	Er!   r   c                  l   ^  \ rS rSr  SSSS.           S	U 4S jjjjrS
S jrSSS jjrSrU =r$ )Unsupported   N)r   rl   c                  > [         TU ]  U5        U(       d(  [        R                  R                  R                  5       nXPl        Xl        X0l        S U l	        U R                  5         X l        SU l        g NF)r(   r)   ri   rj   rk   r   rl   rh   
skip_framecategoryadd_to_statsgb_typelogged)r,   rh   r   r   r   rl   r/   s         r   r)   Unsupported.__init__   s[     	55CCEJ$$$(#*r!   c                    U R                   c   e[        U R                      U R                  ==   S-  ss'   [        U R                      U R                     S::  a  [        U R                      U R                  	 g g )Nr   r   r   r   rh   r,   s    r   remove_from_statsUnsupported.remove_from_stats   sc    }}((()Q.)DMM"488,1'1 2r!   c                L    Xl         [        U   U R                  ==   S-  ss'   g )Nr   r   )r,   r   s     r   r   Unsupported.add_to_stats   s      488$)$r!   )r   r   r   rh   rl   r   ) F)rh   rr   r   rr   r   boolr   rG   rl   rs   r1   r2   r   )unimplemented)r   rr   r1   r2   )	r3   r4   r5   r6   r)   r   r   r8   r9   r:   s   @r   r   r      sk    
   !%*. 	
   ( 
 *2* *r!   r   c                      \ rS rSrSrg)$UnknownPropertiesDuringBackwardTrace   r>   Nr?   r>   r!   r   r   r      r@   r!   r   c                      \ rS rSrSrg)RecompileError   r>   Nr?   r>   r!   r   r   r      r@   r!   r   c                      \ rS rSrSrg)InfiniteGeneratorError   r>   Nr?   r>   r!   r   r   r          r!   r   c                      \ rS rSrSrSrg)CondOpArgsMismatchError   z7
Internal error from cond() due to arguments mismatch.
r>   NrS   r>   r!   r   r   r      s    r!   r   c                      \ rS rSr\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r	\" 5       r
\" 5       r\" 5       rSrg)UserErrorTypei  r>   N)r3   r4   r5   r6   r   DYNAMIC_CONTROL_FLOWANTI_PATTERNSTANDARD_LIBRARYCONSTRAINT_VIOLATIONDYNAMIC_DIMINVALID_INPUTINVALID_OUTPUT*UNSUPPORTED_ALIASED_MUTATED_DYNAMIC_INPUTSr8   r>   r!   r   r   r     s>    66Lv6&KFMVN15.r!   r   c                  @   ^  \ rS rSr S       SU 4S jjjrSrU =r$ )	UserErrori  c                P  > UbF  [        U[        5      (       d   eUR                  S5      (       a  US-  nOUS-  nU[        U5      -  n[        TU ]  U5        [        R                  R                  R                  5       U l
        SU l        SU l        Xl        X l        X l        g)a  
Type of errors that would be valid in Eager, but not supported in TorchDynamo.
The error message should tell user about next actions.

error_type: Type of user error
msg: Actionable error message
case_name: (Optional) Unique name (snake case) for the usage example in exportdb.
N. 
F)
isinstancerr   endswithr    r(   r)   ri   rj   rk   r   rl   r   r   
error_typerh   message)r,   r   rh   r   r/   s       r   r)   UserError.__init__  s      i----||C  s
t))44C--66DDF$r!   )r   r   r   rh   rl   r   r'   )r   r   rh   rr   r   rG   r1   r2   rt   r:   s   @r   r   r     s0    KO'.1>H	 r!   r   c                  0   ^  \ rS rSrSSU 4S jjjrSrU =r$ )StepUnsupportedi,  c                   > [         TU ]  U5        Xl        U(       d(  [        R                  R
                  R                  5       nX l        SU l        g r   )	r(   r)   rh   ri   rj   rk   r   rl   r   rm   s      r   r)   StepUnsupported.__init__-  s<    55CCEJ$r!   )r   rh   rl   r'   rq   rt   r:   s   @r   r   r   ,  s     r!   r   c                      \ rS rSrSrg)UnsafeScriptObjectErrori6  r>   Nr?   r>   r!   r   r   r   6  r@   r!   r   c                  0   ^  \ rS rSrSSU 4S jjjrSrU =r$ )UncapturedHigherOrderOpErrori:  c                   > [         TU ]  U5        Xl        Ub  UU l        g [        R                  R
                  R                  5       U l        g r'   rg   rm   s      r   r)   %UncapturedHigherOrderOpError.__init__;  ro   r!   rp   r'   rq   rt   r:   s   @r   r   r   :  ru   r!   r   c                      \ rS rSrSrg)FailOnRecompileLimitHitiH  r>   Nr?   r>   r!   r   r   r   H  r@   r!   r   c                      \ rS rSrSrg)PackageErroriL  r>   Nr?   r>   r!   r   r   r   L  r@   r!   r   c                  B   ^  \ rS rSrSS.       SU 4S jjjrSrU =r$ )ObservedExceptioniP  Nrl   c                  > [         TU ]  " U0 UD6  Ub  UU l        g [        R                  R                  R                  5       U l        g r'   )r(   r)   ri   rj   rk   r   rl   r,   rl   r-   r.   r/   s       r   r)   ObservedException.__init__R  sJ     	$)&) %  	 --;;= 	r!   r-   r   rl   rs   r.   r   r1   r2   rt   r:   s   @r   r   r   P  s3     =A

&9
LO
	
 
r!   r   c                  N   ^  \ rS rSr% S\S'   SS.       SU 4S jjjrSrU =r$ )	ObservedUserStopIterationi]  z
Any | NonevalueNr   c               d   > [         TU ]  SUS9  [        U5      S:  a  US   U l        g S U l        g )Nzunhandled `raise StopIteration`r   r   )r(   r)   lenr   r   s       r   r)   "ObservedUserStopIteration.__init__c  s5     	:zRt9q=aDJDJr!   r   r   rK   r:   s   @r   r   r   ]  s9    
 =A&9LO	 r!   r   c                      \ rS rSrSrg)ObservedLookupErrorim  r>   Nr?   r>   r!   r   r   r   m  r   r!   r   c                      \ rS rSrSrg)ObservedIndexErrorir  r>   Nr?   r>   r!   r   r   r   r  r   r!   r   c                      \ rS rSrSrg)ObservedKeyErroriw  r>   Nr?   r>   r!   r   r   r   w  r   r!   r   c                      \ rS rSrSrg)ObservedGeneratorExiti|  r>   Nr?   r>   r!   r   r   r   |  r@   r!   r   c                      \ rS rSrSrg)ObservedAttributeErrori  r>   Nr?   r>   r!   r   r   r     r   r!   r   c                      \ rS rSrSrg)ObservedRuntimeErrori  r>   Nr?   r>   r!   r   r   r     r   r!   r   c                      \ rS rSrSrg)ObservedNotImplementedErrori  r>   Nr?   r>   r!   r   r  r    r@   r!   r  c                      \ rS rSrSrg)ObservedTypeErrori  r>   Nr?   r>   r!   r   r  r    r   r!   r  c                    U [         ;  a3  [        U S[        U 5      5      n[        SU S3[        40 5      [         U '   [         U    $ )Nr3   ObservedError)observed_exception_mapr   rr   r   r   )exc_typerz   s     r   get_dynamo_observed_exceptionr	    sN    --xS];+/tfE"%6$8",
x( "(++r!   )r-   r.   c                  SSK Jn  SSKJn  U(       a9  U Vs/ s H+  n[	        U[
        5      (       a  UR                  X5      OUPM-     nnO/ nUR                  X5      R                  XU=(       d    0 5      n[	        X5      (       d   eUR                  U5        UR                  R                  U5        [        U 5      n	U(       a  U	" U6 eU	es  snf )Nr   )ExceptionVals)SourcelessBuilder)symbolic_convertr  variables.builderr  r   rr   createcall_function_attach_traceback_to_exceptionexn_vt_stackset_current_exceptionr	  )
r  txr-   r.   r  r  argargs_exception_vt
raised_excs
             r   raise_observed_exceptionr    s     04 
 2<C1E1E$$R-3N 	 

 (* %++B9GG
6<RL l2222%%l3OO)),7.x8J%  
'
s   2Cc                "    [        [        X/S9  g)z:Raise a TypeError as an observed exception during tracing.)r-   N)r  	TypeError)r  rh   s     r   raise_type_errorr    s    Y7r!   c                8    U R                   R                  5         g r'   )r  clear_current_exception)r  s    r   handle_observed_exceptionr    s    2 OO++-r!   c          	        ^ [        X5      m[        R                  R                  SS U4S jS9  [        R                  ST5        [        nU" UUUUU SS9  g )Nartifactc                     SSS.$ )Ndynamo_graph_break_reasonstring)rz   encodingr>   r>   r!   r   <lambda>,unimplemented_with_warning.<locals>.<lambda>	  s    / 
r!   c                    > T $ r'   r>   )graph_break_msgs   r   r&  r'    s    ?r!   )metadata_fn
payload_fnz%sT)r   contextexplanationhintsfrom_exclog_warning)format_error_msg_verboseri   _loggingtrace_structuredgraph_breaks_logdebugr   )ecoder   r,  r-  r.  _unimplementedr)  s          @r   unimplemented_with_warningr9    sd      /q7O	NN##
 + $  41"Nr!   c                   [         R                  " US5      R                  5       nSR                  S U 5       5      n[         R                  " US5      R                  5       nU  SU SU SU 3n[	        U 5      nU(       a  USU 3-  nU$ )N    r   c              3  r   #    U  H-  nS [         R                  " US5      R                  5       -   v   M/     g7f)z  Hint: r;  N)r   indentlstrip).0hints     r   	<genexpr>-format_graph_break_message.<locals>.<genexpr>#  s,      HM
X__T6299;;s   57z
  Explanation: z

  Developer debug context: z:

 For more details about this graph break, please visit: )r   r=  r>  joinget_gbid_documentation_link)r   r,  r-  r.  	hints_strrh   documentation_links          r   format_graph_break_messagerG    s     //+v6==?K		 HM I oogv.557G 		 
} 
 #9(C 5W=MN`MabbJr!   )maxsizec                     [        [        5      R                  5       R                  n [	        S[        U 5      S5      n[        U5       n[        R                  " U5      nSSS5        0 nWR                  5        H  u  pVU H
  nXTUS   '   M     M     U$ ! , (       d  f       N;= f! [         a    [        R                  S5        0 n Naf = f)z
Loads the gb_type to gb_id map from the graph break registry from JSON file with caching.

Includes historical gb_type (mapping behavior of duplicate gb_types with different gb_ids is undefined).
r   zgraph_break_registry.jsonNz!Error accessing the registry fileGb_type)r   __file__resolveparentr   rr   openjsonloadr   log	exceptionitems)
script_dirregistry_pathfregistrymappingkventrys           r   _load_gb_type_to_gb_id_mapr\  6  s    
(^++-44
'J!<
 - Ayy|H ! G E()E)$%  ! N !  9:s0   AB' 
B!B' 
B$ B' $B' '!C
Cc                X    Sn[        5       nX;   a  U SX    R                  S5       S3$ g)z
Retrieves the GBID documentation link for a given graph break type.

Args:
    gb_type: The graph break type to look up.

Returns:
    A string containing the documentation URL if found, otherwise None.
z;https://meta-pytorch.github.io/compile-graph-break-site/gb/gbGBz.htmlN)r\  r>  )r   GRAPH_BREAK_SITE_URLgb_type_to_gb_id_maps      r   rD  rD  Q  sJ     	F  67&#$B';'D'K'KD'Q&RRWX	
 r!   F)r/  r0  r   c                0   [        XX#5      nU(       a  [        R                  U5        U[        LaZ  Sn[	        US5      (       a  UR
                  n[        U[        5      (       a  UR                   SU 3n[        XpXhS9e[        XpXhS9Ue[        XpU5      e)a  
Called within dynamo to cause a graph break.
Args:
    gb_type: Context-free graph break type. It should be a short string without any
             information specific to the tracing context (i.e. no dynamically-generated strings)
    context: Developer context for the graph break. It can contain tracing context/dynamic strings.
    explanation: User-facing context-dependent explanation for the graph break. Can be dynamic.
    hints: List of user-facing hints for the graph break.
Nrl   zJ

*** While handling this graph break, another graph break occurred: ***

r   )	rG  rQ  warning_NOTHINGhasattrrl   r   r   rh   )	r   r,  r-  r.  r/  r0  r   rh   past_real_stacks	            r   r   r   l  s    ( %W{
JCCx8\**&11Oh,,\\N"pqtpuvCcJSS*
	 cJ
//r!   c                  2    \ rS rSrSS jrSS jrSS jrSrg)	KeyErrorMsgi  c                    Xl         g r'   r   )r,   r   s     r   r)   KeyErrorMsg.__init__  s    
r!   c                ,    [        U R                  5      $ r'   )rr   r   r   s    r   __str__KeyErrorMsg.__str__  s    4::r!   c                "    U R                  5       $ r'   )rl  r   s    r   __repr__KeyErrorMsg.__repr__  s    ||~r!   r   N)r   r   r1   r2   )r1   rr   )r3   r4   r5   r6   r)   rl  ro  r8   r>   r!   r   rh  rh    s    r!   rh  c                    [        U S5      (       a/  UR                  S5      nUS    SU R                   US    US    3nU$ )N	_hop_namez
  Explanation:r   z
  Higher Order Operator: r      )re  	partitionrr  )excrh   liness      r   !augment_exc_message_with_hop_namerw    sT     sK  01Qxj3CMM?58*USTXJW 	 Jr!   c                   SS K nS U l        [        U 5      nUb?  [        U5      S:  a0  US   U l        USSR	                  UR                  U5      5       3-  n[        R                  (       a1  [        U S5      (       a   USU R                   SU R                   S3-  n[        R                  (       d  [        U S	5      (       a  US
-  n[        U S5      (       a  [        U R                  S5      (       am  [        U R                  S5      (       a5  USU R                  R                   SU R                  R                   S3-  nOUSU R                  R                   S3-  n[        U R                  5      S:X  a  SO[        U R                  S   5      n[!        X5      n[#        U [$        5      (       a$  ['        XQ-   5      4U R                  SS  -   U l        g XQ-   nU4U R                  SS  -   U l        g )Nr   z
from user code:
 r   record_filenamez!
Last frame execution written to zD. To run only this frame while debugging, run torch._dynamo.replay('z').
rl   z
Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"
r   minifier_pathbuck_commandz
Minifier script written to zW. Run this buck command to find the smallest traced graph which reproduces this error: r   zQ. Run this script to find the smallest traced graph which reproduces this error.
r   )	tracebackinnermost_user_frame_summaryget_real_stackr   rC  r
   r   replay_record_enabledre  rz  r   r   r{  r|  r-   rr   rw  r   KeyErrorrh  )ru  rh   exportr}  rl   old_msgnew_msgs          r   augment_exc_messager    s   '+C$$J#j/A"5+5b>(%bggi.C.CJ.O&P%QRR##5F(G(G01D1D0E F++,E3	

 >>gc<88J	
 s%&&7_, , 3&&77/0C0C0Q0Q/R S0030C0C0P0P/QQSUC /0C0C0Q0Q/R S_ _C
 MQ&bC,<G/=G#x  .0388AB<?-:,r!   c                    S nS nU R                   b,  U R                   R                  nU R                   R                  nXl        X#4$ r'   )r~  filenamelineno
compile_id)r6  r  r  r  s       r   get_exc_messager    sJ     HF%%111:://66Lr!   c                 (    [        [        5       5      $ r'   )filter_stackr   r>   r!   r   get_stack_above_dynamor    s    ((r!   c                    [        U SS 5      nUc  g Ub  [        5       nO
[        5       n[        R                  " X2-   5      $ )Nrl   )r   r  r   	from_list)ru  framerl   stack_above_dynamos       r   r  r    sK     lD1J  45)^!!"4"ABBr!   c                    [        5       nU  Hi  nUR                  c  M  SUR                  ;   a    U$ SUR                  ;   d!  UR                  (       a  SUR                  ;   a  MX  UR                  U5        Mk     U$ )Nconvert_frame
eval_frameztorch._dynamo.optimize()r   r  lineappend)stack
user_stackr  s      r   r  r    sq    J>>!enn,  5>>)JJ4

B%   r!   c                v    SSK Jn  [        R                  " U S3U 5      nU(       a  UR	                  S5      $ U $ )Nr   )TORCH_DYNAMO_RESUME_IN_PREFIXz_(\w+)_at_\d+)resume_executionr  rematchgroup)rz   r  r  s      r   remove_resume_prefixr    s4    ?HH56oFME{{1~Kr!   c                    [        5       nU  Hk  nUR                  c  M  [        UR                  5      nU(       a&  U(       a  US   R                  U:X  a  X!S'   X2l        MT  X2l        UR	                  U5        Mm     U$ )a  
When we graph break, we create a resume function and make a regular Python call
to it, which gets intercepted by Dynamo. This behavior is normally shown in the
traceback, which can be confusing to a user. So we can filter out resume frames
for better traceback clarity.

Example:
File "..." line 3, in f
    <line 3>
File "..." line 5, in torch_dynamo_resume_in_f_at_80
    <line 5>
File "..." line 10, in torch_dynamo_resume_in_f_at_120
    <line 10>

becomes
File "..." line 10, in f
    <line 10>
ry  )r   r  r  rz   r  )r  	new_stackr  rz   s       r   collapse_resume_framesr  (  sm    ( I>>!#EJJ/)B-"4"4"<!bMJJU#  r!   c                    SUR                    SUR                   SUR                   S3nUS-  nU[        5       -  n[	        X5      nUb,  US-  nUSR                  [        U5      5      -  nUS-  nUS-  nU$ )	NWON'T CONVERT r    line r   z.========== TorchDynamo Stack Trace ==========
zY
========== The above exception occurred while processing the following code ==========

r   z
==========)co_nameco_filenameco_firstlinenor	   r  rC  r
   )ru  r7  rz  r  rh   rl   s         r   r1  r1  K  s     a(8(8'9@S@S?TTVW  CCC:<C+J	
 	rww{:.//txJr!   c           	     Z    [        U SS5       S[        U SS5       S[        U SS5       S3$ )	Nr  z	<unknown>z (r  r  r  r   ))r   )r7  s    r   format_frame_infor  f  sF    4K0
1 2D-56 7.231	6r!   c                8    U b  [        U 5      nSU SU 3$ SU 3$ )Nz6torch.compile intentionally decided to skip the frame z! and fall back to eager.
Reason: zVtorch.compile intentionally decided to skip the frame and fall back to eager.
Reason: )r  )r7  reason
frame_infos      r   format_skip_frame_messager  n  sB    &t,
DZL Qh 	
h 	
r!   c           	         [         R                  (       a  [        XX#5      $ SUR                   SUR                   SUR
                   S[        5        3$ )Nr  r   r  z 
due to: 
)r   r   r1  r  r  r  r	   )ru  r7  rz  r  s       r   format_error_msgr  |  sS     ~~'?JJDLL>4+;+;*< ==8 8r!   )r   rr   r1   rr   )r  type[Exception]r1   ztype[ObservedException])
r  r  r  r   r-   z(list[VariableTracker] | list[str] | Noner.   z!dict[str, VariableTracker] | Noner1   r   )r  r   rh   rr   r1   r   )r  r   r1   r2   )r6  r   r7  types.CodeTyper   rr   r,  rr   r-  rr   r.  	list[str]r1   r   )
r   rr   r,  rr   r-  rr   r.  r  r1   rr   )r1   zdict[str, Any])r   rr   r1   rG   )r   rr   r,  rr   r-  rr   r.  r  r/  r   r0  r   r   r   r1   r   )ru  r   rh   rr   r1   rr   )r   F)ru  r   rh   rr   r  r   r1   r2   )r6  r   r  r   r1   ztuple[str | None, int | None])r1   r   r'   )ru  r   r  DynamoFrameType | Noner1   rs   )r  r   r1   r   )rz   rr   r1   rr   )r  z!StackSummary | list[FrameSummary]r1   r   )NN)
ru  r   r7  r  rz  rG   r  r  r1   rr   )r7  r  r1   rr   )r7  ztypes.CodeType | Noner  rr   r1   rr   )
__future__r   rO  loggingr  r   typingenumr   r   	functoolsr   pathlibr   r}  r   r	   r
   r   r   r   r   r   torch._guardsri   torch._utils_internalr   r   r   utilsr   typestorch._dynamo.variablesr   r   output_graphr   r  r   r   r   r    	getLoggerr3   rQ  r2  getArtifactLoggerr4  RuntimeErrorr$   r<   rB   rE   rN   rQ   rU   rX   r[   r^   ra   rd   rw   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  StopIterationLookupError
IndexErrorGeneratorExitr  AttributeErrorNotImplementedErrorr  r  r	  r  r  r  _subclassesfake_tensorDataDependentOutputExceptionDynamicOutputShapeExceptionUnsupportedOperatorExceptionUnsupportedFakeTensorException$UnsupportedMutationAliasingException!exceptions_allowed_to_be_fallbackr9  rG  r\  rD  objectrd  r   rh  rw  r  r  r  r  r  r  r  r1  r  r  r  r>   r!   r   <module>r     s[   "2   	      X X / /  1   7'0;9 !>>33HnM B< B$	3 		!5 	 *  	 	/ / 	/ 		 		_ 		$ 	
, 

) 
	
( 	
'+ '"
E, 
E$*& *B	+? 		) 		1 	
2 8D 8$ :* 	2 	
#7 
	i 		' 	

, 

 1  	+ 	
	, 	
	* 	
	- 		. 	
	, 	
	"3 		) 	 ,$"(*&4 
 , 6:04! 3	
 . B8
.< 
!!>>	!!==	!!>>	!!@@	!!FF% !##
# 	#
 # # # #L  	
 	4 1 40 8 %0%0 %0 	%0
 %0 %0 %0 %0 %0T 	.-b		'	"	)
 59C	C1CCB  L #'$(		
   "	
 	6
" #'$(		8		8
	8  	8 "		8
 		8r!   