
    N jnq                       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'  SxS 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#\35      r8 " S$ S%\05      r9 " S& S'\05      r: " S( S)\05      r; " S* S+\05      r< " S, S-\05      r= " S. S/\=5      r> " S0 S1\05      r? " S2 S3\05      r@ " S4 S5\05      rA " S6 S7\05      rB " S8 S9\05      rC " S: S;\	5      rD " S< S=\?5      rE " S> S?\05      rF " S@ SA\05      rG " SB SC\05      rH " SD SE\I5      rJ " SF SG\I5      rK " SH SI\05      rL " SJ SK\05      rM " SL SM\M5      rN " SN SO\M5      rO " SP SQ\O5      rP " SR SS\O5      rQ " ST SU\M5      rR " SV SW\M5      rS " SX SY\M5      rT " SZ S[\M5      rU " S\ S]\M5      rV\W\N\X\O\Y\P\Z\R\[\Q\\\S\/\T\]\U\^\V0	r_SyS^ jr`SSS_.         SzS` jjraS{Sa jrb\R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  4rj              S|Sb jrk          S}Sc jrl\" S	Sd9S~Se j5       rmSSf jrn\o" 5       rp\pSgSgSh.               SSi jjrq " Sj Sk5      rrSSl jrsSSSm jjrt      SSn jruSSo jrv S     SSp jjrwSSq jrxSSr jrySSs jrz  S         SSt jjr{SSu jr|SSv jr}  S         SSw 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    b/root/GenerationalWealth/GenerationalWealth/venv/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Srg)AutogradGradRestartAnalysisk   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   k   s    r!   rQ   c                      \ rS rSrSrg)UnspecializeRestartAnalysisr   r>   Nr?   r>   r!   r   rU   rU   r   r@   r!   rU   c                      \ rS rSrSrg) CompileCollectiveRestartAnalysisv   r>   Nr?   r>   r!   r   rX   rX   v   r@   r!   rX   c                      \ rS rSrSrg)TensorifyScalarRestartAnalysisz   r>   Nr?   r>   r!   r   r[   r[   z   r@   r!   r[   c                      \ rS rSrSrg)	SkipFrame   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$ )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,   re   ri   r/   s      r   r)   TorchRuntimeError.__init__   H     %  	 --;;= 	r!   re   ri   r'   re   strri   StackSummary | Noner1   r2   r3   r4   r5   r6   r)   r8   r9   r:   s   @r   ra   ra          
 
r!   ra   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>   )rw   ro   r1   r2   rq   r:   s   @r   rt   rt      s    
 
r!   rt   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   rq   r:   s   @r   rz   rz      s    
 
r!   rz   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   Optional[types.FrameType]r.   r   r1   r2   )r1   ztyping.Self)r3   r4   r5   r6   r)   r   r8   r9   r:   s   @r   r   r      s2    55.G5SV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   re   r/   s        r   r)   BackendCompilerFailed.__init__   sZ     $J
C@.**-Z_8M8V8V7WWYZiYjkDr!   )r   r   )r   r   r   	Exceptionr   r   r1   r2   rq   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   ri   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)   rf   rg   rh   r   ri   re   
skip_framecategoryadd_to_statsgb_typelogged)r,   re   r   r   r   ri   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   re   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   re   ri   r   ) F)re   ro   r   ro   r   boolr   rG   ri   rp   r1   r2   r   )unimplemented)r   ro   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)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$ )	UserErrori  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   )
isinstancero   endswithr    r(   r)   
error_typemessage)r,   r   re   r   r/   s       r   r)   UserError.__init__  sl      i----||C  s
t))44C9i+F$r!   )r   r   r'   )r   r   re   ro   r   rG   r1   r2   rq   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)   re   rf   rg   rh   r   ri   r   rj   s      r   r)   StepUnsupported.__init__   s<    55CCEJ$r!   )r   re   ri   r'   rn   rq   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'   rd   rj   s      r   r)   %UncapturedHigherOrderOpError.__init__.  rl   r!   rm   r'   rn   rq   r:   s   @r   r   r   -  rr   r!   r   c                      \ rS rSrSrg)IncorrectUsagei8  r>   Nr?   r>   r!   r   r   r   8  r@   r!   r   c                      \ rS rSrSrg)FailOnRecompileLimitHiti?  r>   Nr?   r>   r!   r   r   r   ?  r@   r!   r   c                      \ rS rSrSrg)PackageErroriC  r>   Nr?   r>   r!   r   r   r   C  r@   r!   r   c                  B   ^  \ rS rSrSS.       SU 4S jjjrSrU =r$ )ObservedExceptioniG  Nri   c                  > [         TU ]  " U0 UD6  Ub  UU l        g [        R                  R                  R                  5       U l        g r'   )r(   r)   rf   rg   rh   r   ri   r,   ri   r-   r.   r/   s       r   r)   ObservedException.__init__I  sJ     	$)&) %  	 --;;= 	r!   r-   r   ri   Optional[StackSummary]r.   r   r1   r2   rq   r:   s   @r   r   r   G  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$ )	ObservedUserStopIterationiT  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__Z  s5     	:zRt9q=aDJDJr!   r   r   rK   r:   s   @r   r   r   T  s:    
 @D&<OR	 r!   r   c                      \ rS rSrSrg)ObservedLookupErrorid  r>   Nr?   r>   r!   r   r   r   d  r   r!   r   c                      \ rS rSrSrg)ObservedIndexErrorii  r>   Nr?   r>   r!   r   r   r   i  r   r!   r   c                      \ rS rSrSrg)ObservedKeyErrorin  r>   Nr?   r>   r!   r   r   r   n  r   r!   r   c                      \ rS rSrSrg)ObservedGeneratorExitis  r>   Nr?   r>   r!   r   r   r   s  r@   r!   r   c                      \ rS rSrSrg)ObservedAttributeErroriw  r>   Nr?   r>   r!   r   r   r   w  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   ro   r   r   )exc_typerw   s     r   get_dynamo_observed_exceptionr
    sN    --xS];+/tfE"%6$8",
