a
    þd  ã                   @   sL   d Z ddlZddlmZ ddlZddlmZ ddlm	Z	 G dd„ de	ƒZ
dS )z{
Fault-Tolerance
^^^^^^^^^^^^^^^

Contains callbacks for fault-tolerance support. These are not meant to be used publicly.
é    N)ÚAny)Ú_PATH)Ú
Checkpointc                       sj   e Zd ZdZdZdeeddœ‡ fdd„Zeedœd	d
„ƒZ	de
e
ddœdd„Zde
e
ddœdd„Z‡  ZS )Ú_FaultToleranceCheckpointz7Used to save a fault-tolerance checkpoint on exception.z.ckptú.pl_auto_saveN)ÚdirpathÚfilenameÚreturnc                    s&   t ƒ  ¡  || _|stdƒ‚|| _d S )NzThe filename cannot be empty)ÚsuperÚ__init__r   Ú
ValueErrorr   )Úselfr   r   ©Ú	__class__© út/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pytorch_lightning/callbacks/fault_tolerance.pyr   !   s
    
z"_FaultToleranceCheckpoint.__init__)r	   c                 C   s   t j | j| j| j ¡S ©N)ÚosÚpathÚjoinr   r   ÚFILE_EXTENSION)r   r   r   r   Ú	ckpt_path)   s    z#_FaultToleranceCheckpoint.ckpt_pathz
pl.Trainer)ÚtrainerÚ_Ú__r	   c                 O   s   |  | j¡ d S r   )Zsave_checkpointr   ©r   r   r   r   r   r   r   Úon_exception-   s    z&_FaultToleranceCheckpoint.on_exceptionc                 O   s   |j  | j¡ d S r   )ZstrategyZremove_checkpointr   r   r   r   r   Úteardown1   s    z"_FaultToleranceCheckpoint.teardown)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ústrr   Úpropertyr   r   r   r   Ú__classcell__r   r   r   r   r      s   r   )r!   r   Útypingr   Zpytorch_lightningÚplZ lightning_fabric.utilities.typesr   Zpytorch_lightning.callbacksr   r   r   r   r   r   Ú<module>   s   