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 discard old checkpoints, keeping only the last
  n_ckp_to_keep
  
  Args:
      model_folder (str): the folder where the checkpoints are saved
      model_name (str): the name of the model
      n_ckp_to_keep (int): the number of checkpoints to keep
docstr_tok: ["Method","to","discard","old","checkpoints",",","keeping","only","the","last","n_ckp_to_keep","Args",":","model_folder","(","str",")",":","the","folder","where","the","checkpoints","are","saved","model_name","(","str",")",":","the","name","of","the","model","n_ckp_to_keep","(","int",")",":","the","number","of","checkpoints","to","keep"]
code: def delete_old_checkpoints(
      model_folder: str, model_name: str, n_ckp_to_keep: int = 5
  ):
      """Method to discard old checkpoints, keeping only the last
      n_ckp_to_keep
  
      Args:
          model_folder (str): the folder where the checkpoints are saved
          model_name (str): the name of the model
          n_ckp_to_keep (int): the number of checkpoints to keep
      """
  
      # remove .pt to model name
      model_name = model_name.split(".")[0]
      checkpoints = [
          f
          for f in os.listdir(model_folder)
          if f.startswith(model_name)
      ]
      if len(checkpoints) == 0:
          return
      else:
          checkpoints = sorted(checkpoints)
          # check if the number of checkpoint is greater than 5
          if len(checkpoints) > n_ckp_to_keep:
              for c in checkpoints[:-n_ckp_to_keep]:
                  checkpoint_path = os.path.join(model_folder, c)
                  os.remove(checkpoint_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 9 for calling the ModelLoader obj's underlying member method code with example usage: obj.delete_old_checkpoints(model_folder, model_name, n_ckp_to_keep) without return types