code: def last_n_checkpoints(paths, n, update_based, upper_bound=None):
      assert len(paths) == 1
      path = paths[0]
      if update_based:
          pt_regexp = re.compile(r"checkpoint_\d+_(\d+)\.pt")
      else:
          pt_regexp = re.compile(r"checkpoint(\d+)\.pt")
      files = PathManager.ls(path)
  
      entries = []
      for f in files:
          m = pt_regexp.fullmatch(f)
          if m is not None:
              sort_key = int(m.group(1))
              if upper_bound is None or sort_key <= upper_bound:
                  entries.append((sort_key, m.group(0)))
      if len(entries) < n:
          raise Exception(
              "Found {} checkpoint files but need at least {}",
              len(entries),
              n,
          )
      return [
          os.path.join(path, x[1])
          for x in sorted(entries, reverse=True)[:n]
      ]
  
file_path: fairseq/scripts/average_checkpoints.py
imports: import argparse
  import collections
  import os
  import re
  import torch
  from fairseq.file_io import PathManager
label_desc: Use image node_id 2 for calling a global function with example usage: last_n_checkpoints(paths, n, update_based, upper_bound) and returns: unknown