
    Phh*              	       F   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dlmZ  e       rd d	lmZ nd
 Zd dlZ ej0                  e      Zej6                  j9                  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      Z0 G d0 d1e1      Z2ejf                  jh                  jj                  ejf                  jh                  jl                  ejf                  jh                  jn                  ejf                  jh                  jp                  fZ9d2e1d3e:d4efd5Z;d3e:d4efd6Z<d3e:d4dfd7Z= G d8 d9      Z>dAd:e1d3e:d;e?d4dfd<Z@dBd:e1d4ee	   fd=ZAd> ZB	 dCd:e1d4e:fd?ZCdCd:e1d4e:fd@ZDy)D    N)autoEnum)extract_stack
format_excformat_listStackSummary)castNoReturnOptional   )config)	is_fbcode)counters)exportdb_error_messagec                 ,    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    \C:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/exc.pyr   r      s"    MS)*	
    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(   0   r    r   r(   c                       e Zd Zy)	SkipFrameNr   r   r   r   r*   r*   4   r    r   r*   c                       e Zd Zy)TorchRuntimeErrorNr   r   r   r   r,   r,   8   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   r2   zInvalidBackend.__init__=   s    x'de	
r   r   r   r   r2   __classcell__r5   s   @r   r.   r.   <   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.
                )r1   r2   textwrapdedent)r3   r5   s    r   r2   zResetRequired.__init__D   s!    OO	
r   r6   r8   s   @r   r:   r:   C   s    
 
r   r:   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   r1   r2   )r3   
backend_fnrD   msgr5   s       r   r2   zBackendCompilerFailed.__init__P   sW    #J
C@.**-Z_8M8V8V7WWYZiYjkr   r6   r8   s   @r   r?   r?   O   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)
r1   r2   torch_guardsTracingContextr   
real_stackrG   categoryadd_to_statsr3   rG   r5   s     r   r2   zUnsupported.__init__X   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   rP   r   rG   r3   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   rT   )r3   rP   s     r   rQ   zUnsupported.add_to_statse   s"     488$)$r   )unimplemented)r   r   r   r2   rV   rQ   r7   r8   s   @r   rI   rI   W   s    2*r   rI   c                       e Zd Zy)RecompileErrorNr   r   r   r   rZ   rZ   j   r    r   rZ   c                        e Zd Z fdZ xZS )ArgsMismatchErrorc                 $    t         |   |       y rK   r0   rR   s     r   r2   zArgsMismatchError.__init__o       r   r6   r8   s   @r   r\   r\   n        r   r\   c                        e Zd Z fdZ xZS )AttributeMutationErrorc                 $    t         |   |       y rK   r0   rR   s     r   r2   zAttributeMutationError.__init__t   r^   r   r6   r8   s   @r   ra   ra   s   r_   r   ra   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 rK   r0   rR   s     r   r2   z CondOpArgsMismatchError.__init__}   r^   r   )r   r   r   __doc__r2   r7   r8   s   @r   rd   rd   x   s     r   rd   c                   `    e Zd 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_INPUTr   r   r   rh   rh      s/    66Lv6&KFMr   rh   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   r1   r2   rq   message)r3   rq   rG   r   r5   s       r   r2   zUserError.__init__   sd      i---||C s
t))44C$r   rK   )r   r   r   rh   r2   r7   r8   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}   erG   returnc                     t        | |      }t        j                  d|       t        j	                  |       t        |      | )Nz%s)format_error_msg_verbosegraph_breaks_logdebuglogwarningrX   )r~   coderG   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getrI   rG   s    r   rX   rX      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 rK   )value)r3   r   s     r   r2   zKeyErrorMsg.__init__   s	    
r   c                 ,    t        | j                        S rK   )rw   r   rU   s    r   __str__zKeyErrorMsg.__str__   s    4::r   r   c                 "    | j                         S rK   )r   rU   s    r   __repr__zKeyErrorMsg.__repr__   s    ||~r   N)r   r   r   r2   r   rw   r   r   r   r   r   r      s    # r   r   excexportc                 v   dd l }t        |       }|&|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').
rO   zI
Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information
rD   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get_real_stackjoinr   r   replay_record_enabledhasattrr   verboserD   r   r   suppress_errorslenargsrw   rv   KeyErrorr   )r   rG   r   r   rO   old_msgnew_msgs          r   augment_exc_messager      s   $J%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 )NrO   )rB   filter_stackr   r	   r   )r   framerO   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   rG   rO   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   rG   s        r   format_error_msgr   F  so    
**q.C~~&sD/5I
 J t||nAd.>.>-? @=8 Jr   )ru   FrK   )NN)Er   r<   enumr   r   r   r   r   r   r   typingr	   r
   r   torch._guardsrL   r   r   r   utilsr   torch.fb.exportdb.loggingr   logging	getLoggerr   r   _logginggetArtifactLoggerr   RuntimeErrorr   r"   r$   r&   r(   r*   r,   r.   r:   r?   rI   rZ   r\   ra   rd   rh   rp   r{   	Exceptionr}   _subclassesfake_tensorDataDependentOutputExceptionDynamicOutputShapeExceptionUnsupportedOperatorExceptionUnsupportedFakeTensorException!exceptions_allowed_to_be_fallbackrw   r   rX   r   r   boolr   r   r   r   r   r   r   r   <module>r      sf   	   J J + +    ;@
 g!>>33HnM 	< 		3 		* 		 		/ 		$ 		, 	
) 
	
( 	
0 *& *&	) 	 
[ 
/ D  ,	#7 		Y 	 
!!>>	!!==	!!>>	!!@@	% !$) $ $ $s x 
1 1 1 +-Y +-S +- +-RV +-\?	 ?(<2H ?<	 7;	0	) 	PS 	r   