
    inq                       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' dxdZ( ejR                  e*      Z+ejX                  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, d-e0      Z= G d. d/e=      Z> G d0 d1e0      Z? G d2 d3e0      Z@ G d4 d5e0      ZA G d6 d7e0      ZB G d8 d9e0      ZC G d: d;e	      ZD G d< d=e?      ZE G d> d?e0      ZF G d@ dAe0      ZG G dB dCe0      ZH G dD dEeI      ZJ G dF dGeI      ZK G dH dIe0      ZL G dJ dKe0      ZM G dL dMeM      ZN G dN dOeM      ZO G dP dQeO      ZP G dR dSeO      ZQ G dT dUeM      ZR G dV dWeM      ZS G dX dYeM      ZT G dZ d[eM      ZU G d\ d]eM      ZVeWeNeXeOeYePeZeRe[eQe\eSe/eTe]eUe^eVi	Z_dyd^Z`ddd_	 	 	 	 	 	 	 	 	 dzd`Zad{daZbej                  j                  j                  ej                  j                  j                  ej                  j                  j                  ej                  j                  j                  ej                  j                  j                  fZj	 	 	 	 	 	 	 	 	 	 	 	 	 	 d|dbZk	 	 	 	 	 	 	 	 	 	 d}dcZl ed	d      d~de       ZmddfZn eo       Zpepdgdgdh	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddiZq G dj dk      ZrddlZsdddmZt	 	 	 	 	 	 ddnZuddoZv	 d	 	 	 	 	 ddpZwddqZxddrZyddsZz	 	 d	 	 	 	 	 	 	 	 	 ddtZ{dduZ|ddvZ}	 	 d	 	 	 	 	 	 	 	 	 ddwZ~y)    )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                ,    d| j                  dd      z   S )NzhFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#_-)replace)	case_names    b/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/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.
    c                @    t        |   |i | d | _        d | _        y N)super__init___torch_dynamo_tracer_outputframe_exec_strategy)selfargskwargs	__class__s      r   r(   zTorchDynamoException.__init__Q   s%    $)&)IM(=A r!   )r,   r   r-   r   returnNone)__name__
__module____qualname____doc__r(   __classcell__r.   s   @r   r$   r$   E   s    	B Br!   r$   c                      e Zd Zy)InternalTorchDynamoErrorNr1   r2   r3    r!   r   r8   r8   W       r!   r8   c                      e Zd Zy)ResumePrologueTracingErrorNr9   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)rA   c               ,    || _         t        |   |  y r&   )rA   r'   r(   )r+   rA   r,   r.   s      r   r(   zRestartAnalysis.__init__b   s    ,$r!   )r,   r   rA   r@   r/   r0   r1   r2   r3   __annotations__r(   r5   r6   s   @r   r?   r?   _   s    !!CG    r!   r?   c                      e Zd Zy)SpeculationRestartAnalysisNr9   r:   r!   r   rF   rF   g   r;   r!   rF   c                      e Zd ZdZy)AutogradGradRestartAnalysiszRaised when autograd.grad consumed grad_fns that are returned.

    On restart, autograd.grad will graph break instead of being traced.
    Nr1   r2   r3   r4   r:   r!   r   rH   rH   k   s    r!   rH   c                      e Zd Zy)UnspecializeRestartAnalysisNr9   r:   r!   r   rK   rK   r   r;   r!   rK   c                      e Zd Zy) CompileCollectiveRestartAnalysisNr9   r:   r!   r   rM   rM   v   r;   r!   rM   c                      e Zd Zy)TensorifyScalarRestartAnalysisNr9   r:   r!   r   rO   rO   z   r;   r!   rO   c                      e Zd Zy)	SkipFrameNr9   r:   r!   r   rQ   rQ      r;   r!   rQ   c                  "     e Zd Zdd fdZ xZS )TorchRuntimeErrorc                    t         |   |       || _        ||| _        y t        j                  j
                  j                         | _        y r&   r'   r(   msgtorch_guardsTracingContextr   
real_stackr+   rV   rZ   r.   s      r   r(   zTorchRuntimeError.__init__   J     %  	 --;;= 	r!   r&   rV   strrZ   StackSummary | Noner/   r0   r1   r2   r3   r(   r5   r6   s   @r   rS   rS          
 
r!   rS   c                        e Zd Zd fdZ xZS )InvalidBackendc                ,    t         |   d|d       y )NzInvalid backend: z=, see `torch._dynamo.list_backends()` for available backends.)r'   r(   )r+   namer.   s     r   r(   zInvalidBackend.__init__   s    x'de	
r!   )re   r^   r/   r0   r`   r6   s   @r   rc   rc      s    
 
r!   rc   c                        e Zd Zd fdZ xZS )ResetRequiredc                J    t         |   t        j                  d             y )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(   zResetRequired.__init__   s!    OO	
r!   r/   r0   r`   r6   s   @r   rg   rg      s    
 
