code: def _filter_checkpoint_files(
      filenames: List[str], sort_by_num: bool = True
  ) -> List[SingleCheckpoint]:
      """
      Given a list of potential file names, return the ones that match checkpoint pattern along with
      the checkpoint number of each file name.
      :param filenames: list of all filenames
      :param sort_by_num: whether to sort the output result by checkpoint number
      :return: list of (checkpoint-number, checkpoint-filename) tuples
      """
      parser = CheckpointFilenameParser()
      checkpoints = [
          ckp
          for ckp in [parser.parse(fn) for fn in filenames]
          if ckp is not None
      ]
      if sort_by_num:
          checkpoints.sort(key=lambda x: x.num)
      return checkpoints
  
imports: import os
  import re
  from typing import List, Union, Tuple
label_desc: Use image node_id 1 for calling a global function with example usage: _filter_checkpoint_files(filenames, sort_by_num) and returns: checkpoints