
    ȅin                       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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&J'r'  SvS jr(\RR                  " \*5      r+\RX                  R[                  \*S5      r. " S S\/5      r0 " S S\05      r1 " S S\05      r2 " S S\05      r3 " S S\35      r4 " S S\35      r5 " S S\35      r6 " S  S!\35      r7 " S" S#\05      r8 " S$ S%\05      r9 " S& S'\05      r: " S( S)\05      r; " S* S+\05      r< " S, S-\<5      r= " S. S/\05      r> " S0 S1\05      r? " S2 S3\05      r@ " S4 S5\05      rA " S6 S7\05      rB " S8 S9\	5      rC " S: S;\>5      rD " S< S=\05      rE " S> S?\05      rF " S@ SA\05      rG " SB SC\H5      rI " SD SE\H5      rJ " SF SG\05      rK " SH SI\05      rL " SJ SK\L5      rM " SL SM\L5      rN " SN SO\N5      rO " SP SQ\N5      rP " SR SS\L5      rQ " ST SU\L5      rR " SV SW\L5      rS " SX SY\L5      rT " SZ S[\L5      rU\V\M\W\N\X\O\Y\Q\Z\P\[\R\/\S\\\T\]\U0	r^SwS\ jr_SSS].         SxS^ jjr`SyS_ jra\R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  4ri              SzS` jrj          S{Sa jrk\" S	Sb9S|Sc j5       rlS}Sd jrm\n" 5       ro\oSeSeSf.               S~Sg jjrp " Sh Si5      rqSSj jrrSSSk jjrs      SSl jrtSSm jru S     SSn jjrvSSo jrwSSp jrxSSq jry  S         SSr jjrzSSs jr{SSt jr|  S         SSu jjr}g)    )annotationsN)autoEnum)	lru_cache)Path)extract_stack
format_excformat_listFrameSummaryStackSummary)AnyNoReturnOptionalTYPE_CHECKING)get_file_path_2   )config)counters)	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/james-whalen/.local/lib/python3.13/site-packages/torch/_dynamo/exc.pyexportdb_error_messager    9   s"    	I


C
%	&    graph_breaksc                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )TorchDynamoExceptionE   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__Q   s%    $)&)IM(=A r!   )r*   r+   )r-   r   r.   r   returnNone)__name__
__module____qualname____firstlineno____doc__r)   __static_attributes____classcell__r/   s   @r   r$   r$   E   s    	B Br!   r$   c                      \ rS rSrSrg)InternalTorchDynamoErrorW    Nr3   r4   r5   r6   r8   r>   r!   r   r<   r<   W       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_   Optional[str]restart_reasonN)rH   c               ,   > Xl         [        TU ]  " U6   g r'   )rH   r(   r)   )r,   rH   r-   r/   s      r   r)   RestartAnalysis.__init__b   s    ,$r!   )r-   r   rH   rG   r1   r2   r3   r4   r5   r6   __annotations__r)   r8   r9   r:   s   @r   rE   rE   _   s    !!CG      r!   rE   c                      \ rS rSrSrg)SpeculationRestartAnalysisg   r>   Nr?   r>   r!   r   rN   rN   g   r@   r!   rN   c                      \ rS rSrSrg)UnspecializeRestartAnalysisk   r>   Nr?   r>   r!   r   rQ   rQ   k   r@   r!   rQ   c                      \ rS rSrSrg) CompileCollectiveRestartAnalysiso   r>   Nr?   r>   r!   r   rT   rT   o   r@   r!   rT   c                      \ rS rSrSrg)TensorifyScalarRestartAnalysiss   r>   Nr?   r>   r!   r   rW   rW   s   r@   r!   rW   c                      \ rS rSrSrg)	SkipFrame{   r>   Nr?   r>   r!   r   rZ   rZ   {   r@   r!   rZ   c                      \ rS rSrSrg)TorchRuntimeError   r>   Nr?   r>   r!   r   r]   r]      r@   r!   r]   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>   )rc   strr1   r2   r3   r4   r5   r6   r)   r8   r9   r:   s   @r   r`   r`      s    
 