x( "(++r!   )r-   r.   c          
     x   SSK Jn  SSKJn  UR	                  X5      R                  UU(       a!  U Vs/ s H  oeR	                  X5      PM     snO/ U=(       d    0 5      n[        Xt5      (       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  createcall_functionr   _attach_traceback_to_exceptionexn_vt_stackset_current_exceptionr
  )	r	  txr-   r.   r  r  aexception_vt
raised_excs	            r   raise_observed_exceptionr    s     04 %++B9GG
;?$7$Q	!	!"	($7R"L
 l2222%%l3OO)),7.x8J$
 	8s   B7
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)rw   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_verboserf   _loggingtrace_structuredgraph_breaks_logdebugr   )ecoder   r)  r*  r+  _unimplementedr&  s          @r   unimplemented_with_warningr6    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: r8  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_strre   documentation_links          r   format_graph_break_messagerD    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   ro   openjsonloadr   log	exceptionitems)
script_dirregistry_pathfregistrymappingkventrys           r   _load_gb_type_to_gb_id_maprY  "  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)rY  r;  )r   GRAPH_BREAK_SITE_URLgb_type_to_gb_id_maps      r   rA  rA  =  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.
Nri   zJ

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

r   )	rD  rN  warning_NOTHINGhasattrri   r   r   re   )	r   r)  r*  r+  r,  r-  r   re   past_real_stacks	            r   r   r   X  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'   )ro   r   r   s    r   __str__KeyErrorMsg.__str__  s    4::r!   c                "    U R                  5       $ r'   )ri  r   s    r   __repr__KeyErrorMsg.__repr__  s    ||~r!   r   N)r   r   r1   r2   )r1   ro   )r3   r4   r5   r6   r)   ri  rl  r8   r>   r!   r   re  re    s    r!   re  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      )rb  	partitionro  )excre   liness      r   !augment_exc_message_with_hop_namert    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').
ri   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   r@  r
   r   replay_record_enabledrb  rw  r   r   rx  ry  r-   ro   rt  r   KeyErrorre  )rr  re   exportrz  ri   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)r3  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      $ )Nri   )r   r  r   	from_list)rr  frameri   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                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)rw   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>
rv  )r   r  r  rw   r  )r  	new_stackr  rw   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	   r|  r@  r
   )rr  r4  rw  r  re   ri   s         r   r.  r.  3  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   )r4  s    r   format_frame_infor  N  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  )r4  reason
frame_infos      r   format_skip_frame_messager  V  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   r.  r  r  r  r	   )rr  r4  rw  r  s       r   format_error_msgr  d  sS     ~~'?JJDLL>4+;+;*< ==8 8r!   )r   ro   r1   ro   )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   )r3  r   r4  types.CodeTyper   ro   r)  ro   r*  ro   r+  	list[str]r1   r   )
r   ro   r)  ro   r*  ro   r+  r  r1   ro   )r1   zdict[str, Any])r   ro   r1   rG   )r   ro   r)  ro   r*  ro   r+  r  r,  r   r-  r   r   r   r1   r   )rr  r   re   ro   r1   ro   )r   F)rr  r   re   ro   r  r   r1   r2   )r3  r   r  r   r1   z#tuple[Optional[str], Optional[int]])r1   r   r'   )rr  r   r  Optional[DynamoFrameType]r1   r   )r  r   r1   r   )rw   ro   r1   rG   )r  z!StackSummary | list[FrameSummary]r1   r   )NN)
rr  r   r4  r  rw  rG   r  r  r1   ro   )r4  r  r1   ro   )r4  zOptional[types.CodeType]r  ro   r1   ro   )
__future__r   rL  loggingr  r}   typingenumr   r   	functoolsr   pathlibr   rz  r   r	   r
   r   r   r   r   r   r   torch._guardsrf   torch._utils_internalr   r   r   utilsr   typesr   output_graphr   r  r   r   r   r    	getLoggerr3   rN  r/  getArtifactLoggerr1  RuntimeErrorr$   r<   rB   rE   rN   rQ   rU   rX   r[   r^   ra   rt   rz   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NotImplementedError	TypeErrorr  r
  r  r  _subclassesfake_tensorDataDependentOutputExceptionDynamicOutputShapeExceptionUnsupportedOperatorExceptionUnsupportedFakeTensorException$UnsupportedMutationAliasingException!exceptions_allowed_to_be_fallbackr6  rD  rY  rA  objectra  r   re  rt  r  r  r  r|  r  r  r  r.  r  r  r  r>   r!   r   <module>r     sQ   "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 
 , !%'+! 	
 % 6.< 
!!>>	!!==	!!>>	!!@@	!!FF% !##
# 	#
 # # # #L  	
 	4 1 4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!   