code: def has_index_file(
      checkpoint_path: str,
  ) -> Tuple[bool, Optional[Path]]:
      """
      Check whether the checkpoint has an index file.
  
      Args:
          checkpoint_path (str): path to the checkpoint.
  
      Returns:
          Tuple[bool, Optional[Path]]: a tuple of (has_index_file, index_file_path)
      """
      checkpoint_path = Path(checkpoint_path)
      if checkpoint_path.is_file():
          # check if it is .index.json
          reg = re.compile("(.*?).index((\..*)?).json")
          if reg.fullmatch(checkpoint_path.name) is not None:
              return True, checkpoint_path
          else:
              return False, None
      elif checkpoint_path.is_dir():
          # check if there is only one a file ending with .index.json in this directory
          index_files = list(checkpoint_path.glob("*.index.*json"))
  
          # if we found a .index.json file, make sure there is only one
          if len(index_files) > 0:
              assert (
                  len(index_files) == 1
              ), f"Expected to find one .index.json file in {checkpoint_path}, but found {len(index_files)}"
  
          if len(index_files) == 1:
              return True, index_files[0]
          else:
              return False, None
      else:
          raise RuntimeError(
              f"Invalid checkpoint path {checkpoint_path}. Expected a file or a directory."
          )
  
imports: import os
  import re
  from collections import abc
  from collections import defaultdict
  from itertools import chain
  from pathlib import Path
  from typing import Iterator, List, Mapping, Optional, OrderedDict, Tuple
  import torch
  import torch.nn
  from packaging.version import Version
  from torch.optim import Optimizer
  from torch.utils._pytree import tree_map
  from colossalai.tensor.d_tensor import is_customized_distributed_tensor, is_distributed_tensor, to_global, to_global_for_customized_distributed_tensor
label_desc: Use image node_id 23 for calling a global function with example usage: has_index_file(checkpoint_path) and returns: True,  checkpoint_path, False,  None, True,  index_files, False,  None