U
    ©Ê¹jä  ã                   @   sd   d dl mZmZmZ d dlZeeejf ZdgZ	eedœdd„Z
eedœdd	„ZG d
d„ deƒZdS )é    )ÚDictÚTupleÚAnyNÚCheckpointException)ÚexcÚreturnc                 C   s   | t  | j¡fS ©N)ÚtbÚ
extract_tbÚ__traceback__)r   © r   ú_/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/distributed/checkpoint/api.pyÚ_wrap_exception	   s    r   )Úobjr   c                 C   s<   t | tƒsdS t| ƒdkrdS t | d tƒo:t | d tjƒS )NFé   r   é   )Ú
isinstanceÚtupleÚlenÚBaseExceptionr	   ÚStackSummary)r   r   r   r   Ú_is_wrapped_exception   s    
 ÿr   c                       sR   e Zd ZdZeeeef dœ‡ fdd„Ze	eeef dœdd„ƒZ
dd	„ Z‡  ZS )
r   zX
    Exception raised if failure was detected as part of a checkpoint load or save.
    )ÚmsgÚfailuresc                    s   t ƒ  ||¡ || _d S r   )ÚsuperÚ__init__Ú	_failures)Úselfr   r   ©Ú	__class__r   r   r      s    zCheckpointException.__init__)r   c                 C   s   | j S )z—
        Returns:
            Dict of failed nodes and their associated exception.
              Keys are node ranks and values are exceptions
        )r   )r   r   r   r   r       s    zCheckpointException.failuresc                 C   sz   d| j  ¡ › d�}| j  ¡ D ]X\}}|\}}|d|› d�7 }|d k	rX|d t |¡¡7 }|d tjt|ƒ|d�¡7 }q|S )NzCheckpointException ranks:Ú
z)Traceback (most recent call last): (RANK z)
Ú )Úvalue)r   ÚkeysÚitemsÚjoinr	   Úformat_listÚformat_exception_onlyÚtype)r   ÚstrZrankZexc_pairr   Útracer   r   r   Ú__str__)   s    zCheckpointException.__str__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r   ÚintÚWRAPPED_EXCEPTIONr   Úpropertyr   r+   Ú__classcell__r   r   r   r   r      s
   )Útypingr   r   r   Ú	tracebackr	   r   r   r1   Ú__all__r   Úboolr   r   r   r   r   r   Ú<module>   s   
