class_docstr: 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_00000*/      Ray Train Checkpoint
      └─ checkpoint.ckpt      PyTorch Lightning Checkpoint
  
  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>`.
class_docstr_tok: ["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_00000","*","\/","Ray","Train","Checkpoint","\u2514\u2500","checkpoint.ckpt","PyTorch","Lightning","Checkpoint","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",">","`","."]
code: def __init__(self) -> None:
      super().__init__()
      self.trial_name = train.get_context().get_trial_name()
      self.local_rank = train.get_context().get_local_rank()
      self.tmpdir_prefix = os.path.join(
          tempfile.gettempdir(), self.trial_name
      )
      if os.path.isdir(self.tmpdir_prefix) and self.local_rank == 0:
          shutil.rmtree(self.tmpdir_prefix)
  
      record_extra_usage_tag(
          TagKey.TRAIN_LIGHTNING_RAYTRAINREPORTCALLBACK, "1"
      )
  
imports: import logging
  import os
  import shutil
  import tempfile
  from typing import Any, Dict
  import torch
  from packaging.version import Version
  import ray
  from ray import train
  from ray._private.usage.usage_lib import TagKey, record_extra_usage_tag
  from ray.train import Checkpoint
  from ray.util import PublicAPI
label_desc: Use image node_id 1 to create a new RayTrainReportCallback object from inherited base classes: pl.callbacks with example: obj = RayTrainReportCallback()