r!   rg   c                  8     e Zd Z	 	 	 	 	 	 	 	 d fdZddZ xZS )ShortenTracebackc               2    t        |   |i | || _        y r&   )r'   r(   first_useful_frame)r+   ro   r,   r-   r.   s       r   r(   zShortenTraceback.__init__   s     	$)&)"4r!   c                   | j                   }| j                  |t        j                  r| S |j                  | j                  ur.|j
                  }|J d       |j                  | j                  ur.| j                  |      S )Nz#internal error, please report a bug)__traceback__ro   r   verbosetb_frametb_nextwith_traceback)r+   tbs     r   remove_dynamo_framesz%ShortenTraceback.remove_dynamo_frames   sz    ""*bjFNNKkk!8!88B>H#HH> kk!8!88 ""2&&r!   )r,   r   ro   Optional[types.FrameType]r-   r   r/   r0   )r/   ztyping.Self)r1   r2   r3   r(   rw   r5   r6   s   @r   rm   rm      s-    55.G5SV5	5'r!   rm   c                  0     e Zd Z	 	 	 	 	 	 	 	 d fdZ xZS )BackendCompilerFailedc                    t        |dd      | _        || _        d| j                  dt        |      j                   d| }t
        |   ||       y )Nr1   ?zbackend=z	 raised:
