
    '}hc)              	          d dl Z d dlZd dlmZmZ d dlmZmZmZm	Z	 d dl
mZmZmZ d dlZddlmZ ddlmZ d Zd dlZ ej,                  e      Zej2                  j5                  ed	      Z G d
 de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z# G d de      Z$ G d de      Z% G d de      Z& G d de      Z' G d  d!e      Z( G d" d#e'      Z) G d$ d%e'      Z* G d& d'e)      Z+ G d( d)e      Z, G d* d+e'      Z- G d, d-e      Z. G d. d/e/      Z0ejb                  jd                  jf                  ejb                  jd                  jh                  ejb                  jd                  jj                  ejb                  jd                  jl                  fZ7d0e/d1e8d2efd3Z9d1e8d2efd4Z:d1e8d2dfd5Z; G d6 d7      Z<d?d8e/d1e8d9e=d2dfd:Z>d@d8e/d2ee	   fd;Z?d< Z@	 dAd8e/d2e8fd=ZAdAd8e/d2e8fd>ZBy)B    N)autoEnum)extract_stack
format_excformat_listStackSummary)castNoReturnOptional   )config)countersc                 ,    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    P/var/www/html/test/engine/venv/lib/python3.12/site-packages/torch/_dynamo/exc.pyexportdb_error_messager      s"    	I


C
%	&    graph_breaksc                       e Zd Zy)TorchDynamoExceptionN__name__
__module____qualname__ r   r   r   r          r   r   c                       e Zd Zy)InternalTorchDynamoErrorNr   r   r   r   r!   r!       r   r   r!   c                       e Zd Zy)RestartAnalysisNr   r   r   r   r#   r#   $   r   r   r#   c                       e Zd Zy)SpeculationRestartAnalysisNr   r   r   r   r%   r%   (   r   r   r%   c                       e Zd Zy)UnspecializeRestartAnalysisNr   r   r   r   r'   r'   ,   r   r   r'   c                       e Zd Zy)	SkipFrameNr   r   r   r   r)   r)   0   r   r   r)   c                       e Zd Zy)TorchRuntimeErrorNr   r   r   r   r+   r+   4   r   r   r+   c                        e Zd Z fdZ xZS )InvalidBackendc                 ,    t         |   d|d       y )NzInvalid backend: z=, see `torch._dynamo.list_backends()` for available backends.super__init__)selfname	__class__s     r   r1   zInvalidBackend.__init__9   s    x'de	
r   r   r   r   r1   __classcell__r4   s   @r   r-   r-   8   s    
 
r   r-   c                        e Zd Z 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.
                )r0   r1   textwrapdedent)r2   r4   s    r   r1   zResetRequired.__init__@   s!    OO	
r   r5   r7   s   @r   r9   r9   ?   s    
 
r   r9   c                        e Zd Z fdZ xZS )BackendCompilerFailedc                     t        |dd      | _        || _        d| j                  dt        |      j                   d| }t
        |   |       y )Nr   ?zbackend=z	 raised:
z: )getattrbackend_nameinner_exceptiontyper   r0   r1   )r2   
backend_fnrC   msgr4   s       r   r1   zBackendCompilerFailed.__init__L   sW    #J
C@.**-Z_8M8V8V7WWYZiYjkr   r5   r7   s   @r   r>   r>   K   s     r   r>   c                   ,     e Zd Z fdZd ZddZ xZS )Unsupportedc                     t         |   |       t        j                  j                  j                         | _        || _        d | _        | j                          y N)
r0   r1   torch_guardsTracingContextr   
real_stackrF   categoryadd_to_statsr2   rF   r4   s     r   r1   zUnsupported.__init__T   sD    --66DDF'+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   rO   r   rF   r2   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   rS   )r2   rO   s     r   rP   zUnsupported.add_to_statsa   s"     488$)$r   )unimplemented)r   r   r   r1   rU   rP   r6   r7   s   @r   rH   rH   S   s    2*r   rH   c                       e Zd Zy)RecompileErrorNr   r   r   r   rY   rY   f   r   r   rY   c                        e Zd Z fdZ xZS )ArgsMismatchErrorc                 $    t         |   |       y rJ   r/   rQ   s     r   r1   zArgsMismatchError.__init__k       r   r5   r7   s   @r   r[   r[   j        r   r[   c                        e Zd Z fdZ xZS )AttributeMutationErrorc                 $    t         |   |       y rJ   r/   rQ   s     r   r1   zAttributeMutationError.__init__p   r]   r   r5   r7   s   @r   r`   r`   o   r^   r   r`   c                   "     e Zd ZdZ fdZ xZS )CondOpArgsMismatchErrorz?
    Internal error from cond() due to arguments mismatch.
    c                 $    t         |   |       y rJ   r/   rQ   s     r   r1   z CondOpArgsMismatchError.__init__y   r]   r   )r   r   r   __doc__r1   r6   r7   s   @r   rc   rc   t   s     r   rc   c                   n    e Zd Z e       Z e       Z e       Z e       Z e       Z e       Z	 e       Z
