U
    <cW                     @  s   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	d
dddg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dS )zONNX exporter exceptions.    )annotationsN)Optional)_C)
_constants)diagnosticsOnnxExporterErrorOnnxExporterWarningCallHintViolationWarningCheckerErrorUnsupportedOperatorErrorSymbolicValueErrorc                   @  s   e Zd ZdZdS )r   z1Base class for all warnings in the ONNX exporter.N__name__
__module____qualname____doc__ r   r   5/tmp/pip-unpacked-wheel-gikjz4vx/torch/onnx/errors.pyr      s   c                   @  s   e Zd ZdZdS )r	   zCWarning raised when a type hint is violated during a function call.Nr   r   r   r   r   r	      s   c                   @  s   e Zd ZdZdS )r   z#Errors raised by the ONNX exporter.Nr   r   r   r   r   r   !   s   c                   @  s   e Zd ZdZdS )r
   z2Raised when ONNX checker detects an invalid model.Nr   r   r   r   r   r
   '   s   c                      s,   e Zd ZdZddddd fddZ  ZS )r   z7Raised when an operator is unsupported by the exporter.strintzOptional[int])domainop_nameversionsupported_versionc                   s   |dkrd| d| d| d}|d k	rd|d| d7 }t jjt jjt jj| d| ||fd q|d	7 }|tj7 }t jjt jj	t jj| d| |tjfd n8d
| d| d}t jjt jj
t jj| d| fd t | d S )N>    atenprim	quantizedzExporting the operator 'z::z' to ONNX opset version z is not supported. z/Support for this operator was added in version z", try exporting with this version.)Zmessage_argszPPlease feel free to request support or submit a pull request on PyTorch GitHub: z?ONNX export failed on an operator with unrecognized namespace 'zp'. If you are trying to export a custom operator, make sure you registered it with the right domain and version.)r   contextZdiagnoserulesZ)operator_supported_in_newer_opset_versionlevelsERRORr   ZPYTORCH_GITHUB_ISSUES_URLZ"missing_standard_symbolic_functionZ missing_custom_symbolic_functionsuper__init__)selfr   r   r   r   msg	__class__r   r   r#   0   s@    


z!UnsupportedOperatorError.__init__r   r   r   r   r#   __classcell__r   r   r&   r   r   -   s   c                      s(   e Zd ZdZddd fddZ  ZS )r   z+Errors around TorchScript values and nodes.r   z_C.Value)r%   valuec              
     s   | d| d|   d|   d}|  }|rH|d| d7 }zl|d7 }|tdd	d
d t|  D p|d d	 d d	dd t| 	 D pd d7 }W n t
k
r   |d7 }Y nX t | d S )Nz  [Caused by the value 'z	' (type 'z;') in the TorchScript graph. The containing node has kind 'z'.] z
    (node defined in )z

zInputs:

c                 s  s.   | ]&\}}d | d| d|   dV  qdS z    #z: z	  (type 'z')Ntype).0iZinput_r   r   r   	<genexpr>u   s   z.SymbolicValueError.__init__.<locals>.<genexpr>z	    Emptyz	Outputs:
c                 s  s.   | ]&\}}d | d| d|   dV  qdS r-   r.   )r0   r1   outputr   r   r   r2   ~   s   z    zv Failed to obtain its input and output for debugging. Please refer to the TorchScript graph for debugging information.)r/   nodekindZsourceRangetextwrapindentjoin	enumerateinputsoutputsAttributeErrorr"   r#   )r$   r%   r*   messageZcode_locationr&   r   r   r#   d   s<    &
	


zSymbolicValueError.__init__r(   r   r   r&   r   r   a   s   )r   
__future__r   r6   typingr   Ztorchr   Z
torch.onnxr   Ztorch.onnx._internalr   __all__UserWarningr   r	   RuntimeErrorr   r
   r   r   r   r   r   r   <module>   s&   
4