o
    Æ µiï!  ã                   @   s´   d dl Z d dlmZ d dlZd dlZd dlmZ e  d¡ e  	d¡Z
G dd„ dejƒZeƒ ZG dd	„ d	ƒZG d
d„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZdS )é    N)ÚAny)ÚENABLED_FEATURESTz,torch_tensorrt [TensorRT Conversion Context]c                   @   s0   e Zd Zd	dd„Zdejjdeddfdd„ZdS )
Ú
_TRTLoggerÚreturnNc                 C   s   t j | ¡ d S ©N)ÚtrtÚILoggerÚ__init__)Úself© r   úJ/home/ubuntu/.local/lib/python3.10/site-packages/torch_tensorrt/logging.pyr	      s   z_TRTLogger.__init__ÚseverityÚmsgc                 C   s”   |t jjjkrt |¡ t|ƒ‚|t jjjkrt |¡ d S |t jjj	kr,t 
|¡ d S |t jjjkr:t |¡ d S |t jjjkrHt |¡ d S d S r   )r   r   ÚSeverityÚINTERNAL_ERRORÚ_LOGGERÚcriticalÚRuntimeErrorÚERRORÚerrorÚWARNINGÚwarningÚINFOÚinfoÚVERBOSEÚdebug)r
   r   r   r   r   r   Úlog   s   
ÿz_TRTLogger.log©r   N)	Ú__name__Ú
__module__Ú__qualname__r	   r   r   r   Ústrr   r   r   r   r   r      s    
r   c                   @   ó4   e Zd ZdZddd„Zdedededdfd	d
„ZdS )Úinternal_errorszãContext-manager to limit displayed log messages to just internal errors

    Example:

        .. code-block:: py

            with torch_tensorrt.logging.internal_errors():
                outputs = model_torchtrt(inputs)
    r   Nc                 C   óx   t  ¡ | _t  tj¡ tjr"ddlm} | 	¡ | _
| |jj¡ d S tjr:tjj ¡ | _tjj ttjjjƒ¡ d S d S ©Nr   ©Úlogging)r   ÚgetEffectiveLevelÚexternal_lvlÚsetLevelr'   ÚCRITICALr   Útorchscript_frontendÚtorch_tensorrt.tsÚget_reportable_log_levelÚts_levelÚset_reportable_log_levelÚLevelÚInternalErrorÚtorch_tensorrt_runtimeÚtorchÚopsÚtensorrtÚget_logging_levelÚrt_levelÚset_logging_levelÚintr   r   r   r   ©r
   Ú
ts_loggingr   r   r   Ú	__enter__-   s   

ÿþzinternal_errors.__enter__Úexc_typeÚ	exc_valueÚexc_tbc                 C   óL   t  | j¡ tjrddlm} | | j¡ d S tj	r$t
jj | j¡ d S d S r%   ©r   r*   r)   r   r,   r-   r'   r0   r/   r3   r4   r5   r6   r9   r8   ©r
   r>   r?   r@   r<   r   r   r   Ú__exit__=   ó   ÿzinternal_errors.__exit__r   ©r   r   r    Ú__doc__r=   r   rD   r   r   r   r   r#   "   s    

r#   c                   @   r"   )ÚerrorszÛContext-manager to limit displayed log messages to just errors and above

    Example:

        .. code-block:: py

            with torch_tensorrt.logging.errors():
                outputs = model_torchtrt(inputs)
    r   Nc                 C   óx   t  ¡ | _t  tj¡ tjr"ddlm} | 	¡ | _
| |jj¡ d S tjr:tjj ¡ | _tjj ttjjjƒ¡ d S d S r%   )r   r(   r)   r*   r'   r   r   r,   r-   r.   r/   r0   r1   ÚErrorr3   r4   r5   r6   r7   r8   r9   r:   r   r   r   r;   r   r   r   r=   T   ó   

þzerrors.__enter__r>   r?   r@   c                 C   rA   r%   rB   rC   r   r   r   rD   b   rE   zerrors.__exit__r   rF   r   r   r   r   rH   I   ó    

rH   c                   @   r"   )ÚwarningszðContext-manager to limit displayed log messages to just warnings and above

    Example:

        .. code-block:: py

            with torch_tensorrt.logging.warnings():
                model_trt = torch_tensorrt.compile(model, **spec)
    r   Nc                 C   rI   r%   )r   r(   r)   r*   r'   r   r   r,   r-   r.   r/   r0   r1   ÚWarningr3   r4   r5   r6   r7   r8   r9   r:   r   r   r   r;   r   r   r   r=   y   rK   zwarnings.__enter__r>   r?   r@   c                 C   rA   r%   rB   rC   r   r   r   rD   ‡   rE   zwarnings.__exit__r   rF   r   r   r   r   rM   n   rL   rM   c                   @   r"   )r   zãContext-manager to display all info and greater severity messages

    Example:

        .. code-block:: py

            with torch_tensorrt.logging.info():
                model_trt = torch_tensorrt.compile(model, **spec)
    r   Nc                 C   rI   r%   )r   r(   r)   r*   r'   r   r   r,   r-   r.   r/   r0   r1   ÚInfor3   r4   r5   r6   r7   r8   r9   r:   r   r   r   r;   r   r   r   r=   ž   rK   zinfo.__enter__r>   r?   r@   c                 C   rA   r%   rB   rC   r   r   r   rD   ¬   rE   zinfo.__exit__r   rF   r   r   r   r   r   “   rL   r   c                   @   r"   )r   zçContext-manager to display full debug information through the logger

    Example:

        .. code-block:: py

            with torch_tensorrt.logging.debug():
                model_trt = torch_tensorrt.compile(model, **spec)
    r   Nc                 C   r$   r%   )r   r(   r)   r*   r'   ÚDEBUGr   r,   r-   r.   r/   r0   r1   ÚDebugr3   r4   r5   r6   r7   r8   r9   r:   r   r   r   r   r;   r   r   r   r=   Ã   rK   zdebug.__enter__r>   r?   r@   c                 C   rA   r%   rB   rC   r   r   r   rD   Ñ   rE   zdebug.__exit__r   rF   r   r   r   r   r   ¸   rL   r   c                   @   r"   )Úgraphsa#  Context-manager to display the results of intermediate lowering passes
    as well as full debug information through the logger

    Example:

        .. code-block:: py

            with torch_tensorrt.logging.graphs():
                model_trt = torch_tensorrt.compile(model, **spec)
    r   Nc                 C   s|   t  ¡ | _t  tj¡ tjr"ddlm} | 	¡ | _
| |jj¡ d S tjr<tjj ¡ | _tjj ttjjjƒd ¡ d S d S )Nr   r&   é   )r   r(   r)   r*   r'   ÚNOTSETr   r,   r-   r.   r/   r0   r1   ÚGraphr3   r4   r5   r6   r7   r8   r9   r:   r   r   r   r   r;   r   r   r   r=   é   s   

 þzgraphs.__enter__r>   r?   r@   c                 C   rA   r%   rB   rC   r   r   r   rD   ÷   rE   zgraphs.__exit__r   rF   r   r   r   r   rR   Ý   s    
rR   )r'   Útypingr   r6   r   r4   Útorch_tensorrt._featuresr   ÚcaptureWarningsÚ	getLoggerr   r   r   Ú
TRT_LOGGERr#   rH   rM   r   r   rR   r   r   r   r   Ú<module>   s    

'%%%%