code: def get_snapshot_dir_from_cache_dir(cache_dir):
      # given a huggingface format cache dir, get the latest snapshot from it
      # TODO: probably add rolling strategy if any model fails
      invalidInputError(
          os.path.exists(cache_dir),
          errMsg=">> Local model does not exist.",
      )
      snapshots_dir = os.path.join(cache_dir, "snapshots")
      snapshots = os.listdir(snapshots_dir)
      invalidInputError(
          len(snapshots) != 0,
          errMsg=f">> No models available, please download the model first",
      )
      current_latest_snapshot = snapshots[0]
      current_latest_mtime = os.path.getmtime(
          os.path.join(snapshots_dir, current_latest_snapshot)
      )
      for snap in snapshots:
          dir = os.path.join(snapshots_dir, snap)
          if os.path.getmtime(dir) > current_latest_mtime:
              current_latest_mtime = os.path.getmtime(dir)
              current_latest_snapshot = snap
      return os.path.join(snapshots_dir, current_latest_snapshot)
  
imports: import os
  from bigdl.nano.utils.common import invalidInputError
label_desc: Use image node_id 2 for calling a global function with example usage: get_snapshot_dir_from_cache_dir(cache_dir) and returns: os