
    /jnq                    l   d dl mZ 	 d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZmZmZ d dlmZmZmZmZ d dlZd dlmZ d	d
lmZ d	dlmZ erd dl Z d dlm!Z! d	dl"m#Z# d	dl$m%Z% d	dl m&Z&m'Z' ddZ( ej)        e*          Z+ej,        -                    e*d          Z. G d de/          Z0 G d de0          Z1 G d de0          Z2 G d de0          Z3 G d de3          Z4 G d d e3          Z5 G d! d"e3          Z6 G d# d$e3          Z7 G d% d&e3          Z8 G d' d(e0          Z9 G d) d*e0          Z: G d+ d,e0          Z; G d- d.e0          Z< G d/ d0e0          Z= G d1 d2e=          Z> G d3 d4e0          Z? G d5 d6e0          Z@ G d7 d8e0          ZA G d9 d:e0          ZB G d; d<e0          ZC G d= d>e	          ZD G d? d@e?          ZE G dA dBe0          ZF G dC dDe0          ZG G dE dFe0          ZH G dG dHeI          ZJ G dI dJeI          ZK G dK dLe0          ZL G dM dNe0          ZM G dO dPeM          ZN G dQ dReM          ZO G dS dTeO          ZP G dU dVeO          ZQ G dW dXeM          ZR G dY dZeM          ZS G d[ d\eM          ZT G d] d^eM          ZU G d_ d`eM          ZVeWeNeXeOeYePeZeRe[eQe\eSe/eTe]eUe^eVi	Z_dddZ`dddeddmZaddpZbejc        jd        je        ejc        jd        jf        ejc        jd        jg        ejc        jd        jh        ejc        jd        ji        fZjddzZkdd{Zl ed	|          dd~            ZmddZn eo            ZpepdddddZq G d d          ZrddZsdddZtddZuddZv	 dddZwddZxddZyddZz	 	 dddZ{ddZ|ddZ}	 	 dddZ~dS )    )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FrameExecStrategy	case_namestrreturnc                4    d|                      dd          z   S )NzhFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#_-)replace)r   s    V/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/torch/_dynamo/exc.pyexportdb_error_messager"   9   s%    	I


C
%
%	&    graph_breaksc                  $     e Zd ZdZd fdZ xZS )	TorchDynamoExceptiona6  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.
    argsr   kwargsr   Nonec                V     t                      j        |i | d | _        d | _        d S N)super__init___torch_dynamo_tracer_outputframe_exec_strategy)selfr'   r(   	__class__s      r!   r-   zTorchDynamoException.__init__Q   s5    $)&)))IM(=A   r#   )r'   r   r(   r   r   r)   )__name__
__module____qualname____doc__r-   __classcell__r1   s   @r!   r&   r&   E   sQ        	 	B B B B B B B B B Br#   r&   c                      e Zd ZdS )InternalTorchDynamoErrorNr2   r3   r4    r#   r!   r9   r9   W           Dr#   r9   c                      e Zd ZdS )ResumePrologueTracingErrorNr:   r;   r#   r!   r>   r>   [   r<   r#   r>   c                  2     e Zd ZU ded<   ddd
 fd	Z xZS )RestartAnalysisOptional[str]restart_reasonN)rB   r'   r   r   r)   c               B    || _          t                      j        |  d S r+   )rB   r,   r-   )r0   rB   r'   r1   s      r!   r-   zRestartAnalysis.__init__b   s%    ,$r#   )r'   r   rB   rA   r   r)   r2   r3   r4   __annotations__r-   r6   r7   s   @r!   r@   r@   _   sX         !!!!CG                        r#   r@   c                      e Zd ZdS )SpeculationRestartAnalysisNr:   r;   r#   r!   rG   rG   g   r<   r#   rG   c                      e Zd ZdZdS )AutogradGradRestartAnalysiszRaised when autograd.grad consumed grad_fns that are returned.

    On restart, autograd.grad will graph break instead of being traced.
    Nr2   r3   r4   r5   r;   r#   r!   rI   rI   k   s           r#   rI   c                      e Zd ZdS )UnspecializeRestartAnalysisNr:   r;   r#   r!   rL   rL   r   r<   r#   rL   c                      e Zd ZdS ) CompileCollectiveRestartAnalysisNr:   r;   r#   r!   rN   rN   v   r<   r#   rN   c                      e Zd ZdS )TensorifyScalarRestartAnalysisNr:   r;   r#   r!   rP   rP   z   r<   r#   rP   c                      e Zd ZdS )	SkipFrameNr:   r;   r#   r!   rR   rR      r<   r#   rR   c                  "     e Zd Zd	d
 fdZ xZS )TorchRuntimeErrorNmsgr   
