class_docstr: Create a checkpoint for a given model
  
  Argumemnts:
      - load_dir: directory where to load the checkpoint from (if exists)
      - check_name: Name of the checkpoint (without the .pt extension)
      - selection_stage: Stage that is used for selecting the best model
      - run_config: Config of the run. In resume mode, this gets discarded
      - resume: Resume a previous training - this creates optimizers
      - strict: If strict and checkpoint is empty then it raises a ValueError. Being in resume mode forces strict
class_docstr_tok: ["Create","a","checkpoint","for","a","given","model","Argumemnts",":","-","load_dir",":","directory","where","to","load","the","checkpoint","from","(","if","exists",")","-","check_name",":","Name","of","the","checkpoint","(","without","the",".pt","extension",")","-","selection_stage",":","Stage","that","is","used","for","selecting","the","best","model","-","run_config",":","Config","of","the","run",".","In","resume","mode",",","this","gets","discarded","-","resume",":","Resume","a","previous","training","-","this","creates","optimizers","-","strict",":","If","strict","and","checkpoint","is","empty","then","it","raises","a","ValueError",".","Being","in","resume","mode","forces","strict"]
docstr: [This function is responsible to save checkpoint under the current metrics and their associated DEFAULT_METRICS_FUNC]
  Arguments:
      model {[CheckpointInterface]} -- [Model]
      metrics_holder {[Dict]} -- [Need to contain stage, epoch, current_metrics]
docstr_tok: ["[","This","function","is","responsible","to","save","checkpoint","under","the","current","metrics","and","their","associated","DEFAULT_METRICS_FUNC","]","Arguments",":","model","{","[","CheckpointInterface","]","}","--","[","Model","]","metrics_holder","{","[","Dict","]","}","--","[","Need","to","contain","stage",",","epoch",",","current_metrics","]"]
code: def save_best_models_under_current_metrics(
      self,
      model: model_interface.CheckpointInterface,
      metrics_holder: dict,
      metric_func_dict: dict,
      **kwargs,
  ):
      """[This function is responsible to save checkpoint under the current metrics and their associated DEFAULT_METRICS_FUNC]
      Arguments:
          model {[CheckpointInterface]} -- [Model]
          metrics_holder {[Dict]} -- [Need to contain stage, epoch, current_metrics]
      """
      metrics = metrics_holder["current_metrics"]
      stage = metrics_holder["stage"]
      epoch = metrics_holder["epoch"]
  
      stats = self._checkpoint.stats
      state_dict = copy.deepcopy(model.state_dict())
  
      current_stat = {}
      current_stat["epoch"] = epoch
  
      models_to_save = self._checkpoint.models
      if stage not in stats:
          stats[stage] = []
  
      if stage == "train":
          models_to_save[Checkpoint._LATEST] = state_dict
      else:
          if len(stats[stage]) > 0:
              latest_stats = stats[stage][-1]
  
              msg = ""
              improved_metric = 0
  
              for metric_name, current_metric_value in metrics.items():
                  current_stat[metric_name] = current_metric_value
  
                  metric_func = self.find_func_from_metric_name(
                      metric_name, metric_func_dict
                  )
                  best_metric_from_stats = latest_stats.get(
                      "best_{}".format(metric_name),
                      current_metric_value,
                  )
                  best_value = metric_func(
                      best_metric_from_stats, current_metric_value
                  )
                  current_stat[
                      "best_{}".format(metric_name)
                  ] = best_value
  
                  # This new value seems to be better under metric_func
                  if (self._selection_stage == stage) and (
                      current_metric_value == best_value
                  ):  # Update the model weights
                      models_to_save[
                          "best_{}".format(metric_name)
                      ] = state_dict
  
                      msg += "{}: {} -> {}, ".format(
                          metric_name,
                          best_metric_from_stats,
                          best_value,
                      )
                      improved_metric += 1
  
              if improved_metric > 0:
                  colored_print(COLORS.VAL_COLOR, msg[:-2])
          else:
              # stats[stage] is empty.
              for metric_name, metric_value in metrics.items():
                  current_stat[metric_name] = metric_value
                  current_stat[
                      "best_{}".format(metric_name)
                  ] = metric_value
                  models_to_save[
                      "best_{}".format(metric_name)
                  ] = state_dict
  
      kwargs["model_props"] = {
          "num_epochs": model.num_epochs,  # type: ignore
          "num_batches": model.num_batches,  # type: ignore
          "num_samples": model.num_samples,  # type: ignore
      }
  
      self._checkpoint.stats[stage].append(current_stat)
      self._checkpoint.save_objects(
          models_to_save,
          stage,
          current_stat,
          model.optimizer,
          model.schedulers,
          **kwargs,
      )
  
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  import os
  import torch
  import logging
  import copy
  import glob
  import shutil
  from omegaconf import OmegaConf
  from omegaconf import DictConfig
  from torch_points3d.models import model_interface
  from torch_points3d.utils.colors import COLORS, colored_print
  from torch_points3d.core.schedulers.lr_schedulers import instantiate_scheduler
  from torch_points3d.core.schedulers.bn_schedulers import instantiate_bn_scheduler
  from torch_points3d.models.model_factory import instantiate_model
label_desc: Use image node_id 15 for calling the ModelCheckpoint obj's underlying member method code with example usage: obj.save_best_models_under_current_metrics(model, metrics_holder, metric_func_dict) without return types