z: )ro   )getattrbackend_nameinner_exceptiontyper1   r'   r(   )r+   
backend_fnr   ro   rV   r.   s        r   r(   zBackendCompilerFailed.__init__   s_     $J
C@.**-Z_8M8V8V7WWYZiYjk1CDr!   )r   r   r   	Exceptionro   rx   r/   r0   r`   r6   s   @r   rz   rz      s9    	E	E #	E 6		E
 
	E 	Er!   rz   c                  V     e Zd Z	 	 dddd	 	 	 	 	 	 	 	 	 	 	 d fdZddZd	d
dZ xZS )UnsupportedN)r   rZ   c                   t         |   |       |s(t        j                  j                  j                         }|| _        || _        || _        d | _	        | j                          || _        d| _        y NF)r'   r(   rW   rX   rY   r   rZ   rV   
skip_framecategoryadd_to_statsgb_typelogged)r+   rV   r   r   r   rZ   r.   s         r   r(   zUnsupported.__init__   sc     	55CCEJ$$'+#*r!   c                    | j                   J t        | j                      | j                  xx   dz  cc<   t        | j                      | j                     dk  rt        | j                      | j                  = y y )Nr   r   r   r   rV   r+   s    r   remove_from_statszUnsupported.remove_from_stats   sc    }}((()Q.)DMM"488,1'1 2r!   c                N    || _         t        |   | j                  xx   dz  cc<   y )Nr   r   )r+   r   s     r   r   zUnsupported.add_to_stats   s"     488$)$r!   ) F)rV   r^   r   r^   r   boolr   r@   rZ   r_   r/   r0   rk   )unimplemented)r   r^   r/   r0   )r1   r2   r3   r(   r   r   r5   r6   s   @r   r   r      sf    
   $(*. 	
  ! ( 
*2* *r!   r   c                      e Zd Zy)$UnknownPropertiesDuringBackwardTraceNr9   r:   r!   r   r   r      r;   r!   r   c                      e Zd Zy)RecompileErrorNr9   r:   r!   r   r   r      r;   r!   r   c                      e Zd Zy)InfiniteGeneratorErrorNr9   r:   r!   r   r   r          r!   r   c                      e Zd ZdZy)CondOpArgsMismatchErrorz?
    Internal error from cond() due to arguments mismatch.
    NrI   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y)UserErrorTypeN)r1   r2   r3   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      s>    66Lv6&KFMVN15.r!   r   c                  2     e Zd Z	 d	 	 	 	 	 	 	 d fdZ xZS )	UserErrorc                    |<t        |t              sJ |j                  d      r|dz  }n|dz  }|t        |      z  }t        |   ||r|nd       || _        || _        y)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(   
error_typemessage)r+   r   rV   r   r.   s       r   r(   zUserError.__init__  sj      i---||C s
t))44C9i+F$r!   r&   )r   r   rV   r^   r   r@   r/   r0   r`   r6   s   @r   r   r     s0    NR'.1>K	 r!   r   c                  "     e Zd Zdd fdZ xZS )StepUnsupportedc                    t         |   |       || _        |s(t        j                  j
                  j                         }|| _        d| _        y r   )	r'   r(   rV   rW   rX   rY   r   rZ   r   r[   s      r   r(   zStepUnsupported.__init__   s@    55CCEJ$r!   r&   r]   r`   r6   s   @r   r   r     s     r!   r   c                      e Zd Zy)UnsafeScriptObjectErrorNr9   r:   r!   r   r   r   )  r;   r!   r   c                  "     e Zd Zdd fdZ xZS )UncapturedHigherOrderOpErrorc                    t         |   |       || _        ||| _        y t        j                  j
                  j                         | _        y r&   rU   r[   s      r   r(   z%UncapturedHigherOrderOpError.__init__.  r\   r!   r&   r]   r`   r6   s   @r   r   r   -  ra   r!   r   c                      e Zd Zy)IncorrectUsageNr9   r:   r!   r   r   r   8  r;   r!   r   c                      e Zd Zy)FailOnRecompileLimitHitNr9   r:   r!   r   r   r   ?  r;   r!   r   c                      e Zd Zy)PackageErrorNr9   r:   r!   r   r   r   C  r;   r!   r   c                  4     e Zd Zdd	 	 	 	 	 	 	 d fdZ xZS )ObservedExceptionNrZ   c                   t        |   |i | ||| _        y t        j                  j                  j                         | _        y r&   )r'   r(   rW   rX   rY   r   rZ   r+   rZ   r,   r-   r.   s       r   r(   zObservedException.__init__I  sJ     	$)&) %  	 --;;= 	r!   r,   r   rZ   Optional[StackSummary]r-   r   r/   r0   r`   r6   s   @r   r   r   G  s4     @D

&<
OR
	
 
r!   r   c                  @     e Zd ZU ded<   dd	 	 	 	 	 	 	 d fdZ xZS )ObservedUserStopIterationzOptional[Any]valueNr   c               h    t         |   d|       t        |      dkD  r|d   | _        y d | _        y )Nzunhandled `raise StopIteration`r   r   )r'   r(   lenr   r   s       r   r(   z"ObservedUserStopIteration.__init__Z  s5     	:zRt9q=aDJDJr!   r   rC   r6   s   @r   r   r   T  s:    
 @D&<OR	 r!   r   c                      e Zd Zy)ObservedLookupErrorNr9   r:   r!   r   r   r   d  r   r!   r   c                      e Zd Zy)ObservedIndexErrorNr9   r:   r!   r   r   r   i  r   r!   r   c                      e Zd Zy)ObservedKeyErrorNr9   r:   r!   r   r   r   n  r   r!   r   c                      e Zd Zy)ObservedGeneratorExitNr9   r:   r!   r   r   r   s  r;   r!   r   c                      e Zd Zy)ObservedAttributeErrorNr9   r:   r!   r   r   r   w  r   r!   r   c                      e Zd Zy)ObservedRuntimeErrorNr9   r:   r!   r   r   r   |  r   r!   r   c                      e Zd Zy)ObservedNotImplementedErrorNr9   r:   r!   r   r   r     r;   r!   r   c                      e Zd Zy)ObservedTypeErrorNr9   r:   r!   r   r   r     r   r!   r   c                    | t         vr3t        | dt        |             }t        d| dt        fi       t         | <   t         |    S )Nr1   ObservedError)observed_exception_mapr}   r^   r   r   )exc_typere   s     r   get_dynamo_observed_exceptionr     sN    --xS];+/tfE"%6$8",
x( "(++r!   )r,   r-   c          
     R   ddl m} ddlm} |j	                  ||       j                  ||r |D cg c]  }|j	                  ||       c}ng |xs i       }t        ||      sJ |j                  |       |j                  j                  |       t        |       }|r || |c c}w )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
;?$7Q		!	!"a	(7R"L
 lM222%%l3OO)),7.x8J$
 	8s   B$