real_stackStackSummary | Noner   r)   c                    t                                          |           || _        ||n"t          j        j                                        | _        d S r+   r,   r-   rU   torch_guardsTracingContextr   rV   r0   rU   rV   r1   s      r!   r-   zTorchRuntimeError.__init__   P     % J-;;== 	r#   r+   rU   r   rV   rW   r   r)   r2   r3   r4   r-   r6   r7   s   @r!   rT   rT      B        
 
 
 
 
 
 
 
 
 
 
r#   rT   c                        e Zd Zd fdZ xZS )InvalidBackendnamer   r   r)   c                R    t                                          d|d           d S )NzInvalid backend: z=, see `torch._dynamo.list_backends()` for available backends.)r,   r-   )r0   rd   r1   s     r!   r-   zInvalidBackend.__init__   s7    eeee	
 	
 	
 	
 	
r#   )rd   r   r   r)   r`   r7   s   @r!   rc   rc      s=        
 
 
 
 
 
 
 
 
 
r#   rc   c                        e Zd Zd fdZ xZS )ResetRequiredr   r)   c                n    t                                          t          j        d                     d S )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)r0   r1   s    r!   r-   zResetRequired.__init__   s=    O 	
 	
 	
 	
 	
r#   r   r)   r`   r7   s   @r!   rg   rg      s=        
 
 
 
 
 
 
 
 
 
r#   rg   c                  (     e Zd Zd fdZdd
Z xZS )ShortenTracebackr'   r   first_useful_frameOptional[types.FrameType]r(   r   r)   c               H     t                      j        |i | || _        d S r+   )r,   r-   rn   )r0   rn   r'   r(   r1   s       r!   r-   zShortenTraceback.__init__   s/     	$)&)))"4r#   typing.Selfc                    | j         }| j        |t          j        r| S |j        | j        ur!|j        }|
J d            |j        | j        u!|                     |          S )Nz#internal error, please report a bug)__traceback__rn   r   verbosetb_frametb_nextwith_traceback)r0   tbs     r!   remove_dynamo_framesz%ShortenTraceback.remove_dynamo_frames   sq    "*bjFNjKk!888B>>#H>>> k!888 ""2&&&r#   )r'   r   rn   ro   r(   r   r   r)   )r   rq   )r2   r3   r4   r-   ry   r6   r7   s   @r!   rm   rm      sQ        5 5 5 5 5 5' ' ' ' ' ' ' 'r#   rm   c                        e Zd Zd
 fd	Z xZS )BackendCompilerFailed
