o
    "i&                     @   sD  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 d dlZddlmZ ddlmZ ddlmZ e rDd d	lmZ nd
d Zd dlZeeZejedZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#G dd deZ$G dd deZ%G dd deZ&G dd  d eZ'G d!d" d"e&Z(G d#d$ d$e&Z)G d%d& d&e(Z*G d'd( d(eZ+G d)d* d*e&Z,G d+d, d,e-Z.ej/j0j1ej/j0j2ej/j0j3ej/j0j4fZ5d-d. Z6d/e7fd0d1Z8d/e7fd2d3Z9G d4d5 d5Z:dCd8d9Z;dDd:ee	 fd;d<Z<d=d> Z=dEd?d@Z>dEdAdBZ?dS )F    N)autoEnum)extract_stack
format_excformat_listStackSummary)castOptional   )config)	is_fbcode)counters)exportdb_error_messagec                 C   s   dS )N  )	case_namer   r   `/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torch/_dynamo/exc.pyr      s   r   Zgraph_breaksc                   @      e Zd ZdS )TorchDynamoExceptionN__name__
__module____qualname__r   r   r   r   r          r   c                   @   r   )InternalTorchDynamoErrorNr   r   r   r   r   r       r   r   c                   @   r   )RestartAnalysisNr   r   r   r   r   r   $   r   r   c                   @   r   )	SkipFrameNr   r   r   r   r   r   (   r   r   c                   @   r   )TorchRuntimeErrorNr   r   r   r   r   r   ,   r   r   c                          e Zd Z fddZ  ZS )InvalidBackendc                    s   t  d|d d S )NzInvalid backend: z=, see `torch._dynamo.list_backends()` for available backends.super__init__)selfname	__class__r   r   r"   1   s   
zInvalidBackend.__init__r   r   r   r"   __classcell__r   r   r%   r   r   0       r   c                       r   )ResetRequiredc                    s   t  t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r#   r%   r   r   r"   8   s
   zResetRequired.__init__r'   r   r   r%   r   r*   7   r)   r*   c                       r   )BackendCompilerFailedc                    sB   t |dd| _|| _d| jdt|j d| }t | d S )Nr   ?zbackend=z	 raised:
z: )getattrbackend_nameinner_exceptiontyper   r!   r"   )r#   Z
backend_fnr2   msgr%   r   r   r"   D   s   zBackendCompilerFailed.__init__r'   r   r   r%   r   r.   C   r)   r.   c                       s.   e Zd Z fddZdd ZdddZ  ZS )	Unsupportedc                    s2   t  | tjj | _|| _d | _| 	  d S N)
r!   r"   torchZ_guardsZTracingContextr   
real_stackr4   categoryadd_to_statsr#   r4   r%   r   r   r"   L   s
   zUnsupported.__init__c                 C   sB   t | j | j  d8  < t | j | j dkrt | j | j= d S d S )Nr
   r   )r   r9   r4   r-   r   r   r   remove_from_statsS   s   zUnsupported.remove_from_statsunimplementedc                 C   s    || _ t| | j  d7  < d S )Nr
   )r9   r   r4   )r#   r9   r   r   r   r:   X   s   zUnsupported.add_to_stats)r=   )r   r   r   r"   r<   r:   r(   r   r   r%   r   r5   K   s    r5   c                   @   r   )RecompileErrorNr   r   r   r   r   r>   ]   r   r>   c                       r   )ArgsMismatchErrorc                       t  | d S r6   r    r;   r%   r   r   r"   b      zArgsMismatchError.__init__r'   r   r   r%   r   r?   a   r)   r?   c                       r   )AttributeMutationErrorc                    r@   r6   r    r;   r%   r   r   r"   g   rA   zAttributeMutationError.__init__r'   r   r   r%   r   rB   f   r)   rB   c                       s    e Zd ZdZ fddZ  ZS )CondOpArgsMismatchErrorz?
    Internal error from cond() due to arguments mismatch.
    c                    r@   r6   r    r;   r%   r   r   r"   p   rA   z CondOpArgsMismatchError.__init__)r   r   r   __doc__r"   r(   r   r   r%   r   rC   k   s    rC   c                   @   s0   e Zd Ze Ze Ze Ze Ze Ze Z	dS )UserErrorTypeN)
r   r   r   r   ZDYNAMIC_CONTROL_FLOWZANTI_PATTERNZSTANDARD_LIBRARYZCONSTRAIN_VIOLATIONZDYNAMIC_DIMZINVALID_INPUTr   r   r   r   rE   t   s    
rE   c                       s$   e Zd Zddef fddZ  ZS )	UserErrorN
error_typec                    s>   |durt |tsJ |t|7 }t | || _|| _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)
isinstancestrr   r!   r"   rG   message)r#   rG   r4   r   r%   r   r   r"   ~   s   	
zUserError.__init__r6   )r   r   r   rE   r"   r(   r   r   r%   r   rF   }   s    rF   c                   @   r   )IncorrectUsageNr   r   r   r   r   rK      r   rK   c                 C   s*   t | |}td| t| t|| )Nz%s)format_error_msg_verbosegraph_breaks_logdebuglogwarningr=   )ecoder4   Zgraph_break_msgr   r   r   unimplemented_with_warning   s   


rS   r4   c                 C   s   | t jddksJ t| )NBREAKF)osenvirongetr5   r4   r   r   r   r=      s   r=   c                 C   s.   t d |   d7  < | tjddksJ d S )Nwarningsr
   rT   F)r   rU   rV   rW   rX   r   r   r   rP      s   rP   c                   @   s*   e Zd Zdd Zdd ZdefddZdS )	KeyErrorMsgc                 C   s
   || _ d S r6   )value)r#   r[   r   r   r   r"         
zKeyErrorMsg.__init__c                 C   s
   t | jS r6   )rI   r[   r-   r   r   r   __str__   r\   zKeyErrorMsg.__str__returnc                 C   s   |   S r6   )r]   r-   r   r   r   __repr__   s   zKeyErrorMsg.__repr__N)r   r   r   r"   r]   rI   r_   r   r   r   r   rZ      s    rZ   
Fc                 C   sN  dd l }t| }|d ur|dd|t|  7 }tjr0t| dr0|d| j d| j d7 }tjs<t| dr<|d	7 }t| d
rgt| j	drgt| j	dr]|d| j	j
 d| j	j d7 }n
|d| j	j
 d7 }tjsp|sp|d7 }t| jdkrydnt| jd }t| trt|| f| jdd   | _d S || }|f| jdd   | _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').
r8   zI
Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information
r2   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.
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   Zreplay_record_enabledhasattrra   verboser2   rb   rc   Zsuppress_errorslenargsrI   rH   KeyErrorrZ   )excr4   Zexportrd   r8   Zold_msgZnew_msgr   r   r   augment_exc_message   sB   

 
"rm   r^   c                 C   s<   t | dd }|d u rd S g }|d urtt }tt|| S )Nr8   )r0   filter_stackr   r   r   )rl   framer8   Zstack_above_dynamor   r   r   re      s   
re   c                 C   sB   g }| D ]}d|j v r |S d|j v sd|jv rq|| q|S )NZconvert_frameZ
eval_frameztorch._dynamo.optimize()filenamelineappend)stackZ
user_stackro   r   r   r   rn     s   
rn   c                 C   sp   d|j  d|j d|j d}|d7 }|t 7 }t| |}|d ur6|d7 }|dt|7 }|d7 }|d7 }|S )	NWON'T CONVERT   line r`   z.========== TorchDynamo Stack Trace ==========
zY
========== The above exception occurred while processing the following code ==========

r   z
==========)co_nameco_filenameco_firstlinenor   re   rf   r   )rl   rR   ra   ro   r4   r8   r   r   r   rL     s   

rL   c              
   C   sN   t jd }tjrt| |||}|S d|j d|j d|j dtdd }|S )N   rt   ru   rv   z 
due to: 
)limit)	rU   linesepr   rh   rL   rw   rx   ry   r   )rl   rR   ra   ro   r4   r   r   r   format_error_msg1  s   
r~   )r`   Fr6   )NN)@rU   r+   enumr   r   rd   r   r   r   r   typingr   r	   Ztorch._guardsr7   r   r   r   utilsr   Ztorch.fb.exportdb.loggingr   logging	getLoggerr   rO   Z_loggingZgetArtifactLoggerrM   RuntimeErrorr   r   r   r   r   r   r*   r.   r5   r>   r?   rB   rC   rE   rF   	ExceptionrK   Z_subclassesZfake_tensorZDataDependentOutputExceptionZDynamicOutputShapeExceptionZUnsupportedOperatorExceptionZUnsupportedFakeTensorExceptionZ!exceptions_allowed_to_be_fallbackrS   rI   r=   rP   rZ   rm   re   rn   rL   r~   r   r   r   r   <module>   sZ    
		
0