c                8    | j                   j                          y r&   )r   clear_current_exception)r   s    r   handle_observed_exceptionr     s    2 OO++-r!   c                   t        | |      t        j                  j                  dd fd       t        j                  d       t        } |||||| d       y )Nartifactc                     dddS )Ndynamo_graph_break_reasonstring)re   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   contextexplanationhintsfrom_exclog_warning)format_error_msg_verboserW   _loggingtrace_structuredgraph_breaks_logdebugr   )ecoder   r   r   r   _unimplementedr   s          @r   unimplemented_with_warningr    sf      /q$7O	NN##
 + $  41"Nr!   c                
   t        j                  |d      j                         }dj                  d |D              }t        j                  |d      j                         }|  d| d| d| }t	        |       }|r|d| z  }|S )N    r   c              3  j   K   | ]+  }d t        j                  |d      j                         z    - yw)z  Hint: r  N)ri   indentlstrip).0hints     r   	<genexpr>z-format_graph_break_message.<locals>.<genexpr>  s.      @D
X__T6299;;s   13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_strrV   documentation_links          r   format_graph_break_messager    s     //+v6==?K		 HM I oogv.557G 		 
} 
 #9(C 5W=MN`MabbJr!   )maxsizec                    	 t        t              j                         j                  } t	        dt        |       d      }t        |      5 }t        j                  |      }ddd       i }j                         D ]  \  }}|D ]
  }|||d   <     |S # 1 sw Y   4xY w# t        $ r t        j                  d       i }Y Yw xY w)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_mapr-  "  s    
(^++-44
'J!<
 -  	$Ayy|H	$ G  *1 	*E()GE)$%	** N	$ 	$ 9:s*   AB 
B B BB  CCc                X    d}t               }| |v r| d||    j                  d       dS y)z
    Retrieves the GBID documentation link for a given graph break type.

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

    Returns:
        A string containing the documentation URL if found, otherwise None.
    z;https://meta-pytorch.github.io/compile-graph-break-site/gb/gbGBz.htmlN)r-  r  )r   GRAPH_BREAK_SITE_URLgb_type_to_gb_id_maps      r   r  r  =  sO     	F  67&&#$B';G'D'K'KD'Q&RRWX	
 r!   F)r  r  r   c                *   t        | |||      }|rt        j                  |       |t        urZd}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.
    NrZ   zJ

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

r   )	r  r"  warning_NOTHINGhasattrrZ   r   r   rV   )	r   r   r   r   r  r  r   rV   past_real_stacks	            r   r   r   X  s    ( %Wg{E
JCCx8\*&11Oh,\\N"pqtpuvCc7J?SS*
	 c7J
//r!   c                  $    e Zd ZddZddZddZy)KeyErrorMsgc                    || _         y r&   )r   )r+   r   s     r   r(   zKeyErrorMsg.__init__  s	    
r!   c                ,    t        | j                        S r&   )r^   r   r   s    r   __str__zKeyErrorMsg.__str__  s    4::r!   c                "    | j                         S r&   )r<  r   s    r   __repr__zKeyErrorMsg.__repr__  s    ||~r!   N)r   r   r/   r0   )r/   r^   )r1   r2   r3   r(   r<  r>  r:   r!   r   r9  r9    s    r!   r9  c                |    t        | d      r/|j                  d      }|d    d| j                   |d    |d    }|S )N	_hop_namez
  Explanation:r   z
  Higher Order Operator: r      )r6  	partitionr@  )excrV   liness      r   !augment_exc_message_with_hop_namerE    sQ     sK 01Qxj3CMM?58*USTXJW 	 Jr!   c                   dd l }d | _        t        |       }|>t        |      dkD  r0|d   | _        |ddj	                  |j                  |             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      rht        | j                  d      r5|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   | _        y ||z   }|f| j                  dd  z   | _        y )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').
rZ   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_enabledr6  rH  rr   r   rI  rJ  r,   r^   rE  r   KeyErrorr9  )rC  rV   exportrK  rZ   old_msgnew_msgs          r   augment_exc_messagerS    s   '+C$$J#j/A"5+5b>(%bggi.C.CJ.O&P%QRR##5F(G01D1D0E F++,E3	

 >>gc<8J	
 s%&7_, 3&&7/0C0C0Q0Q/R S0030C0C0P0P/QQSUC /0C0C0Q0Q/R S_ _C
 MQ&bC,<G/W=G#x #.0388AB<?C-:,r!   c                    d }d }| j                   ,| j                   j                  }| j                   j                  }|| _        ||fS r&   )rL  filenamelineno