backend_fnr   inner_exception	Exceptionrn   ro   r   r)   c                    t          |dd          | _        || _        d| j        dt          |          j         d| }t                                          ||           d S )Nr2   ?zbackend=z	 raised:
z: )rn   )getattrbackend_namer}   typer2   r,   r-   )r0   r|   r}   rn   rU   r1   s        r!   r-   zBackendCompilerFailed.__init__   sq     $J
C@@.k*kk_8M8M8VkkZikk1CDDDDDr#   )r|   r   r}   r~   rn   ro   r   r)   r`   r7   s   @r!   r{   r{      sG        	E 	E 	E 	E 	E 	E 	E 	E 	E 	Er#   r{   c                  @     e Zd Z	 	 ddddd fdZddZdddZ xZS )Unsupported FN)r   rV   rU   r   gb_type
skip_frameboolr   rA   rV   rW   r   r)   c                  t                                          |           |s#t          j        j                                        }|| _        || _        || _        d | _	        | 
                                 || _        d| _        d S NF)r,   r-   rZ   r[   r\   r   rV   rU   r   categoryadd_to_statsr   logged)r0   rU   r   r   r   rV   r1   s         r!   r-   zUnsupported.__init__   s|     	 	F5CCEEJ$$'+#*r#   c                    | j         J t          | j                  | j        xx         dz  cc<   t          | j                  | j                 dk    rt          | j                  | j        = d S d S )Nr   r   r   r   rU   r0   s    r!   remove_from_statszUnsupported.remove_from_stats   sm    }((()))Q.)))DM"48,11'111 21r#   unimplementedr   c                T    || _         t          |         | j        xx         dz  cc<   d S )Nr   r   )r0   r   s     r!   r   zUnsupported.add_to_stats   s2     48$$$)$$$$$r#   )r   F)rU   r   r   r   r   r   r   rA   rV   rW   r   r)   rk   )r   )r   r   r   r)   )r2   r3   r4   r-   r   r   r6   r7   s   @r!   r   r      s        
   $(*.       *2 2 2 2* * * * * * * * *r#   r   c                      e Zd ZdS )$UnknownPropertiesDuringBackwardTraceNr:   r;   r#   r!   r   r      r<   r#   r   c                      e Zd ZdS )RecompileErrorNr:   r;   r#   r!   r   r      r<   r#   r   c                      e Zd ZdS )InfiniteGeneratorErrorNr:   r;   r#   r!   r   r              Dr#   r   c                      e Zd ZdZdS )CondOpArgsMismatchErrorz?
    Internal error from cond() due to arguments mismatch.
    NrJ   r;   r#   r!   r   r      s           r#   r   c                      e Zd Z e            Z e            Z e            Z e            Z e            Z e            Z	 e            Z
 e            ZdS )UserErrorTypeN)r2   r3   r4   r   DYNAMIC_CONTROL_FLOWANTI_PATTERNSTANDARD_LIBRARYCONSTRAINT_VIOLATIONDYNAMIC_DIMINVALID_INPUTINVALID_OUTPUT*UNSUPPORTED_ALIASED_MUTATED_DYNAMIC_INPUTSr;   r#   r!   r   r      sl        466466Ltvv466$&&KDFFMTVVN15...r#   r   c                  $     e Zd Z	 dd fd
Z xZS )	UserErrorN
error_typer   rU   r   r   rA   r   r)   c                   |It          |t                    sJ |                    d          r|dz  }n|dz  }|t          |          z  }t	                                          ||r|nd           || _        || _        dS )aG  
        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   )
isinstancer   endswithr"   r,   r-   r   message)r0   r   rU   r   r1   s       r!   r-   zUserError.__init__  s      i-----||C   s
t))444C9Eii+FFF$r#   r+   )r   r   rU   r   r   rA   r   r)   r`   r7   s   @r!   r   r     sE        NR          r#   r   c                  "     e Zd Zd	d
 fdZ xZS )StepUnsupportedNrU   r   rV   rW   r   r)   c                    t                                          |           || _        |s#t          j        j                                        }|| _        d| _        d S r   )	r,   r-   rU   rZ   r[   r\   r   rV   r   r]   s      r!   r-   zStepUnsupported.__init__   sS     	F5CCEEJ$r#   r+   r_   r`   r7   s   @r!   r   r     sB                  r#   r   c                      e Zd ZdS )UnsafeScriptObjectErrorNr:   r;   r#   r!   r   r   )  r<   r#   r   c                  "     e Zd Zd	d
 fdZ xZS )UncapturedHigherOrderOpErrorNrU   r   rV   rW   r   r)   c                    t                                          |           || _        ||n"t          j        j                                        | _        d S r+   rY   r]   s      r!   r-   z%UncapturedHigherOrderOpError.__init__.  r^   r#   r+   r_   r`   r7   s   @r!   r   r   -  ra   r#   r   c                      e Zd ZdS )IncorrectUsageNr:   r;   r#   r!   r   r   8  r<   r#   r   c                      e Zd ZdS )FailOnRecompileLimitHitNr:   r;   r#   r!   r   r   ?  r<   r#   r   c                      e Zd ZdS )PackageErrorNr:   r;   r#   r!   r   r   C  r<   r#   r   c                  &     e Zd Zddd fd