r!   r`   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   rf   r:   s   @r   rh   rh      s    
 
r!   rh   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,   rs   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__rs   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!   rs   )r-   r   rs   Optional[types.FrameType]r.   r   r1   r2   )r1   ztyping.Self)r3   r4   r5   r6   r)   r|   r8   r9   r:   s   @r   rp   rp      s2    55.G5SV5	5' 'r!   rp   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   rs   msgr/   s        r   r)   BackendCompilerFailed.__init__   sZ     $J
C@.**-Z_8M8V8V7WWYZiYjkDr!   )r   r   )r   r   r   	Exceptionrs   r   r1   r2   rf   r:   s   @r   r   r      s9    	E	E #	E 6		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   
real_stackc                  > [         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)   torch_guardsTracingContextr   r   r   
skip_framecategoryadd_to_statsgb_typelogged)r,   r   r   r   r   r   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   r   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   r   r   r   ) F)r   re   r   re   r   boolr   rG   r   StackSummary | Noner1   r2   rn   )unimplemented)r   re   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>   N)r3   r4   r5   r6   r7   r8   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)UserErrorType   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$ )	UserError   c                   > UbF  [        U[        5      (       d   eUR                  S5      (       a  US-  nOUS-  nU[        U5      -  n[        TU ]  X#(       a  UOS5        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. 
r   )
isinstancere   endswithr    r(   r)   
error_typemessage)r,   r   r   r   r/   s       r   r)   UserError.__init__   sl      i----||C  s
t))44C9i+F$r!   )r   r   r'   )r   r   r   re   r   rG   r1   r2   rf   r:   s   @r   r   r      s0    NR'.1>K	 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)   r   r   r   r   r   r   r   r,   r   r   r/   s      r   r)   StepUnsupported.__init__  s<    55CCEJ$r!   )r   r   r   r'   r   re   r   r   r1   r2   rf   r:   s   @r   r   r     s     r!   r   c                      \ rS rSrSrg)UnsafeScriptObjectErrori  r>   Nr?   r>   r!   r   r   r     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'   )r(   r)   r   r   r   r   r   r   r   s      r   r)   %UncapturedHigherOrderOpError.__init__   sH     %  	 --;;= 	r!   )r   r   r'   r   rf   r:   s   @r   r   r     s    
 
r!   r   c                      \ rS rSrSrg)IncorrectUsagei*  r>   Nr?   r>   r!   r   r   r   *  r@   r!   r   c                      \ rS rSrSrg)FailOnRecompileLimitHiti1  r>   Nr?   r>   r!   r   r   r   1  r@   r!   r   c                      \ rS rSrSrg)PackageErrori5  r>   Nr?   r>   r!   r   r   r   5  r@   r!   r   c                  B   ^  \ rS rSrSS.       SU 4S jjjrSrU =r$ )ObservedExceptioni9  Nr   c                  > [         TU ]  " U0 UD6  Ub  UU l        g [        R                  R                  R                  5       U l        g r'   )r(   r)   r   r   r   r   r   r,   r   r-   r.   r/   s       r   r)   ObservedException.__init__;  sJ     	$)&) %  	 --;;= 	r!   r-   r   r   Optional[StackSummary]r.   r   r1   r2   rf   r:   s   @r   r   r   9  s4     @D

&<
OR
	
 
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$ )	ObservedUserStopIterationiF  zOptional[Any]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__L  s5     	:zRt9q=aDJDJr!   r   r   rK   r:   s   @r   r   r   F  s:    
 @D&<OR	 r!   r   c                      \ rS rSrSrg)ObservedLookupErroriV  r>   Nr?   r>   r!   r   r   r   V  r   r!   r   c                      \ rS rSrSrg)ObservedIndexErrori[  r>   Nr?   r>   r!   r   r   r   [  r   r!   r   c                      \ rS rSrSrg)ObservedKeyErrori`  r>   Nr?   r>   r!   r   r   r   `  r   r!   r   c                      \ rS rSrSrg)ObservedGeneratorExitie  r>   Nr?   r>   r!   r   r   r   e  r@   r!   r   c                      \ rS rSrSrg)ObservedAttributeErrorii  r>   Nr?   r>   r!   r   r   r   i  r   r!   r   c                      \ rS rSrSrg)ObservedRuntimeErrorin  r>   Nr?   r>   r!   r   r   r   n  r   r!   r   c                      \ rS rSrSrg)ObservedNotImplementedErroris  r>   Nr?   r>   r!   r   r   r   s  r@   r!   r   c                      \ rS rSrSrg)ObservedTypeErroriw  r>   Nr?   r>   r!   r   r   r   w  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   re   r   r   )exc_typerc   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" U 5      R	                  X=(       d    / U=(       d    0 5      n[        Xd5      (       d   eUR                  U5        UR                  R                  U5        [        U 5      nU(       a  U" U6 eUe)Nr   )ExceptionVals)BuiltinVariable)
symbolic_convertr  	variablesr  call_functionr   _attach_traceback_to_exceptionexn_vt_stackset_current_exceptionr  )r   txr-   r.   r  r  exception_vt
raised_excs           r   raise_observed_exceptionr    s{     0* #8,::2zr6<UWXLl2222%%l3OO)),7.x8J$
r!   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)rc   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_verboser   _loggingtrace_structuredgraph_breaks_logdebugr   )ecoder   r  r  r   _unimplementedr  s          @r   unimplemented_with_warningr+    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)rk   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: )rk   r/  r0  joinget_gbid_documentation_link)r   r  r  r   	hints_strr   documentation_links          r   format_graph_break_messager9    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   re   openjsonloadr   log	exceptionitems)
script_dirregistry_pathfregistrymappingkventrys           r   _load_gb_type_to_gb_id_maprN    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)rN  r0  )r   GRAPH_BREAK_SITE_URLgb_type_to_gb_id_maps      r   r6  r6  *  sJ     	F  67&#$B';'D'K'KD'Q&RRWX	
 r!   F)r!  r"  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.
Nr   zJ

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

r   )	r9  rC  warning_NOTHINGhasattrr   r   r   r   )	r   r  r  r   r!  r"  r   r   past_real_stacks	            r   r   r   E  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)	KeyErrorMsgil  c                    Xl         g r'   r   )r,   r   s     r   r)   KeyErrorMsg.__init__m  s    
r!   c                ,    [        U R                  5      $ r'   )re   r   r   s    r   __str__KeyErrorMsg.__str__p  s    4::r!   c                "    U R                  5       $ r'   )r^  r   s    r   __repr__KeyErrorMsg.__repr__s  s    ||~r!   r   N)r   r   r1   r2   )r1   re   )r3   r4   r5   r6   r)   r^  ra  r8   r>   r!   r   rZ  rZ  l  s    r!   rZ  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      )rW  	partitionrd  )excr   liness      r   !augment_exc_message_with_hop_nameri  w  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').
r   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   r5  r
   r   replay_record_enabledrW  rl  rw   r   rm  rn  r-   re   ri  r   KeyErrorrZ  )rg  r   exportro  r   old_msgnew_msgs          r   augment_exc_messagerw    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'   )rp  filenamelineno
compile_id)r(  r{  ry  rz  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      $ )Nr   )r   r  r   	from_list)rg  framer   stack_above_dynamos       r   rq  rq    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   ry  lineappend)stack
user_stackr  s      r   r~  r~    sq    J>>!enn,  5>>)JJ4

B%   r!   c                t    SSK Jn  [        R                  " U S3U 5      nU(       a  UR	                  S5      $ g )Nr   )TORCH_DYNAMO_RESUME_IN_PREFIXz_(\w+)_at_\d+)resume_executionr  rematchgroup)rc   r  r  s      r   remove_resume_prefixr    s2    ?HH56oFME{{1~r!   c                    [        5       nU  He  nUR                  c  M  [        UR                  5      nU(       a&  U(       a  US   R                  U:X  a  X!S'   X2l        MT  UR	                  U5        Mg     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>
rk  )r   ry  r  rc   r  )r  	new_stackr  rc   s       r   collapse_resume_framesr    sh    ( I>>!#EJJ/)B-"4"4"<!bM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	   rq  r5  r
   )rg  r)  rl  r  r   r   s         r   r#  r#     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   )r)  s    r   format_frame_infor  ;  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  )r)  reason
frame_infos      r   format_skip_frame_messager  C  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   rw   r#  r  r  r  r	   )rg  r)  rl  r  s       r   format_error_msgr  Q  sS     ~~'?JJDLL>4+;+;*< ==8 8r!   )r   re   r1   re   )r   type[Exception]r1   ztype[ObservedException])
r   r  r  r   r-   zOptional[list[Any]]r.   zOptional[dict[str, Any]]r1   r   )r  r   r1   r2   )r(  r   r)  types.CodeTyper   re   r  re   r  re   r   	list[str]r1   r   )
r   re   r  re   r  re   r   r  r1   re   )r1   zdict[str, Any])r   re   r1   rG   )r   re   r  re   r  re   r   r  r!  r   r"  r   r   r   r1   r   )rg  r   r   re   r1   re   )r   F)rg  r   r   re   rt  r   r1   r2   )r(  r   r{  r   r1   z#tuple[Optional[str], Optional[int]])r1   r   r'   )rg  r   r  Optional[DynamoFrameType]r1   r   )r  r   r1   r   )rc   re   r1   rG   )r  z!StackSummary | list[FrameSummary]r1   r   )NN)
rg  r   r)  r  rl  rG   r  r  r1   re   )r)  r  r1   re   )r)  zOptional[types.CodeType]r  re   r1   re   )~
__future__r   rA  loggingr  rk   typingenumr   r   	functoolsr   pathlibr   ro  r   r	   r
   r   r   r   r   r   r   torch._guardsr   torch._utils_internalr   r   r   utilsr   typesr   output_graphr   r  r   r   r   r    	getLoggerr3   rC  r$  getArtifactLoggerr&  RuntimeErrorr$   r<   rB   rE   rN   rQ   rT   rW   rZ   r]   r`   rh   rp   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GeneratorExitrs  AttributeErrorNotImplementedError	TypeErrorr   r  r  r  _subclassesfake_tensorDataDependentOutputExceptionDynamicOutputShapeExceptionUnsupportedOperatorExceptionUnsupportedFakeTensorException$UnsupportedMutationAliasingException!exceptions_allowed_to_be_fallbackr+  r9  rN  r6  objectrV  r   rZ  ri  rw  r|  r  rq  r~  r  r  r#  r  r  r  r>   r!   r   <module>r     sE   "2   	      X X 9 9  1   '0;9 !>>33HnM B< B$	3 		!5 	 *  	 		/ 		 		_ 		$ 		, 	
) 
	
( 	
'+ '"
E, 
E$*& *B	+? 		) 		1 	
2 8D 8 2* 	2 	
#7 
	Y 		i 		' 	

, 

 1  	+ 	
	, 	
	* 	
	- 		. 	
	, 	
	"3 		) 	 ,$"(*&4 
 , !%'+! 	
 % ..< 
!!>>	!!==	!!>>	!!@@	!!FF% !##
# 	#
 # # # #L  	
 	4 1 20 8 "0"0 "0 	"0
 "0 "0 "0 "0 "0N 	.-b		'	(	)
 8<C	C4CCB J &*'+		
 # %	
 	6
" &*'+		8		8
	8 #	8 %		8
 		8r!   