code: def find_latest_checkpoint(model_dir, model_type="bigdl"):
      import os
      import re
      import datetime
  
      ckpt_path = None
      latest_version = None
      optim_prefix = None
      optim_regex = None
      if model_type == "bigdl":
          optim_regex = ".*\.([0-9]+)$"
      elif model_type == "pytorch":
          optim_regex = "TorchModel[0-9a-z]*\.([0-9]+)$"
      elif model_type == "tf":
          optim_regex = "TFParkTraining\.([0-9]+)$"
      else:
          ValueError(
              "Only bigdl, pytorch and tf are supported for now."
          )
  
      file_list = get_file_list(model_dir, recursive=True)
      optim_dict = {}
      pattern_re = re.compile(
          "(.*)(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})(.*)optimMethod-"
          + optim_regex
      )
      for file_path in file_list:
          matched = pattern_re.match(file_path)
          if matched is not None:
              try:
                  # check if dir name is date time
                  timestamp = matched.group(2)
                  datetime.datetime.strptime(
                      timestamp, "%Y-%m-%d_%H-%M-%S"
                  )
                  if timestamp in optim_dict:
                      optim_dict[timestamp].append(
                          (
                              int(matched.group(4)),
                              os.path.dirname(file_path),
                              os.path.basename(file_path).split(".")[0],
                          )
                      )
                  else:
                      optim_dict[timestamp] = [
                          (
                              int(matched.group(4)),
                              os.path.dirname(file_path),
                              os.path.basename(file_path).split(".")[0],
                          )
                      ]
              except:
                  continue
      if optim_dict:
          latest_timestamp = max(optim_dict)
          latest_version, ckpt_path, optim_prefix = max(
              optim_dict[latest_timestamp],
              key=lambda version_path: version_path[0],
          )
  
      return ckpt_path, optim_prefix, latest_version
  
file_path: analytics-zoo/pyzoo/zoo/orca/learn/utils.py
imports: from zoo.common.utils import get_file_list
  from zoo.orca.data import SparkXShards
  from zoo.orca.data.utils import get_size
  from zoo.util.utils import convert_row_to_numpy
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: find_latest_checkpoint(model_dir, model_type) and returns: ckpt_path,  optim_prefix,  latest_version