Z xZS )ObservedExceptionNrV   r'   r   rV   Optional[StackSummary]r(   r   r)   c                    t                      j        |i | ||n"t          j        j                                        | _        d S r+   )r,   r-   rZ   r[   r\   r   rV   r0   rV   r'   r(   r1   s       r!   r-   zObservedException.__init__I  sO     	$)&))) % J-;;== 	r#   r'   r   rV   r   r(   r   r   r)   r`   r7   s   @r!   r   r   G  sN         @D
 
 
 
 
 
 
 
 
 
 
 
r#   r   c                  2     e Zd ZU ded<   ddd fdZ xZS )ObservedUserStopIterationzOptional[Any]valueNr   r'   r   rV   r   r(   r   r)   c                   t                                          d|           t          |          dk    r|d         | _        d S d | _        d S )Nzunhandled `raise StopIteration`r   r   )r,   r-   lenr   r   s       r!   r-   z"ObservedUserStopIteration.__init__Z  sL     	:zRRRt99q==aDJJJDJJJr#   r   rD   r7   s   @r!   r   r   T  s\         
 @D           r#   r   c                      e Zd ZdS )ObservedLookupErrorNr:   r;   r#   r!   r   r   d  r   r#   r   c                      e Zd ZdS )ObservedIndexErrorNr:   r;   r#   r!   r   r   i  r   r#   r   c                      e Zd ZdS )ObservedKeyErrorNr:   r;   r#   r!   r   r   n  r   r#   r   c                      e Zd ZdS )ObservedGeneratorExitNr:   r;   r#   r!   r   r   s  r<   r#   r   c                      e Zd ZdS )ObservedAttributeErrorNr:   r;   r#   r!   r   r   w  r   r#   r   c                      e Zd ZdS )ObservedRuntimeErrorNr:   r;   r#   r!   r   r   |  r   r#   r   c                      e Zd ZdS )ObservedNotImplementedErrorNr:   r;   r#   r!   r   r     r<   r#   r   c                      e Zd ZdS )ObservedTypeErrorNr:   r;   r#   r!   r   r     r   r#   r   exc_typetype[Exception]type[ObservedException]c                    | t           vrAt          | dt          |                     }t          d| dt          fi           t           | <   t           |          S )Nr2   ObservedError)observed_exception_mapr   r   r   r   )r   rd   s     r!   get_dynamo_observed_exceptionr     s]    ---xS]];;+/"t"""%6$8",
 ,