compile_id)r  rW  rU  rV  s       r   get_exc_messagerX    sN     HF%%111:://66ALVr!   c                 (    t        t                     S r&   )filter_stackr   r:   r!   r   get_stack_above_dynamor[    s    ((r!   c                    t        | dd       }|y |t               }n
t               }t        j                  ||z         S )NrZ   )r}   r[  r   	from_list)rC  framerZ   stack_above_dynamos       r   rM  rM    sM     lD1J  45)^!!"4z"ABBr!   c                    t               }| D ]Z  }|j                  d|j                  v r |S d|j                  v s|j                  rd|j                  v rJ|j                  |       \ |S )Nconvert_frame
eval_frameztorch._dynamo.optimize()r   rU  lineappend)stack
user_stackr^  s      r   rZ  rZ    sv    J 	!>>!enn,  5>>)JJ4

B% 	! r!   c                h    ddl m} t        j                  | d|       }|r|j	                  d      S y )Nr   )TORCH_DYNAMO_RESUME_IN_PREFIXz_(\w+)_at_\d+)resume_executionrh  rematchgroup)re   rh  rk  s      r   remove_resume_prefixrm    s2    ?HH56oFME{{1~r!   c                    t               }| D ]X  }|j                  t        |j                        }|r!|r|d   j                  |k(  r||d<   ||_        H|j	                  |       Z |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>
    rG  )r   rU  rm  re   rd  )re  	new_stackr^  re   s       r   collapse_resume_framesrp    sq    ( I $>>!#EJJ/)B-"4"4"<!IbMEJU#$ r!   c                    d|j                    d|j                   d|j                   d}|dz  }|t               z  }t	        | |      }|,|dz  }|dj                  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	   rM  r  r
   )rC  r	  rH  r^  rV   rZ   s         r   r  r  3  s     a(8(8'9@S@S?TTVW  CCC:<CU+J	
 	rww{:.//txJr!   c           	     Z    t        | dd       dt        | dd       dt        | dd       dS )	Nrt  z	<unknown>z (ru  rs  rv  r   ))r}   )r	  s    r   format_frame_infory  N  sF    4K0
1 2D-56 7.231	6r!   c                6    | 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: )ry  )r	  reason
frame_infos      r   format_skip_frame_messager}  V  sB    &t,
DZL Qh 	
h 	
r!   c           	         t         j                  rt        | |||      S d|j                   d|j                   d|j
                   dt                S )Nrr  r   rs  z 
due to: 
)r   rr   r  rt  ru  rv  r	   )rC  r	  rH  r^  s       r   format_error_msgr  d  sW     ~~'T?EJJDLL>4+;+;*< ==8 8r!   )r   r^   r/   r^   )r   type[Exception]r/   ztype[ObservedException])
r   r  r   r   r,   zOptional[list[Any]]r-   zOptional[dict[str, Any]]r/   r   )r   r   r/   r0   )r  r   r	  types.CodeTyper   r^   r   r^   r   r^   r   	list[str]r/   r   )
r   r^   r   r^   r   r^   r   r  r/   r^   )r/   zdict[str, Any])r   r^   r/   r@   )r   r^   r   r^   r   r^   r   r  r  r   r  r   r   r   r/   r   )rC  r   rV   r^   r/   r^   )r   F)rC  r   rV   r^   rP  r   r/   r0   )r  r   rW  r   r/   z#tuple[Optional[str], Optional[int]])r/   r   r&   )rC  r   r^  Optional[DynamoFrameType]r/   r   )re  r   r/   r   )re   r^   r/   r@   )re  z!StackSummary | list[FrameSummary]r/   r   )NN)
rC  r   r	  r  rH  r@   r^  r  r/   r^   )r	  r  r/   r^   )r	  zOptional[types.CodeType]r{  r^   r/   r^   )
__future__r   r   loggingrj  ri   typingenumr   r   	functoolsr   pathlibr   rK  r   r	   r
   r   r   r   r   r   r   torch._guardsrW   torch._utils_internalr   r   r   utilsr   typesr   output_graphr   r   r   r   r   r    	getLoggerr1   r"  r  getArtifactLoggerr  RuntimeErrorr$   r8   r=   r?   rF   rH   rK   rM   rO   rQ   rS   rc   rg   rm   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   StopIterationLookupError
IndexErrorGeneratorExitrO  AttributeErrorNotImplementedError	TypeErrorr   r   r   r   _subclassesfake_tensorDataDependentOutputExceptionDynamicOutputShapeExceptionUnsupportedOperatorExceptionUnsupportedFakeTensorException$UnsupportedMutationAliasingException!exceptions_allowed_to_be_fallbackr  r  r-  r  objectr5  r   r9  rE  rS  rX  r[  rM  rZ  rm  rp  r  ry  r}  r  r:   r!   r   <module>r     sS   "2   	      X X 9 9  1   '0;9 g!>>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!   