class_docstr: Class to load and save models and their checkpoints during training.
class_docstr_tok: ["Class","to","load","and","save","models","and","their","checkpoints","during","training","."]
docstr: Method to check if the model path exists to load models
  or checkpoints.
  
  Args:
      config (ConfigType): the config object, contains info of the model
      is_checkpoint (bool): if True, the path is for a checkpoint
      current_epoch (Optional[int]): the current epoch.
          is is_checkpoint is True, and current_epoch is None,
          it will look for the last checkpoint and return it.
  
  Returns:
      path (Optional[str]): the path to the model. If is_checkpoint is
          True, and current_epoch is None, search for the last checkpoint
          and return it. If no checkpoint is found, return None.
      epoch (Optional[int]): the epoch of the checkpoint if an actual
          checkpoint is found. If no checkpoint is found, return None.
docstr_tok: ["Method","to","check","if","the","model","path","exists","to","load","models","or","checkpoints",".","Args",":","config","(","ConfigType",")",":","the","config","object",",","contains","info","of","the","model","is_checkpoint","(","bool",")",":","if","True",",","the","path","is","for","a","checkpoint","current_epoch","(","Optional","[","int","]",")",":","the","current","epoch",".","is","is_checkpoint","is","True",",","and","current_epoch","is","None",",","it","will","look","for","the","last","checkpoint","and","return","it",".","Returns",":","path","(","Optional","[","str","]",")",":","the","path","to","the","model",".","If","is_checkpoint","is","True",",","and","current_epoch","is","None",",","search","for","the","last","checkpoint","and","return","it",".","If","no","checkpoint","is","found",",","return","None",".","epoch","(","Optional","[","int","]",")",":","the","epoch","of","the","checkpoint","if","an","actual","checkpoint","is","found",".","If","no","checkpoint","is","found",",","return","None","."]
code: def check_model_path(
      config: ConfigType,
      is_checkpoint: bool = False,
      current_epoch: Optional[int] = None,
      current_step: Optional[int] = None,
  ) -> Optional[int]:
      """Method to check if the model path exists to load models
      or checkpoints.
  
      Args:
          config (ConfigType): the config object, contains info of the model
          is_checkpoint (bool): if True, the path is for a checkpoint
          current_epoch (Optional[int]): the current epoch.
              is is_checkpoint is True, and current_epoch is None,
              it will look for the last checkpoint and return it.
  
      Returns:
          path (Optional[str]): the path to the model. If is_checkpoint is
              True, and current_epoch is None, search for the last checkpoint
              and return it. If no checkpoint is found, return None.
          epoch (Optional[int]): the epoch of the checkpoint if an actual
              checkpoint is found. If no checkpoint is found, return None.
      """
      model_folder, model_name, path = ModelLoader.get_model_path(
          config,
          is_checkpoint,
          current_epoch,
      )
  
      # If i am looking for a checkpoint.
      if is_checkpoint and current_epoch is None:
          # If the checkpoint is specified by name use it
          checkpoint_name = ModelLoader.get_checkpoint_name(config)
          if checkpoint_name is not None:
              checkpoint = ModelLoader.look_for_checkpoint_by_name(
                  model_folder, checkpoint_name
              )
          else:
              checkpoint = ModelLoader.look_for_last_checkpoint(
                  model_folder, model_name
              )
          if checkpoint is not None:
              path = os.path.join(model_folder, checkpoint)
              # Get the epoch number from the checkpoint name
  
      if path is not None:
          if os.path.exists(path) is False:
              path = None
  
      if path is None:
          if is_checkpoint:
              checkpoint_name = ModelLoader.get_checkpoint_name(config)
              if checkpoint_name is not None:
                  print(
                      f"No checkpoint found at {model_folder} "
                      f"with name {config.checkpoint_name}"
                  )
              else:
                  print(
                      f"No previous checkpoint found at "
                      f"{model_folder} for {model_name}"
                  )
          else:
              print(
                  f"No previous model found at "
                  f"{model_folder} for model {model_name}"
              )
      else:
          if is_checkpoint:
              # the name is modelname_epoch_00000001_step_00000001.pt
              # or modelname_epoch_00000001.pt
              if "_step_" in path:
                  epoch = int(path.split("_epoch_")[-1].split("_")[0])
                  step = int(path.split("_step_")[-1].split(".")[0])
                  print(
                      f"Found checkpoint for epoch {epoch + 1},"
                      f" step {step + 1}..."
                  )
              else:
                  epoch = int(path.split("_epoch_")[-1].split(".")[0])
                  print(f"Found checkpoint for epoch {epoch + 1} ...")
          else:
              print(f"Found model at {path}")
      return path
  
file_path: nebuly/optimization/chatllama/chatllama/rlhf/model_loader.py
imports: import os
  import shutil
  from beartype.typing import Union, Optional, Tuple
  from chatllama.rlhf.config import Config, ConfigActor, ConfigCritic, ConfigReward
  from chatllama.rlhf.model_list import hf_models
label_desc: Use image node_id 11 for calling the ModelLoader obj's underlying member method code with example usage: obj.check_model_path(config, is_checkpoint, current_epoch, current_step) and returns: path