x( "(++r#   )r'   r(   txr   r'   Optional[list[Any]]r(   Optional[dict[str, Any]]r   c               L   ddl m} ddlm                     |                               |rfd|D             ng |pi           }t          ||          sJ                     |           j        	                    |           t          |           }|r || |)Nr   )ExceptionVals)SourcelessBuilderc                <    g | ]}                     |          S r;   )create).0ar   r   s     r!   
<listcomp>z,raise_observed_exception.<locals>.<listcomp>  s*    777Q		!	!"a	(	(777r#   )symbolic_convertr   variables.builderr   r   call_functionr   _attach_traceback_to_exceptionexn_vt_stackset_current_exceptionr   )r   r   r'   r(   r   exception_vt
raised_excr   s    `     @r!   raise_observed_exceptionr     s     0/////444444 %++B99GG
;?G77777$7777R" L
 lM22222%%l333O)),777.x88J  j$
r#   r   r)   c                8    | j                                          d S r+   )r   clear_current_exception)r   s    r!   handle_observed_exceptionr     s    2 O++-----r#   er~   codetypes.CodeTyper   contextexplanationhints	list[str]c                   t          | |          t          j                            dd fd           t                              d           t          } |||||| d           d S )Nartifactc                     dddS )Ndynamo_graph_break_reasonstring)rd   encodingr;   r;   r#   r!   <lambda>z,unimplemented_with_warning.<locals>.<lambda>  s    / 
 
 r#   c                      S r+   r;   )graph_break_msgs   r!   r  z,unimplemented_with_warning.<locals>.<lambda>  s    ? r#   )metadata_fn
payload_fnz%sT)r   r   r   r   from_exclog_warning)format_error_msg_verboserZ   _loggingtrace_structuredgraph_breaks_logdebugr   )r   r   r   r   r   r   _unimplementedr
  s          @r!   unimplemented_with_warningr    s      /q$77O	N##
 
 +*** $    4111"NN     r#   c                ,   t          j        |d                                          }d                    d |D                       }t          j        |d                                          }|  d| d| d| }t	          |           }|r|d| z  }|S )N    r   c              3  j   K   | ].}d t          j        |d                                          z   V  /dS )z  Hint: r  N)ri   indentlstrip)r   hints     r!   	<genexpr>z-format_graph_break_message.<locals>.<genexpr>  sP        @D
X_T62299;;;     r#   z
  Explanation: z

  Developer debug context: z:

 For more details about this graph break, please visit: )ri   r  r  joinget_gbid_documentation_link)r   r   r   r   	hints_strrU   documentation_links          r!   format_graph_break_messager!    s     /+v66==??K		  HM    I ogv..5577G 	( (( ( ( (
 $( (C 5W== cbN`bbbJr#   )maxsizedict[str, Any]c                    	 t          t                                                    j        } t	          dt          |           d          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   n,# t          $ r t                              d           i }Y nw xY wi }|                                D ]\  }}|D ]}|||d         <   |S )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   r   openjsonloadr~   log	exceptionitems)
script_dirregistry_pathfregistrymappingkventrys           r!   _load_gb_type_to_gb_id_mapr7  "  s6   
(^^++--4
'J!<
 
 -   	$Ay||H	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$   9:::
 G   * *1 	* 	*E()GE)$%%	* Ns6   AB A;/B ;A??B A?B &B0/B0rA   c                p    d}t                      }| |v r!| d||                              d           dS dS )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)r7  r  )r   GRAPH_BREAK_SITE_URLgb_type_to_gb_id_maps      r!   r  r  =  s[     	F  677&&&#XX';G'D'K'KD'Q'QXXX	
 4r#   F)r  r  r   r  r  r   r   c                T   t          | |||          }|rt                              |           |t          urad}t	          |d          r|j        }t          |t                    r|j         d| }t          || ||          t          || ||          |t          || |          )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.
    NrV   zJ

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

r   )	r!  r,  warning_NOTHINGhasattrrV   r   r   rU   )	r   r   r   r   r  r  r   rU   past_real_stacks	            r!   r   r   X  s    ( %Wg{E
J
JC Cx8\** 	2&1Oh,, 	T\vvqtvvCc7J?SSSS*
 
 
	 c7J
/
//r#   c                  &    e Zd Zd
dZddZddZd	S )KeyErrorMsgr   r   r   r)   c                    || _         d S r+   )r   )r0   r   s     r!   r-   zKeyErrorMsg.__init__  s    


r#   r   c                *    t          | j                  S r+   )r   r   r   s    r!   __str__zKeyErrorMsg.__str__  s    4:r#   c                *    |                                  S r+   )rF  r   s    r!   __repr__zKeyErrorMsg.__repr__  s    ||~~r#   N)r   r   r   r)   )r   r   )r2   r3   r4   r-   rF  rH  r;   r#   r!   rC  rC    sP                   r#   rC  excrU   c                    t          | d          r7|                    d          }|d          d| j         |d          |d          }|S )N	_hop_namez
  Explanation:r   z
  Higher Order Operator: r      )r@  	partitionrK  )rI  rU   liness      r!   !augment_exc_message_with_hop_namerO    s^     sK   
