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 get the path to the right model file. Used when saving
  the model.
  The hierarchy of the model folder is:
  -- model_folder: here store the models trained, for each type of model
                  there is a dedicated folder
      -- actor
      -- critic
      -- reward
      -- actor_rl
      -- checkpoints: here store the checkpoints during training, for
                      each type of model there is a dedicated folder
          -- actor
          -- critic
          -- reward
          -- actor_rl
  
  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, used to create
          the checkpoint name. If is_checkpoint is True, and
          current_epoch is None, return just the folder and the simple
          model name for the possible checkpoint.
      current_step (Optional[int]): the current step, used to create
          the checkpoint name.
      max_epochs (Optional[int]): the maximum number of epochs, used to
          create the checkpoint name.
      max_steps (Optional[int]): the maximum number of steps, used to
          create the checkpoint name.
  
  Returns:
      model_folder (str): the folder where the model is saved
      model_name (str): the name of the model
      path (Optional[str]): the path to the model. If is_checkpoint is
          True, and current_epoch is None, return None
docstr_tok: ["Method","to","get","the","path","to","the","right","model","file",".","Used","when","saving","the","model",".","The","hierarchy","of","the","model","folder","is",":","--","model_folder",":","here","store","the","models","trained",",","for","each","type","of","model","there","is","a","dedicated","folder","--","actor","--","critic","--","reward","--","actor_rl","--","checkpoints",":","here","store","the","checkpoints","during","training",",","for","each","type","of","model","there","is","a","dedicated","folder","--","actor","--","critic","--","reward","--","actor_rl","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",",","used","to","create","the","checkpoint","name",".","If","is_checkpoint","is","True",",","and","current_epoch","is","None",",","return","just","the","folder","and","the","simple","model","name","for","the","possible","checkpoint",".","current_step","(","Optional","[","int","]",")",":","the","current","step",",","used","to","create","the","checkpoint","name",".","max_epochs","(","Optional","[","int","]",")",":","the","maximum","number","of","epochs",",","used","to","create","the","checkpoint","name",".","max_steps","(","Optional","[","int","]",")",":","the","maximum","number","of","steps",",","used","to","create","the","checkpoint","name",".","Returns",":","model_folder","(","str",")",":","the","folder","where","the","model","is","saved","model_name","(","str",")",":","the","name","of","the","model","path","(","Optional","[","str","]",")",":","the","path","to","the","model",".","If","is_checkpoint","is","True",",","and","current_epoch","is","None",",","return","None"]
code: def get_model_path(
      config: ConfigType,
      is_checkpoint: bool = False,
      current_epoch: Optional[int] = None,
      current_step: Optional[int] = None,
      max_epochs: int = 1_000_000_000,
      max_steps: int = 1_000_000_000,
  ) -> Tuple[str, str, Optional[str]]:
      """Method to get the path to the right model file. Used when saving
      the model.
      The hierarchy of the model folder is:
      -- model_folder: here store the models trained, for each type of model
                      there is a dedicated folder
          -- actor
          -- critic
          -- reward
          -- actor_rl
          -- checkpoints: here store the checkpoints during training, for
                          each type of model there is a dedicated folder
              -- actor
              -- critic
              -- reward
              -- actor_rl
  
      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, used to create
              the checkpoint name. If is_checkpoint is True, and
              current_epoch is None, return just the folder and the simple
              model name for the possible checkpoint.
          current_step (Optional[int]): the current step, used to create
              the checkpoint name.
          max_epochs (Optional[int]): the maximum number of epochs, used to
              create the checkpoint name.
          max_steps (Optional[int]): the maximum number of steps, used to
              create the checkpoint name.
  
      Returns:
          model_folder (str): the folder where the model is saved
          model_name (str): the name of the model
          path (Optional[str]): the path to the model. If is_checkpoint is
              True, and current_epoch is None, return None
      """
      model_folder = ModelLoader.get_base_model_folder_from_config(
          config
      )
  
      # Add the checkpoint path if necessary
      if is_checkpoint:
          model_folder = os.path.join(model_folder, "checkpoints")
  
      # Create the folder for the model type
      #  (Actor, Critic, Reward, Actor_RL)
      model_type = ModelLoader.get_model_type_from_config(config)
      model_folder = os.path.join(model_folder, model_type)
  
      # Make the path if not exists
      if os.path.exists(model_folder) is False:
          os.makedirs(model_folder, exist_ok=True)
          print(
              f"Model folder does not exist. Creating it: {model_folder}"
          )
  
      # Create the model name
      model_name = ModelLoader.get_model_name_from_config(config)
  
      # If is a checkpoint and current epoch are available
      # extend the model name with the epoch, if none epoch is provided
      # just return the simple model name
      if is_checkpoint and current_epoch is not None:
          # number of characters to store the checkpoints
          n_char = max(len(str(max_epochs)), len(str(max_steps)))
          # create the string epoch such that it is always the same length
          # equalt to n_char (i.e. 00000001) necessary for sorting
          string_epoch = str(current_epoch)
          string_epoch = (
              "0" * (n_char - len(string_epoch)) + string_epoch
          )
          string_epoch = f"_epoch_{string_epoch}"
          if current_step is not None:
              string_step = str(current_step)
              string_step = (
                  "0" * (n_char - len(string_step)) + string_step
              )
              string_step = f"_step_{string_step}"
              model_name = f"{model_name}{string_epoch}{string_step}.pt"
          else:
              model_name = f"{model_name}{string_epoch}.pt"
      else:
          model_name = f"{model_name}.pt"
  
      # if the epoch is not provided, and it is a checkpoint
      # is impossible to know the path to the file.
      # but we can know the model folder and the model name
      if is_checkpoint and current_epoch is None:
          path = None
      else:
          path = os.path.join(model_folder, model_name)
      return model_folder, model_name, 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 10 for calling the ModelLoader obj's underlying member method code with example usage: obj.get_model_path(config, is_checkpoint, current_epoch, current_step, max_epochs, max_steps) and returns: model_folder,  model_name,  path