o
    ci	                     @   s|   d dl Z d dlZd dlZd dlmZ d dlZd dlmZm	Z	 d dl
mZmZ d dlmZ e ZeddG dd	 d	eZdS )
    N)Path)TagKeyrecord_extra_usage_tag)RayTrainReportCallbackimport_lightning)	PublicAPIbeta)	stabilityc                   @   s   e Zd ZdZdddZdS )r   u7  A simple callback that reports checkpoints to Ray on train epoch end.

    This callback is a subclass of `lightning.pytorch.callbacks.Callback
    <https://lightning.ai/docs/pytorch/stable/api/lightning.pytorch.callbacks.Callback.html#lightning.pytorch.callbacks.Callback>`_.

    It fetches the latest `trainer.callback_metrics` and reports together with
    the checkpoint on each training epoch end.

    Checkpoints will be saved in the following structure:

        checkpoint_{timestamp}/      Ray Train's checkpoint folder
        └─ checkpoint.ckpt           Lightning's checkpoint format

    For customized reporting and checkpointing logic, implement your own
    `lightning.pytorch.callbacks.Callback` following this user
    guide: :ref:`Saving and Loading Checkpoints <train-dl-saving-checkpoints>`.
    returnNc                 C   s~   t   }t j  }t j  | _tt	
 d| d|  | _tj| jr7| jdkr7t| j ttjd d S )Nzlightning_checkpoints-job_id=z-name=r   1)rayget_runtime_context
get_job_idtrainget_contextget_experiment_nameget_local_rank
local_rankr   tempfile
gettempdiras_posixtmpdir_prefixospathisdirshutilrmtreer   r   &TRAIN_LIGHTNING_RAYTRAINREPORTCALLBACK)selfjob_idexperiment_name r!   Z/home/ubuntu/.local/lib/python3.10/site-packages/ray/train/v2/lightning/lightning_utils.py__init__%   s   	zRayTrainReportCallback.__init__)r
   N)__name__
__module____qualname____doc__r#   r!   r!   r!   r"   r      s    r   )r   r   r   pathlibr   	ray.trainr   ray._private.usage.usage_libr   r   $ray.train.lightning._lightning_utilsr   RayTrainReportCallbackV1r   ray.utilr   plr!   r!   r!   r"   <module>   s    