011QxWWCMW58WUSTXWW 	 Jr#   r   exportc                   dd l }d | _        t          |           }|Nt          |          dk    r;|d         | _        |dd                    |                    |                     z  }t          j        r&t          | d          r|d| j	         d| j	         dz  }t          j
        st          | d	          r|d
z  }t          | d          r^t          | j        d          rIt          | j        d          r!|d| j        j         d| j        j         dz  }n|d| j        j         dz  }t          | j                  dk    rdnt          | j        d                   }t!          | |          }t#          | t$                    r*t'          ||z             f| j        dd          z   | _        d S ||z   }|f| j        dd          z   | _        d S )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').
rV   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_enabledr@  rS  rt   r}   rT  rU  r'   r   rO  r   KeyErrorrC  )rI  rU   rP  rV  rV   old_msgnew_msgs          r!   augment_exc_messager]    s;   '+C$$$J#j//A"5"5+5b>(Rbggi.C.CJ.O.O&P&PRRR# 
5F(G(G 
31D 3 3+3 3 3	

 > 
gc<88 
J	
 s%&& 7_, ,  3&77 
	U0C0Q U U030C0PU U UCC _0C0Q _ _ _C
 MMQ&&bbC,<,<G/W==G#x   -#..038ABB<?C-:,r#   
compile_idr   #tuple[Optional[str], Optional[int]]c                ^    d }d }| j         | j         j        }| j         j        }|| _        ||fS r+   )rW  filenamelinenor^  )r   r^  ra  rb  s       r!   get_exc_messagerc    s?     HF%11:/6ALVr#   r   c                 8    t          t                                S r+   )filter_stackr   r;   r#   r!   get_stack_above_dynamorf    s    (((r#   frameOptional[DynamoFrameType]r   c                    t          | dd           }|d S |t                      }nt                      }t          j        ||z             S )NrV   )r   rf  r   	from_list)rI  rg  rV   stack_above_dynamos       r!   rX  rX    sZ     lD11Jt  455)^^!"4z"ABBBr#   stackc                    t                      }| D ]D}|j        
d|j        v r n0d|j        v s|j        r
d|j        v r/|                    |           E|S )Nconvert_frame
eval_frameztorch._dynamo.optimize()r   ra  lineappend)rl  
user_stackrg  s      r!   re  re    s{    J 	! 	!>!en,,E5>))J *4
BB%    r#   rd   c                p    ddl m} t          j        | d|           }|r|                    d          S d S )Nr   )TORCH_DYNAMO_RESUME_IN_PREFIXz_(\w+)_at_\d+)resume_executionrt  rematchgroup)rd   rt  rw  s      r!   remove_resume_prefixry    sL    ??????H5FFFMME {{1~~4r#   !StackSummary | list[FrameSummary]c                    t                      }| D ]U}|j        
t          |j                  }|r |r|d         j        |k    r||d<   ||_        @|                    |           V|S )a1  
    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>
    NrR  )r   ra  ry  rd   rq  )rl  	new_stackrg  rd   s       r!   collapse_resume_framesr}    s    ( I $ $>!#EJ// 	$ 	$)B-"4"<"<!IbMEJJU####r#   rS  c                    d|j          d|j         d|j         d}|dz  }|t                      z  }t	          | |          }|4|dz  }|d                    t          |                    z  }|dz  }|dz  }|S )	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	   rX  r  r
   )rI  r   rS  rg  rU   rV   s         r!   r  r  3  s     	XWW(8WW@SWWW  CCC:<<CU++J	
 	rww{:..///txJr#   c           	     r    t          | dd           dt          | dd           dt          | dd           dS )	Nr  z	<unknown>z (r  r  r  r   ))r   )r   s    r!   format_frame_infor  N  sX    4K00 	6 	6D-55	6 	6.22	6 	6 	6r#   Optional[types.CodeType]reasonc                >    | t          |           }d| d| S d| S )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   r  
frame_infos      r!   format_skip_frame_messager  V  sO    &t,,
 Z       	
    	
r#   c           	         t           j        rt          | |||          S d|j         d|j         d|j         dt                       S )Nr  r   r  z 
due to: 
)r   rt   r  r  r  r  r	   )rI  r   rS  rg  s       r!   format_error_msgr  d  sk     ~ K'T?EJJJ8DL 8 84+; 8 88 8)38 8 8r#   )r   r   r   r   )r   r   r   r   )
r   r   r   r   r'   r   r(   r   r   r   )r   r   r   r)   )r   r~   r   r   r   r   r   r   r   r   r   r  r   r   )
r   r   r   r   r   r   r   r  r   r   )r   r#  )r   r   r   rA   )r   r   r   r   r   r   r   r  r  r   r  r   r   r   r   r   )rI  r~   rU   r   r   r   )r   F)rI  r~   rU   r   rP  r   r   r)   )r   r~   r^  r   r   r_  )r   r   r+   )rI  r~   rg  rh  r   r   )rl  r   r   r   )rd   r   r   rA   )rl  rz  r   r   )NN)
rI  r~   r   r   rS  rA   rg  rh  r   r   )r   r   r   r   )r   r  r  r   r   r   )
__future__r   r*  loggingrv  ri   typingenumr   r   	functoolsr   pathlibr   rV  r   r	   r
   r   r   r   r   r   r   torch._guardsrZ   torch._utils_internalr   r   r   utilsr   typesr   output_graphr   r   r   r   r   r"   	getLoggerr2   r,  r  getArtifactLoggerr  RuntimeErrorr&   r9   r>   r@   rG   rI   rL   rN   rP   rR   rT   rc   rg   rm   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GeneratorExitrZ  AttributeErrorNotImplementedError	TypeErrorr   r   r   r   _subclassesfake_tensorDataDependentOutputExceptionDynamicOutputShapeExceptionUnsupportedOperatorExceptionUnsupportedFakeTensorException$UnsupportedMutationAliasingException!exceptions_allowed_to_be_fallbackr  r!  r7  r  objectr?  r   rC  rO  r]  rc  rf  rX  re  ry  r}  r  r  r  r  r;   r#   r!   <module>r     s
   " " " " " "2   				                       X X X X X X X X X X X X X X 9 9 9 9 9 9 9 9 9 9 9 9     1 1 1 1 1 1              :LLL''''''000000;;;;;;99999999    g!!>33HnMM B B B B B< B B B$	 	 	 	 	3 	 	 		 	 	 	 	!5 	 	 	         *      	 	 	 	 	 	 	 	    /   	 	 	 	 	/ 	 	 		 	 	 	 	 	 	 		 	 	 	 	_ 	 	 		 	 	 	 	$ 	 	 	
 
 
 
 