y)UserErrorTypeN)r   r   r   r   DYNAMIC_CONTROL_FLOWANTI_PATTERNSTANDARD_LIBRARYCONSTRAINT_VIOLATIONDYNAMIC_DIMINVALID_INPUTINVALID_OUTPUTr   r   r   rg   rg   }   s6    66Lv6&KFMVNr   rg   c                   &     e Zd Zddef fdZ xZS )	UserError
error_typec                     |<t        |t              sJ |j                  d      r|dz  }n|dz  }|t        |      z  }t        |   |       || _        || _        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. 
)
isinstancestrendswithr   r0   r1   rq   message)r2   rq   rF   r   r4   s       r   r1   zUserError.__init__   sd      i---||C s
t))44C$r   rJ   )r   r   r   rg   r1   r6   r7   s   @r   rp   rp      s    =  r   rp   c                       e Zd Zy)UncapturedHigherOrderOpErrorNr   r   r   r   r{   r{      r   r   r{   c                       e Zd Zy)IncorrectUsageNr   r   r   r   r}   r}      r   r   r}   erF   returnc                     t        | |      }t        j                  d|       t        j	                  |       t        |      | )Nz%s)format_error_msg_verbosegraph_breaks_logdebuglogwarningrW   )r~   coderF   graph_break_msgs       r   unimplemented_with_warningr      s9     /q$7O41KK

!#r   c                 b    | t         j                  j                  dd      k7  sJ t        |       )NBREAKF)osenvirongetrH   rF   s    r   rW   rW      s*    "**..%0000
c
r   c                 v    t         d   | xx   dz  cc<   | t        j                  j                  dd      k7  sJ y )Nwarningsr   r   F)r   r   r   r   r   s    r   r   r      s4    Z""**..%0000r   c                   $    e Zd Zd Zd ZdefdZy)KeyErrorMsgc                     || _         y rJ   )value)r2   r   s     r   r1   zKeyErrorMsg.__init__   s	    
r   c                 ,    t        | j                        S rJ   )rw   r   rT   s    r   __str__zKeyErrorMsg.__str__   s    4::r   r   c                 "    | j                         S rJ   )r   rT   s    r   __repr__zKeyErrorMsg.__repr__   s    ||~r   N)r   r   r   r1   r   rw   r   r   r   r   r   r      s    # r   r   excexportc                    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                  s|s|dz  }t        | j                        dk(  rdnt!        | j                  d         }t#        | t$              r%t'        ||z         f| j                  dd  z   | _        y ||z   }|f| j                  dd  z   | _        y )Nr   z
from user code:
  record_filenamez!
Last frame execution written to zD. To run only this frame while debugging, run torch._dynamo.replay('z').
rN   zI
Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information
rC   minifier_pathbuck_commandz
Minifier script written to zW. Run this buck command to find the smallest traced graph which reproduces this error: ru   zQ. Run this script to find the smallest traced graph which reproduces this error.
z

You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True
r   )	tracebackinnermost_user_frame_summaryget_real_stacklenjoinr   r   replay_record_enabledhasattrr   verboserC   r   r   suppress_errorsargsrw   rv   KeyErrorr   )r   rF   r   r   rN   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3C4G4G3H I++,E3 	3 >>gc<8\\s%&7_, 3&&7/0C0C0Q0Q/R S0030C0C0P0P/QQSUC /0C0C0Q0Q/R S_ _C
 !!&@	
 MQ&bC,<G#x #.0388AB<?C-:,r   c                 v    t        | dd       }|y g }|t        t                     }t        t        ||z         S )NrN   )rA   filter_stackr   r	   r   )r   framerN   stack_above_dynamos       r   r   r     sI    lD1J  *-/:0:=>>r   c                     g }| D ]A  }d|j                   v r |S d|j                   v sd|j                  v r1|j                  |       C |S )Nconvert_frame
eval_frameztorch._dynamo.optimize()filenamelineappend)stack
user_stackr   s      r   r   r   "  s`    J !enn,
 	 5>>)-F%**-T% ! 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 rt    line ru   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   )r   r   r   r   rF   rN   s         r   r   r   .  s     a(8(8'9@S@S?TTVW  CCC:<CU+J	
 	rww{:.//txJr   c           	          t         j                  dz  }t        j                  rt	        | |||      }|S d|j
                   d|j                   d|j                   dt                }|S )N   r   rt   r   z 
due to: 
)	r   linesepr   r   r   r   r   r   r   )r   r   r   r   rF   s        r   format_error_msgr   F  so    
**q.C~~&sD/5I
 J t||nAd.>.>-? @=8 Jr   )ru   FrJ   )NN)Cr   r;   enumr   r   r   r   r   r   r   typingr	   r
   r   torch._guardsrK   r   r   utilsr   r   logging	getLoggerr   r   _logginggetArtifactLoggerr   RuntimeErrorr   r!   r#   r%   r'   r)   r+   r-   r9   r>   rH   rY   r[   r`   rc   rg   rp   r{   	Exceptionr}   _subclassesfake_tensorDataDependentOutputExceptionDynamicOutputShapeExceptionUnsupportedOperatorExceptionUnsupportedFakeTensorException!exceptions_allowed_to_be_fallbackrw   r   rW   r   r   boolr   r   r   r   r   r   r   r   <module>r      s[   	   J J + +    g!>>33HnM 	< 		3 		* 		 		/ 		$ 		, 	
) 
	
( 	
0 *& *&	) 	 
[ 
/ D  ,	#7 		Y 	 
!!>>	!!==	!!>>	!!@@	% !$) $ $ $s x 
1 1 1 .-Y .-S .- .-RV .-b?	 ?(<2H ?<	 7;	0	) 	PS 	r   