, 
 
 

 
 
 
 
) 
 
 
	
 	
 	
 	
 	
( 	
 	
 	
' ' ' ' '+ ' ' '"
E 
E 
E 
E 
E, 
E 
E 
E$* * * * *& * * *B	 	 	 	 	+? 	 	 		 	 	 	 	) 	 	 		 	 	 	 	1 	 	 	
    2   8 8 8 8 8D 8 8 8       2    *   	 	 	 	 	2 	 	 	
 
 
 
 
#7 
 
 
	 	 	 	 	Y 	 	 		 	 	 	 	i 	 	 		 	 	 	 	' 	 	 	

 

 

 

 

, 

 

 

     1    	 	 	 	 	+ 	 	 	
	 	 	 	 	, 	 	 	
	 	 	 	 	* 	 	 	
	 	 	 	 	- 	 	 		 	 	 	 	. 	 	 	
	 	 	 	 	, 	 	 	
	 	 	 	 	"3 	 	 		 	 	 	 	) 	 	 	 ,$"(*&4 
 , , , , !%'+     6. . . .< 
!>	!=	!>	!@	!F% !# # # #L   4 1   4   0 688 "0 "0 "0 "0 "0 "0N       	 	 	 	.- .- .- .- .-b	 	 	 	) ) ) )
 8<C C C C CB          J &*'+	    6   
 
 
 
" &*'+		8 	8 	8 	8 	8 	8 	8r#   